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>
7 #include <algorithm>
8 #include <string>
9 
13 
15 {
17 {
18  ros::NodeHandle nh("~/" + name_), g_nh;
19  current_ = true;
20  first_time_ = true;
21  people_sub_ = nh.subscribe("/people", 1, &SocialLayer::peopleCallback, this);
22 }
23 
24 void SocialLayer::peopleCallback(const people_msgs::People& people)
25 {
26  boost::recursive_mutex::scoped_lock lock(lock_);
27  people_list_ = people;
28 }
29 
30 
31 void SocialLayer::updateBounds(double origin_x, double origin_y, double origin_z, double* min_x, double* min_y,
32  double* max_x, double* max_y)
33 {
34  boost::recursive_mutex::scoped_lock lock(lock_);
35 
36  std::string global_frame = layered_costmap_->getGlobalFrameID();
37  transformed_people_.clear();
38 
39  for (unsigned int i = 0; i < people_list_.people.size(); i++)
40  {
41  people_msgs::Person& person = people_list_.people[i];
42  people_msgs::Person tpt;
43  geometry_msgs::PointStamped pt, opt;
44 
45  try
46  {
47  pt.point.x = person.position.x;
48  pt.point.y = person.position.y;
49  pt.point.z = person.position.z;
50  pt.header.frame_id = people_list_.header.frame_id;
51  tf_.transformPoint(global_frame, pt, opt);
52  tpt.position.x = opt.point.x;
53  tpt.position.y = opt.point.y;
54  tpt.position.z = opt.point.z;
55 
56  pt.point.x += person.velocity.x;
57  pt.point.y += person.velocity.y;
58  pt.point.z += person.velocity.z;
59  tf_.transformPoint(global_frame, pt, opt);
60 
61  tpt.velocity.x = opt.point.x - tpt.position.x;
62  tpt.velocity.y = opt.point.y - tpt.position.y;
63  tpt.velocity.z = opt.point.z - tpt.position.z;
64 
65  transformed_people_.push_back(tpt);
66  }
67  catch (tf::LookupException& ex)
68  {
69  ROS_ERROR("No Transform available Error: %s\n", ex.what());
70  continue;
71  }
72  catch (tf::ConnectivityException& ex)
73  {
74  ROS_ERROR("Connectivity Error: %s\n", ex.what());
75  continue;
76  }
77  catch (tf::ExtrapolationException& ex)
78  {
79  ROS_ERROR("Extrapolation Error: %s\n", ex.what());
80  continue;
81  }
82  }
83  updateBoundsFromPeople(min_x, min_y, max_x, max_y);
84  if (first_time_)
85  {
86  last_min_x_ = *min_x;
87  last_min_y_ = *min_y;
88  last_max_x_ = *max_x;
89  last_max_y_ = *max_y;
90  first_time_ = false;
91  }
92  else
93  {
94  double a = *min_x, b = *min_y, c = *max_x, d = *max_y;
95  *min_x = std::min(last_min_x_, *min_x);
96  *min_y = std::min(last_min_y_, *min_y);
97  *max_x = std::max(last_max_x_, *max_x);
98  *max_y = std::max(last_max_y_, *max_y);
99  last_min_x_ = a;
100  last_min_y_ = b;
101  last_max_x_ = c;
102  last_max_y_ = d;
103  }
104 }
105 }; // namespace social_navigation_layers
d
LayeredCostmap * layered_costmap_
std::list< people_msgs::Person > transformed_people_
Definition: social_layer.h:37
std::string getGlobalFrameID() const
virtual void updateBoundsFromPeople(double *min_x, double *min_y, double *max_x, double *max_y)=0
void transformPoint(const std::string &target_frame, const geometry_msgs::PointStamped &stamped_in, geometry_msgs::PointStamped &stamped_out) 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)
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 Thu Mar 4 2021 04:02:57