|
@@ -6,12 +6,13 @@
|
|
|
*/
|
|
|
#include "drive_square.h"
|
|
|
|
|
|
-Drive_Square::Drive_Square(){
|
|
|
+Drive_Square::Drive_Square()
|
|
|
+{
|
|
|
ros::param::param<std::string>("~odom_frame", odom_frame, "odom");
|
|
|
ros::param::param<std::string>("~base_frame", base_frame, "base_link");
|
|
|
ros::param::param<float>("~angular_speed", angular_speed, 0.2);
|
|
|
ros::param::param<float>("~linear_speed", linear_speed, 0.2);
|
|
|
- ros::param::param<float>("~square_side_length", square_side_length, 0.2);
|
|
|
+ ros::param::param<float>("~square_side_length", square_side_length, 0.4);
|
|
|
_cmd_vel_pub = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 1);
|
|
|
go();
|
|
|
}
|
|
@@ -20,13 +21,15 @@ Drive_Square::~Drive_Square(){
|
|
|
|
|
|
}
|
|
|
|
|
|
-void Drive_Square::publish_twist_cmd(float x, float z){
|
|
|
+void Drive_Square::publish_twist_cmd(float x, float z)
|
|
|
+{
|
|
|
twist.linear.x = x;
|
|
|
twist.angular.z = z;
|
|
|
_cmd_vel_pub.publish(twist);
|
|
|
}
|
|
|
|
|
|
-void Drive_Square::go_forward(const float square_side_length){
|
|
|
+void Drive_Square::go_forward(const float square_side_length)
|
|
|
+{
|
|
|
tf::TransformListener tf_Listener;
|
|
|
tf::StampedTransform tf_Transform;
|
|
|
float dist = 0.0; //每次前进移动的距离
|
|
@@ -52,7 +55,7 @@ void Drive_Square::go_forward(const float square_side_length){
|
|
|
publish_twist_cmd(linear_speed, 0);
|
|
|
ros::Duration(0.10).sleep(); //100 ms
|
|
|
|
|
|
- tf_Listener.lookupTransform(odom_frame, base_frame, ros::Time(0),tf_Transform);
|
|
|
+ tf_Listener.lookupTransform(odom_frame, base_frame, ros::Time(0), tf_Transform);
|
|
|
float x = tf_Transform.getOrigin().x();
|
|
|
float y = tf_Transform.getOrigin().y();
|
|
|
dist = sqrt(pow((x - x_start), 2) + pow((y - y_start), 2));
|
|
@@ -61,7 +64,8 @@ void Drive_Square::go_forward(const float square_side_length){
|
|
|
ROS_INFO("Go forward finish !!!");
|
|
|
}
|
|
|
|
|
|
-void Drive_Square::go_circle(){
|
|
|
+void Drive_Square::go_circle()
|
|
|
+{
|
|
|
tf::TransformListener tf_Listener;
|
|
|
tf::StampedTransform tf_Transform;
|
|
|
float check_angle = M_PI / 2.0;
|
|
@@ -83,7 +87,7 @@ void Drive_Square::go_circle(){
|
|
|
while((fabs(turn_angle) < check_angle)&&(ros::ok()))
|
|
|
{
|
|
|
publish_twist_cmd(0, angular_speed); //原地转弯,不需要linear_x,y的控制
|
|
|
- ros::Duration(0.10).sleep(); //100 ms
|
|
|
+ ros::Duration(0.05).sleep(); //50 ms
|
|
|
|
|
|
try
|
|
|
{
|
|
@@ -106,7 +110,8 @@ void Drive_Square::go_circle(){
|
|
|
ros::Duration(0.1).sleep(); //100 ms
|
|
|
}
|
|
|
|
|
|
-void Drive_Square::go(){
|
|
|
+void Drive_Square::go()
|
|
|
+{
|
|
|
for (size_t i = 0; i < 4; i++)
|
|
|
{
|
|
|
Drive_Square::go_forward(square_side_length);
|
|
@@ -124,4 +129,4 @@ int main(int argc, char **argv)
|
|
|
|
|
|
//使ROS中回调函数生效
|
|
|
ros::spin();
|
|
|
-}
|
|
|
+}
|