online_walking_module.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2017 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 /* Author: SCH */
18 
19 #ifndef OP3_ONLINE_WALKING_MODULE_ONLINE_WALKING_MODULE_H_
20 #define OP3_ONLINE_WALKING_MODULE_ONLINE_WALKING_MODULE_H_
21 
22 #include <map>
23 #include <ros/ros.h>
24 #include <ros/callback_queue.h>
25 #include <ros/package.h>
26 #include <std_msgs/Bool.h>
27 #include <std_msgs/Int16.h>
28 #include <std_msgs/Float64.h>
29 #include <std_msgs/String.h>
30 #include <sensor_msgs/Imu.h>
31 #include <geometry_msgs/Pose.h>
32 #include <geometry_msgs/WrenchStamped.h>
33 #include <geometry_msgs/PoseStamped.h>
34 #include <boost/thread.hpp>
35 #include <eigen3/Eigen/Eigen>
36 #include <yaml-cpp/yaml.h>
37 
38 #include "joint_control.h"
39 #include "wholebody_control.h"
40 #include "walking_control.h"
41 #include "op3_kdl.h"
42 
43 #include "robotis_controller_msgs/JointCtrlModule.h"
44 #include "robotis_controller_msgs/StatusMsg.h"
47 
48 //#include "op3_kinematics_dynamics/op3_kinematics_dynamics.h"
50 
51 #include "op3_online_walking_module_msgs/JointPose.h"
52 #include "op3_online_walking_module_msgs/KinematicsPose.h"
53 #include "op3_online_walking_module_msgs/FootStepCommand.h"
54 #include "op3_online_walking_module_msgs/PreviewRequest.h"
55 #include "op3_online_walking_module_msgs/PreviewResponse.h"
56 #include "op3_online_walking_module_msgs/WalkingParam.h"
57 
58 #include "op3_online_walking_module_msgs/GetJointPose.h"
59 #include "op3_online_walking_module_msgs/GetKinematicsPose.h"
60 #include "op3_online_walking_module_msgs/GetPreviewMatrix.h"
61 
62 #include "op3_online_walking_module_msgs/Step2D.h"
63 #include "op3_online_walking_module_msgs/Step2DArray.h"
64 
65 namespace robotis_op
66 {
67 
74 };
75 
77  ON,
79 };
80 
82  public robotis_framework::Singleton<OnlineWalkingModule>
83 {
84 public:
86  virtual ~OnlineWalkingModule();
87 
88  /* ROS Topic Callback Functions */
89  void setResetBodyCallback(const std_msgs::Bool::ConstPtr& msg);
90  void setWholebodyBalanceMsgCallback(const std_msgs::String::ConstPtr& msg);
91  void setBodyOffsetCallback(const geometry_msgs::Pose::ConstPtr& msg);
92  void setFootDistanceCallback(const std_msgs::Float64::ConstPtr& msg);
93 
94  void goalJointPoseCallback(const op3_online_walking_module_msgs::JointPose &msg);
95  void goalKinematicsPoseCallback(const op3_online_walking_module_msgs::KinematicsPose& msg);
96  void footStepCommandCallback(const op3_online_walking_module_msgs::FootStepCommand& msg);
97  void walkingParamCallback(const op3_online_walking_module_msgs::WalkingParam& msg);
98 
99  void footStep2DCallback(const op3_online_walking_module_msgs::Step2DArray& msg);
100 
101  void imuDataCallback(const sensor_msgs::Imu::ConstPtr& msg);
102  void leftFootForceTorqueOutputCallback(const geometry_msgs::WrenchStamped::ConstPtr &msg);
103  void rightFootForceTorqueOutputCallback(const geometry_msgs::WrenchStamped::ConstPtr &msg);
104 
105  /* ROS Service Functions */
106  bool getJointPoseCallback(op3_online_walking_module_msgs::GetJointPose::Request &req,
107  op3_online_walking_module_msgs::GetJointPose::Response &res);
108  bool getKinematicsPoseCallback(op3_online_walking_module_msgs::GetKinematicsPose::Request &req,
109  op3_online_walking_module_msgs::GetKinematicsPose::Response &res);
110  bool getPreviewMatrix(op3_online_walking_module_msgs::PreviewRequest msg);
111  bool definePreviewMatrix();
112 
113  /* ROS Framework Functions */
114  void initialize(const int control_cycle_msec, robotis_framework::Robot *robot);
115  void process(std::map<std::string, robotis_framework::Dynamixel *> dxls, std::map<std::string, double> sensors);
116  void stop();
117  bool isRunning();
118 
119  /* yaml Functions */
120  void parseBalanceGainData(const std::string &path);
121  void parseJointFeedbackGainData(const std::string &path);
122  void parseJointFeedforwardGainData(const std::string &path);
123 
124  /* ROS Publish Functions */
125  void publishStatusMsg(unsigned int type, std::string msg);
126 
127  /* Parameter */
130 
132 
133 private:
134  void queueThread();
135 
136  void initJointControl();
137  void calcJointControl();
138  void initWholebodyControl();
139  void calcWholebodyControl();
140  void initOffsetControl();
141  void calcOffsetControl();
142  void initWalkingControl();
143  void calcWalkingControl();
144  void initBalanceControl();
145  void calcBalanceControl();
146 
147  void initFeedforwardControl();
148  void setFeedforwardControl();
149 
150  void sensoryFeedback(const double &rlGyroErr, const double &fbGyroErr, double *balance_angle);
151 
152  void calcRobotPose();
153 
154  void setTargetForceTorque();
155  void setBalanceControlGain();
156  bool setBalanceControl();
157  void setFeedbackControl();
158  void resetBodyPose();
159 
160  std::map<std::string, int> joint_name_to_id_;
161 
163  boost::thread queue_thread_;
164  boost::mutex queue_mutex_;
165  boost::mutex imu_data_mutex_lock_;
166 
167  std_msgs::String movement_done_msg_;
168 
173 
174 // ros::ServiceClient get_preview_matrix_client_;
175 
177 
180  double mov_time_;
181 
188 
191 
196 
198  std::vector<std::string> joint_name_;
200 
201  // Joint Command
205 
206  std::vector<double_t> des_joint_feedback_;
207  std::vector<double_t> des_joint_feedforward_;
208  std::vector<double_t> des_joint_pos_to_robot_;
209 
215 
216  // Walking Control
217  std::vector<double_t> x_lipm_, y_lipm_;
218 
219  op3_online_walking_module_msgs::FootStepCommand foot_step_command_;
220  op3_online_walking_module_msgs::PreviewRequest preview_request_;
221  op3_online_walking_module_msgs::PreviewResponse preview_response_;
222  op3_online_walking_module_msgs::WalkingParam walking_param_;
223 
224  op3_online_walking_module_msgs::Step2DArray foot_step_2d_;
226 
227  std::vector<double_t> preview_response_K_;
229 
230  std::vector<double_t> preview_response_P_;
232 
233  // Wholebody Control
234  geometry_msgs::Pose wholebody_goal_msg_;
235 
236  // Balance Control
238 
241 
244 
245  std::vector<double_t> joint_feedforward_gain_;
246 
247  std::vector<double_t> des_balance_gain_ratio_;
248  std::vector<double_t> goal_balance_gain_ratio_;
249 
250  // Body Offset
251  std::vector<double_t> des_body_offset_;
252  std::vector<double_t> goal_body_offset_;
253 
256 
257  //
259 
260  // Balance Gain
265 
270 
277 
282 
285 
288 
292 
295 
300 
301  // Balance Control : Desired Force
308 
315 
316  Eigen::MatrixXd g_to_r_leg_, g_to_l_leg_;
317 
318  // Sensor msgs
319  sensor_msgs::Imu imu_data_msg_;
320  geometry_msgs::Wrench l_foot_ft_data_msg_;
321  geometry_msgs::Wrench r_foot_ft_data_msg_;
322 
323  double total_mass_;
324 };
325 
326 }
327 
328 #endif
void setWholebodyBalanceMsgCallback(const std_msgs::String::ConstPtr &msg)
std::vector< double_t > des_body_pos_
robotis_framework::MinimumJerk * joint_tra_
void setBodyOffsetCallback(const geometry_msgs::Pose::ConstPtr &msg)
std::vector< double_t > des_body_accel_
std::vector< double_t > des_joint_accel_
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, double > sensors)
op3_online_walking_module_msgs::WalkingParam walking_param_
geometry_msgs::Wrench l_foot_ft_data_msg_
std::vector< std::string > joint_name_
std::vector< double_t > des_r_leg_vel_
std::vector< double_t > preview_response_K_
void walkingParamCallback(const op3_online_walking_module_msgs::WalkingParam &msg)
std::vector< double_t > des_r_arm_accel_
std::vector< double_t > des_l_arm_accel_
std::vector< double_t > des_l_leg_accel_
std::vector< double_t > des_r_leg_pos_
BalanceControlUsingPDController balance_control_
std::vector< double_t > des_r_arm_pos_
void footStepCommandCallback(const op3_online_walking_module_msgs::FootStepCommand &msg)
std::vector< double_t > curr_joint_pos_
std::vector< double_t > des_l_leg_Q_
op3_online_walking_module_msgs::PreviewRequest preview_request_
std::vector< double_t > des_joint_pos_to_robot_
void imuDataCallback(const sensor_msgs::Imu::ConstPtr &msg)
std::map< std::string, int > joint_name_to_id_
bool getJointPoseCallback(op3_online_walking_module_msgs::GetJointPose::Request &req, op3_online_walking_module_msgs::GetJointPose::Response &res)
std::vector< double_t > des_l_arm_pos_
void setFootDistanceCallback(const std_msgs::Float64::ConstPtr &msg)
bool getPreviewMatrix(op3_online_walking_module_msgs::PreviewRequest msg)
std::vector< double_t > goal_balance_gain_ratio_
void footStep2DCallback(const op3_online_walking_module_msgs::Step2DArray &msg)
void goalJointPoseCallback(const op3_online_walking_module_msgs::JointPose &msg)
std::vector< double_t > des_body_vel_
std::vector< double_t > preview_response_P_
op3_online_walking_module_msgs::PreviewResponse preview_response_
std::vector< double_t > joint_feedforward_gain_
void setResetBodyCallback(const std_msgs::Bool::ConstPtr &msg)
std::vector< double_t > des_l_arm_Q_
std::vector< double_t > curr_joint_accel_
void rightFootForceTorqueOutputCallback(const geometry_msgs::WrenchStamped::ConstPtr &msg)
std::vector< double_t > des_balance_gain_ratio_
robotis_framework::MinimumJerkViaPoint * feed_forward_tra_
void sensoryFeedback(const double &rlGyroErr, const double &fbGyroErr, double *balance_angle)
op3_online_walking_module_msgs::FootStepCommand foot_step_command_
void leftFootForceTorqueOutputCallback(const geometry_msgs::WrenchStamped::ConstPtr &msg)
BalancePDController joint_feedback_[12]
robotis_framework::MinimumJerk * balance_tra_
void goalKinematicsPoseCallback(const op3_online_walking_module_msgs::KinematicsPose &msg)
void parseJointFeedforwardGainData(const std::string &path)
std::vector< double_t > des_l_leg_pos_
std::vector< double_t > des_joint_pos_
std::vector< double_t > des_l_leg_vel_
std::vector< double_t > curr_joint_vel_
std::vector< double_t > des_r_leg_accel_
op3_online_walking_module_msgs::Step2DArray foot_step_2d_
robotis_framework::MinimumJerk * body_offset_tra_
std::vector< double_t > des_r_arm_Q_
std::vector< double_t > des_r_arm_vel_
void parseBalanceGainData(const std::string &path)
std::vector< double_t > des_joint_vel_
void publishStatusMsg(unsigned int type, std::string msg)
std::vector< double_t > des_joint_feedback_
std::vector< double_t > goal_joint_accel_
std::vector< double_t > goal_body_offset_
std::vector< double_t > des_r_leg_Q_
std::vector< double_t > goal_joint_vel_
std::vector< double_t > des_body_offset_
std::vector< double_t > goal_joint_pos_
std::vector< double_t > des_joint_feedforward_
geometry_msgs::Wrench r_foot_ft_data_msg_
bool getKinematicsPoseCallback(op3_online_walking_module_msgs::GetKinematicsPose::Request &req, op3_online_walking_module_msgs::GetKinematicsPose::Response &res)
void parseJointFeedbackGainData(const std::string &path)
std::vector< double_t > des_l_arm_vel_
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)


op3_online_walking_module
Author(s): SCH
autogenerated on Mon Jun 10 2019 14:41:22