20 Protobuf2RosPublisher::Protobuf2RosPublisher(
ros::NodeHandle& nh,
const string& topic,
const string& pbMsgType,
21 const string& frame_id_prefix)
22 : _tfPrefix(frame_id_prefix)
24 if (pbMsgType ==
"Imu")
28 else if (pbMsgType ==
"Frame")
30 pub = nh.
advertise<geometry_msgs::PoseStamped>(topic, 1000);
35 msg <<
"Protobuf message type '" << pbMsgType <<
"' not supported!";
36 throw runtime_error(msg.str());
47 string msg_name = pbMsg->GetDescriptor()->name();
49 if (msg_name ==
"Imu")
53 shared_ptr<roboception::msgs::Imu> protoImu = dynamic_pointer_cast<roboception::msgs::Imu>(pbMsg);
56 throw runtime_error(
"Given protobuf message was not of type Imu!");
60 rosImu->header.frame_id =
_tfPrefix + rosImu->header.frame_id;
63 else if (msg_name ==
"Frame")
67 shared_ptr<roboception::msgs::Frame> protoFrame = dynamic_pointer_cast<roboception::msgs::Frame>(pbMsg);
70 throw runtime_error(
"Given protobuf message was not of type Frame!");
74 rosPose->header.frame_id =
_tfPrefix + rosPose->header.frame_id;
80 msg <<
"Protobuf message type '" << msg_name <<
"' not supported!";
81 throw runtime_error(msg.str());
geometry_msgs::PoseStampedPtr toRosPoseStamped(const roboception::msgs::Frame &frame)
void publish(const boost::shared_ptr< M > &message) const
sensor_msgs::ImuPtr toRosImu(const roboception::msgs::Imu &imu)
virtual void publish(std::shared_ptr<::google::protobuf::Message > pbMsg)
Publish the generic protobuf message as a corresponding Ros Message.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const std::string _tfPrefix
uint32_t getNumSubscribers() const
virtual bool used()
Returns true if there are subscribers to the topic.