reachability_polygon.cpp
Go to the documentation of this file.
2 
3 
4 
6 {
8  : ReachabilityPlugin("reachability_polygon")
9  , ivpStepRange(nullptr)
10 {
11 }
12 
14 {
15  if (ivpStepRange)
16  delete[] ivpStepRange;
17 }
18 
19 bool ReachabilityPolygon::loadParams(const ParameterSet& params)
20 {
21  if (!ReachabilityPlugin::loadParams(params))
22  return false;
23 
24  int num_angle_bins;
25  params.getParam("collision_check/cell_size", cell_size);
26  params.getParam("collision_check/num_angle_bins", num_angle_bins);
27  angle_bin_size = 2.0*M_PI / static_cast<double>(num_angle_bins);
28 
29  // step range
30  std::vector<std::pair<int, int> > step_range;
31  XmlRpc::XmlRpcValue step_range_x;
32  XmlRpc::XmlRpcValue step_range_y;
33 
34  if (!params.getParam("step_range/x", step_range_x) || !params.getParam("step_range/y", step_range_y))
35  {
36  ROS_ERROR("Can't initialize ReachabilityPolygon due to missing step_range in parameter set!");
37  return false;
38  }
39 
40  assert((step_range_x.size() == step_range_y.size()) && (step_range_x.size() > 0));
41 
42  // load step range
43  step_range.clear();
44  step_range.reserve(step_range_x.size());
45 
46  for (int i = 0; i < step_range_x.size(); i++)
47  {
48  double x = static_cast<double>(step_range_x[i]);
49  double y = static_cast<double>(step_range_y[i]);
50 
51  step_range.push_back(std::pair<int, int>(disc_val(x, cell_size), disc_val(y, cell_size)));
52  }
53 
54  // get step range limits
55  params.getParam("max_step_range/x", max_step_range_x);
56  params.getParam("max_step_range/y", max_step_range_y);
57  params.getParam("max_step_range/yaw", max_step_range_yaw);
58 
59  params.getParam("max_step_range/inv_x", max_step_range_inv_x);
60  params.getParam("max_step_range/inv_y", max_step_range_inv_y);
61  params.getParam("max_step_range/inv_yaw", max_step_range_inv_yaw);
62 
63  params.getParam("max_step_range/width", max_step_range_width_sq);
65 
66  int max_step_range_x_disc = disc_val(max_step_range_x, cell_size);
67  int max_step_range_y_disc = disc_val(max_step_range_y, cell_size);
68 
69  int max_step_range_inv_x_disc = disc_val(max_step_range_inv_x, cell_size);
70  int max_step_range_inv_y_disc = disc_val(max_step_range_inv_y, cell_size);
71 
72  step_range_size_x = max_step_range_x_disc - max_step_range_inv_x_disc + 1;
73  step_range_size_y = max_step_range_y_disc - max_step_range_inv_y_disc + 1;
75 
76  if (ivpStepRange)
77  delete[] ivpStepRange;
78  ivpStepRange = new bool[step_range_size];
79 
80  // compute reachability polygon
81  ROS_INFO("Reachability Polygon:");
82  std::string msg;
83  for (int y = max_step_range_inv_y_disc; y <= max_step_range_y_disc; y++)
84  {
85  msg += boost::lexical_cast<std::string>(y) + ": ";
86  for (int x = max_step_range_inv_x_disc; x <= max_step_range_x_disc; x++)
87  {
88  ivpStepRange[(y - max_step_range_inv_y_disc) * step_range_size_x + (x - max_step_range_inv_x_disc)] = pointWithinPolygon(x, y, step_range);
89  msg += pointWithinPolygon(x, y, step_range) ? "+ " : "- ";
90  }
91  ROS_INFO("%s", msg.c_str());
92  msg.clear();
93  }
94 
95  return true;
96 }
97 
98 bool ReachabilityPolygon::isReachable(const State& current, const State& next) const
99 {
100  if (current.getLeg() == next.getLeg())
101  return false;
102 
103  if (euclidean_distance_sq(current.getX(), current.getY(), next.getX(), next.getY()) > max_step_range_width_sq)
104  return false;
105 
106  // reconstruct step primitive
107  tf::Transform step = current.getPose().inverse() * next.getPose();
108  double dx = step.getOrigin().x();
109  double dy = step.getOrigin().y();
110  double dyaw = angles::shortest_angular_distance(current.getYaw(), next.getYaw());
111 
112  // adjust for the left foot
113  if (current.getLeg() == LEFT)
114  {
115  dy = -dy;
116  dyaw = -dyaw;
117  }
118 
119  // consider discretization error
120  dx = pround(dx, cell_size);
121  dy = pround(dy, cell_size);
122  dyaw = pround(dyaw, angle_bin_size);
123 
124  // check if footstep_x is not within the executable range
125  if (dx > max_step_range_x || dx < max_step_range_inv_x)
126  return false;
127  // check if footstep_y is not within the executable range
128  if (dy > max_step_range_y || dy < max_step_range_inv_y)
129  return false;
130  // check if stance_yaw_diff is not within the executable range
131  if (dyaw > max_step_range_yaw || dyaw < max_step_range_inv_yaw)
132  return false;
133 
134  int footstep_x = floor((dx-max_step_range_inv_x) / cell_size);
135  int footstep_y = floor((dy-max_step_range_inv_y) / cell_size);
136 
137  assert((footstep_x + footstep_y * step_range_size_x) < step_range_size);
138 
139  // check reachability polygon
140  if (!ivpStepRange[footstep_x + footstep_y * step_range_size_x])
141  return false;
142 
143  return true;
144 }
145 }
146 
147 #include <pluginlib/class_list_macros.h>
148 PLUGINLIB_EXPORT_CLASS(vigir_footstep_planning::ReachabilityPolygon, vigir_footstep_planning::ReachabilityPlugin)
bool loadParams(const ParameterSet &params=vigir_generic_params::ParameterSet()) override
int size() const
bool isReachable(const State &current, const State &next) const override
#define ROS_INFO(...)
#define ROS_ERROR(...)


vigir_footstep_planning_default_plugins
Author(s): Alexander Stumpf
autogenerated on Sun Nov 17 2019 03:30:01