14 if (!_nh.
hasParam(
"csv_config_dir"))
return false;
18 ROS_INFO(
"start to make stroke convert table");
20 ROS_INFO(
"finish to make stroke convert table");
26 (std::vector<seed_converter::StrokeMap>& _table,
const std::string _file_name)
30 std::ifstream ifs_0(
file_path_ +
"/" + _file_name, std::ios_base::in);
31 if (!ifs_0.is_open()) {
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());
44 sm.
angle = std::stof(str.substr(0, pos));
45 sm.
stroke = std::stof(str.substr(pos+1));
50 if (_table.at(1).angle < _table.at(0).angle) std::reverse(_table.begin(), _table.end());
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;
61 (std::vector<seed_converter::StrokeMap>& _inv_table,
62 const std::vector<seed_converter::StrokeMap>& _table)
68 if (_table.at(1).stroke < _table.at(0).stroke) std::reverse(_inv_table.begin(),_inv_table.end());
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);
78 (
const float _angle,
const std::vector<seed_converter::StrokeMap>& _table)
83 if (_angle < _table.front().angle) angle.
angle = _table.front().angle;
84 if (_angle > _table.back().angle) angle.
angle = _table.back().angle;
86 auto ref = std::upper_bound(_table.begin()+1, _table.end()-1, angle,
92 return ref->stroke - (ref->angle - angle.
angle) * ref->range;
96 (
const float _stroke,
const std::vector<seed_converter::StrokeMap>& _inv_table)
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;
104 auto ref = std::upper_bound(_inv_table.begin()+1, _inv_table.end()-1, stroke,
110 return ref->angle - (ref->stroke - stroke.
stroke) / ref->range;
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)
121 if (_is_pitch)
return {stroke2 + stroke1, stroke1 - stroke2};
122 else return {stroke2 + stroke1, stroke2 - stroke1};
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)
TFSIMD_FORCE_INLINE const tfScalar & x() const
float setAngleToStroke(const float _angle, const std::vector< StrokeMap > &_table)
virtual void makeTables()=0
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)