op3_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: Kayman */
18 
19 #ifndef OP3_WALKING_MODULE_H_
20 #define OP3_WALKING_MODULE_H_
21 
22 #include "op3_walking_parameter.h"
23 
24 #include <stdio.h>
25 #include <math.h>
26 #include <fstream>
27 #include <boost/thread.hpp>
28 #include <eigen3/Eigen/Eigen>
29 #include <yaml-cpp/yaml.h>
30 
31 #include <ros/ros.h>
32 #include <ros/callback_queue.h>
33 #include <ros/package.h>
34 #include <std_msgs/String.h>
35 #include <sensor_msgs/Imu.h>
37 
38 #include "robotis_controller_msgs/StatusMsg.h"
39 #include "op3_walking_module_msgs/WalkingParam.h"
40 #include "op3_walking_module_msgs/GetWalkingParam.h"
41 #include "op3_walking_module_msgs/SetWalkingParam.h"
42 
47 
48 namespace robotis_op
49 {
50 
51 typedef struct
52 {
53  double x, y, z;
54 } Position3D;
55 
56 typedef struct
57 {
58  double x, y, z, roll, pitch, yaw;
59 } Pose3D;
60 
62 {
63 
64  public:
65  enum
66  {
67  PHASE0 = 0,
68  PHASE1 = 1,
69  PHASE2 = 2,
70  PHASE3 = 3
71  };
72 
73  WalkingModule();
74  virtual ~WalkingModule();
75 
76  void initialize(const int control_cycle_msec, robotis_framework::Robot *robot);
77  void process(std::map<std::string, robotis_framework::Dynamixel *> dxls, std::map<std::string, double> sensors);
78  void stop();
79  bool isRunning();
80  void onModuleEnable();
81  void onModuleDisable();
82 
84  {
85  return phase_;
86  }
87  double getBodySwingY()
88  {
89  return body_swing_y;
90  }
91  double getBodySwingZ()
92  {
93  return body_swing_z;
94  }
95 
96  private:
97  enum
98  {
103  };
104 
105  const bool DEBUG;
106 
107  void queueThread();
108 
109  /* ROS Topic Callback Functions */
110  void walkingCommandCallback(const std_msgs::String::ConstPtr &msg);
111  void walkingParameterCallback(const op3_walking_module_msgs::WalkingParam::ConstPtr &msg);
112  bool getWalkigParameterCallback(op3_walking_module_msgs::GetWalkingParam::Request &req,
113  op3_walking_module_msgs::GetWalkingParam::Response &res);
114 
115  /* ROS Service Callback Functions */
116  void processPhase(const double &time_unit);
117  bool computeLegAngle(double *leg_angle);
118  void computeArmAngle(double *arm_angle);
119  void sensoryFeedback(const double &rlGyroErr, const double &fbGyroErr, double *balance_angle);
120 
121  void publishStatusMsg(unsigned int type, std::string msg);
122  double wSin(double time, double period, double period_shift, double mag, double mag_shift);
123  bool computeIK(double *out, double x, double y, double z, double a, double b, double c);
124  void updateTimeParam();
125  void updateMovementParam();
126  void updatePoseParam();
127  void startWalking();
128  void loadWalkingParam(const std::string &path);
129  void saveWalkingParam(std::string &path);
130  void iniPoseTraGene(double mov_time);
131 
134  std::string param_path_;
135  boost::thread queue_thread_;
136  boost::mutex publish_mutex_;
137 
138  /* ROS Topic Publish Functions */
141 
142  Eigen::MatrixXd calc_joint_tra_;
143 
144  Eigen::MatrixXd target_position_;
145  Eigen::MatrixXd goal_position_;
146  Eigen::MatrixXd init_position_;
147  Eigen::MatrixXi joint_axis_direction_;
148  std::map<std::string, int> joint_table_;
151  op3_walking_module_msgs::WalkingParam walking_param_;
153 
154  // variable for walking
155  double period_time_;
156  double dsp_ratio_;
157  double ssp_ratio_;
165  double ssp_time_;
170  double phase1_time_;
171  double phase2_time_;
172  double phase3_time_;
173 
174  double x_offset_;
175  double y_offset_;
176  double z_offset_;
177  double r_offset_;
178  double p_offset_;
179  double a_offset_;
180 
202 
207 
210  double time_;
211 
212  int phase_;
213  double body_swing_y;
214  double body_swing_z;
215 };
216 
217 }
218 
219 #endif /* OP3_WALKING_MODULE_H_ */
bool computeLegAngle(double *leg_angle)
OP3KinematicsDynamics * op3_kd_
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
void walkingCommandCallback(const std_msgs::String::ConstPtr &msg)
void publishStatusMsg(unsigned int type, std::string msg)
Eigen::MatrixXi joint_axis_direction_
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, double > sensors)
op3_walking_module_msgs::WalkingParam walking_param_
double wSin(double time, double period, double period_shift, double mag, double mag_shift)
void walkingParameterCallback(const op3_walking_module_msgs::WalkingParam::ConstPtr &msg)
void saveWalkingParam(std::string &path)
void loadWalkingParam(const std::string &path)
void processPhase(const double &time_unit)
bool getWalkigParameterCallback(op3_walking_module_msgs::GetWalkingParam::Request &req, op3_walking_module_msgs::GetWalkingParam::Response &res)
bool computeIK(double *out, double x, double y, double z, double a, double b, double c)
std::map< std::string, int > joint_table_
void computeArmAngle(double *arm_angle)
void sensoryFeedback(const double &rlGyroErr, const double &fbGyroErr, double *balance_angle)
void iniPoseTraGene(double mov_time)


op3_walking_module
Author(s): Kayman
autogenerated on Mon Jun 10 2019 14:41:25