JointLimitTable.cpp
Go to the documentation of this file.
1 #include "JointLimitTable.h"
2 #include <iostream>
3 #include <iomanip>
4 #include <limits.h>
5 #include <float.h>
6 
7 double hrp::JointLimitTable::getInterpolatedLimitAngle (const double target_joint_angle, const bool is_llimit_angle) const
8 {
9  double target_angle = target_joint_angle * 180.0 / M_PI; // [rad]=>[deg]
10  int int_target_angle = static_cast<int>(std::floor(target_angle));
11  int target_range[2] = {int_target_angle, 1+int_target_angle};
12  double self_joint_range[2];
13  for (size_t i = 0; i < 2; i++) {
15  self_joint_range[i] = (is_llimit_angle ? llimit_table(idx) : ulimit_table(idx));
16  }
17  double tmp_ratio = target_angle - int_target_angle;
18  return (self_joint_range[0] * (1-tmp_ratio) + self_joint_range[1] * tmp_ratio) * M_PI / 180.0; // [deg]=>[rad]
19 };
20 
21 void hrp::readJointLimitTableFromProperties (std::map<std::string, hrp::JointLimitTable>& joint_limit_tables,
23  const std::string& prop_string,
24  const std::string& instance_name)
25 {
26  if (prop_string != "") {
27  coil::vstring limit_tables = coil::split(prop_string, ":");
28  size_t limit_table_size = 6; // self_joint_name:target_joint_name:target_min_angle:target_max_angle:min:max
29  size_t num_limit_table = limit_tables.size() / limit_table_size;
30  std::cerr << "[" << instance_name << "] Load joint limit table [" << num_limit_table << "]" << std::endl;
31  for (size_t i = 0; i < num_limit_table; i++) {
32  size_t start_idx = i*limit_table_size;
34  coil::stringTo(target_llimit_angle, limit_tables[start_idx+2].c_str());
35  coil::stringTo(target_ulimit_angle, limit_tables[start_idx+3].c_str());
36  coil::vstring llimit_str_v = coil::split(limit_tables[start_idx+4], ",");
37  coil::vstring ulimit_str_v = coil::split(limit_tables[start_idx+5], ",");
38  hrp::dvector llimit_table(llimit_str_v.size()), ulimit_table(ulimit_str_v.size());
39  int target_jointId = -1;
40  for (size_t j = 0; j < m_robot->numJoints(); j++) {
41  if ( m_robot->joint(j)->name == limit_tables[start_idx+1]) target_jointId = m_robot->joint(j)->jointId;
42  }
43  if ( llimit_str_v.size() != ulimit_str_v.size() || target_jointId == -1 ) {
44  std::cerr << "[" << instance_name << "] " << limit_tables[start_idx+0] << ":" << limit_tables[start_idx+1] << " fail" << std::endl;
45  } else {
46  std::cerr << "[" << instance_name << "] " << limit_tables[start_idx+0] << ":" << limit_tables[start_idx+1] << "(" << target_jointId << ")" << std::endl;
47  std::cerr << "[" << instance_name << "] target_llimit_angle " << limit_tables[start_idx+2] << "[deg], target_ulimit_angle " << limit_tables[start_idx+3] << "[deg]" << std::endl;
48  std::cerr << "[" << instance_name << "] llimit_table[deg] " << limit_tables[start_idx+4] << std::endl;
49  std::cerr << "[" << instance_name << "] ulimit_table[deg] " << limit_tables[start_idx+5] << std::endl;
50  for (int j = 0; j < llimit_table.size(); j++) {
51  coil::stringTo(llimit_table[j], llimit_str_v[j].c_str());
52  coil::stringTo(ulimit_table[j], ulimit_str_v[j].c_str());
53  }
54  joint_limit_tables.insert(std::pair<std::string, hrp::JointLimitTable>(limit_tables[start_idx],
55  hrp::JointLimitTable(target_jointId, target_llimit_angle, target_ulimit_angle, llimit_table, ulimit_table)));
56  }
57  }
58  } else {
59  std::cerr << "[" << instance_name << "] Do not load joint limit table" << std::endl;
60  }
61 };
#define max(a, b)
bool stringTo(To &val, const char *str)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
hrp::dvector llimit_table
hrp::dvector ulimit_table
png_uint_32 i
Eigen::VectorXd dvector
void readJointLimitTableFromProperties(std::map< std::string, hrp::JointLimitTable > &joint_mm_tables, hrp::BodyPtr m_robot, const std::string &prop_string, const std::string &instance_name)
#define min(a, b)
std::vector< std::string > vstring
double getInterpolatedLimitAngle(const double target_joint_angle, const bool is_llimit_angle) const
def j(str, encoding="cp932")
#define M_PI
hrp::BodyPtr m_robot


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50