Moving Turtlebot to a goal without a map
Hi there! We're two newbies. We installed Ros Electric on a pc acer aspire 5740g running Ubuntu Lucid 10.04. Our task is to move Turtlebot giving vocal commands. We're doing it writing publishers and subscribers in c++. We have a node which does the speech recognition, it publishes on a topic the identified word. When for example it publishes "advance" and "one", the turtlebot should move forward for one meter and then stop, waiting for new commands. We have to make the turtlebot do this without a map, only using odometry data. Our problem is that turtlebot doesn't stop after it has reached the goal.
To give you an idea of what we're doing, here's part of the code:
geometry_msgs::PoseWithCovarianceStamped msg;
double pos_x,pos_y,pos_z,ori_x,ori_y,ori_z,ori_w;
void odomcallback(const geometry_msgs::PoseWithCovarianceStamped msg_turtlebot)
{
msg=msg_turtlebot;
pos_x=msg.pose.pose.position.x;
pos_y=msg.pose.pose.position.y;
pos_z=msg.pose.pose.position.z;
ori_x=msg.pose.pose.orientation.x;
ori_y=msg.pose.pose.orientation.y;
ori_z=msg.pose.pose.orientation.z;
ori_w=msg.pose.pose.orientation.w; }
int main(int argc, char **argv) {
ros::init(argc, argv, "nodo_che_movimenta");
ros::NodeHandle node;
ros::Subscriber sub_odom = node.subscribe("odom", 1000, odomcallback);
ros::Publisher vel_pub = node.advertise<geometry_msgs::twist>("cmd_vel", 10);
[...]
geometry_msgs::Twist vel;
ros::Rate rate(10.0);
const double a=pos_x+1;
while (node.ok()) {
ros::spinOnce();
sostituto_quantita=quantita;
bool select=true;
if (attiva) {
printf("niente\n")
[...] if(complesso==103 ) {
printf("complesso_on\n");
printf("Inserisci quantità \n");
if(sostituto_quantita==1 && select==true) {
printf("1 meter\n");
if(pos_x<a) {vel.linear.x="0.3;" vel.linear.y="vel.linear.z=0.0;" vel.angular.x="vel.angular.y=vel.angular.z=0.0;" }="" <br="">
else
{
select=false;
}
} [...]
}
vel_pub.publish(vel);
rate.sleep();
}
ros::spin();
return 0;
}
I think you forgot to stop publishing or to put vel.linear.x = 0.0 after you reached the goal.
We tried to put vel.linear.x=0 instead of the bool variable, but it didn't work. We suppose that the real problem is the condition we put in the if instruction: if(pos_x<a). It is always true since both pos_x and a continously update their values.
An easy way to find it out is to print 'a' value.
I am not sure weither it would work or not (I am using python and not C++ for ROS programming), but you could try to remove the ros::spin() and to use ros::spinOnce() at the end of your while loop.
We printed the values both of the odometry and of the target using the printf function and we found out that they don't change at all! Is this a loop? How to find out? We tried also to remove ros::spin() and use ros::spinOnce(), but it didn't serve. It still doesn't want to perform the task.l.
I just answered on the google group