bed_detection.cpp
Go to the documentation of this file.
1 /*************************************************************
2  Copyright (C) 2019 Earth Rover Limited. All rights reserved.
3 *************************************************************/
4 
13 
14 using BD = BedDetection;
15 
16 
17 BD::BedDetection(const ros::NodeHandle &node_handle, const ros::NodeHandle &private_node_handle) :
18  _nh(node_handle), _pnh(private_node_handle)
19 {
20  _is_init = true;
21  this->init();
22 }
23 
24 
25 void BD::init()
26 {
27  // topic names
28  std::string itopic_odom = "odom";
29  std::string otopic_is_straight = "is_straight";
30 
31  // Init variables
32  _first_time = true;
33 
34  // Get ROS parameters
35  std::string threshold_time = "/bed_detection/threshold_time";
36  if( !_nh.getParam(threshold_time, _threshold_time) )
37  {
38  ROS_ERROR_STREAM("[MAPPING] Missing parameter: " << threshold_time);
39  _threshold_time = 0.5;
40  }
41  ROS_INFO_STREAM("/threshold_time: " << _threshold_time);
42  std::string threshold_twist = "/bed_detection/threshold_twist";
43  if( !_nh.getParam(threshold_twist, _threshold_twist) )
44  {
45  ROS_ERROR_STREAM("[MAPPING] Missing parameter: " << threshold_twist);
46  _threshold_twist = 0.2;
47  }
48  ROS_INFO_STREAM("/threshold_twist: " << _threshold_twist);
49 
50  // Init subscribers
51  _sub_odom = _nh.subscribe(itopic_odom, 1, &BD::cb_is_straight, this);
52 
53  // Init publishers
54  _pub_is_straight = _nh.advertise<std_msgs::Bool>(otopic_is_straight, 1000);
55 
56 }
57 
58 
59 bool BD::ok()
60 {
61  return _is_init;
62 }
63 
64 
65 void BD::cb_is_straight(const nm::OdometryPtr& odom)
66 {
67  // get message data
68  _odom = *odom;
69 
70  // process message
71  std_msgs::Bool msg;
72  msg.data = BD::is_straight();
73  // msg.data = BD::is_straight_time();
74 
75  // publish result
77 
78 }
79 
80 
82 {
83  if( abs(_odom.twist.twist.angular.z) > _threshold_twist )
84  {
85  ROS_INFO_STREAM("false");
86  return false;
87  }
88  else
89  {
90  ROS_INFO_STREAM("true");
91  return true;
92  }
93 }
94 
95 
97 {
98  if( abs(_odom.twist.twist.angular.z) > _threshold_twist )
99  {
100  if (_first_time == true)
101  {
102  _tp_1 = ros::Time::now();
103  _first_time = false;
104  }
105  ros::Time tp_2 = ros::Time::now();
106  double track_time = (tp_2 - _tp_1).toSec();
107  // ROS_INFO_STREAM(track_time);
108  if (track_time > _threshold_time)
109  {
110  ROS_INFO_STREAM("Not Straight");
111  return false;
112  }
113  }
114  else
115  {
116  _first_time = true;
117  ROS_INFO_STREAM("Straight");
118  return true;
119  }
120 }
Header for theBed Detection Class.
bool is_straight()
void publish(const boost::shared_ptr< M > &message) const
double _threshold_twist
Definition: bed_detection.h:82
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool is_straight_time()
ros::Time _tp_1
Definition: bed_detection.h:83
nm::Odometry _odom
Definition: bed_detection.h:86
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool _is_init
states if system is init
Definition: bed_detection.h:79
ros::Publisher _pub_is_straight
Definition: bed_detection.h:76
#define ROS_INFO_STREAM(args)
BedDetection(const ros::NodeHandle &node_handle, const ros::NodeHandle &private_node_handle)
bool getParam(const std::string &key, std::string &s) const
static Time now()
double _threshold_time
Definition: bed_detection.h:81
void cb_is_straight(const nm::OdometryPtr &odom_sub)
#define ROS_ERROR_STREAM(args)
This class implements the detection of a bed given an odometry.
Definition: bed_detection.h:34
ros::NodeHandle _nh
node handle
Definition: bed_detection.h:69
ros::Subscriber _sub_odom
Definition: bed_detection.h:73


earth_rover_bed_detection
Author(s):
autogenerated on Wed Apr 28 2021 02:15:32