Moving of iRobot Roomba by C++
Dear ALL,
I am a college student and very new in this forum, ROS and C++. I want to move Roomba on x-axis for 2-meter, y-axis 1 meter and then it stops and come back to its initial condition.
I have made a small code in which Roomba is rotating on z direction but now I want to put some conditions to make it able to move on X and Y axis. Please modify this code as per I need. I will be really thankful to you.
#include <iostream>
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "nav_msgs/Odometry.h"
void odomcallback(const nav_msgs::Odometry::ConstPtr& odom)
{
ROS_INFO("I receive Odom: [%f,%f]", odom->pose.pose.position.x, odom->pose.pose.position.y);
}
int main (int argc, char** argv)
{
ros::init(argc, argv, "controller");
ros::NodeHandle n;
ros::Publisher create_pub = n.advertise<geometry_msgs::Twist>("cmd_vel_ex1", 1);
ros::Subscriber sub_odom = n.subscribe("odom_ex1", 1000, odomcallback);
while (ros::ok())
{
geometry_msgs::Twist roomba_vel;
roomba_vel.linear.x = 0;
roomba_vel.linear.y = 0;
roomba_vel.angular.z = 0.1;
create_pub.publish(roomba_vel);
ros::spinOnce();
}
return 0;
}