IFL-CAMP / iiwa_stack

ROS integration for the KUKA LBR IIWA R800/R820 (7/14 Kg).
Other
337 stars 250 forks source link

class clash between iiwa_msgs and geometry_msgs when using CartesianQuantityFromDouble() #155

Open avpai opened 5 years ago

avpai commented 5 years ago

Hi, I am trying to use the Cartesian Pose feature to control the end effector. But I am having an Issue with setting the CartesianPose. Below is my current program:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <iiwa_ros.h>
#include <conversions.h>

geometry_msgs::PoseStamped my_cartesian_pose;

iiwa_ros::iiwaRos my_iiwa;

void getcart(const geometry_msgs::PoseStamped::ConstPtr& value)
{       
        my_cartesian_pose = *value;
    ROS_INFO_STREAM("I got a Cartesian Pose and its contents is :" << my_cartesian_pose.pose);  
}

int main (int argc,char **argv)
{
    ros::init(argc,argv,"iiwa_ros");
    ros::NodeHandle n;
    ROS_INFO("Started");
    my_iiwa.init(); // initialize iiwa_ros class        
    ros::Subscriber sub = n.subscribe("iiwa/state/CartesianPose",1000,getcart);        
        ros::Rate loop_rate(0.2);

  while (ros::ok())
  {
   my_cartesian_pose.pose = iiwa_ros::CartesianQuantityFromDouble(0.55,0.04,0.09,-0.19,0.97,-0.04); 
   ROS_INFO("publish");
   my_iiwa.setCartesianPose(my_cartesian_pose);
    loop_rate.sleep();   
  }
    return 0;
}

I identified the problem. The my_cartesian_pose is defined to be from the geometry_msgs class while the CartesianQuantityFromDouble() uses iiwa_msgs. I checked the iiwa_ros.cpp to see if we defined the my_cartesian_pose correctly and even in that file its using the geometry_msgs. I am able to subscribe and read the current cartesian pose (x,y,z and a,b,c) but this clash between two classes is stopping me from publishing new pose. Is there any work around? Am I defining the 'my_cartesian_pose' right?

SalvoVirga commented 5 years ago

You correctly use a geometry_msgs::PoseStamped to get the messages from the subscriber to /iiwa/state/CartesianPose. iiwa_ros::CartesianQuantityFromDouble simply does what the name says, gives you a CartesianQuantity, which is defined in iiwa_msgs as (X,Y,Z,A,B,C), as a Cartesian pose is (weirdly) internally represented in Sunrise. So a CartesianQuantity is just different than a geometry_msgs::Pose, you should simply not use that function. It is to create a CartesianQuantity, which you don't need.

Just fill the fields of the message to send in some other way ^^