semio_ros  0.10.6
humanoid_sink_ros.cpp
Go to the documentation of this file.
2 
3 semio::ros::HumanoidSinkROS::HumanoidSinkROS( ::ros::NodeHandle const & nh_rel, std::string const & topic )
4 :
5  _nh_rel( nh_rel ),
6  _humanoids_pub( _nh_rel.advertise<_HumanoidsMsg>( topic, 10 ) )
7 {
8  //
9 }
10 
11 semio::ros::HumanoidSinkROS::_HumanoidJointMsg::Ptr semio::ros::HumanoidSinkROS::toROSMsgPtr( HumanoidJoint const & joint )
12 {
13  _HumanoidJointMsg::Ptr joint_msg_ptr( new _HumanoidJointMsg() );
14  auto & joint_msg( *joint_msg_ptr );
15 
16  joint_msg.type = static_cast<uint32_t>( joint.joint_type_ );
17  joint_msg.position_confidence = joint.position_confidence_;
18  joint_msg.orientation_confidence = joint.orientation_confidence_;
19  joint_msg.position.x = joint.position_.x();
20  joint_msg.position.y = joint.position_.y();
21  joint_msg.position.z = joint.position_.z();
22  joint_msg.orientation.w = joint.orientation_.w();
23  joint_msg.orientation.x = joint.orientation_.x();
24  joint_msg.orientation.y = joint.orientation_.y();
25  joint_msg.orientation.z = joint.orientation_.z();
26 
27  return joint_msg_ptr;
28 }
29 
31 {
32  return *HumanoidSinkROS::toROSMsgPtr( joint );
33 }
34 
35 semio::ros::HumanoidSinkROS::_HumanoidMsg::Ptr semio::ros::HumanoidSinkROS::toROSMsgPtr( Humanoid const & humanoid )
36 {
37  _HumanoidMsg::Ptr humanoid_msg_ptr( new _HumanoidMsg() );
38  auto & humanoid_msg( *humanoid_msg_ptr );
39 
40  humanoid_msg.id = humanoid.id_;
41  humanoid_msg.tracking_state = static_cast<uint32_t>( humanoid.tracking_state_ );
42  humanoid_msg.joints.reserve( humanoid.joints_.size() );
43 
44  for( auto const & joint_item : humanoid.joints_ )
45  {
46  humanoid_msg.joints.emplace_back( std::move( HumanoidSinkROS::toROSMsg( joint_item.second ) ) );
47  }
48 
49  return humanoid_msg_ptr;
50 }
51 
53 {
54  return *HumanoidSinkROS::toROSMsgPtr( humanoid );
55 }
56 
57 semio::ros::HumanoidSinkROS::_HumanoidsMsg::Ptr semio::ros::HumanoidSinkROS::toROSMsgPtr( HumanoidArray const & humanoids )
58 {
59  _HumanoidsMsg::Ptr humanoids_msg_ptr( new _HumanoidsMsg() );
60  auto & humanoids_msg( *humanoids_msg_ptr );
61 
62  humanoids_msg.humanoids.reserve( humanoids.size() );
63 
64  for( auto const & humanoid : humanoids )
65  {
66  humanoids_msg.humanoids.emplace_back( std::move( HumanoidSinkROS::toROSMsg( humanoid ) ) );
67  }
68 
69  return humanoids_msg_ptr;
70 }
71 
73 {
74  return *HumanoidSinkROS::toROSMsgPtr( humanoids );
75 }
76 
78 {
79  _humanoids_pub.publish( HumanoidSinkROS::toROSMsgPtr( humanoids ) );
80 }
virtual void publishToSink(HumanoidArray const &humanoids)
Convert humanoids to a ROS message and publish it to ROS.
TrackingState tracking_state_
_JointArray joints_
semio_msgs_ros::Humanoid _HumanoidMsg
ROS message for a single humanoid.
static _HumanoidJointMsg toROSMsg(HumanoidJoint const &joint)
Create a _HumanoidJointMsg from a semio::HumanoidJoint.
Eigen::Vector3d position_
semio_msgs_ros::HumanoidJoint _HumanoidJointMsg
ROS message for a humanoid joint.
static _HumanoidJointMsg::Ptr toROSMsgPtr(HumanoidJoint const &joint)
Create a _HumanoidJointMsg::Ptr from a semio::HumanoidJoint.
semio_msgs_ros::Humanoids _HumanoidsMsg
ROS message for a vector of humanoids.
Eigen::Quaterniond orientation_
std::vector< semio::Humanoid > HumanoidArray
::ros::Publisher _humanoids_pub
Publisher for humanoid messages.
HumanoidSinkROS(::ros::NodeHandle const &nh_rel, std::string const &topic="humanoids")