thormang3_walking_demo.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /*
18  * thormang3_walking_demo.cpp
19  *
20  * Created on: 2016. 2. 18.
21  * Author: Jay Song
22  */
23 
25 
28 
34 
36 
37 
38 double g_start_end_time = 2.0; //sec
39 double g_step_time = 1.0; //sec
40 double g_step_length = 0.1; //meter
41 double g_body_z_swap = 0.01; //meter
42 double g_foot_z_swap = 0.1; //meter
43 
44 
45 void walkingModuleStatusMSGCallback(const robotis_controller_msgs::StatusMsg::ConstPtr &msg)
46 {
47  ROS_INFO_STREAM("[" << msg->module_name <<"] : " << msg->status_msg);
48 }
49 
50 void initialize()
51 {
52  ros::NodeHandle nh;
53 
54  g_wholebody_ini_pose_pub = nh.advertise<std_msgs::String>("/robotis/base/ini_pose", 0);
55  g_enable_ctrl_module_pub = nh.advertise<std_msgs::String>("/robotis/enable_ctrl_module", 0);
56 
57  g_get_ref_step_data_client = nh.serviceClient<thormang3_walking_module_msgs::GetReferenceStepData>("/robotis/walking/get_reference_step_data");
58  g_add_step_data_array_client = nh.serviceClient<thormang3_walking_module_msgs::AddStepDataArray>("/robotis/walking/add_step_data");
59  g_is_running_client = nh.serviceClient<thormang3_walking_module_msgs::IsRunning>("/robotis/walking/is_running");
60 
61  g_set_balance_param_client = nh.serviceClient<thormang3_walking_module_msgs::SetBalanceParam>("/robotis/walking/set_balance_param");
62  g_set_feedback_gain_client = nh.serviceClient<thormang3_walking_module_msgs::SetJointFeedBackGain>("/robotis/walking/joint_feedback_gain");
63 
64  g_walking_module_status_msg_sub = nh.subscribe("/robotis/status", 10, walkingModuleStatusMSGCallback);
65 }
66 
68 {
69  std_msgs::String str_msg;
70  str_msg.data = "ini_pose";
71 
72  g_wholebody_ini_pose_pub.publish( str_msg );
73 }
74 
76 {
77  std_msgs::String set_ctrl_mode_msg;
78  set_ctrl_mode_msg.data = "walking_module";
79  g_enable_ctrl_module_pub.publish( set_ctrl_mode_msg );
80 }
81 
82 bool loadBalanceParam(thormang3_walking_module_msgs::SetBalanceParam& set_param)
83 {
84  ros::NodeHandle ros_node;
85  std::string balance_yaml_path = "";
86  balance_yaml_path = ros::package::getPath("thormang3_walking_demo") + "/data/balance_param.yaml";
87 
88  YAML::Node doc;
89  try
90  {
91  // load yaml
92  doc = YAML::LoadFile(balance_yaml_path.c_str());
93  }
94  catch(const std::exception& e)
95  {
96  ROS_ERROR("Failed to load balance param yaml file.");
97  return false;
98  }
99 
100  double cob_x_offset_m = doc["cob_x_offset_m"].as<double>();
101  double cob_y_offset_m = doc["cob_y_offset_m"].as<double>();
102 
103  double hip_roll_swap_angle_rad = doc["hip_roll_swap_angle_rad"].as<double>();
104 
105  double foot_roll_gyro_p_gain = doc["foot_roll_gyro_p_gain"].as<double>();
106  double foot_roll_gyro_d_gain = doc["foot_roll_gyro_d_gain"].as<double>();
107  double foot_pitch_gyro_p_gain = doc["foot_pitch_gyro_p_gain"].as<double>();
108  double foot_pitch_gyro_d_gain = doc["foot_pitch_gyro_d_gain"].as<double>();
109 
110  double foot_roll_angle_p_gain = doc["foot_roll_angle_p_gain"].as<double>();
111  double foot_roll_angle_d_gain = doc["foot_roll_angle_d_gain"].as<double>();
112  double foot_pitch_angle_p_gain = doc["foot_pitch_angle_p_gain"].as<double>();
113  double foot_pitch_angle_d_gain = doc["foot_pitch_angle_d_gain"].as<double>();
114 
115  double foot_x_force_p_gain = doc["foot_x_force_p_gain"].as<double>();
116  double foot_x_force_d_gain = doc["foot_x_force_d_gain"].as<double>();
117  double foot_y_force_p_gain = doc["foot_y_force_p_gain"].as<double>();
118  double foot_y_force_d_gain = doc["foot_y_force_d_gain"].as<double>();
119  double foot_z_force_p_gain = doc["foot_z_force_p_gain"].as<double>();
120  double foot_z_force_d_gain = doc["foot_z_force_d_gain"].as<double>();
121  double foot_roll_torque_p_gain = doc["foot_roll_torque_p_gain"].as<double>();
122  double foot_roll_torque_d_gain = doc["foot_roll_torque_d_gain"].as<double>();
123  double foot_pitch_torque_p_gain = doc["foot_pitch_torque_p_gain"].as<double>();
124  double foot_pitch_torque_d_gain = doc["foot_pitch_torque_d_gain"].as<double>();
125 
126  double roll_gyro_cut_off_frequency = doc["roll_gyro_cut_off_frequency"].as<double>();
127  double pitch_gyro_cut_off_frequency = doc["pitch_gyro_cut_off_frequency"].as<double>();
128  double roll_angle_cut_off_frequency = doc["roll_angle_cut_off_frequency"].as<double>();
129  double pitch_angle_cut_off_frequency = doc["pitch_angle_cut_off_frequency"].as<double>();
130  double foot_x_force_cut_off_frequency = doc["foot_x_force_cut_off_frequency"].as<double>();
131  double foot_y_force_cut_off_frequency = doc["foot_y_force_cut_off_frequency"].as<double>();
132  double foot_z_force_cut_off_frequency = doc["foot_z_force_cut_off_frequency"].as<double>();
133  double foot_roll_torque_cut_off_frequency = doc["foot_roll_torque_cut_off_frequency"].as<double>();
134  double foot_pitch_torque_cut_off_frequency = doc["foot_pitch_torque_cut_off_frequency"].as<double>();
135 
136  set_param.request.balance_param.cob_x_offset_m = cob_x_offset_m;
137  set_param.request.balance_param.cob_y_offset_m = cob_y_offset_m;
138  set_param.request.balance_param.hip_roll_swap_angle_rad = hip_roll_swap_angle_rad;
139  set_param.request.balance_param.foot_roll_gyro_p_gain = foot_roll_gyro_p_gain;
140  set_param.request.balance_param.foot_roll_gyro_d_gain = foot_roll_gyro_d_gain;
141  set_param.request.balance_param.foot_pitch_gyro_p_gain = foot_pitch_gyro_p_gain;
142  set_param.request.balance_param.foot_pitch_gyro_d_gain = foot_pitch_gyro_d_gain;
143  set_param.request.balance_param.foot_roll_angle_p_gain = foot_roll_angle_p_gain;
144  set_param.request.balance_param.foot_roll_angle_d_gain = foot_roll_angle_d_gain;
145  set_param.request.balance_param.foot_pitch_angle_p_gain = foot_pitch_angle_p_gain;
146  set_param.request.balance_param.foot_pitch_angle_d_gain = foot_pitch_angle_d_gain;
147  set_param.request.balance_param.foot_x_force_p_gain = foot_x_force_p_gain;
148  set_param.request.balance_param.foot_x_force_d_gain = foot_x_force_d_gain;
149  set_param.request.balance_param.foot_y_force_p_gain = foot_y_force_p_gain;
150  set_param.request.balance_param.foot_y_force_d_gain = foot_y_force_d_gain;
151  set_param.request.balance_param.foot_z_force_p_gain = foot_z_force_p_gain;
152  set_param.request.balance_param.foot_z_force_d_gain = foot_z_force_d_gain;
153  set_param.request.balance_param.foot_roll_torque_p_gain = foot_roll_torque_p_gain;
154  set_param.request.balance_param.foot_roll_torque_d_gain = foot_roll_torque_d_gain;
155  set_param.request.balance_param.foot_pitch_torque_p_gain = foot_pitch_torque_p_gain;
156  set_param.request.balance_param.foot_pitch_torque_d_gain = foot_pitch_torque_d_gain;
157  set_param.request.balance_param.roll_gyro_cut_off_frequency = roll_gyro_cut_off_frequency;
158  set_param.request.balance_param.pitch_gyro_cut_off_frequency = pitch_gyro_cut_off_frequency;
159  set_param.request.balance_param.roll_angle_cut_off_frequency = roll_angle_cut_off_frequency;
160  set_param.request.balance_param.pitch_angle_cut_off_frequency = pitch_angle_cut_off_frequency;
161  set_param.request.balance_param.foot_x_force_cut_off_frequency = foot_x_force_cut_off_frequency;
162  set_param.request.balance_param.foot_y_force_cut_off_frequency = foot_y_force_cut_off_frequency;
163  set_param.request.balance_param.foot_z_force_cut_off_frequency = foot_z_force_cut_off_frequency;
164  set_param.request.balance_param.foot_roll_torque_cut_off_frequency = foot_roll_torque_cut_off_frequency;
165  set_param.request.balance_param.foot_pitch_torque_cut_off_frequency = foot_pitch_torque_cut_off_frequency;
166 
167  return true;
168 }
169 
170 bool loadFeedBackGain(thormang3_walking_module_msgs::SetJointFeedBackGain& set_gain)
171 {
172  ros::NodeHandle ros_node;
173  std::string feedback_gain_yaml_path = "";
174  feedback_gain_yaml_path = ros::package::getPath("thormang3_walking_demo") + "/data/joint_feedback_gain.yaml";
175 
176  YAML::Node doc;
177  try
178  {
179  // load yaml
180  doc = YAML::LoadFile(feedback_gain_yaml_path.c_str());
181  }
182  catch(const std::exception& e)
183  {
184  ROS_ERROR("Failed to load feedback gain yaml file.");
185  return false;
186  }
187 
188  double r_leg_hip_y_p_gain = doc["r_leg_hip_y_p_gain"].as<double>();
189  double r_leg_hip_y_d_gain = doc["r_leg_hip_y_d_gain"].as<double>();
190  double r_leg_hip_r_p_gain = doc["r_leg_hip_r_p_gain"].as<double>();
191  double r_leg_hip_r_d_gain = doc["r_leg_hip_r_d_gain"].as<double>();
192  double r_leg_hip_p_p_gain = doc["r_leg_hip_p_p_gain"].as<double>();
193  double r_leg_hip_p_d_gain = doc["r_leg_hip_p_d_gain"].as<double>();
194  double r_leg_kn_p_p_gain = doc["r_leg_kn_p_p_gain"].as<double>();
195  double r_leg_kn_p_d_gain = doc["r_leg_kn_p_d_gain"].as<double>();
196  double r_leg_an_p_p_gain = doc["r_leg_an_p_p_gain"].as<double>();
197  double r_leg_an_p_d_gain = doc["r_leg_an_p_d_gain"].as<double>();
198  double r_leg_an_r_p_gain = doc["r_leg_an_r_p_gain"].as<double>();
199  double r_leg_an_r_d_gain = doc["r_leg_an_r_d_gain"].as<double>();
200  double l_leg_hip_y_p_gain = doc["l_leg_hip_y_p_gain"].as<double>();
201  double l_leg_hip_y_d_gain = doc["l_leg_hip_y_d_gain"].as<double>();
202  double l_leg_hip_r_p_gain = doc["l_leg_hip_r_p_gain"].as<double>();
203  double l_leg_hip_r_d_gain = doc["l_leg_hip_r_d_gain"].as<double>();
204  double l_leg_hip_p_p_gain = doc["l_leg_hip_p_p_gain"].as<double>();
205  double l_leg_hip_p_d_gain = doc["l_leg_hip_p_d_gain"].as<double>();
206  double l_leg_kn_p_p_gain = doc["l_leg_kn_p_p_gain"].as<double>();
207  double l_leg_kn_p_d_gain = doc["l_leg_kn_p_d_gain"].as<double>();
208  double l_leg_an_p_p_gain = doc["l_leg_an_p_p_gain"].as<double>();
209  double l_leg_an_p_d_gain = doc["l_leg_an_p_d_gain"].as<double>();
210  double l_leg_an_r_p_gain = doc["l_leg_an_r_p_gain"].as<double>();
211  double l_leg_an_r_d_gain = doc["l_leg_an_r_d_gain"].as<double>();
212 
213  set_gain.request.feedback_gain.r_leg_hip_y_p_gain = r_leg_hip_y_p_gain;
214  set_gain.request.feedback_gain.r_leg_hip_y_d_gain = r_leg_hip_y_d_gain;
215  set_gain.request.feedback_gain.r_leg_hip_r_p_gain = r_leg_hip_r_p_gain;
216  set_gain.request.feedback_gain.r_leg_hip_r_d_gain = r_leg_hip_r_d_gain;
217  set_gain.request.feedback_gain.r_leg_hip_p_p_gain = r_leg_hip_p_p_gain;
218  set_gain.request.feedback_gain.r_leg_hip_p_d_gain = r_leg_hip_p_d_gain;
219  set_gain.request.feedback_gain.r_leg_kn_p_p_gain = r_leg_kn_p_p_gain ;
220  set_gain.request.feedback_gain.r_leg_kn_p_d_gain = r_leg_kn_p_d_gain ;
221  set_gain.request.feedback_gain.r_leg_an_p_p_gain = r_leg_an_p_p_gain ;
222  set_gain.request.feedback_gain.r_leg_an_p_d_gain = r_leg_an_p_d_gain ;
223  set_gain.request.feedback_gain.r_leg_an_r_p_gain = r_leg_an_r_p_gain ;
224  set_gain.request.feedback_gain.r_leg_an_r_d_gain = r_leg_an_r_d_gain ;
225  set_gain.request.feedback_gain.l_leg_hip_y_p_gain = l_leg_hip_y_p_gain;
226  set_gain.request.feedback_gain.l_leg_hip_y_d_gain = l_leg_hip_y_d_gain;
227  set_gain.request.feedback_gain.l_leg_hip_r_p_gain = l_leg_hip_r_p_gain;
228  set_gain.request.feedback_gain.l_leg_hip_r_d_gain = l_leg_hip_r_d_gain;
229  set_gain.request.feedback_gain.l_leg_hip_p_p_gain = l_leg_hip_p_p_gain;
230  set_gain.request.feedback_gain.l_leg_hip_p_d_gain = l_leg_hip_p_d_gain;
231  set_gain.request.feedback_gain.l_leg_kn_p_p_gain = l_leg_kn_p_p_gain ;
232  set_gain.request.feedback_gain.l_leg_kn_p_d_gain = l_leg_kn_p_d_gain ;
233  set_gain.request.feedback_gain.l_leg_an_p_p_gain = l_leg_an_p_p_gain ;
234  set_gain.request.feedback_gain.l_leg_an_p_d_gain = l_leg_an_p_d_gain ;
235  set_gain.request.feedback_gain.l_leg_an_r_p_gain = l_leg_an_r_p_gain ;
236  set_gain.request.feedback_gain.l_leg_an_r_d_gain = l_leg_an_r_d_gain ;
237 
238  return true;
239 }
240 
241 
243 {
244  // update balance parameter
245  thormang3_walking_module_msgs::SetBalanceParam set_balance_param_srv;
246  set_balance_param_srv.request.updating_duration = 2.0*1.0; //sec
247 
248  if(loadBalanceParam(set_balance_param_srv) == false)
249  {
250  ROS_ERROR("[Demo] : Failed to Load Balance YAML");
251  return;
252  }
253 
254 
255  if(g_set_balance_param_client.call(set_balance_param_srv) == true)
256  {
257  int set_balance_param_srv_result = set_balance_param_srv.response.result;
258  if( set_balance_param_srv_result == thormang3_walking_module_msgs::SetBalanceParam::Response::NO_ERROR)
259  ROS_INFO("[Demo] : Succeed to set balance param");
260  else
261  {
262  if(set_balance_param_srv_result & thormang3_walking_module_msgs::SetBalanceParam::Response::NOT_ENABLED_WALKING_MODULE)
263  ROS_ERROR("[Demo] : BALANCE_PARAM_ERR::NOT_ENABLED_WALKING_MODULE");
264  if(set_balance_param_srv_result & thormang3_walking_module_msgs::SetBalanceParam::Response::PREV_REQUEST_IS_NOT_FINISHED)
265  ROS_ERROR("[Demo] : BALANCE_PARAM_ERR::PREV_REQUEST_IS_NOT_FINISHED");
266 // if(set_balance_param_srv_result & thormang3_walking_module_msgs::SetBalanceParam::Response::CUT_OFF_FREQUENCY_IS_ZERO_OR_NEGATIVE)
267 // ROS_ERROR("[Demo] : BALANCE_PARAM_ERR::TIME_CONST_IS_ZERO_OR_NEGATIVE");
268  }
269  }
270  else
271  {
272  ROS_ERROR("[Demo] : Failed to set balance param ");
273  }
274 
275  // update joint feed back gain
276  thormang3_walking_module_msgs::SetJointFeedBackGain set_feedback_gain_srv;
277  set_feedback_gain_srv.request.updating_duration = 2.0*1.0; //sec
278 
279  if(loadFeedBackGain(set_feedback_gain_srv) == false)
280  {
281  ROS_ERROR("[Demo] : Failed to Load Balance YAML");
282  return;
283  }
284 
285 
286  if(g_set_feedback_gain_client.call(set_feedback_gain_srv) == true)
287  {
288  int set_feedback_gain_srv_result = set_feedback_gain_srv.response.result;
289  if( set_feedback_gain_srv_result == thormang3_walking_module_msgs::SetJointFeedBackGain::Response::NO_ERROR)
290  ROS_INFO("[Demo] : Succeed to set joint feedback gain");
291  else
292  {
293  if(set_feedback_gain_srv_result & thormang3_walking_module_msgs::SetJointFeedBackGain::Response::NOT_ENABLED_WALKING_MODULE)
294  ROS_ERROR("[Demo] : FEEDBACK_GAIN_ERR::NOT_ENABLED_WALKING_MODULE");
295  if(set_feedback_gain_srv_result & thormang3_walking_module_msgs::SetJointFeedBackGain::Response::PREV_REQUEST_IS_NOT_FINISHED)
296  ROS_ERROR("[Demo] : FEEDBACK_GAIN_ERR::PREV_REQUEST_IS_NOT_FINISHED");
297  }
298  }
299  else
300  {
301  ROS_ERROR("[Demo] : Failed to set joint feedback gain");
302  }
303 }
304 
306 {
307  thormang3_walking_module_msgs::SetBalanceParam set_balance_param_srv;
308  set_balance_param_srv.request.updating_duration = 1.0; //sec
309 
310  if(loadBalanceParam(set_balance_param_srv) == false)
311  {
312  ROS_ERROR("[Demo] : Failed to Load Balance YAML");
313  return;
314  }
315 
316  set_balance_param_srv.request.balance_param.hip_roll_swap_angle_rad = 0;
317  set_balance_param_srv.request.balance_param.foot_roll_gyro_p_gain = 0;
318  set_balance_param_srv.request.balance_param.foot_roll_gyro_d_gain = 0;
319  set_balance_param_srv.request.balance_param.foot_pitch_gyro_p_gain = 0;
320  set_balance_param_srv.request.balance_param.foot_pitch_gyro_d_gain = 0;
321  set_balance_param_srv.request.balance_param.foot_roll_angle_p_gain = 0;
322  set_balance_param_srv.request.balance_param.foot_roll_angle_d_gain = 0;
323  set_balance_param_srv.request.balance_param.foot_pitch_angle_p_gain = 0;
324  set_balance_param_srv.request.balance_param.foot_pitch_angle_d_gain = 0;
325  set_balance_param_srv.request.balance_param.foot_x_force_p_gain = 0;
326  set_balance_param_srv.request.balance_param.foot_x_force_d_gain = 0;
327  set_balance_param_srv.request.balance_param.foot_y_force_p_gain = 0;
328  set_balance_param_srv.request.balance_param.foot_y_force_d_gain = 0;
329  set_balance_param_srv.request.balance_param.foot_z_force_p_gain = 0;
330  set_balance_param_srv.request.balance_param.foot_z_force_d_gain = 0;
331  set_balance_param_srv.request.balance_param.foot_roll_torque_p_gain = 0;
332  set_balance_param_srv.request.balance_param.foot_roll_torque_d_gain = 0;
333  set_balance_param_srv.request.balance_param.foot_pitch_torque_p_gain = 0;
334  set_balance_param_srv.request.balance_param.foot_pitch_torque_d_gain = 0;
335 
336  if(g_set_balance_param_client.call(set_balance_param_srv) == true)
337  {
338  int set_balance_param_srv_result = set_balance_param_srv.response.result;
339  if( set_balance_param_srv_result == thormang3_walking_module_msgs::SetBalanceParam::Response::NO_ERROR)
340  ROS_INFO("[Demo] : Succeed to set balance param");
341  else
342  {
343  if(set_balance_param_srv_result & thormang3_walking_module_msgs::SetBalanceParam::Response::NOT_ENABLED_WALKING_MODULE)
344  ROS_ERROR("[Demo] : BALANCE_PARAM_ERR::NOT_ENABLED_WALKING_MODULE");
345  if(set_balance_param_srv_result & thormang3_walking_module_msgs::SetBalanceParam::Response::PREV_REQUEST_IS_NOT_FINISHED)
346  ROS_ERROR("[Demo] : BALANCE_PARAM_ERR::PREV_REQUEST_IS_NOT_FINISHED");
347 // if(set_balance_param_srv_result & thormang3_walking_module_msgs::SetBalanceParam::Response::CUT_OFF_FREQUENCY_IS_ZERO_OR_NEGATIVE)
348 // ROS_ERROR("[Demo] : BALANCE_PARAM_ERR::TIME_CONST_IS_ZERO_OR_NEGATIVE");
349  }
350  }
351  else
352  {
353  ROS_ERROR("[Demo] : Failed to set balance param ");
354  }
355 }
356 
358 {
359  thormang3_walking_module_msgs::GetReferenceStepData get_ref_stp_data_srv;
360  thormang3_walking_module_msgs::AddStepDataArray add_stp_data_srv;
361  thormang3_walking_module_msgs::IsRunning is_running_srv;
362  thormang3_walking_module_msgs::StepData stp_data_msg;
363 
364  if(g_is_running_client.call(is_running_srv) == false)
365  {
366  ROS_ERROR("Failed to get walking_module status");
367  }
368  else
369  {
370  if(is_running_srv.response.is_running == true)
371  {
372  ROS_ERROR("[Demo] : ROBOT_IS_WALKING_NOW");
373  return;
374  }
375  }
376 
377  if(g_get_ref_step_data_client.call(get_ref_stp_data_srv) == false)
378  ROS_ERROR("Failed to get reference step data");
379 
380  stp_data_msg = get_ref_stp_data_srv.response.reference_step_data;
381 
382  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING_STARTING;
383  stp_data_msg.time_data.dsp_ratio = 0.2;
384  stp_data_msg.time_data.abs_step_time += g_start_end_time;
385  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::STANDING;
386  stp_data_msg.position_data.body_z_swap = 0;
387  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
388 
389  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING;
390  stp_data_msg.time_data.abs_step_time += g_step_time;
391  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::RIGHT_FOOT_SWING;
392  stp_data_msg.position_data.body_z_swap = g_body_z_swap;
393  stp_data_msg.position_data.foot_z_swap = g_foot_z_swap;
394  stp_data_msg.position_data.right_foot_pose.x += g_step_length;
395  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
396 
397  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING;
398  stp_data_msg.time_data.abs_step_time += g_step_time;
399  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::LEFT_FOOT_SWING;
400  stp_data_msg.position_data.body_z_swap = g_body_z_swap;
401  stp_data_msg.position_data.foot_z_swap = g_foot_z_swap;
402  stp_data_msg.position_data.left_foot_pose.x += g_step_length;
403  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
404 
405  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING_ENDING;
406  stp_data_msg.time_data.abs_step_time += g_start_end_time;
407  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::STANDING;
408  stp_data_msg.position_data.body_z_swap = 0;
409  stp_data_msg.position_data.foot_z_swap = 0;
410  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
411 
412  add_stp_data_srv.request.auto_start = true;
413  add_stp_data_srv.request.remove_existing_step_data = true;
414 
415  if(g_add_step_data_array_client.call(add_stp_data_srv) == true)
416  {
417  int add_stp_data_srv_result = add_stp_data_srv.response.result;
418  if(add_stp_data_srv_result== thormang3_walking_module_msgs::AddStepDataArray::Response::NO_ERROR)
419  ROS_INFO("[Demo] : Succeed to add step data array");
420  else
421  {
422  ROS_ERROR("[Demo] : Failed to add step data array");
423  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::NOT_ENABLED_WALKING_MODULE)
424  ROS_ERROR("[Demo] : STEP_DATA_ERR::NOT_ENABLED_WALKING_MODULE");
425  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::PROBLEM_IN_POSITION_DATA)
426  ROS_ERROR("[Demo] : STEP_DATA_ERR::PROBLEM_IN_POSITION_DATA");
427  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::PROBLEM_IN_TIME_DATA)
428  ROS_ERROR("[Demo] : STEP_DATA_ERR::PROBLEM_IN_TIME_DATA");
429  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::ROBOT_IS_WALKING_NOW)
430  ROS_ERROR("[Demo] : STEP_DATA_ERR::ROBOT_IS_WALKING_NOW");
431  }
432  }
433  else
434  {
435  ROS_ERROR("[Demo] : Failed to add step data array ");
436  }
437 }
438 
440 {
441  thormang3_walking_module_msgs::GetReferenceStepData get_ref_stp_data_srv;
442  thormang3_walking_module_msgs::AddStepDataArray add_stp_data_srv;
443  thormang3_walking_module_msgs::IsRunning is_running_srv;
444  thormang3_walking_module_msgs::StepData stp_data_msg;
445 
446  if(g_is_running_client.call(is_running_srv) == false)
447  {
448  ROS_ERROR("Failed to get walking_module status");
449  }
450  else
451  {
452  if(is_running_srv.response.is_running == true)
453  {
454  ROS_ERROR("[Demo] : ROBOT_IS_WALKING_NOW");
455  return;
456  }
457  }
458 
459  g_get_ref_step_data_client.call(get_ref_stp_data_srv);
460 
461  stp_data_msg = get_ref_stp_data_srv.response.reference_step_data;
462 
463  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING_STARTING;
464  stp_data_msg.time_data.dsp_ratio = 0.2;
465  stp_data_msg.time_data.abs_step_time += g_start_end_time;
466  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::STANDING;
467  stp_data_msg.position_data.body_z_swap = 0;
468  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
469 
470 
471  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING;
472  stp_data_msg.time_data.abs_step_time += g_step_time;
473  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::RIGHT_FOOT_SWING;
474  stp_data_msg.position_data.body_z_swap = g_body_z_swap;
475  stp_data_msg.position_data.foot_z_swap = g_foot_z_swap;
476  stp_data_msg.position_data.right_foot_pose.x -= g_step_length;
477  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
478 
479 
480  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING;
481  stp_data_msg.time_data.abs_step_time += g_step_time;
482  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::LEFT_FOOT_SWING;
483  stp_data_msg.position_data.body_z_swap = g_body_z_swap;
484  stp_data_msg.position_data.foot_z_swap = g_foot_z_swap;
485  stp_data_msg.position_data.left_foot_pose.x -= g_step_length;
486  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
487 
488 
489  stp_data_msg.time_data.walking_state = thormang3_walking_module_msgs::StepTimeData::IN_WALKING_ENDING;
490  stp_data_msg.time_data.abs_step_time += g_start_end_time;
491  stp_data_msg.position_data.moving_foot = thormang3_walking_module_msgs::StepPositionData::STANDING;
492  stp_data_msg.position_data.body_z_swap = 0;
493  stp_data_msg.position_data.foot_z_swap = 0;
494  add_stp_data_srv.request.step_data_array.push_back(stp_data_msg);
495 
496 
497  add_stp_data_srv.request.auto_start = true;
498  add_stp_data_srv.request.remove_existing_step_data = true;
499 
500  if(g_add_step_data_array_client.call(add_stp_data_srv) == true)
501  {
502  int add_stp_data_srv_result = add_stp_data_srv.response.result;
503  if(add_stp_data_srv_result== thormang3_walking_module_msgs::AddStepDataArray::Response::NO_ERROR)
504  ROS_INFO("[Demo] : Succeed to add step data array");
505  else
506  {
507  ROS_ERROR("[Demo] : Failed to add step data array");
508  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::NOT_ENABLED_WALKING_MODULE)
509  ROS_ERROR("[Demo] : STEP_DATA_ERR::NOT_ENABLED_WALKING_MODULE");
510  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::PROBLEM_IN_POSITION_DATA)
511  ROS_ERROR("[Demo] : STEP_DATA_ERR::PROBLEM_IN_POSITION_DATA");
512  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::PROBLEM_IN_TIME_DATA)
513  ROS_ERROR("[Demo] : STEP_DATA_ERR::PROBLEM_IN_TIME_DATA");
514  if(add_stp_data_srv_result & thormang3_walking_module_msgs::AddStepDataArray::Response::ROBOT_IS_WALKING_NOW)
515  ROS_ERROR("[Demo] : STEP_DATA_ERR::ROBOT_IS_WALKING_NOW");
516  }
517  }
518  else
519  {
520  ROS_ERROR("[Demo] : Failed to add step data array ");
521  }
522 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
double g_step_time
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void setBalanceOn()
void setBalanceOff()
bool call(MReq &req, MRes &res)
void walkForward()
double g_step_length
ros::ServiceClient g_get_ref_step_data_client
void walkBackward()
void walkingModuleStatusMSGCallback(const robotis_controller_msgs::StatusMsg::ConstPtr &msg)
ros::ServiceClient g_is_running_client
double g_body_z_swap
ros::ServiceClient g_add_step_data_array_client
double g_start_end_time
#define ROS_INFO(...)
bool loadFeedBackGain(thormang3_walking_module_msgs::SetJointFeedBackGain &set_gain)
ros::Publisher g_enable_ctrl_module_pub
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::ServiceClient g_set_balance_param_client
ROSLIB_DECL std::string getPath(const std::string &package_name)
ros::Publisher g_wholebody_ini_pose_pub
double g_foot_z_swap
ros::Subscriber g_walking_module_status_msg_sub
#define ROS_INFO_STREAM(args)
void moveToInitPose()
void initialize()
#define ROS_ERROR(...)
void setCtrlModule()
bool loadBalanceParam(thormang3_walking_module_msgs::SetBalanceParam &set_param)
ros::ServiceClient g_set_feedback_gain_client


thormang3_walking_demo
Author(s): Zerom , SCH , Kayman , Jay Song
autogenerated on Mon Jun 10 2019 15:39:39