ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hi,
As far as I know, there are no real constructors (in the sens that they fill the values) for ros messages, because it would be to complicated to do (because the classes for ros messages are automatically generated from the .msg files). And according to the following git issue, it seems that the idea was definitively abondoned for ROS 1 (development is now foccused on ROS 2). :
https://github.com/ros/ros_comm/issues/148
If you use a lot of quaternions, you can simply write your own function :
geometry_msgs::Quaternion quaternion_from_rpy(double roll, double pitch, double yaw)
{
tf2::Quaternion quaternion_tf2;
quaternion_tf2.setRPY(roll, pitch, yaw);
geometry_msgs::Quaternion quaternion = tf2::toMsg(quaternion_tf2);
return quaternion;
}
and use it to creat your quaternions
If you don't want to write your own function, you can create directly a constructor with arguments for the tf2::Quaternion in order to have one line less. They are 3 options according to
http://docs.ros.org/en/jade/api/tf2/html/classtf2_1_1Quaternion.html
Quaternion (const tf2Scalar &x, const tf2Scalar &y, const tf2Scalar &z, const tf2Scalar &w)
Quaternion (const Vector3 &axis, const tf2Scalar &angle)
Quaternion (const tf2Scalar &yaw, const tf2Scalar &pitch, const tf2Scalar &roll) __attribute__((deprecated))
Note however that the one you would like to use (the one from yaw, pitch and roll) is deprecated. So up to you to decide if you still want to use it or not
2 | No.2 Revision |
Hi,
As far as I know, there are no real constructors (in the sens that they fill the values) for ros messages, because it would be to complicated to do (because the classes for ros messages are automatically generated from the .msg files). And according to the following git issue, it seems that the idea was definitively abondoned for ROS 1 (development is now foccused on ROS 2). :
https://github.com/ros/ros_comm/issues/148
If you use a lot of quaternions, you can simply write your own function :
geometry_msgs::Quaternion quaternion_from_rpy(double roll, double pitch, double yaw)
{
tf2::Quaternion quaternion_tf2;
quaternion_tf2.setRPY(roll, pitch, yaw);
geometry_msgs::Quaternion quaternion = tf2::toMsg(quaternion_tf2);
return quaternion;
}
and use it to creat your quaternions
If you don't want to write your own function, you can create directly a constructor with arguments for the tf2::Quaternion in order to have one line less. They are 3 options according to
http://docs.ros.org/en/jade/api/tf2/html/classtf2_1_1Quaternion.html
Quaternion (const tf2Scalar &x, const tf2Scalar &y, const tf2Scalar &z, const tf2Scalar &w)
Quaternion (const Vector3 &axis, const tf2Scalar &angle)
Quaternion (const tf2Scalar &yaw, const tf2Scalar &pitch, const tf2Scalar &roll) __attribute__((deprecated))
Note however that the one you would like to use (the one from yaw, pitch and roll) is deprecated. So up to you to decide if you still want to use it or not