ddsproxyposewithcovariancestamped.cpp
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2012  DFKI GmbH, Bremen, Germany
00003 *
00004 *  This file is free software: you may copy, redistribute and/or modify it
00005 *  under the terms of the GNU General Public License as published by the
00006 *  Free Software Foundation, either version 3 of the License, or (at your
00007 *  option) any later version.
00008 *
00009 *  This file is distributed in the hope that it will be useful, but
00010 *  WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 *  General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 *
00017 *   Author: Ronny Hartanto (ronny.hartanto@dfki.de)
00018 *
00019 *       FILE ---  ddsproxyposewithcovariancestamped.cpp
00020 *
00021 *  Created on: Aug 6, 2012
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         // Init participant for DDS. And typesupport for ddsProxyWithCovarianceStamped
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         // Init ROS
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                 // Filling in data for *proxyPoseWithCovarianceStamped.idl*
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         // fill pose/position
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         // fill pose/orientation
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         // fill pose/covariance
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                 // ROS_INFO("Print return code %d", ret);
00091         }
00092 }
00093 
00094 void DDSProxyPoseWithCovarianceStamped::update() {
00095         proxyPoseWithCovarianceStampedSeq_var proxyPoseWithCovarianceStamped_msgSeq = new proxyPoseWithCovarianceStampedSeq();
00096         SampleInfoSeq_var infoSeq = new SampleInfoSeq();
00097 
00098         //ROS_INFO_ONCE("while inner loop");
00099         //ReportStatus_t status
00100         m_data_reader->take(*proxyPoseWithCovarianceStamped_msgSeq, *infoSeq, LENGTH_UNLIMITED,
00101                         ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
00102         //checkStatus(status, "MsgDataReader::take");
00103         //ROS_INFO("Reading data %d", proxyPoseWithCovarianceStamped_msgSeq->length());
00104         //ROS_INFO("Reading info %d",infoSeq->length());
00105         for (ULong i = 0; i < proxyPoseWithCovarianceStamped_msgSeq->length(); ++i) {
00106                 //ROS_INFO("publishing message");
00107                 ROS_DEBUG("receiving message via DDS!");
00108                 //ROS_INFO("Sender info %d", proxyPoseWithCovarianceStamped_msgSeq[i]->)
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                 //position
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                 //orientation
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                 //covariance
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                 //ROS_INFO("Find robot name at %d", ddsPoseWithCovarianceStamped_msg.header.frame_id.find(robot_name.c_str()));
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         //checkStatus(status, "MsgDataReader::return_loan");
00139 
00140 }
00141 
00142 


proxyPoseWithCovarianceStamped
Author(s): Ronny Hartanto
autogenerated on Mon Oct 6 2014 06:54:21