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

Tomm's profile - activity

2020-05-17 15:38:19 -0500 received badge  Nice Question (source)
2018-07-10 10:42:19 -0500 received badge  Famous Question (source)
2017-07-11 22:28:19 -0500 received badge  Notable Question (source)
2017-06-27 02:45:00 -0500 marked best answer how to get yaw from quaternion values?

Hello everyone,

I am new to ROS and this community. I am working with pioneer 3dx robot. My aim is to drive it in a square shape path and return back to its initial position. I am able to get quaternion values [x,y,z,w] from my robot. But for the purpose of turning the robot 90 degree I think I need rotation about z axis [yaw]. I have written the following code:

#include "ros/ros.h"

#include "nav_msgs/Odometry.h" 
#include <ros/console.h>
#include "geometry_msgs/Pose.h"
#include <tf/transform_datatypes.h>

double quatx;
double quaty;
double quatz;
double quatw;


void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg);


int main(int argc, char **argv)
{
    ros::init(argc, argv, "Test_FK"); // connect to roscore
    ros::NodeHandle n;                                     // node object
    ros::Subscriber ComPose_sub = n.subscribe("/RosAria/pose", 1000, ComPoseCallback);
    ros::spin();
}


void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg)            
{
    ROS_INFO("Seq: [%d]", msg->header.seq);
    ROS_INFO("Position-> x: [%f], y: [%f], z: [%f]", msg->pose.pose.position.x,msg->pose.pose.position.y, msg->pose.pose.position.z);
    ROS_INFO("Orientation-> x: [%f], y: [%f], z: [%f], w: [%f]", msg->pose.pose.orientation.x, msg->pose.pose.orientation.y, msg->pose.pose.orientation.z, msg->pose.pose.orientation.w);

   float linearposx=msg->pose.pose.position.x;
   float linearposy=msg->pose.pose.position.y;
   double quatx= msg->pose.pose.orientation.x;
   double quaty= msg->pose.pose.orientation.y;
   double quatz= msg->pose.pose.orientation.z;
   double quatw= msg->pose.pose.orientation.w;

    tf::Quaternion q(quatx, quaty, quatz, quatw);
    tf::Matrix3x3 m(q);
    double roll, pitch, yaw;
    m.getRPY(roll, pitch, yaw);

    ROS_INFO("Roll: [%f],Pitch: [%f],Yaw: [%f]",roll,pitch,yaw);
    return ;
}

I code compiles and do return some values. I was just spinning the robot in anti clockwise direction. Here are the values:

Position-> x: [0.000000], y: [-0.001000], z: [0.000000] Orientation-> x: [0.000000], y: [0.000000], z: [-0.054026], w: [0.998540] Roll: [0.000000],Pitch: [0.000000],Yaw: [-0.10810]

Position-> x: [0.000000], y: [-0.001000], z: [0.000000] Orientation-> x: [0.000000], y: [0.000000], z: [-0.055554], w: [0.998456] Roll: [0.000000],Pitch: [0.000000],Yaw: [-0.111165]

Position-> x: [0.000000], y: [-0.001000], z: [0.000000] Orientation-> x: [0.000000], y: [0.000000], z: [-0.055554], w: [0.998456] Roll: [0.000000],Pitch: [0.000000],Yaw: [-0.111165]

I don't understand whether i am getting the correct values or not. To my understanding Yaw is in radians and must increase with time [spinning at one posiiton].

2017-06-27 02:30:35 -0500 received badge  Famous Question (source)
2017-05-23 02:13:47 -0500 received badge  Famous Question (source)
2016-11-03 13:33:32 -0500 received badge  Famous Question (source)
2016-07-19 06:18:43 -0500 received badge  Notable Question (source)
2016-07-18 04:58:49 -0500 received badge  Famous Question (source)
2016-07-09 09:35:35 -0500 received badge  Notable Question (source)
2016-07-08 18:01:22 -0500 received badge  Popular Question (source)
2016-07-08 14:48:06 -0500 commented answer How to publish and subscribe to a boolean message?

I have done the changes you suggested and got errors. I have edited the post and copied my errors there. Please have a look. Please note that I am using Arduino IDE for compiling my sketches. Thanks.

2016-07-08 13:49:36 -0500 asked a question How to publish and subscribe to a boolean message?

Hello everyone, I am moving my robot(pioneer 3dx) from say point A to point B. When my robot reaches point B, I want to publish a boolean message to a topic "PosReached". Then I want to my robotic arm connected to arduino (rosserial_arduino) to subscribe to that message and start working on its task. Here is how I write my publisher:

ros::Publisher BasePos1 = n.advertise<std_msgs::Bool>("PosReached",1000);
std_msgs::Bool Reached;

//some code here

if(linearposx=0.1)
      {
      velocity.linear.x= 0;
      Reached.data = true;
      Velocity_pub.publish(velocity);
      BasePos1.publish(Reached);
      break;
      }

Above code compiles successfully. I just wonder whether it is the right way to do it?

Coming to subscriber here is what I wrote on my Arduino IDE:

void positionreached(const std_msgs::Bool& Reached)
{
Don't know what to write here.
}

ros::Subscriber<std_msgs::Bool> sub("PosReached", &positionreached);

What should I write in the callback function? I don't know how to receive boolean message and the use it in my main loop,to let robotic arm know when to start working on its task.

Can you guys help me with syntax or example codes?

Edit: I did the following changes as suggested:

std_msgs::Bool reached=false;
void positionreached(const std_msgs::Bool::ConstPtr& Reached)
{
  reached=Reached->data;
}

ros::Subscriber<std_msgs::Bool> sub("PosReached", &positionreached);

I get the following errors:

conversion from ‘int’ to non-scalar type ‘std_msgs::Bool’ requested
 #define false 0x0

sketch_jul07a.ino:8:24: note: in expansion of macro ‘false’
sketch_jul07a.ino:10:28: error: ‘ConstPtr’ in ‘class std_msgs::Bool’ does not name a type
sketch_jul07a.ino:10:54: error: ISO C++ forbids declaration of ‘Reached’ with no type [-fpermissive]
sketch_jul07a.ino: In function ‘void positionreached(const int&)’:
sketch_jul07a.ino:12:18: error: base operand of ‘->’ is not a pointer
sketch_jul07a.ino: At global scope:

error: invalid conversion from ‘void (*)(const int&)’ to ‘ros::Subscriber<std_msgs::Bool>::CallbackT {aka void (*)(const std_msgs::Bool&)}’ [-fpermissive]
2016-07-08 00:24:49 -0500 received badge  Famous Question (source)
2016-07-08 00:23:03 -0500 commented answer Problem with publihing velocity,Pioneer 3dx doesnt stop.

Thanks man. Code works !!

2016-07-07 12:56:17 -0500 received badge  Popular Question (source)
2016-07-06 14:52:26 -0500 asked a question Problem with publihing velocity,Pioneer 3dx doesnt stop.

Hi everyone,

I have been trying to move my pioneer from point A to B and return back to point A. I have written a code which starts publishing velocity when the position (x,y,z) is zero. I want it to move to a distance say 0.2m in x direction and stop and then turn and come back to initial position. But the problem is after publishing first velocity command it does not publishes second command i.e. command to stop.

if (linearposx==0)
   {
     Velocity_pub.publish(velocity);
   }
    if(linearposx<=-0.1)
   {
      Velocity_pub.publish(Stop);
   }

Here is my complete code:

#include "ros/ros.h"
#include "nav_msgs/Odometry.h" 
#include <ros/console.h>
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/Twist.h"
#include <tf/transform_datatypes.h>





double quatx;
double quaty;
double quatz;
double quatw;
double linearposx;
double linearposy;



class PioneerData
{
 public: 
 void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg);
};



int main(int argc, char **argv)
{
    PioneerData pioneer_Data;
    ros::init(argc, argv, "Test_FK"); 
    ros::NodeHandle n;                 
    ros::Publisher Velocity_pub = n.advertise<geometry_msgs::Twist>("/RosAria/cmd_vel",1000);
    ros::Subscriber ComPose_sub = n.subscribe("/RosAria/pose", 1000, &PioneerData::ComPoseCallback, &pioneer_Data);


    geometry_msgs::Twist velocity;
    velocity.linear.x =0.02;
    velocity.linear.y =0;
    velocity.linear.z =0;
    velocity.angular.x =0;
    velocity.angular.y =0;
    velocity.angular.z =0;

    geometry_msgs::Twist Stop;
    Stop.linear.x =0;
    Stop.linear.y =0;
    Stop.linear.z =0;
    Stop.angular.x =0;
    Stop.angular.y =0;
    Stop.angular.z =0;




   //ros::Rate loop_rate(10);
  //ros::Rate rate (1);

  while (ros::ok())
   {
    if(Velocity_pub.getNumSubscribers()>0)
    {
    if (linearposx==0)
    {

    Velocity_pub.publish(velocity);

    }
    if(linearposx>=0.1)
    {
      Velocity_pub.publish(Stop);
    }
    ros::spin();

    //sleep(100);
   //break;
    }
   }
  std::cout<<"xPosition"<<" "<<linearposx<<std::endl;   //ROS_INFO("Position-> x: [%f], y: [%f]",linearposx,linearposy);//return 0;
}

void PioneerData::ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg)            
{
    ROS_INFO("Seq: [%d]", msg->header.seq);
    ROS_INFO("Position-> x: [%f], y: [%f], z: [%f]", msg->pose.pose.position.x,msg->pose.pose.position.y, msg->pose.pose.position.z);
    ROS_INFO("Orientation-> x: [%f], y: [%f], z: [%f], w: [%f]", msg->pose.pose.orientation.x, msg->pose.pose.orientation.y, msg->pose.pose.orientation.z, msg->pose.pose.orientation.w);

   linearposx=msg->pose.pose.position.x;
   linearposy=msg->pose.pose.position.y;
   quatx= msg->pose.pose.orientation.x;
   quaty= msg->pose.pose.orientation.y;
   quatz= msg->pose.pose.orientation.z;
   quatw= msg->pose.pose.orientation.w;

   tf::Quaternion q(quatx, quaty, quatz, quatw);
   tf::Matrix3x3 m(q);
   double roll, pitch, yaw;
   m.getEulerYPR(yaw, pitch, roll); //getRPY
   //ROS_INFO("Yaw: [%f],Pitch: [%f],Roll: [%f]",yaw,pitch,roll);

   return ;

}

Edit 1:

Through trial and error I came to know that I am not using ros::spin() or ros::spinOnce correctly. I am getting confused as to where to call ros::spin() or ros::spinOnce.

2016-07-06 14:28:31 -0500 received badge  Famous Question (source)
2016-07-04 21:59:04 -0500 commented answer Using class to get values from callback function??

No more errors after the changes. Thanks a lot man. Cheers.

2016-07-04 19:22:29 -0500 received badge  Notable Question (source)
2016-07-04 14:10:13 -0500 commented answer Using class to get values from callback function??

Hi.Thank you for your reply. I have edited the post. Please have a look at it.

2016-07-04 13:59:34 -0500 received badge  Popular Question (source)
2016-07-03 19:34:02 -0500 asked a question Using class to get values from callback function??

Hi everyone,

I have written a code and I want to use the values of linearposx,linearposy and yaw from the callback function named ComPoseCallback. As shown here, I did the changes in my program (created a class). But when I try to build it, it gives me the following error:

expected primary-expression before ‘)’ token
ros::Subscriber ComPose_sub = n.subscribe("/RosAria/pose", 1000, &PioneerData::ComPoseCallback, PioneerData);

Here is my code:

#include "ros/ros.h"
#include "nav_msgs/Odometry.h" 
#include <ros/console.h>
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/Twist.h"
#include <tf/transform_datatypes.h>

double quatx;
double quaty;
double quatz;
double quatw;
double linearposx;
double linearposy;

class PioneerData
{
 public: 
 void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg);
};



int main(int argc, char **argv)
{
    ros::init(argc, argv, "Test_FK"); 
    ros::NodeHandle n;                 
    ros::Publisher Velocity_pub = n.advertise<geometry_msgs::Twist>("/RosAria/cmd_vel",1000);
    ros::Subscriber ComPose_sub = n.subscribe("/RosAria/pose", 1000, &PioneerData::ComPoseCallback, &PioneerData);

    geometry_msgs::Twist velocity;
    velocity.linear.x =0.1;
    velocity.linear.y =0;
    velocity.linear.z =0;
    velocity.angular.x =0;
    velocity.angular.y =0;
    velocity.angular.z =0;

    geometry_msgs::Twist Stop;
    Stop.linear.x =0;
    Stop.linear.y =0;
    Stop.linear.z =0;
    Stop.angular.x =0;
    Stop.angular.y =0;
    Stop.angular.z =0;



   //std::cout<<"xPosition"<<linearposx<<std::endl;
   //ros::Rate loop_rate(10);
  //ros::Rate rate (1);

  while (ros::ok())
   {


   if(Velocity_pub.getNumSubscribers()>0)
    {
    if (linearposx==0)
    {
    Velocity_pub.publish(velocity);

    }
    else if(linearposx>=0.5)
    {
      Velocity_pub.publish(Stop);
    }
    ros::spin();
     break;
    }
   }
    //return 0;
}

void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg)            
{
    ROS_INFO("Seq: [%d]", msg->header.seq);
    ROS_INFO("Position-> x: [%f], y: [%f], z: [%f]", msg->pose.pose.position.x,msg->pose.pose.position.y, msg->pose.pose.position.z);
    ROS_INFO("Orientation-> x: [%f], y: [%f], z: [%f], w: [%f]", msg->pose.pose.orientation.x, msg->pose.pose.orientation.y, msg->pose.pose.orientation.z, msg->pose.pose.orientation.w);

   linearposx=msg->pose.pose.position.x;
   linearposy=msg->pose.pose.position.y;
   quatx= msg->pose.pose.orientation.x;
   quaty= msg->pose.pose.orientation.y;
   quatz= msg->pose.pose.orientation.z;
   quatw= msg->pose.pose.orientation.w;

   tf::Quaternion q(quatx, quaty, quatz, quatw);
   tf::Matrix3x3 m(q);
   double roll, pitch, yaw;
   m.getEulerYPR(yaw, pitch, roll); //getRPY
   ROS_INFO("Yaw: [%f],Pitch: [%f],Roll: [%f]",yaw,pitch,roll);

   return ;
}

I can't understand the reason for the error. Can you please point out my mistake? Thanks.

Edit :Hi janindu, I did the changes suggested by you. I am getting the following error:

error: extra qualification ‘PioneerData::’ on member ‘ComPoseCallback’ [-fpermissive]
  void PioneerData::ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg);

Edit 1: I did a quick google search and found that I need to remove

Pioneer::

from:

void PioneerData::ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg)

to remove above error shown in edit . After removing that error, I get a new error as you can see below:

CMakeFiles/Test_FK.dir/src/Test_FK.cpp.o: In function `main':
Test_FK.cpp:(.text+0x17e): undefined reference to `PioneerData::ComPoseCallback(boost::shared_ptr<nav_msgs::Odometry_<std::allocator ...
(more)
2016-07-01 02:03:08 -0500 received badge  Notable Question (source)
2016-06-30 12:24:42 -0500 received badge  Enthusiast
2016-06-30 03:42:09 -0500 received badge  Popular Question (source)
2016-06-29 19:00:55 -0500 asked a question How to publish only one message on a topic?

Hi guys,

I have written a program which continuously publishes velocity on a topic. I want to publish only one velocity message at once. In case I change my velocity I need to publish one message per velocity change. How can I do it. Here is my code:

> #include "ros/ros.h"
> #include "nav_msgs/Odometry.h" 
> #include <ros/console.h>
> #include "geometry_msgs/Pose.h"
> #include "geometry_msgs/Twist.h"
> #include <tf/transform_datatypes.h>
> 
> 
> 
> 
> 
> double quatx; double quaty; double
> quatz; double quatw; double
> linearposx; double linearposy;
> 
> void ComPoseCallback(const
> nav_msgs::Odometry::ConstPtr& msg);
> 
> int main(int argc, char **argv) {
>     ros::init(argc, argv, "Test_FK"); 
>     ros::NodeHandle n;                 
>     ros::Publisher Velocity_pub = n.advertise<geometry_msgs::Twist>("/RosAria/cmd_vel",10);
>     ros::Subscriber ComPose_sub = n.subscribe("/RosAria/pose", 1000,
> ComPoseCallback);
> 
>        geometry_msgs::Twist velocity;    velocity.linear.x=1;   
> velocity.linear.y=0;   
> velocity.linear.z=0;   
> velocity.angular.x=0;   
> velocity.angular.y=0;   
> velocity.angular.z=0;
>         //std::cout<<"xPosition"<<linearposx<<std::endl;
> //ros::Rate loop_rate(10);
>        while (ros::ok())
>     {
>         Velocity_pub.publish(velocity);   
> ros::spinOnce();
>     
>    
>     }
>     return 0; }
> 
> void ComPoseCallback(const
> nav_msgs::Odometry::ConstPtr& msg)    
> {
>     ROS_INFO("Seq: [%d]", msg->header.seq);
>     ROS_INFO("Position-> x: [%f], y: [%f], z: [%f]",
> msg->pose.pose.position.x,msg->pose.pose.position.y,
> msg->pose.pose.position.z);
>     ROS_INFO("Orientation-> x: [%f], y: [%f], z: [%f], w: [%f]",
> msg->pose.pose.orientation.x,
> msg->pose.pose.orientation.y,
> msg->pose.pose.orientation.z,
> msg->pose.pose.orientation.w);
>         linearposx=msg->pose.pose.position.x; 
> linearposy=msg->pose.pose.position.y; 
> quatx= msg->pose.pose.orientation.x;  
> quaty= msg->pose.pose.orientation.y;  
> quatz= msg->pose.pose.orientation.z;  
> quatw= msg->pose.pose.orientation.w;
>        tf::Quaternion q(quatx, quaty, quatz, quatw);    tf::Matrix3x3 m(q); 
> double roll, pitch, yaw;   
> m.getEulerYPR(yaw, pitch, roll);
> //getRPY    ROS_INFO("Yaw: [%f],Pitch:
> [%f],Roll: [%f]",yaw,pitch,roll);
> 
>    return ; }

I am using pioneer 3dx robot which maintains its velocity once I give a velocity command. I don't need to send my velocity continuously.

2016-06-29 13:01:35 -0500 commented answer How to use ros::spin() and values from call back function?

Thank you Jacobperron.Adding ros::spinOnce() sloved the problem.

2016-06-29 13:01:03 -0500 marked best answer How to use ros::spin() and values from call back function?

Hi everyone,

I am trying to move my pioneer 3dx robot. I have written a code and it compiles without any error but does not move my robot. I think it has something to do with the call back function of ros::spin(). Please have a look at my code and suggest any corrections : short term goal is to drive the robot to a point and come back to its initial position [straight path]. I want to get linearposx, linearposy and yaw, so that that I can use them in main function of any other function.

One more thing, when I run the code robot does not because of which all the value I print are zero.

#include "ros/ros.h"
#include "nav_msgs/Odometry.h" 
#include <ros/console.h>
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/Twist.h"
#include <tf/transform_datatypes.h>




void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg);

double quatx;
double quaty;
double quatz;
double quatw;
double linearposx;
double linearposy;

int main(int argc, char **argv)
{
    ros::init(argc, argv, "Test_FK"); 
    ros::NodeHandle n;                 
    ros::Subscriber ComPose_sub = n.subscribe("/RosAria/pose", 1000, ComPoseCallback);
    ros::Publisher Velocity_pub = n.advertise<geometry_msgs::Twist>("/RosAria/cmd_vel", 1000);

    geometry_msgs::Twist velocity;
    velocity.linear.x=0.1;

    if(linearposx>=0)
    {
      Velocity_pub.publish(velocity);

    }
    ros::spin();
}

void ComPoseCallback(const nav_msgs::Odometry::ConstPtr& msg)            
{
    ROS_INFO("Seq: [%d]", msg->header.seq);
    ROS_INFO("Position-> x: [%f], y: [%f], z: [%f]", msg->pose.pose.position.x,msg->pose.pose.position.y, msg->pose.pose.position.z);
    ROS_INFO("Orientation-> x: [%f], y: [%f], z: [%f], w: [%f]", msg->pose.pose.orientation.x, msg->pose.pose.orientation.y, msg->pose.pose.orientation.z, msg->pose.pose.orientation.w);

   linearposx=msg->pose.pose.position.x;
   linearposy=msg->pose.pose.position.y;
   quatx= msg->pose.pose.orientation.x;
   quaty= msg->pose.pose.orientation.y;
   quatz= msg->pose.pose.orientation.z;
   quatw= msg->pose.pose.orientation.w;

   tf::Quaternion q(quatx, quaty, quatz, quatw);
   tf::Matrix3x3 m(q);
   double roll, pitch, yaw;
   m.getEulerYPR(yaw, pitch, roll); //getRPY
   ROS_INFO("Yaw: [%f],Pitch: [%f],Roll: [%f]",yaw,pitch,roll);

   return ;
}

EDIT: If I remove this part then also it does not run. I think the problem is in publisher.

if(linearposx>=0)
        {
         }