stroke_converter_base.cpp
Go to the documentation of this file.
2 
3 
5 {
6 }
7 
9 {
10 }
11 
13 {
14  if (!_nh.hasParam("csv_config_dir")) return false;
15 
16  _nh.getParam("csv_config_dir", file_path_); // e.g. $(find package)/config/csv
17 
18  ROS_INFO("start to make stroke convert table");
19  makeTables();
20  ROS_INFO("finish to make stroke convert table");
21 
22  return true;
23 }
24 
26 (std::vector<seed_converter::StrokeMap>& _table, const std::string _file_name)
27 {
28  _table.clear();
29 
30  std::ifstream ifs_0(file_path_ + "/" + _file_name, std::ios_base::in);
31  if (!ifs_0.is_open()) {
32  ROS_ERROR("can't find %s at %s", _file_name.c_str(), file_path_.c_str());
33  return false;
34  }
35 
36  std::string str;
37  while (getline(ifs_0, str)) {
38  size_t pos = str.find(',');
39  if (pos == std::string::npos) {
40  ROS_ERROR("%s has invalid structure", _file_name.c_str());
41  return false;
42  }
44  sm.angle = std::stof(str.substr(0, pos));
45  sm.stroke = std::stof(str.substr(pos+1));
46  _table.push_back(sm);
47  }
48 
49  //sort in ascending order
50  if (_table.at(1).angle < _table.at(0).angle) std::reverse(_table.begin(), _table.end());
51 
52  _table.front().range = 0;
53  for (size_t i = 1; i < _table.size() ; ++i) {
54  _table.at(i).range = _table.at(i).stroke - _table.at(i-1).stroke;
55  }
56 
57  return true;
58 }
59 
61 (std::vector<seed_converter::StrokeMap>& _inv_table,
62  const std::vector<seed_converter::StrokeMap>& _table)
63 {
64  _inv_table.clear();
65  _inv_table = _table;
66 
67  //sort in ascending order
68  if (_table.at(1).stroke < _table.at(0).stroke) std::reverse(_inv_table.begin(),_inv_table.end());
69 
70  _inv_table.front().range = 0;
71  int sign = (_table.at(1).range < 0 ? -1 : 1);
72  for (size_t i = 1; i < _inv_table.size() ; ++i) {
73  _inv_table.at(i).range = sign * (_inv_table.at(i).stroke - _inv_table.at(i-1).stroke);
74  }
75 }
76 
78 (const float _angle, const std::vector<seed_converter::StrokeMap>& _table)
79 {
81  angle.angle = _angle;
82  //limit
83  if (_angle < _table.front().angle) angle.angle = _table.front().angle;
84  if (_angle > _table.back().angle) angle.angle = _table.back().angle;
85 
86  auto ref = std::upper_bound(_table.begin()+1, _table.end()-1, angle,
88  bool {
89  return x.angle < y.angle;
90  });
91 
92  return ref->stroke - (ref->angle - angle.angle) * ref->range;
93 }
94 
96 (const float _stroke, const std::vector<seed_converter::StrokeMap>& _inv_table)
97 {
99  stroke.stroke = _stroke;
100  //limit
101  if (_stroke < _inv_table.front().stroke) stroke.stroke = _inv_table.front().stroke;
102  if (_stroke > _inv_table.back().stroke) stroke.stroke = _inv_table.back().stroke;
103 
104  auto ref = std::upper_bound(_inv_table.begin()+1, _inv_table.end()-1, stroke,
106  bool {
107  return x.stroke < y.stroke;
108  });
109 
110  return ref->angle - (ref->stroke - stroke.stroke) / ref->range;
111 }
112 
114 (const float _r_angle, const float _p_angle,
115  const std::vector<seed_converter::StrokeMap>& _r_table,
116  const std::vector<seed_converter::StrokeMap>& _p_table, const bool _is_pitch)
117 {
118  float stroke1 = setAngleToStroke(_r_angle, _r_table);
119  float stroke2 = setAngleToStroke(_p_angle, _p_table);
120 
121  if (_is_pitch) return {stroke2 + stroke1, stroke1 - stroke2};
122  else return {stroke2 + stroke1, stroke2 - stroke1};
123 }
bool makeTable(std::vector< StrokeMap > &_table, const std::string _file_name)
float setStrokeToAngle(const float _stroke, const std::vector< StrokeMap > &_inv_table)
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
#define ROS_INFO(...)
TFSIMD_FORCE_INLINE const tfScalar & x() const
float setAngleToStroke(const float _angle, const std::vector< StrokeMap > &_table)
bool getParam(const std::string &key, std::string &s) const
DiffJoint setDualAngleToStroke(const float _r_angle, const float _p_angle, const std::vector< StrokeMap > &_r_table, const std::vector< StrokeMap > &_p_table, const bool _is_pitch=false)
bool initialize(ros::NodeHandle &_nh)
bool hasParam(const std::string &key) const
void makeInvTable(std::vector< StrokeMap > &_inv_table, const std::vector< StrokeMap > &_table)
#define ROS_ERROR(...)


seed_r7_ros_controller
Author(s): Yohei Kakiuchi
autogenerated on Sun Apr 18 2021 02:40:34