Move a certain distance, turn, then move (Odometry topic)
Currently, I am able to have my robot move forward for a certain distance, turn right by a certain degree, then move forward again. However, it is extremely inaccurate as highlighted in ahendrix's answer here "http://answers.ros.org/question/204973/robot-pose-slightly-off-when-publishing-to-cmd_vel/".
I want to re-make this program by using the odometry topic. This is the current code that I have, I am currently working on the TurtleBot 2.
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <math.h>
int main(int argc, char **argv)
{
const double PI = 3.14159265358979323846;
ros::init(argc, argv, "move_pub");
ros::NodeHandle n;
ros::Publisher movement_pub = n.advertise<geometry_msgs::Twist>("mobile_base/commands/velocity",1); //for sensors the value after , should be higher to get a more accurate result (queued)
ros::Rate rate(10); //the larger the value, the "smoother" , try value of 1 to see "jerk" movement
//move forward
ros::Time start = ros::Time::now();
while(ros::Time::now() - start < ros::Duration(5.0))
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = 0.1; //speed value m/s
move.angular.z = 0;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
//turn right
ros::Time start_turn = ros::Time::now();
while(ros::Time::now() - start_turn < ros::Duration(4.0))
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = 0; //speed value m/s
move.angular.z = -2.25;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
//move forward again
ros::Time start2 = ros::Time::now();
while(ros::Time::now() - start2 < ros::Duration(5.0))
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = 0.1; //speed value m/s
move.angular.z = 0;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
return 0;
}
How should I go about replicating this program using the odometry topic?
I am a beginner at ROS, all of your help will be greatly appreciated. I am currently on my school holidays and I am feeling great joy learning something new :)
http://answers.ros.org/question/20513...
I was able to find a python script in a library book that achieves this. However, I dont know how to replicate as a ROS C++ node, I posted it as a separate question.