HLR  0.0.1
Driver.hpp
1 #ifndef KINEMATICS_RV2AJ_DRIVER_HPP
2 #define KINEMATICS_RV2AJ_DRIVER_HPP
3 
4 #include <ros/ros.h>
5 #include <std_msgs/String.h>
6 #include "HLR/RV2AJDriverClear.h"
7 #include "HLR/RV2AJDriverContinue.h"
8 #include "HLR/RV2AJDriverMB4.h"
9 #include "HLR/RV2AJDriverPause.h"
10 #include "HLR/RV2AJDriverQueueAdd.h"
11 #include "HLR/RV2AJDriverQueueCount.h"
12 
13 #include <condition_variable>
14 #include <mutex>
15 #include <queue>
16 #include <thread>
17 
18 namespace HLR
19 {
20 namespace Kinematics
21 {
22 namespace RV2AJ
23 {
25 class Driver
26 {
27 public:
29  Driver();
30 
32  virtual ~Driver();
33 
38  Driver(const Driver& d) = delete;
39 
44  Driver(Driver&& d) = delete;
45 
51  Driver& operator=(const Driver& d) = delete;
52 
58  Driver& operator=(Driver&& d) = delete;
59 
66  bool cont(HLR::RV2AJDriverContinue::Request& req,
67  HLR::RV2AJDriverContinue::Response& res);
68 
75  bool pause(HLR::RV2AJDriverPause::Request& req,
76  HLR::RV2AJDriverPause::Response& res);
77 
84  bool clear(HLR::RV2AJDriverClear::Request& req,
85  HLR::RV2AJDriverClear::Response& res);
86 
93  bool queue_count(HLR::RV2AJDriverQueueCount::Request& req,
94  HLR::RV2AJDriverQueueCount::Response& res);
95 
102  bool queue_add(HLR::RV2AJDriverQueueAdd::Request& req,
103  HLR::RV2AJDriverQueueAdd::Response& res);
104 
105 private:
112  struct Command
113  {
118  std::string to_mb4() const;
119 
121  double base;
123  double shoulder;
125  double elbow;
127  double j4;
129  double wrist;
131  double wrist_rotate;
133  double j7;
135  double speed;
136  };
137 
138  enum class State
139  {
141  cont = 0,
143  pause = 1,
145  exit = 2
146  };
147 
149  void work();
150 
152  ros::NodeHandle nh;
153 
155  ros::Publisher pub_mb4;
156 
158  ros::ServiceServer srv_continue;
159 
161  ros::ServiceServer srv_pause;
162 
164  ros::ServiceServer srv_clear;
165 
167  ros::ServiceServer srv_queue_count;
168 
170  ros::ServiceServer srv_queue_add;
171 
173  std::thread worker;
174 
176  State worker_state = State::cont;
177 
179  std::mutex worker_state_m;
180 
182  std::queue<Command> commands;
183 
185  std::mutex commands_m;
186 
188  std::condition_variable commands_cv;
189 };
190 } // namespace RV2AJ
191 } // namespace Kinematics
192 } // namespace HLR
193 
194 #endif /* KINEMATICS_RV2AJ_DRIVER_HPP */
Driver for the Mitsubishi RV2-AJ.
Definition: Driver.hpp:25
bool queue_add(HLR::RV2AJDriverQueueAdd::Request &req, HLR::RV2AJDriverQueueAdd::Response &res)
Add requested command to the queue if compliant.
virtual ~Driver()
Destructor.
bool pause(HLR::RV2AJDriverPause::Request &req, HLR::RV2AJDriverPause::Response &res)
Pause processing events in queue.
bool clear(HLR::RV2AJDriverClear::Request &req, HLR::RV2AJDriverClear::Response &res)
Clears all to-be processed events in queue.
bool cont(HLR::RV2AJDriverContinue::Request &req, HLR::RV2AJDriverContinue::Response &res)
Continue processing events in queue.
bool queue_count(HLR::RV2AJDriverQueueCount::Request &req, HLR::RV2AJDriverQueueCount::Response &res)
Returns the number of elements currently inside the queue.
Driver & operator=(const Driver &d)=delete
Copy assignment operator, deleted.