semio_ros  0.10.6
semio_humanoid_server_node.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 
6 
7 //! Serve humanoids using source/sink model
9 {
10 protected:
11  //! Pointer to the input source for humanoids
13  //! Vector of pointers to the output sinks for humanoids
14  std::vector<semio::HumanoidSink::Ptr> _humanoid_sinks;
15 
16 public:
17  /**
18  @param humanoid_source_ptr @copybrief _humanoid_source_ptr
19  @param humanoid_sinks @copybrief _humanoid_sinks
20  */
21  SemioHumanoidServerNode( semio::HumanoidSource::Ptr humanoid_source_ptr, std::vector<semio::HumanoidSink::Ptr> const & humanoid_sinks )
22  :
23  _humanoid_source_ptr( humanoid_source_ptr ),
24  _humanoid_sinks( humanoid_sinks )
25  {
26  //
27  }
28 
29  //! Main loop
30  void spin()
31  {
32  ros::Rate loop_rate( 30 );
33 
34  while( ros::ok() )
35  {
36  //! - Trigger ROS callbacks
37  ros::spinOnce();
38 
39  //----------
40  //! - Publish humanoids from our input source to our output sinks
41  auto const & humanoids( _humanoid_source_ptr->update() );
42  for( auto & sink_ptr : _humanoid_sinks )
43  {
44  if( sink_ptr ) sink_ptr->publish( humanoids );
45  }
46  //----------
47 
48  loop_rate.sleep();
49  }
50  }
51 };
52 
53 int main( int argc, char ** argv )
54 {
55  ros::init( argc, argv, "semio_humanoid_server_node" );
56  //! - Create NodeHandle with relative namespace
57  ros::NodeHandle nh_rel( "~" );
58 
59  //! - Create vector of humanoid sinks; initialize with a semio::ros::HumanoidSinkROS publishing to `~humanoids/raw`
60  std::vector<semio::HumanoidSink::Ptr> humanoid_sinks{
61  std::make_shared<semio::ros::HumanoidSinkROS>( nh_rel, "humanoids/raw" ) };
62 
63  //! - If any form of smoothing is enabled, create a standard ROS humanoid sink via semio::ros::HumanoidSinkAdapter
64  if( nh_rel.hasParam( "humanoid_sink/filter/smoothing" ) )
65  {
66  humanoid_sinks.push_back( semio::ros::HumanoidSinkAdapter( nh_rel, "ros" ).getHumanoidSink() );
67  }
68 
69  //! - Create SemioHumanoidServerNode; pass node handle, humanoid source, and humanoid sinks
70  SemioHumanoidServerNode semio_humanoid_server_node(
71  semio::ros::HumanoidSourceAdapter( nh_rel ).getHumanoidSource(),
72  humanoid_sinks );
73 
74  //! - Start main loop SemioHumanoidServerNode::spin()
75  semio_humanoid_server_node.spin();
76 
77  return 0;
78 }
Utility class to simplify the creation of semio::HumanoidSink instances.
SemioHumanoidServerNode(semio::HumanoidSource::Ptr humanoid_source_ptr, std::vector< semio::HumanoidSink::Ptr > const &humanoid_sinks)
decltype(std::make_shared< HumanoidSource >()) typedef Ptr
std::vector< semio::HumanoidSink::Ptr > _humanoid_sinks
Vector of pointers to the output sinks for humanoids.
Utility class to simplify the creation of semio::HumanoidSource instances.
int main(int argc, char **argv)
Serve humanoids using source/sink model.
semio::HumanoidSource::Ptr _humanoid_source_ptr
Pointer to the input source for humanoids.