ddsproxyposestamped.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 --- ddsproxyposestamped.cpp
00020 *
00021 *  Created on: Sep 10, 2012
00022 */
00023 
00024 #include "ddsproxyposestamped.h"
00025 #include "ros/ros.h"
00026 
00027 
00028 DDSProxyPoseStamped::DDSProxyPoseStamped() {
00029 }
00030 
00031 DDSProxyPoseStamped::~DDSProxyPoseStamped() {
00032 
00033 }
00034 
00035 void DDSProxyPoseStamped::registerProxy() {
00036         // Init participant for DDS. And typesupport for ddsProxyStamped
00037         proxyPoseStampedTypeSupport_var data = new proxyPoseStampedTypeSupport();
00038         DDSManager::instance().registerType(dds_domain_name, data.in());
00039         m_data_topic = DDSManager::instance().createTopic(dds_domain_name.c_str(),
00040                         dds_message_name.c_str(), data->get_type_name());
00041         DataWriter_ptr writer = DDSManager::instance().createWriter(
00042                         dds_domain_name.c_str(), ros_message_type.c_str(), m_data_topic);
00043         DataReader_ptr reader = DDSManager::instance().createReader(
00044                         dds_domain_name.c_str(), ros_message_type.c_str(),
00045                         m_data_topic.in());
00046         m_data_writer = proxyPoseStampedDataWriter::_narrow(writer);
00047         m_data_reader = proxyPoseStampedDataReader::_narrow(reader);
00048         // Init ROS
00049         std::string topic_name = "/shared_";
00050         topic_name.append(ros_message_name.c_str());
00051         pub = nh_.advertise<geometry_msgs::PoseStamped>(topic_name.c_str(), 10);
00052         sub = nh_.subscribe(ros_message_name.c_str(), 1, &DDSProxyPoseStamped::messageCallback <geometry_msgs::PoseStamped>, this);
00053         ROS_INFO("DDSProxyPoseStamped Initialization completed.");
00054 }
00055 
00056 template <class T> void DDSProxyPoseStamped::messageCallback(
00057                 const ros::MessageEvent<T const>& event) {
00058                 ROS_DEBUG("[Debug]: Received message event of type geometry_msgs::PoseStamped\n");
00059         //      if (event.getPublisherName() != node_name) {
00060                 ROS_DEBUG("Received message from %s", event.getPublisherName().c_str());
00061                 ros::Time receipt_time = event.getReceiptTime();
00062                 const geometry_msgs::PoseStampedConstPtr& msg = event.getMessage();
00063                 proxyPoseStamped *proxyPoseStamped_msg = new proxyPoseStamped();
00064 
00065                 // Filling in data for *proxyPoseStamped.idl*
00066                 std::string frame_id = "/";
00067                 frame_id.append(robot_name.c_str());
00068                 frame_id.append(std::string(msg->header.frame_id).c_str());
00069 
00070                 proxyPoseStamped_msg->header.frame_id = frame_id.c_str();
00071                 proxyPoseStamped_msg->header.seq = msg->header.seq;
00072                 proxyPoseStamped_msg->header.stamp.nsec = msg->header.stamp.nsec;
00073                 proxyPoseStamped_msg->header.stamp.sec = msg->header.stamp.sec;
00074 
00075         // fill pose/position
00076                 proxyPoseStamped_msg->pose.position.x = msg->pose.position.x;
00077                 proxyPoseStamped_msg->pose.position.y = msg->pose.position.y;
00078                 proxyPoseStamped_msg->pose.position.z = msg->pose.position.z;
00079 
00080         // fill pose/orientation
00081                 proxyPoseStamped_msg->pose.orientation.x = msg->pose.orientation.x;
00082                 proxyPoseStamped_msg->pose.orientation.y = msg->pose.orientation.y;
00083                 proxyPoseStamped_msg->pose.orientation.z = msg->pose.orientation.z;
00084                 proxyPoseStamped_msg->pose.orientation.w = msg->pose.orientation.w;
00085 
00086                 ReturnCode_t ret = m_data_writer->write(*proxyPoseStamped_msg, NULL);
00087                 checkStatus(ret, "proxyPoseStamped::Write");
00088                 // ROS_INFO("Print return code %d", ret);
00089                 //}
00090 }
00091 
00092 void DDSProxyPoseStamped::update() {
00093         proxyPoseStampedSeq_var proxyPoseStamped_msgSeq = new proxyPoseStampedSeq();
00094         SampleInfoSeq_var infoSeq = new SampleInfoSeq();
00095 
00096         //ROS_INFO_ONCE("while inner loop");
00097         //ReportStatus_t status
00098         m_data_reader->take(*proxyPoseStamped_msgSeq, *infoSeq, LENGTH_UNLIMITED,
00099                         ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
00100         //checkStatus(status, "MsgDataReader::take");
00101         //ROS_INFO("Reading data %d", proxyPoseStamped_msgSeq->length());
00102         //ROS_INFO("Reading info %d",infoSeq->length());
00103         for (ULong i = 0; i < proxyPoseStamped_msgSeq->length(); ++i) {
00104                 //ROS_INFO("publishing message");
00105                 ROS_DEBUG("receiving message via DDS!");
00106                 //ROS_INFO("Sender info %d", proxyPoseStamped_msgSeq[i]->)
00107 
00108                 geometry_msgs::PoseStamped ddsPoseStamped_msg;
00109                 proxyPoseStamped *ROS_proxyPoseStamped_msg;
00110                 ROS_proxyPoseStamped_msg = &(proxyPoseStamped_msgSeq[i]);
00111 
00112                 // An empty message makes the program crash
00113                 if(ROS_proxyPoseStamped_msg->header.seq == 0 && 
00114                         ROS_proxyPoseStamped_msg->header.stamp.sec == 0){
00115                         ROS_INFO("[Message %u] is empty. I ignore it.", i);
00116                 //      nEmptyItems++;
00117                         continue;
00118                 }
00119 
00120                 ddsPoseStamped_msg.header.stamp.sec = ROS_proxyPoseStamped_msg->header.stamp.sec;
00121                 ddsPoseStamped_msg.header.stamp.nsec = ROS_proxyPoseStamped_msg->header.stamp.nsec;
00122                 ddsPoseStamped_msg.header.seq = ROS_proxyPoseStamped_msg->header.seq;
00123                 ddsPoseStamped_msg.header.frame_id = ROS_proxyPoseStamped_msg->header.frame_id;
00124 
00125                 //position
00126                 ddsPoseStamped_msg.pose.position.x = ROS_proxyPoseStamped_msg->pose.position.x;
00127                 ddsPoseStamped_msg.pose.position.y = ROS_proxyPoseStamped_msg->pose.position.y;
00128                 ddsPoseStamped_msg.pose.position.z = ROS_proxyPoseStamped_msg->pose.position.z;
00129 
00130                 //orientation
00131                 ddsPoseStamped_msg.pose.orientation.x = ROS_proxyPoseStamped_msg->pose.orientation.x;
00132                 ddsPoseStamped_msg.pose.orientation.y = ROS_proxyPoseStamped_msg->pose.orientation.y;
00133                 ddsPoseStamped_msg.pose.orientation.z = ROS_proxyPoseStamped_msg->pose.orientation.z;
00134                 ddsPoseStamped_msg.pose.orientation.w = ROS_proxyPoseStamped_msg->pose.orientation.w;
00135 
00136 
00137                 //ROS_INFO("Find robot name at %d", ddsPoseStamped_msg.header.frame_id.find(robot_name.c_str()));
00138                 //if (ddsPoseStamped_msg.header.frame_id.find(robot_name.c_str()) == -1 )
00139                         pub.publish(ddsPoseStamped_msg);
00140         }
00141         m_data_reader->return_loan(*proxyPoseStamped_msgSeq, *infoSeq);
00142         //checkStatus(status, "MsgDataReader::return_loan");
00143 
00144 }
00145 
00146 


proxyPoseStamped
Author(s): Ronny Hartanto
autogenerated on Mon Oct 6 2014 06:54:41