Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ddsproxyposewithcovariancestamped.h"
00025 #include "ros/ros.h"
00026
00027 DDSProxyPoseWithCovarianceStamped::DDSProxyPoseWithCovarianceStamped() {
00028 }
00029
00030 DDSProxyPoseWithCovarianceStamped::~DDSProxyPoseWithCovarianceStamped() {
00031
00032 }
00033
00034 void DDSProxyPoseWithCovarianceStamped::registerProxy() {
00035
00036 proxyPoseWithCovarianceStampedTypeSupport_var data = new proxyPoseWithCovarianceStampedTypeSupport();
00037 DDSManager::instance().registerType(dds_domain_name, data.in());
00038 m_data_topic = DDSManager::instance().createTopic(dds_domain_name.c_str(),
00039 dds_message_name.c_str(), data->get_type_name());
00040 DataWriter_ptr writer = DDSManager::instance().createWriter(
00041 dds_domain_name.c_str(), ros_message_type.c_str(), m_data_topic);
00042 DataReader_ptr reader = DDSManager::instance().createReader(
00043 dds_domain_name.c_str(), ros_message_type.c_str(),
00044 m_data_topic.in());
00045 m_data_writer = proxyPoseWithCovarianceStampedDataWriter::_narrow(writer);
00046 m_data_reader = proxyPoseWithCovarianceStampedDataReader::_narrow(reader);
00047
00048 pub = nh_.advertise<geometry_msgs::PoseWithCovarianceStamped>("amcl_pose", 10);
00049 sub = nh_.subscribe("amcl_pose", 1, &DDSProxyPoseWithCovarianceStamped::messageCallback <geometry_msgs::PoseWithCovarianceStamped>, this);
00050 ROS_INFO("DDSPosePoseWithCovarianceStamped Initialization completed.");
00051 }
00052
00053 template <class T> void DDSProxyPoseWithCovarianceStamped::messageCallback(
00054 const ros::MessageEvent<T const>& event) {
00055 ROS_DEBUG("[Debug]: Received message event of type geometry_msgs::PoseWithCovarianceStamped\n");
00056 if (event.getPublisherName() != node_name) {
00057 ROS_DEBUG("Received message from %s", event.getPublisherName().c_str());
00058 ros::Time receipt_time = event.getReceiptTime();
00059 const geometry_msgs::PoseWithCovarianceStampedConstPtr& msg = event.getMessage();
00060 proxyPoseWithCovarianceStamped *proxyPoseWithCovarianceStamped_msg = new proxyPoseWithCovarianceStamped();
00061
00062
00063 std::string frame_id = std::string(msg->header.frame_id).c_str();
00064 frame_id.append("/");
00065 frame_id.append(robot_name.c_str());
00066 proxyPoseWithCovarianceStamped_msg->header.frame_id = frame_id.c_str();
00067 proxyPoseWithCovarianceStamped_msg->header.seq = msg->header.seq;
00068 proxyPoseWithCovarianceStamped_msg->header.stamp.nsec = msg->header.stamp.nsec;
00069 proxyPoseWithCovarianceStamped_msg->header.stamp.sec = msg->header.stamp.sec;
00070
00071
00072 proxyPoseWithCovarianceStamped_msg->pose.pose.position.x = msg->pose.pose.position.x;
00073 proxyPoseWithCovarianceStamped_msg->pose.pose.position.y = msg->pose.pose.position.y;
00074 proxyPoseWithCovarianceStamped_msg->pose.pose.position.z = msg->pose.pose.position.z;
00075
00076
00077 proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.x = msg->pose.pose.orientation.x;
00078 proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.y = msg->pose.pose.orientation.y;
00079 proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.z = msg->pose.pose.orientation.z;
00080 proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.w = msg->pose.pose.orientation.w;
00081
00082
00083 proxyPoseWithCovarianceStamped_msg->pose.covariance.length(msg->pose.covariance.size());
00084 for (unsigned int i=0; i < msg->pose.covariance.size(); i++) {
00085 proxyPoseWithCovarianceStamped_msg->pose.covariance[i] = msg->pose.covariance[i];
00086 }
00087
00088 ReturnCode_t ret = m_data_writer->write(*proxyPoseWithCovarianceStamped_msg, NULL);
00089 checkStatus(ret, "proxyPoseWithCovarianceStamped::Write");
00090
00091 }
00092 }
00093
00094 void DDSProxyPoseWithCovarianceStamped::update() {
00095 proxyPoseWithCovarianceStampedSeq_var proxyPoseWithCovarianceStamped_msgSeq = new proxyPoseWithCovarianceStampedSeq();
00096 SampleInfoSeq_var infoSeq = new SampleInfoSeq();
00097
00098
00099
00100 m_data_reader->take(*proxyPoseWithCovarianceStamped_msgSeq, *infoSeq, LENGTH_UNLIMITED,
00101 ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
00102
00103
00104
00105 for (ULong i = 0; i < proxyPoseWithCovarianceStamped_msgSeq->length(); ++i) {
00106
00107 ROS_DEBUG("receiving message via DDS!");
00108
00109 geometry_msgs::PoseWithCovarianceStamped ddsPoseWithCovarianceStamped_msg;
00110 proxyPoseWithCovarianceStamped *ROS_proxyPoseWithCovarianceStamped_msg;
00111 ROS_proxyPoseWithCovarianceStamped_msg = &(proxyPoseWithCovarianceStamped_msgSeq[i]);
00112 ddsPoseWithCovarianceStamped_msg.header.stamp.sec = ROS_proxyPoseWithCovarianceStamped_msg->header.stamp.sec;
00113 ddsPoseWithCovarianceStamped_msg.header.stamp.nsec = ROS_proxyPoseWithCovarianceStamped_msg->header.stamp.nsec;
00114 ddsPoseWithCovarianceStamped_msg.header.seq = ROS_proxyPoseWithCovarianceStamped_msg->header.seq;
00115 ddsPoseWithCovarianceStamped_msg.header.frame_id = ROS_proxyPoseWithCovarianceStamped_msg->header.frame_id;
00116
00117
00118 ddsPoseWithCovarianceStamped_msg.pose.pose.position.x = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.position.x;
00119 ddsPoseWithCovarianceStamped_msg.pose.pose.position.y = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.position.y;
00120 ddsPoseWithCovarianceStamped_msg.pose.pose.position.z = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.position.z;
00121
00122
00123 ddsPoseWithCovarianceStamped_msg.pose.pose.orientation.x = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.x;
00124 ddsPoseWithCovarianceStamped_msg.pose.pose.orientation.y = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.y;
00125 ddsPoseWithCovarianceStamped_msg.pose.pose.orientation.z = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.z;
00126 ddsPoseWithCovarianceStamped_msg.pose.pose.orientation.w = ROS_proxyPoseWithCovarianceStamped_msg->pose.pose.orientation.w;
00127
00128
00129 for (int i = 0; i < ROS_proxyPoseWithCovarianceStamped_msg->pose.covariance.length(); i++) {
00130 ddsPoseWithCovarianceStamped_msg.pose.covariance[i] = ROS_proxyPoseWithCovarianceStamped_msg->pose.covariance[i];
00131 }
00132
00133
00134 if (ddsPoseWithCovarianceStamped_msg.header.frame_id.find(robot_name.c_str()) == -1 )
00135 pub.publish(ddsPoseWithCovarianceStamped_msg);
00136 }
00137 m_data_reader->return_loan(*proxyPoseWithCovarianceStamped_msgSeq, *infoSeq);
00138
00139
00140 }
00141
00142