make robot move in square using base_link?

asked 2020-06-18 21:17:52 -0600

slick32214 gravatar image

Hello. Below here I have the code from

typedef actionlib::SimpleActionClient<move_base_msgs::movebaseaction> MoveBaseClient;

int main(int argc, char** argv){ ros::init(argc, argv, "simple_navigation_goals");

//tell the action client that we want to spin a thread by default
MoveBaseClient ac("move_base", true);

//wait for the action server to come up
ROS_INFO("Waiting for the move_base action server to come up"); }

move_base_msgs::MoveBaseGoal goal;

//we'll send a goal to the robot to move 1 meter forward
goal.target_pose.header.frame_id = "base_link";
goal.target_pose.header.stamp = ros::Time::now();

goal.target_pose.pose.position.x = 1.0; goal.target_pose.pose.orientation.w = 1.0;

ROS_INFO("Sending goal"); ac.sendGoal(goal);


if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
ROS_INFO("Hooray, the base moved 1 meter forward");
ROS_INFO("The base failed to move forward 1 meter for some reason");

return 0; }

This code is just to make the robot move forward 1m but how do I make it move in a 2m by 2m square? I wanted to use this code as an outline for achieving this goal but I don't understand base_link. I wanted to make it go in a ccw square starting from the bottom left and ending facing the same way it started. I try to use goal.target_pose.pose.orientation.y but it just makes the robot spin in a circle. I tried to use it like this...

goal.target_pose.pose.position.x = 2;
goal.target_pose.pose.orientation.w = 1.0; goal.target_pose.pose.position.y = 2;
goal.target_pose.pose.orientation.w = 1.0;
goal.target_pose.pose.position.x = -2;
goal.target_pose.pose.orientation.w = 1.0; goal.target_pose.pose.position.y = -2;
goal.target_pose.pose.orientation.w = -3.14;

but it didn't work. Help please!

edit retag flag offensive close merge delete


To make the question clear, did you send the action before change to the new values?

And you are using the orientation wrong, the orientation in the pose messages are declared as quaternions and not in Euler angles, you need to convert euler<-->quaternion before changing the pose message. Maybe this question ( ) helps you.

Teo Cardoso gravatar image Teo Cardoso  ( 2020-06-19 14:37:32 -0600 )edit