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
00025 #include "ddsproxyjoy.h"
00026 #include "ros/ros.h"
00027
00028 DDSProxyJoy::DDSProxyJoy() {
00029 }
00030
00031 DDSProxyJoy::~DDSProxyJoy() {
00032
00033 }
00034
00035 void DDSProxyJoy::registerProxy() {
00036
00037 ddsJoyTypeSupport_var data = new ddsJoyTypeSupport();
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 = ddsJoyDataWriter::_narrow(writer);
00047 m_data_reader = ddsJoyDataReader::_narrow(reader);
00048
00049 pub = nh_.advertise<sensor_msgs::Joy>("joy", 10);
00050 sub = nh_.subscribe("joy", 1, &DDSProxyJoy::messageCallback <sensor_msgs::Joy>, this);
00051 ROS_INFO("DDSJoy Initialization completed.");
00052 }
00053
00054 template <class T> void DDSProxyJoy::messageCallback(
00055 const ros::MessageEvent<T const>& event) {
00056 ROS_DEBUG("[Debug]: Received message event of type sensor_msgs::Joy\n");
00057 if ((event.getPublisherName() != node_name) && (event.getPublisherName() != local_publisher_node_name)) {
00058 ROS_DEBUG("Received message from %s", event.getPublisherName().c_str());
00059 ros::Time receipt_time = event.getReceiptTime();
00060 const sensor_msgs::JoyConstPtr& msg = event.getMessage();
00061 ddsJoy *ddsJoy_msg = new ddsJoy();
00062
00063
00064 ddsJoy_msg->header.frame_id = std::string(msg->header.frame_id).c_str();
00065 ddsJoy_msg->header.seq = msg->header.seq;
00066 ddsJoy_msg->header.stamp.nsec = msg->header.stamp.nsec;
00067 ddsJoy_msg->header.stamp.sec = msg->header.stamp.sec;
00068 ddsJoy_msg->axes.length(msg->axes.size());
00069
00070 for (int i = 0; i < msg->axes.size(); i++) {
00071 ddsJoy_msg->axes[i] = msg->axes[i];
00072 }
00073
00074 ddsJoy_msg->buttons.length(msg->buttons.size());
00075
00076 for (int i = 0; i < msg->buttons.size(); i++) {
00077 ddsJoy_msg->buttons[i] = msg->buttons[i];
00078 }
00079
00080 ReturnCode_t ret = m_data_writer->write(*ddsJoy_msg, NULL);
00081 checkStatus(ret, "ddsJoy::Write");
00082
00083 }
00084 }
00085
00086 void DDSProxyJoy::update() {
00087 ddsJoySeq_var ddsJoy_msgSeq = new ddsJoySeq();
00088 SampleInfoSeq_var infoSeq = new SampleInfoSeq();
00089
00090
00091
00092 m_data_reader->take(*ddsJoy_msgSeq, *infoSeq, LENGTH_UNLIMITED,
00093 ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
00094
00095
00096
00097 for (ULong i = 0; i < ddsJoy_msgSeq->length(); ++i) {
00098
00099 sensor_msgs::Joy ddsJoy_msg;
00100 ddsJoy *ROS_ddsJoy_msg;
00101 ROS_ddsJoy_msg = &(ddsJoy_msgSeq[i]);
00102 ddsJoy_msg.header.stamp.sec = ROS_ddsJoy_msg->header.stamp.sec;
00103 ddsJoy_msg.header.stamp.nsec = ROS_ddsJoy_msg->header.stamp.nsec;
00104 ddsJoy_msg.header.seq = ROS_ddsJoy_msg->header.seq;
00105 ddsJoy_msg.header.frame_id = ROS_ddsJoy_msg->header.frame_id;
00106
00107 ddsJoy_msg.axes.resize(ROS_ddsJoy_msg->axes.length());
00108 for (int i = 0; i < ROS_ddsJoy_msg->axes.length(); i++) {
00109 ddsJoy_msg.axes[i] = ROS_ddsJoy_msg->axes[i];
00110 }
00111
00112 ddsJoy_msg.buttons.resize(ROS_ddsJoy_msg->buttons.length());
00113 for (int i = 0; i < ROS_ddsJoy_msg->buttons.length(); i++) {
00114 ddsJoy_msg.buttons[i] = ROS_ddsJoy_msg->buttons[i];
00115 }
00116 pub.publish(ddsJoy_msg);
00117 m_data_reader->return_loan(*ddsJoy_msgSeq, *infoSeq);
00118
00119 }
00120 }
00121
00122