social_layer.cpp
Go to the documentation of this file.
1 // Copyright 2018 David V. Lu!!
3 #include <math.h>
4 #include <angles/angles.h>
5 #include <geometry_msgs/PointStamped.h>
8 #include <algorithm>
9 #include <string>
10 
14 
16 {
18 {
19  ros::NodeHandle nh("~/" + name_), g_nh;
20  current_ = true;
21  first_time_ = true;
22  people_sub_ = nh.subscribe("/people", 1, &SocialLayer::peopleCallback, this);
23 }
24 
25 void SocialLayer::peopleCallback(const people_msgs::People& people)
26 {
27  boost::recursive_mutex::scoped_lock lock(lock_);
28  people_list_ = people;
29 }
30 
31 
32 void SocialLayer::updateBounds(double origin_x, double origin_y, double origin_z, double* min_x, double* min_y,
33  double* max_x, double* max_y)
34 {
35  boost::recursive_mutex::scoped_lock lock(lock_);
36 
37  std::string global_frame = layered_costmap_->getGlobalFrameID();
38  transformed_people_.clear();
39 
40  for (unsigned int i = 0; i < people_list_.people.size(); i++)
41  {
42  people_msgs::Person& person = people_list_.people[i];
43  people_msgs::Person tpt;
44  geometry_msgs::PointStamped pt, opt;
45 
46  try
47  {
48  pt.point.x = person.position.x;
49  pt.point.y = person.position.y;
50  pt.point.z = person.position.z;
51  pt.header.frame_id = people_list_.header.frame_id;
52  pt.header.stamp = people_list_.header.stamp;
53  tf_->transform(pt, opt, global_frame);
54  tpt.position.x = opt.point.x;
55  tpt.position.y = opt.point.y;
56  tpt.position.z = opt.point.z;
57 
58  pt.point.x += person.velocity.x;
59  pt.point.y += person.velocity.y;
60  pt.point.z += person.velocity.z;
61  tf_->transform(pt, opt, global_frame);
62 
63  tpt.velocity.x = opt.point.x - tpt.position.x;
64  tpt.velocity.y = opt.point.y - tpt.position.y;
65  tpt.velocity.z = opt.point.z - tpt.position.z;
66 
67  transformed_people_.push_back(tpt);
68  }
69  catch (tf2::LookupException& ex)
70  {
71  ROS_ERROR("No Transform available Error: %s\n", ex.what());
72  continue;
73  }
74  catch (tf2::ConnectivityException& ex)
75  {
76  ROS_ERROR("Connectivity Error: %s\n", ex.what());
77  continue;
78  }
79  catch (tf2::ExtrapolationException& ex)
80  {
81  ROS_ERROR("Extrapolation Error: %s\n", ex.what());
82  continue;
83  }
84  }
85  updateBoundsFromPeople(min_x, min_y, max_x, max_y);
86  if (first_time_)
87  {
88  last_min_x_ = *min_x;
89  last_min_y_ = *min_y;
90  last_max_x_ = *max_x;
91  last_max_y_ = *max_y;
92  first_time_ = false;
93  }
94  else
95  {
96  double a = *min_x, b = *min_y, c = *max_x, d = *max_y;
97  *min_x = std::min(last_min_x_, *min_x);
98  *min_y = std::min(last_min_y_, *min_y);
99  *max_x = std::max(last_max_x_, *max_x);
100  *max_y = std::max(last_max_y_, *max_y);
101  last_min_x_ = a;
102  last_min_y_ = b;
103  last_max_x_ = c;
104  last_max_y_ = d;
105  }
106 }
107 }; // namespace social_navigation_layers
d
LayeredCostmap * layered_costmap_
std::list< people_msgs::Person > transformed_people_
Definition: social_layer.h:37
T & transform(const T &in, T &out, const std::string &target_frame, ros::Duration timeout=ros::Duration(0.0)) const
virtual void updateBoundsFromPeople(double *min_x, double *min_y, double *max_x, double *max_y)=0
std::string getGlobalFrameID() const
static const unsigned char FREE_SPACE
std::string name_
virtual void updateBounds(double origin_x, double origin_y, double origin_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
tf2_ros::Buffer * tf_
void peopleCallback(const people_msgs::People &people)
static const unsigned char LETHAL_OBSTACLE
static const unsigned char NO_INFORMATION
#define ROS_ERROR(...)


social_navigation_layers
Author(s): David V. Lu!!
autogenerated on Mon Feb 28 2022 22:55:31