0
$\begingroup$

Rosanswers logo

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); }


Originally posted by Tubot on ROS Answers with karma: 1 on 2012-12-05

Post score: 0


Original comments

Comment by Lorenz on 2012-12-05:
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.

Comment by Lorenz on 2012-12-05:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Claudio with karma: 859 on 2013-03-04

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.