Ask Your Question
0

Turtlebot not moving

asked 2012-12-04 23:56:34 -0500

Tubot gravatar image

Hey guys, I'm still a beginner in ROS and I wrote a simple program in C++ that makes the turtlebot move in a square trajectory. I have the electric version of ROS installed. I used rosmake to compile the package and rosrun to run the executable file. The problem is, the turtlebot is not moving or anything. I tried to use a printf to see if the code was working and it did. I also tried to use the teleop package and it worked too. So I don't know what else I can do to make it work. Some help with that would be much appreciated :] Here is the code I used:

int main(int argc, char** argv) { // ROS initialisation

ros::init(argc, argv, "turtle_motion");

ros::NodeHandle n;

ros::Publisher vel_pub = n.advertise<geometry_msgs::twist>("/turtlebot_node/cmd_vel", 1);

ros::Rate loop_rate(5);

unsigned int cpt=0;

while(ros::ok()) {

geometry_msgs::Twist cmd_vel;

//Trajectoire: Carré
//Premiere Phase
if (cpt>=0 && cpt<10){
cmd_vel.angular.z = 0;          // rad/s
cmd_vel.linear.x = 0.03;             // m/s
}

//Deuxieme Phase
if (cpt>=10 && cpt<20){
cmd_vel.angular.z = 0.786;          // rad/s
cmd_vel.linear.x = 0;             // m/s
}

//Troisieme Phase
if (cpt>=20 && cpt<30){
cmd_vel.angular.z = 0;          // rad/s
cmd_vel.linear.x = 0.03;             // m/s
}

//Quatrieme Phase
if (cpt>=30 && cpt<40){
cmd_vel.angular.z = 0.786;          // rad/s
cmd_vel.linear.x = 0;             // m/s
}

//Cinquieme Phase
if (cpt>=40 && cpt<50){
cmd_vel.angular.z = 0;          // rad/s
cmd_vel.linear.x = 0.03;             // m/s
}

//Sixieme Phase
if (cpt>=50 && cpt<60){
cmd_vel.angular.z = 0.786;          // rad/s
cmd_vel.linear.x = 0;             // m/s
}

//Septieme Phase
if (cpt>=60 && cpt<70){
cmd_vel.angular.z = 0;          // rad/s
cmd_vel.linear.x = 0.03;             // m/s
}

//Huitieme Phase
if (cpt>=70 && cpt<80){
cmd_vel.angular.z = 0.786;          // rad/s
cmd_vel.linear.x = 0;             // m/s
}
if (cpt>=80) cpt=0;

cpt++;
vel_pub.publish(cmd_vel);    
ros::spinOnce();
loop_rate.sleep();

}

return(0); }

edit retag flag offensive close merge delete

Comments

1

Is this really your code? I doubt that it compiles. The type you specify in the advertise call (geometry_msgs::twist) does not exist. It must be geometry_msgs::Twist. Please make sure you read the support guidelines before posting. Always copy-paste code and format it.

Lorenz gravatar image Lorenz  ( 2012-12-05 00:06:15 -0500 )edit

The first step for debugging your issue is to call rostopic echo /turtlebot_node/cmd_vel and check if your node publishes correct data. If the data looks good, check if the topic is connected: rostopic info /turtlebot_node/cmd_vel. Please edit your question and provide the output.

Lorenz gravatar image Lorenz  ( 2012-12-05 01:09:29 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2013-03-04 05:14:09 -0500

Claudio gravatar image
ros::Publisher vel_pub = n.advertise<geometry_msgs::twist>("/turtlebot_node/cmd_vel", 1);

Check that the turtle is really named turtlebot_node and that its command topic is cmd_vel by doing a

$ rosnode list

this command will show you the list of active nodes. You should have something like

/rosout
/turtle1

then do

$ rostopic list

this should give you something like

/rosout
/turtle1/cmd_vel

if you then do a

$ rostopic info /turtle1/cmd_vel

you should get something like

Type: geometry_msgs/Twist

Publishers: None

Subscribers: 
 * /turtle1

Also check that the turtle doesn't use turtlesim/Velocity messages (as was the case with Fuerte at least) instead of geometry_msgs/Twist.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-12-04 23:56:34 -0500

Seen: 2,315 times

Last updated: Mar 04 '13