semio_ros  0.10.6
humanoid_sink_adapter.cpp
Go to the documentation of this file.
2 
4 
5 semio::ros::HumanoidSinkAdapter::HumanoidSinkAdapter( ::ros::NodeHandle const & nh_rel, std::string const & default_sink )
6 :
7  _nh_rel( nh_rel ),
8  _default_sink( default_sink )
9 {
10  //
11 }
12 
14 {
15  std::string const & sink_type( sink == "param" ? _nh_rel.param( std::string( "humanoid_sink/type" ), _default_sink ) : sink );
16 
18 
19  // apply smoothing filter if specified via params
20  std::shared_ptr<semio::HumanoidSmoothingFilter> smoothing_filter_ptr;
21  {
22  typedef std::function<void(std::string const &)> _ParamFunc;
23  typedef std::pair<std::string, _ParamFunc> _ParamOp;
24 
25  for( auto const & param_op : {
26  _ParamOp(
27  "humanoid_sink/filter/smoothing/add",
28  []( std::string const & param_name ){} ),
29  _ParamOp(
30  "humanoid_sink/filter/smoothing/position",
31  [this,&smoothing_filter_ptr]( std::string const & param_name ){
32  smoothing_filter_ptr->setPositionSmoothing( semio::HumanoidSmoothingFilter::getSmoothing( 0.75, this->_nh_rel.param<double>( param_name, 0 ) ) );
33  } ),
34  _ParamOp(
35  "humanoid_sink/filter/smoothing/orientation",
36  [this,&smoothing_filter_ptr]( std::string const & param_name ){
37  smoothing_filter_ptr->setOrientationSmoothing( semio::HumanoidSmoothingFilter::getSmoothing( 0.75, this->_nh_rel.param<double>( param_name, 0 ) ) );
38  } ),
39  _ParamOp(
40  "humanoid_sink/filter/smoothing/confidence",
41  [this,&smoothing_filter_ptr]( std::string const & param_name ){
42  smoothing_filter_ptr->setConfidenceSmoothing( semio::HumanoidSmoothingFilter::getSmoothing( 0.75, this->_nh_rel.param<double>( param_name, 0 ) ) );
43  } ),
44  _ParamOp(
45  "humanoid_sink/filter/smoothing/window",
46  [this,&smoothing_filter_ptr]( std::string const & param_name ){
47  smoothing_filter_ptr->setSmoothingWindow( this->_nh_rel.param<double>( param_name, 0 ) );
48  } ) } )
49  {
50  auto const & param_name( param_op.first );
51 
52  if( _nh_rel.hasParam( param_name ) )
53  {
54  if( !smoothing_filter_ptr ) smoothing_filter_ptr = std::make_shared<semio::HumanoidSmoothingFilter>();
55 
56  param_op.second( param_name );
57  }
58  }
59  }
60 
61  if( sink_type == "ros" )
62  {
63  if( smoothing_filter_ptr ) result = std::make_shared<semio::ros::HumanoidSinkROS>( _nh_rel, "humanoids/smoothed" );
64  else result = std::make_shared<semio::ros::HumanoidSinkROS>( _nh_rel );
65  }
66  else return std::make_shared<semio::ros::HumanoidSinkROS>( ::ros::NodeHandle( _nh_rel, "/null" ) );
67 
68  // add a smoothing filter and a basic state filter (to remove untracked smoothed humanoids)
69  if( smoothing_filter_ptr )
70  {
71  auto & result_filter( result->getFilter() );
72  result_filter.addFilter( smoothing_filter_ptr );
73  result_filter.addFilter( std::make_shared<semio::HumanoidStateFilter>( semio::HumanoidStateFilter::getStandardFilterHumanoid() ) );
74  }
75 
76  return result;
77 }
decltype(std::make_shared< HumanoidSink >()) typedef Ptr
::ros::NodeHandle _nh_rel
NodeHandle copy for interfacing with ROS.
static double getSmoothing(double const &factor, double const &duration)
HumanoidSinkAdapter(::ros::NodeHandle const &nh_rel, std::string const &default_sink="ros")
static _FilterFuncArray const & getStandardFilterHumanoid()
std::string _default_sink
The type of sink to use by default if param mode is selected and the ROS param _humanoid_sink/type is...
HumanoidSink::Ptr getHumanoidSink(std::string const &sink="param")
Create a semio::HumanoidSink.