control_setting.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <std_msgs/String.h>
3 #include <ros/console.h>
4 #include <string>
5 #include <sstream>
6 #include <map>
8 
10  : node_handle(handle)
11 {
12  joint_num = 0;
13  port_name = "";
14  joint_list.clear();
15 }
16 
18 {
19  /* Nothing todo... */
20 }
21 
23 {
24  bool result;
25 
26  /* Loading tty port name */
27  std::string device_name;
28  uint32_t baudrate;
29 
30  /* Loading tty port name */
31  result = true;
32  device_name = loadPortName();
33  if( device_name.length() > 0 ){
34  port_name = device_name;
35  }else{
36  return false;
37  }
38  /* Loading tty baudrate */
39  baudrate = loadBaudRate();
40  if( baudrate > 0 ){
41  port_baud_rate = baudrate;
42  }else{
43  result = false;
44  }
45  /* Loading joints list */
46  if( loadJointList() ){
48  }else{
49  result = false;
50  }
51 
52  return result;
53 }
54 
55 std::string CONTROL_SETTING::loadPortName( void )
56 {
57  std::string key_port_name = KEY_DXL_PORT;
58  std::string result;
59 
60  key_port_name += KEY_PORTNAME;
61  if( !node_handle.getParam( key_port_name, result ) ){
62  ROS_ERROR("Undefined key %s.", key_port_name.c_str());
63  result = "";
64  }
65 
66  return result;
67 }
68 
70 {
71  std::string key_baud_rate = KEY_DXL_PORT;
72  key_baud_rate += KEY_BAUDRATE;
73  int result;
74 
75  if( !node_handle.getParam( key_baud_rate, result ) ){
76  ROS_ERROR("Undefined key %s.", key_baud_rate.c_str());
77  result = 0;
78  }
79 
80  return (uint32_t)result;
81 }
82 
84 {
85  std::string key_joint_list = KEY_DXL_PORT;
86  bool result = false;
87  XmlRpc::XmlRpcValue load_joints;
88 
89  key_joint_list += KEY_JOINTS;
90  if( !node_handle.getParam( key_joint_list, load_joints ) ){
91  ROS_ERROR("Undefined key %s.", key_joint_list.c_str());
92  }else{
93  if( load_joints.getType() != XmlRpc::XmlRpcValue::TypeArray ){
94  ROS_ERROR("XmlRpc get type error! line%d", __LINE__);
95  }else{
96  for( int32_t i = 0; i < load_joints.size(); ++i ){
97  if( load_joints[i].getType() != XmlRpc::XmlRpcValue::TypeString ){
98  ROS_ERROR("XmlRpc get type[%d] error! line%d", i, __LINE__);
99  }else{
100  XmlRpc::XmlRpcValue &joint_name_work = load_joints[i];
101  ST_SERVO_PARAM work;
102  work.name = (std::string)joint_name_work;
103  joint_list.push_back( work );
104  }
105  }
106  joint_num = joint_list.size();
107  result = true;
108  }
109  }
110  return result;
111 }
112 
114 {
115  std::string key_joint_param = std::string(KEY_DXL_PORT) + "/";
116  XmlRpc::XmlRpcValue load_joint_param;
117  int load_id = 0;
118  int load_center = DEFAULT_CENTER;
119  int load_home = DEFAULT_CENTER;
120  double load_eff_cnst = DEFAULT_EFF_CNST;
121  int load_mode = DEFAULT_OPE_MODE;
122  bool load_result;
123  bool result = true;
124 
125  for( int jj=0 ; jj<joint_list.size() ; ++jj ){
126  std::string key_jname = (key_joint_param + joint_list[jj].name);
127  std::string key_jparam_id = (key_jname + KEY_JPARAM_ID);
128  std::string key_jparam_center = (key_jname + KEY_JPARAM_CENTER);
129  std::string key_jparam_home = (key_jname + KEY_JPARAM_HOME);
130  std::string key_jparam_eff_cnst = (key_jname + KEY_JPARAM_EFFCNST);
131  std::string key_jparam_mode = (key_jname + KEY_JPARAM_OPEMODE);
132  load_result = true;
133 
134  if( !node_handle.getParam( key_jparam_id, load_id ) ){
135  ROS_ERROR("Undefined joint id key %s. line%d", key_jparam_id.c_str(), __LINE__);
136  load_result = false;
137  }
138  if( !node_handle.getParam( key_jparam_center, load_center ) ){
139  ROS_ERROR("Undefined joint id key %s. line%d", key_jparam_id.c_str(), __LINE__);
140  load_result = false;
141  }
142  if( !node_handle.getParam( key_jparam_home, load_home ) ){
143  ROS_ERROR("Undefined joint id key %s. line%d", key_jparam_id.c_str(), __LINE__);
144  load_result = false;
145  }
146  if( !node_handle.getParam( key_jparam_eff_cnst, load_eff_cnst ) ){
147  ROS_ERROR("Undefined joint id key %s. line%d", key_jparam_id.c_str(), __LINE__);
148  load_result = false;
149  }
150  if( !node_handle.getParam( key_jparam_mode, load_mode ) ){
151  ROS_ERROR("Undefined joint id key %s. line%d", key_jparam_id.c_str(), __LINE__);
152  load_result = false;
153  }
154  if( load_result ){
155  joint_list[jj].id = load_id;
156  joint_list[jj].center = load_center;
157  joint_list[jj].home = load_home;
158  joint_list[jj].eff_cnst = load_eff_cnst;
159  joint_list[jj].mode = load_mode;
160  }else{
161  result = false;
162  break;
163  }
164  }
165 
166  return result;
167 }
168 
#define KEY_DXL_PORT
#define KEY_PORTNAME
uint32_t port_baud_rate
std::string name
int size() const
#define KEY_JPARAM_ID
#define KEY_BAUDRATE
bool loadJointParam(void)
ros::NodeHandle node_handle
#define KEY_JPARAM_EFFCNST
#define KEY_JPARAM_CENTER
Type const & getType() const
#define KEY_JPARAM_OPEMODE
#define DEFAULT_OPE_MODE
std::string loadPortName(void)
CONTROL_SETTING(ros::NodeHandle handle)
std::vector< ST_SERVO_PARAM > joint_list
uint32_t loadBaudRate(void)
#define KEY_JOINTS
#define DEFAULT_CENTER
bool getParam(const std::string &key, std::string &s) const
#define DEFAULT_EFF_CNST
#define ROS_ERROR(...)
bool loadJointList(void)
#define KEY_JPARAM_HOME
std::string port_name


crane_x7_control
Author(s): Hiroyuki Nomura , Geoffrey Biggs
autogenerated on Mon Mar 1 2021 03:18:36