ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Tubot's profile - activity

2013-01-29 14:21:05 -0500 received badge  Famous Question (source)
2012-12-05 23:14:10 -0500 received badge  Notable Question (source)
2012-12-05 02:35:07 -0500 received badge  Popular Question (source)
2012-12-04 23:56:34 -0500 asked a question Turtlebot not moving

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