Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "protobuf2ros_conversions.h"
00013
00014 #include <boost/make_shared.hpp>
00015
00016 namespace rc {
00017
00018 sensor_msgs::ImuPtr toRosImu(std::shared_ptr<roboception::msgs::Imu> imu)
00019 {
00020 auto rosImu = boost::make_shared<sensor_msgs::Imu>();
00021 rosImu->header.frame_id = "imu";
00022 rosImu->header.stamp.sec = imu->timestamp().sec();
00023 rosImu->header.stamp.nsec = imu->timestamp().nsec();
00024 rosImu->orientation_covariance[0] = -1;
00025 rosImu->angular_velocity.x = imu->angular_velocity().x();
00026 rosImu->angular_velocity.y = imu->angular_velocity().y();
00027 rosImu->angular_velocity.z = imu->angular_velocity().z();
00028 rosImu->linear_acceleration.x = imu->linear_acceleration().x();
00029 rosImu->linear_acceleration.y = imu->linear_acceleration().y();
00030 rosImu->linear_acceleration.z = imu->linear_acceleration().z();
00031
00032 return rosImu;
00033 }
00034
00035 geometry_msgs::PoseStampedPtr toRosPoseStamped(std::shared_ptr<roboception::msgs::Frame> frame)
00036 {
00037 auto protoPoseStamped = frame->pose();
00038 auto protoPosePose = protoPoseStamped.pose();
00039
00040 auto rosPose = boost::make_shared<geometry_msgs::PoseStamped>();
00041 rosPose->header.frame_id = frame->parent();
00042 rosPose->header.stamp.sec = protoPoseStamped.timestamp().sec();
00043 rosPose->header.stamp.nsec = protoPoseStamped.timestamp().nsec();
00044 rosPose->pose.position.x = protoPosePose.position().x();
00045 rosPose->pose.position.y = protoPosePose.position().y();
00046 rosPose->pose.position.z = protoPosePose.position().z();
00047 rosPose->pose.orientation.x = protoPosePose.orientation().x();
00048 rosPose->pose.orientation.y = protoPosePose.orientation().y();
00049 rosPose->pose.orientation.z = protoPosePose.orientation().z();
00050 rosPose->pose.orientation.w = protoPosePose.orientation().w();
00051 return rosPose;
00052 }
00053
00054 geometry_msgs::PoseWithCovarianceStampedPtr toRosPoseWithCovarianceStamped(std::shared_ptr<roboception::msgs::Frame> frame)
00055 {
00056 auto protoPoseStamped = frame->pose();
00057 auto protoPosePose = protoPoseStamped.pose();
00058 auto protoCov = protoPosePose.covariance();
00059
00060 auto rosPose = boost::make_shared<geometry_msgs::PoseWithCovarianceStamped>();
00061 rosPose->header.frame_id = frame->parent();
00062 rosPose->header.stamp.sec = protoPoseStamped.timestamp().sec();
00063 rosPose->header.stamp.nsec = protoPoseStamped.timestamp().nsec();
00064 rosPose->pose.pose.position.x = protoPosePose.position().x();
00065 rosPose->pose.pose.position.y = protoPosePose.position().y();
00066 rosPose->pose.pose.position.z = protoPosePose.position().z();
00067 rosPose->pose.pose.orientation.x = protoPosePose.orientation().x();
00068 rosPose->pose.pose.orientation.y = protoPosePose.orientation().y();
00069 rosPose->pose.pose.orientation.z = protoPosePose.orientation().z();
00070 rosPose->pose.pose.orientation.w = protoPosePose.orientation().w();
00071 for (int i = 0; i < protoCov.size(); i++)
00072 {
00073 rosPose->pose.covariance[i] = protoCov.Get(i);
00074 }
00075 return rosPose;
00076 }
00077
00078 tf::Transform toRosTfTransform(std::shared_ptr<roboception::msgs::Frame> frame)
00079 {
00080 auto pose = frame->pose().pose();
00081 tf::Transform transform;
00082 transform.setOrigin(tf::Vector3(pose.position().x(),
00083 pose.position().y(),
00084 pose.position().z()));
00085 transform.setRotation(
00086 tf::Quaternion(pose.orientation().x(),
00087 pose.orientation().y(),
00088 pose.orientation().z(),
00089 pose.orientation().w()));
00090 return transform;
00091 }
00092
00093 tf::StampedTransform toRosTfStampedTransform(std::shared_ptr<roboception::msgs::Frame> frame)
00094 {
00095 tf::Transform transform = toRosTfTransform(frame);
00096 ros::Time t(frame->pose().timestamp().sec(),
00097 frame->pose().timestamp().nsec());
00098
00099 return tf::StampedTransform(transform, t, frame->parent(), frame->name());
00100 }
00101
00102
00103 }