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 "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
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
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
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
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
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
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
00089
00090 }
00091
00092 void DDSProxyPoseStamped::update() {
00093 proxyPoseStampedSeq_var proxyPoseStamped_msgSeq = new proxyPoseStampedSeq();
00094 SampleInfoSeq_var infoSeq = new SampleInfoSeq();
00095
00096
00097
00098 m_data_reader->take(*proxyPoseStamped_msgSeq, *infoSeq, LENGTH_UNLIMITED,
00099 ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
00100
00101
00102
00103 for (ULong i = 0; i < proxyPoseStamped_msgSeq->length(); ++i) {
00104
00105 ROS_DEBUG("receiving message via DDS!");
00106
00107
00108 geometry_msgs::PoseStamped ddsPoseStamped_msg;
00109 proxyPoseStamped *ROS_proxyPoseStamped_msg;
00110 ROS_proxyPoseStamped_msg = &(proxyPoseStamped_msgSeq[i]);
00111
00112
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
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
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
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
00138
00139 pub.publish(ddsPoseStamped_msg);
00140 }
00141 m_data_reader->return_loan(*proxyPoseStamped_msgSeq, *infoSeq);
00142
00143
00144 }
00145
00146