map_step_cost_estimator.cpp
Go to the documentation of this file.
2 
3 
4 
6 {
8  : StepCostEstimatorPlugin("map_step_cost_estimator")
9 {
10 }
11 
12 bool MapStepCostEstimator::loadParams(const vigir_generic_params::ParameterSet& params)
13 {
14  if (!StepCostEstimatorPlugin::loadParams(params))
15  return false;
16 
17  std::string filename;
18  params.getParam("map_step_cost_estimator/file", filename);
19 
20  loadFromFile(filename);
21 
22  return true;
23 }
24 
25 bool MapStepCostEstimator::getCost(const State& left_foot, const State& right_foot, const State& swing_foot, double& cost, double& cost_multiplier, double& risk, double& risk_multiplier) const
26 {
27  cost = 0.0;
28  cost_multiplier = 1.0;
29  risk = 0.0;
30  risk_multiplier = 1.0;
31 
32  const State& stand_foot = swing_foot.getLeg() == LEFT ? right_foot : left_foot;
33  double foot_dist = euclidean_distance(stand_foot.getX(), stand_foot.getY(), swing_foot.getX(), swing_foot.getY());
34 
35  const State& swing_foot_before = swing_foot.getLeg() == LEFT ? left_foot : right_foot;
36  double dist = 0.5*euclidean_distance(swing_foot_before.getX(), swing_foot_before.getY(), swing_foot.getX(), swing_foot.getY());
37 
38  if (dist > 0.3 || foot_dist > 0.45)
39  {
40  risk = 1.0;
41  }
42  else
43  {
44  StepCostKey key(left_foot, right_foot, swing_foot, cell_size, angle_bin_size);
45  boost::unordered_map<StepCostKey, std::pair<double, double> >::const_iterator iter = cost_map.find(key);
46 
47  if (iter == cost_map.end())
48  {
49  risk = 1.0;
50  }
51  else
52  {
53  risk = iter->second.second <= 0.25 ? abs(iter->second.first) : 1.0;
54  }
55  }
56 
57  //std::vector<double> state;
58  //key.getState(state);
59  //ROS_INFO("%f %f %f | %f %f %f", swing_foot_before.getX(), swing_foot_before.getY(), swing_foot_before.getYaw(), swing_foot.getX(), swing_foot.getY(), swing_foot.getYaw());
60  //ROS_INFO("%f %f %f | %f %f %f", state[0], state[1], state[2], state[3], state[4], state[5]);
61  //ROS_INFO("------");
62  //if (risk_cost < 1.0 && state[5] > 0.0)
63  // ROS_INFO("Cost: %f + %f + %f Yaw: %f", dist, risk_cost, default_step_cost, state[5]);
64 
65  cost = dist + 2*risk*risk;
66  return true;
67 }
68 
69 void MapStepCostEstimator::insert(const std::vector<double> &key, const std::pair<double, double> &entry)
70 {
72 }
73 
74 void MapStepCostEstimator::loadFromFile(const std::string &filename)
75 {
76  // open file
77  std::ifstream file;
78  file.open(filename.c_str(), std::ios::in | std::ios::binary);
79 
80  if (!file.is_open())
81  {
82  ROS_ERROR("Could not read from file %s", filename.c_str());
83  return;
84  }
85 
86  /* read model */
87 
88  // boundaries
89  read<float>(file, min_x);
90  read<float>(file, max_x);
91  read<float>(file, min_y);
92  read<float>(file, max_y);
93  read<float>(file, min_yaw);
94  read<float>(file, max_yaw);
95 
96  // resolution
97  float temp;
98  read<float>(file, temp);
99  cell_size = temp;
100  read<uint32_t>(file, num_angle_bin);
101  angle_bin_size = 2.0*M_PI/(double)num_angle_bin;
102 
103  // size
104  uint32_t dim_size, num_elements;
105  read<uint32_t>(file, num_elements);
106  read<uint32_t>(file, dim_size);
107  dim_size -= 2;
108 
109  // load map
110  std::vector<double> key;
111  key.resize(dim_size);
112  std::pair<double, double> entry;
113 
114  cost_map.clear();
115  for (unsigned int i = 0; i < num_elements; i++)
116  {
117  // load key
118  for (unsigned int d = 0; d < dim_size; d++)
119  {
120  float k;
121  read<float>(file, k);
122  key[d] = k;
123  }
124 
125  // load entry
126  float c, s;
127  read<float>(file, c); // cost estimation
128  read<float>(file, s); // variance
129  entry.first = c;
130  entry.second = s;
131 
132  // insert to map
133  insert(key, entry);
134  }
135 
136  ROS_INFO("Boundaries (x/y/yaw): %f %f %f %f %f %f", min_x, max_x, min_y, max_y, min_yaw, max_yaw);
137  ROS_INFO("Resolution: long: %f rot: %u %f", cell_size, num_angle_bin, angle_bin_size);
138  ROS_INFO("Loaded step cost map: %u dimensions and %lu entries", dim_size, cost_map.size());
139 
140  // close file
141  file.close();
142 }
143 }
144 
145 #include <pluginlib/class_list_macros.h>
146 PLUGINLIB_EXPORT_CLASS(vigir_footstep_planning::MapStepCostEstimator, vigir_footstep_planning::StepCostEstimatorPlugin)
d
filename
XmlRpcServer s
void insert(const std::vector< double > &key, const std::pair< double, double > &entry)
boost::unordered_map< StepCostKey, std::pair< double, double > > cost_map
bool loadParams(const vigir_generic_params::ParameterSet &params=vigir_generic_params::ParameterSet()) override
#define ROS_INFO(...)
bool getCost(const State &left_foot, const State &right_foot, const State &swing_foot, double &cost, double &cost_multiplier, double &risk, double &risk_multiplier) const override
#define ROS_ERROR(...)


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