qnode.hpp
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 /* Author: Kayman Jung */
18 
19 /*****************************************************************************
20  ** Ifdefs
21  *****************************************************************************/
22 
23 #ifndef thormang3_demo_QNODE_HPP_
24 #define thormang3_demo_QNODE_HPP_
25 
26 /*****************************************************************************
27  ** Includes
28  *****************************************************************************/
29 #ifndef Q_MOC_RUN
30 
31 #include <string>
32 #include <sstream>
33 #include <QThread>
34 #include <QStringListModel>
35 #include <ros/ros.h>
36 #include <ros/package.h>
37 #include <std_msgs/Bool.h>
38 #include <std_msgs/Int32.h>
39 #include <std_msgs/String.h>
40 #include <sensor_msgs/JointState.h>
41 #include <geometry_msgs/Pose2D.h>
42 #include <geometry_msgs/Pose.h>
43 #include <geometry_msgs/PointStamped.h>
44 #include <visualization_msgs/MarkerArray.h>
45 #include <visualization_msgs/InteractiveMarker.h>
48 #include <boost/thread.hpp>
49 #include <yaml-cpp/yaml.h>
50 #include <eigen3/Eigen/Eigen>
51 
52 #include "humanoid_nav_msgs/PlanFootsteps.h"
53 
54 #include "robotis_controller_msgs/JointCtrlModule.h"
55 #include "robotis_controller_msgs/GetJointModule.h"
56 #include "robotis_controller_msgs/StatusMsg.h"
57 
58 #include "thormang3_feet_ft_module_msgs/BothWrench.h"
59 
60 #include "thormang3_manipulation_module_msgs/JointPose.h"
61 #include "thormang3_manipulation_module_msgs/KinematicsPose.h"
62 #include "thormang3_manipulation_module_msgs/GetJointPose.h"
63 #include "thormang3_manipulation_module_msgs/GetKinematicsPose.h"
64 
65 #include "thormang3_walking_module_msgs/SetBalanceParam.h"
66 #include "thormang3_walking_module_msgs/SetJointFeedBackGain.h"
67 
68 #include "thormang3_foot_step_generator/FootStepCommand.h"
69 #include "thormang3_foot_step_generator/Step2DArray.h"
70 
71 #endif // Q_MOC_RUN
72 /*****************************************************************************
73  ** Namespaces
74  *****************************************************************************/
75 
76 namespace thormang3_demo
77 {
78 
79 /*****************************************************************************
80  ** Class
81  *****************************************************************************/
82 
83 class QNodeThor3 : public QThread
84 {
85 Q_OBJECT
86 
87  public:
88  enum LogLevel
89  {
90  Debug = 0,
91  Info = 1,
92  Warn = 2,
93  Error = 3,
94  Fatal = 4
95  };
96 
97  // enum ModuleIndex
98  // {
99  // Control_None = 0,
100  // Control_Walking = 1,
101  // Control_Manipulation = 2,
102  // Control_Head = 3,
103  // };
104 
105  QNodeThor3(int argc, char** argv);
106  virtual ~QNodeThor3();
107 
108  bool init();
109  void run();
110  QStringListModel* loggingModel()
111  {
112  return &logging_model_;
113  }
114  void log(const LogLevel& level, const std::string& msg, std::string sender = "Demo");
115  void clearLog();
116  void assembleLidar();
117  void enableControlModule(const std::string& mode);
118  bool getJointNameFromID(const int& id, std::string& joint_name);
119  bool getIDFromJointName(const std::string& joint_name, int& id);
120  bool getIDJointNameFromIndex(const int& index, int& id, std::string& joint_name);
121  std::string getModuleName(const int& index);
122  int getModuleIndex(const std::string& mode_name);
123  int getModuleTableSize();
124  int getJointTableSize();
125  void clearUsingModule();
126  bool isUsingModule(const std::string& module_name);
127  void moveInitPose();
128  void initFTCommand(std::string command);
129 
130  // Head control
131  void setHeadJoint(double pan, double tilt);
132 
133  // Manipulation
134  void sendInitPoseMsg(std_msgs::String msg);
135  void sendDestJointMsg(thormang3_manipulation_module_msgs::JointPose msg);
136  void sendIkMsg(thormang3_manipulation_module_msgs::KinematicsPose msg);
137  void sendGripperPosition(sensor_msgs::JointState msg);
138 
139  // Walking
140  void setWalkingCommand(thormang3_foot_step_generator::FootStepCommand msg);
141  void setWalkingBalance(bool on_command);
142  void setWalkingBalanceParam(const double& gyro_gain, const double& ft_gain_ratio, const double& imu_time_const,
143  const double& ft_time_const);
144  bool setFeedBackGain();
145 
146  void setWalkingFootsteps();
147  void clearFootsteps();
149  void makeFootstepUsingPlanner(const geometry_msgs::Pose& target_foot_pose);
150  void visualizePreviewFootsteps(bool clear);
151 
152  // motion
153  void playMotion(int motion_index, bool to_action_script = true);
154 
155  // demo
156  void makeInteractiveMarker(const geometry_msgs::Pose& marker_pose);
157  void updateInteractiveMarker(const geometry_msgs::Pose& pose);
159  void clearInteractiveMarker();
160  void manipulationDemo(const int& index);
161  void kickDemo(const std::string& kick_foot);
162 
163  std::map<int, std::string> module_table_;
164  std::map<int, std::string> motion_table_;
165 
166  std::string package_name_;
167 
168  public Q_SLOTS:
169  void getJointControlModule();
170  void getJointPose(std::string joint_name);
171  void getKinematicsPose(std::string group_name);
172  void getKinematicsPoseCallback(const geometry_msgs::Pose::ConstPtr& msg);
173  void setCurrentControlUI(int mode);
174 
175 Q_SIGNALS:
176  void loggingUpdated();
177  void rosShutdown();
178  void updatePresentJointControlModules(std::vector<int> mode);
179 
180  // Manipulation
181  void updateCurrJoint(double value);
182  void updateCurrPos(double x, double y, double z);
183  void updateCurrOri(double x, double y, double z, double w);
184 
185  // Head control
186  void updateHeadJointsAngle(double pan, double tilt);
187 
188  // Interactive marker
189  void updateDemoPoint(const geometry_msgs::Point point);
190  void updateDemoPose(const geometry_msgs::Pose pose);
191 
192  private:
194  {
195  MODE_UI = 0,
200  DEMO_UI = 5,
201  };
202 
203  static const double DEGREE2RADIAN = M_PI / 180.0;
204  static const double RADIAN2DEGREE = 180.0 / M_PI;
205 
206  void parseJointNameFromYaml(const std::string& path);
207  void parseMotionMapFromYaml(const std::string& path);
208  void refreshCurrentJointControlCallback(const robotis_controller_msgs::JointCtrlModule::ConstPtr& msg);
209  void
210  updateHeadJointStatesCallback(const sensor_msgs::JointState::ConstPtr& msg);
211  void initFTFootCallback(const thormang3_feet_ft_module_msgs::BothWrench::ConstPtr& msg);
212  void
213  statusMsgCallback(const robotis_controller_msgs::StatusMsg::ConstPtr& msg);
214  void poseCallback(const geometry_msgs::Pose::ConstPtr& msg);
215  void interactiveMarkerFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback);
216  void pointStampedCallback(const geometry_msgs::PointStamped::ConstPtr& msg);
217  void setBalanceParameter();
219  void turnOnBalance();
220  void turnOffBalance();
222 
224  char** init_argv_;
227 
228  // demo : interactive marker
230  std::string frame_id_;
231  std::string marker_name_;
232  geometry_msgs::Pose pose_from_ui_;
233  geometry_msgs::Pose current_pose_;
235  thormang3_walking_module_msgs::SetBalanceParam set_balance_param_srv_;
236  thormang3_walking_module_msgs::SetJointFeedBackGain set_joint_feedback_gain_srv_;
237 
247 
250 
251  // Head
255 
256  // Manipulation
263 
265 
266  // Walking
273 
274  std::vector<geometry_msgs::Pose2D> preview_foot_steps_;
275  std::vector<int> preview_foot_types_;
276 
277  // Action
280 
282  QStringListModel logging_model_;
283  std::map<int, std::string> id_joint_table_;
284  std::map<std::string, int> joint_id_table_;
285  std::map<int, std::string> index_mode_table_;
286  std::map<std::string, int> mode_index_table_;
287  std::map<std::string, bool> using_mode_table_;
288 };
289 
290 } // namespace thormang3_demo
291 
292 #endif /* thormang3_demo_QNODE_HPP_ */
bool getIDJointNameFromIndex(const int &index, int &id, std::string &joint_name)
Definition: qnode.cpp:288
void statusMsgCallback(const robotis_controller_msgs::StatusMsg::ConstPtr &msg)
Definition: qnode.cpp:1554
void sendInitPoseMsg(std_msgs::String msg)
Definition: qnode.cpp:560
std::string marker_name_
Definition: qnode.hpp:231
ros::Subscriber pose_sub_
Definition: qnode.hpp:249
void pointStampedCallback(const geometry_msgs::PointStamped::ConstPtr &msg)
Definition: qnode.cpp:1266
ros::Publisher motion_page_pub_
Definition: qnode.hpp:279
ros::Publisher set_walking_footsteps_pub_
Definition: qnode.hpp:271
ros::Publisher marker_pub_
Definition: qnode.hpp:248
void parseMotionMapFromYaml(const std::string &path)
Definition: qnode.cpp:232
void poseCallback(const geometry_msgs::Pose::ConstPtr &msg)
Definition: qnode.cpp:1240
void visualizePreviewFootsteps(bool clear)
Definition: qnode.cpp:869
ros::Publisher init_ft_pub_
Definition: qnode.hpp:239
void sendDestJointMsg(thormang3_manipulation_module_msgs::JointPose msg)
Definition: qnode.cpp:567
ros::Subscriber current_module_control_sub_
Definition: qnode.hpp:245
ros::ServiceClient set_balance_param_client_
Definition: qnode.hpp:268
QNodeThor3(int argc, char **argv)
Definition: qnode.cpp:36
void setWalkingBalanceParam(const double &gyro_gain, const double &ft_gain_ratio, const double &imu_time_const, const double &ft_time_const)
Definition: qnode.cpp:714
ros::Publisher set_head_joint_angle_pub_
Definition: qnode.hpp:253
std::vector< int > preview_foot_types_
Definition: qnode.hpp:275
ros::Publisher module_control_pub_
Definition: qnode.hpp:240
bool isUsingModule(const std::string &module_name)
Definition: qnode.cpp:349
#define M_PI
void getKinematicsPose(std::string group_name)
Definition: qnode.cpp:638
void enableControlModule(const std::string &mode)
Definition: qnode.cpp:396
thormang3_walking_module_msgs::SetBalanceParam set_balance_param_srv_
Definition: qnode.hpp:235
void setWalkingBalance(bool on_command)
Definition: qnode.cpp:706
ros::Subscriber current_joint_states_sub_
Definition: qnode.hpp:254
ros::Subscriber init_ft_foot_sub_
Definition: qnode.hpp:243
bool loadBalanceParameterFromYaml()
Definition: qnode.cpp:988
void kickDemo(const std::string &kick_foot)
Definition: qnode.cpp:1496
void playMotion(int motion_index, bool to_action_script=true)
Definition: qnode.cpp:1204
void sendGripperPosition(sensor_msgs::JointState msg)
Definition: qnode.cpp:598
QStringListModel logging_model_
Definition: qnode.hpp:282
void refreshCurrentJointControlCallback(const robotis_controller_msgs::JointCtrlModule::ConstPtr &msg)
Definition: qnode.cpp:464
void updateCurrOri(double x, double y, double z, double w)
ros::Subscriber rviz_clicked_point_sub_
Definition: qnode.hpp:229
void updatePresentJointControlModules(std::vector< int > mode)
static const double RADIAN2DEGREE
Definition: qnode.hpp:204
ROSLIB_DECL std::string command(const std::string &cmd)
bool getJointNameFromID(const int &id, std::string &joint_name)
Definition: qnode.cpp:262
ros::ServiceClient get_module_control_client_
Definition: qnode.hpp:246
std::map< std::string, int > mode_index_table_
Definition: qnode.hpp:286
void interactiveMarkerFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
Definition: qnode.cpp:1276
thormang3_walking_module_msgs::SetJointFeedBackGain set_joint_feedback_gain_srv_
Definition: qnode.hpp:236
void setCurrentControlUI(int mode)
Definition: qnode.cpp:359
static const double DEGREE2RADIAN
Definition: qnode.hpp:203
ros::Publisher motion_index_pub_
Definition: qnode.hpp:278
ros::Publisher send_des_joint_msg_pub_
Definition: qnode.hpp:258
ros::ServiceClient get_joint_pose_client_
Definition: qnode.hpp:261
ros::Publisher module_control_preset_pub_
Definition: qnode.hpp:241
void updateDemoPose(const geometry_msgs::Pose pose)
void parseJointNameFromYaml(const std::string &path)
Definition: qnode.cpp:173
std::vector< geometry_msgs::Pose2D > preview_foot_steps_
Definition: qnode.hpp:274
ros::Subscriber status_msg_sub_
Definition: qnode.hpp:242
std::map< int, std::string > index_mode_table_
Definition: qnode.hpp:285
geometry_msgs::Pose current_pose_
Definition: qnode.hpp:233
ros::Publisher send_gripper_pub_
Definition: qnode.hpp:264
ros::Subscriber kenematics_pose_sub_
Definition: qnode.hpp:260
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > interactive_marker_server_
Definition: qnode.hpp:234
ros::ServiceClient get_kinematics_pose_client_
Definition: qnode.hpp:262
std::string package_name_
Definition: qnode.hpp:166
std::map< int, std::string > id_joint_table_
Definition: qnode.hpp:283
ros::ServiceClient humanoid_footstep_client_
Definition: qnode.hpp:267
ros::Publisher init_pose_pub_
Definition: qnode.hpp:238
void updateCurrPos(double x, double y, double z)
void log(const LogLevel &level, const std::string &msg, std::string sender="Demo")
Definition: qnode.cpp:1559
void getJointPose(std::string joint_name)
Definition: qnode.cpp:604
void setWalkingCommand(thormang3_foot_step_generator::FootStepCommand msg)
Definition: qnode.cpp:692
std::map< std::string, bool > using_mode_table_
Definition: qnode.hpp:287
void getKinematicsPoseCallback(const geometry_msgs::Pose::ConstPtr &msg)
Definition: qnode.cpp:684
void initFTFootCallback(const thormang3_feet_ft_module_msgs::BothWrench::ConstPtr &msg)
Definition: qnode.cpp:536
geometry_msgs::Pose pose_from_ui_
Definition: qnode.hpp:232
void updateHeadJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg)
Definition: qnode.cpp:510
std::map< int, std::string > module_table_
Definition: qnode.hpp:163
void updateHeadJointsAngle(double pan, double tilt)
ros::Publisher send_ik_msg_pub_
Definition: qnode.hpp:259
std::string getModuleName(const int &index)
Definition: qnode.cpp:307
std::map< int, std::string > motion_table_
Definition: qnode.hpp:164
void manipulationDemo(const int &index)
void initFTCommand(std::string command)
Definition: qnode.cpp:377
void updateDemoPoint(const geometry_msgs::Point point)
ros::ServiceClient set_joint_feedback_gain_client_
Definition: qnode.hpp:269
ros::Publisher move_lidar_pub_
Definition: qnode.hpp:252
void sendIkMsg(thormang3_manipulation_module_msgs::KinematicsPose msg)
Definition: qnode.cpp:580
int getModuleIndex(const std::string &mode_name)
Definition: qnode.cpp:319
ros::Subscriber both_ft_foot_sub_
Definition: qnode.hpp:244
void makeInteractiveMarker(const geometry_msgs::Pose &marker_pose)
Definition: qnode.cpp:1309
QStringListModel * loggingModel()
Definition: qnode.hpp:110
ros::Publisher set_walking_balance_pub_
Definition: qnode.hpp:272
ros::Publisher set_walking_command_pub_
Definition: qnode.hpp:270
std::map< std::string, int > joint_id_table_
Definition: qnode.hpp:284
void updateInteractiveMarker(const geometry_msgs::Pose &pose)
Definition: qnode.cpp:1452
ros::Publisher send_ini_pose_msg_pub_
Definition: qnode.hpp:257
void updateCurrJoint(double value)
bool getIDFromJointName(const std::string &joint_name, int &id)
Definition: qnode.cpp:275
void setHeadJoint(double pan, double tilt)
Definition: qnode.cpp:546


thormang3_demo
Author(s): Kayman
autogenerated on Mon Jun 10 2019 15:38:34