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

Revision history [back]

click to hide/show revision 1
initial version

I solved it using a dummy way of pulling the CPU by using a for loop

  for (int i=0 ;i <99999; i++)
        {
            std::cout << "turn left" << std::endl ;
            move_robot_obj_1.turn(0.780);
        }
        loop_rate.sleep();

        for (int i=0 ;i <99999; i++)
        {
            std::cout << "move forward" << std::endl ;
              move_robot_obj_1.move(1.0);
        }
        loop_rate.sleep();
        for (int i=0 ;i <99999; i++)
        {
            std::cout << "turn right" << std::endl ;
            move_robot_obj_1.turn(-1.2);
        }
        loop_rate.sleep();

        for (int i=0 ;i <99999; i++)
        {
            std::cout << "move forward" << std::endl ;
            move_robot_obj_1.move(1.0);
        }

in the turn you should specify the angle in radian not degree and send it to function that define a geometry_msgs::Twist msg and fill it with the required information and publish it. Also while turning, I send a velocity in the forward direction, so the robot will move in a wave form as the following:

  void turn(double val)
  {
      geometry_msgs::Twist msg;
     msg.linear.x = 1.0;
     msg.linear.y =  0.0 ;
     msg.linear.z =  0.0;
     msg.angular.x = 0.0 ;
     msg.angular.y = 0.0 ;
     msg.angular.z = val ;
     vel_pub.publish(msg);
 }

The robot moved in a wave form. I know that it is not the best way to do it. So, if you have another way please let me know.