action_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 /* Authors: Kayman, Jay Song */
18 
19 #ifndef ACTION_MOTION_MODULE_H_
20 #define ACTION_MOTION_MODULE_H_
21 
22 #define _USE_MATH_DEFINES
23 
24 #include <cmath>
25 #include <ros/ros.h>
26 #include <ros/package.h>
27 #include <ros/callback_queue.h>
28 #include <std_msgs/Int32.h>
29 #include <std_msgs/String.h>
30 #include <boost/thread.hpp>
31 
32 #include "robotis_controller_msgs/StatusMsg.h"
33 #include "op3_action_module_msgs/IsRunning.h"
34 #include "op3_action_module_msgs/StartAction.h"
36 #include "action_file_define.h"
37 
38 namespace robotis_op
39 {
40 
42 {
43  public:
44  ActionModule();
45  virtual ~ActionModule();
46 
47  void initialize(const int control_cycle_msec, robotis_framework::Robot *robot);
48  void process(std::map<std::string, robotis_framework::Dynamixel *> dxls, std::map<std::string, double> sensors);
49 
50  void stop();
51  bool isRunning();
52 
53  bool loadFile(std::string file_name);
54  bool createFile(std::string file_name);
55 
56  bool start(int page_number);
57  bool start(std::string page_name);
58  bool start(int page_number, action_file_define::Page* page);
59 
60  void onModuleEnable();
61  void onModuleDisable();
62 
63  void brake();
64  bool isRunning(int* playing_page_num, int* playing_step_num);
65  bool loadPage(int page_number, action_file_define::Page* page);
66  bool savePage(int page_number, action_file_define::Page* page);
68 
69  void enableAllJoints();
70  void actionPlayProcess(std::map<std::string, robotis_framework::Dynamixel *> dxls);
71 
72 private:
73  const int PRE_SECTION;
74  const int MAIN_SECTION;
75  const int POST_SECTION;
76  const int PAUSE_SECTION;
77  const int ZERO_FINISH;
78  const int NONE_ZERO_FINISH;
79  const bool DEBUG_PRINT;
80 
81  void queueThread();
82 
85 
86  void publishStatusMsg(unsigned int type, std::string msg);
87  void publishDoneMsg(std::string msg);
88 
89  bool isRunningServiceCallback(op3_action_module_msgs::IsRunning::Request &req,
90  op3_action_module_msgs::IsRunning::Response &res);
91 
92  void pageNumberCallback(const std_msgs::Int32::ConstPtr& msg);
93  void startActionCallback(const op3_action_module_msgs::StartAction::ConstPtr& msg);
94 
95  int convertRadTow4095(double rad);
96  double convertw4095ToRad(int w4095);
97  std::string convertIntToString(int n);
98 
99  std::map<std::string, bool> action_joints_enable_;
100  std::map<std::string, robotis_framework::DynamixelState *> action_result_;
102  boost::thread queue_thread_;
103 
104  /* sample subscriber & publisher */
108  std::map<std::string, int> joint_name_to_id_;
109  std::map<int, std::string> joint_id_to_name_;
114 
118 
119  bool playing_;
122 
126 };
127 
128 }
129 
130 #endif /* OP3_ACTION_MOTION_MODULE_H_ */
double convertw4095ToRad(int w4095)
ros::Publisher status_msg_pub_
bool loadFile(std::string file_name)
std::string convertIntToString(int n)
std::map< int, std::string > joint_id_to_name_
boost::thread queue_thread_
void resetPage(action_file_define::Page *page)
std::map< std::string, bool > action_joints_enable_
Definition: action_module.h:99
void actionPlayProcess(std::map< std::string, robotis_framework::Dynamixel * > dxls)
void setChecksum(action_file_define::Page *page)
bool createFile(std::string file_name)
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, double > sensors)
bool verifyChecksum(action_file_define::Page *page)
bool start(int page_number)
void publishStatusMsg(unsigned int type, std::string msg)
action_file_define::Page next_play_page_
void startActionCallback(const op3_action_module_msgs::StartAction::ConstPtr &msg)
void publishDoneMsg(std::string msg)
bool isRunningServiceCallback(op3_action_module_msgs::IsRunning::Request &req, op3_action_module_msgs::IsRunning::Response &res)
int convertRadTow4095(double rad)
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
bool loadPage(int page_number, action_file_define::Page *page)
action_file_define::Step current_step_
ros::Publisher done_msg_pub_
std::map< std::string, robotis_framework::DynamixelState * > action_result_
std::map< std::string, int > joint_name_to_id_
action_file_define::Page play_page_
void pageNumberCallback(const std_msgs::Int32::ConstPtr &msg)
bool savePage(int page_number, action_file_define::Page *page)


op3_action_module
Author(s): Kayman , Jay Song
autogenerated on Mon Jun 10 2019 14:41:06