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 
CONTROL_SETTING::loadBaudRate
uint32_t loadBaudRate(void)
Definition: control_setting.cpp:69
XmlRpc::XmlRpcValue::size
int size() const
CONTROL_SETTING::loadPortName
std::string loadPortName(void)
Definition: control_setting.cpp:55
KEY_JOINTS
#define KEY_JOINTS
Definition: control_setting.h:23
DEFAULT_OPE_MODE
#define DEFAULT_OPE_MODE
Definition: control_setting.h:32
CONTROL_SETTING::joint_num
uint32_t joint_num
Definition: control_setting.h:68
CONTROL_SETTING::CONTROL_SETTING
CONTROL_SETTING(ros::NodeHandle handle)
Definition: control_setting.cpp:9
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros.h
SERVO_PARAM::name
std::string name
Definition: control_setting.h:43
CONTROL_SETTING::loadJointList
bool loadJointList(void)
Definition: control_setting.cpp:83
KEY_DXL_PORT
#define KEY_DXL_PORT
Definition: control_setting.h:20
DEFAULT_CENTER
#define DEFAULT_CENTER
Definition: control_setting.h:30
console.h
CONTROL_SETTING::load
bool load(void)
Definition: control_setting.cpp:22
XmlRpc::XmlRpcValue::TypeString
TypeString
control_setting.h
KEY_JPARAM_HOME
#define KEY_JPARAM_HOME
Definition: control_setting.h:26
DEFAULT_EFF_CNST
#define DEFAULT_EFF_CNST
Definition: control_setting.h:31
CONTROL_SETTING::port_name
std::string port_name
Definition: control_setting.h:66
XmlRpc::XmlRpcValue::getType
const Type & getType() const
KEY_JPARAM_ID
#define KEY_JPARAM_ID
Definition: control_setting.h:24
KEY_BAUDRATE
#define KEY_BAUDRATE
Definition: control_setting.h:22
KEY_PORTNAME
#define KEY_PORTNAME
Definition: control_setting.h:21
XmlRpc::XmlRpcValue::TypeArray
TypeArray
KEY_JPARAM_EFFCNST
#define KEY_JPARAM_EFFCNST
Definition: control_setting.h:27
CONTROL_SETTING::loadJointParam
bool loadJointParam(void)
Definition: control_setting.cpp:113
CONTROL_SETTING::node_handle
ros::NodeHandle node_handle
Definition: control_setting.h:64
ROS_ERROR
#define ROS_ERROR(...)
CONTROL_SETTING::port_baud_rate
uint32_t port_baud_rate
Definition: control_setting.h:67
SERVO_PARAM
Definition: control_setting.h:35
CONTROL_SETTING::~CONTROL_SETTING
~CONTROL_SETTING()
Definition: control_setting.cpp:17
KEY_JPARAM_CENTER
#define KEY_JPARAM_CENTER
Definition: control_setting.h:25
XmlRpc::XmlRpcValue
KEY_JPARAM_OPEMODE
#define KEY_JPARAM_OPEMODE
Definition: control_setting.h:28
ros::NodeHandle
CONTROL_SETTING::joint_list
std::vector< ST_SERVO_PARAM > joint_list
Definition: control_setting.h:69


sciurus17_control
Author(s): Hiroyuki Nomura
autogenerated on Fri Aug 2 2024 08:37:24