HLR  0.0.1
RobotController.hpp
1 #ifndef KINEMATICS_ROBOTCONTROLLER_HPP
2 #define KINEMATICS_ROBOTCONTROLLER_HPP
3 
4 #include <ros/ros.h>
5 #include "Planners/Planner.hpp"
6 #include <CGAL/Simple_cartesian.h>
7 #include <CGAL/Surface_mesh.h>
8 #include <Kinematics/ConcurrentQueue.hpp>
9 #include <Kinematics/Matrix.hpp>
10 
11 #include <mutex>
12 #include <stdexcept>
13 #include <thread>
14 #include <unordered_set>
15 
16 #include "RobotDriverHandler.hpp"
17 
18 namespace HLR
19 {
20 namespace Kinematics
21 {
26 {
30  std::uint32_t id;
31 
36 
41 
45  bool is_cup;
46 
50  bool has_speed;
51 
55  CGAL::Surface_mesh<CGAL::Simple_cartesian<double>::Point_3> polyhedron;
56 };
57 
62 {
66  init,
67 
71  idle,
72 
77 
82 
87 
92 
96  moving_cup,
97 
102 
106  stopped
107 };
108 
113 enum class ArmError
114 {
119 
125 
131 };
132 
139 {
140 public:
145  enum class Event
146  {
150  move_to_ready,
151 
155  move_to_cup,
156 
160  pick_up_cup_stage1,
161 
165  pick_up_cup_stage2,
166 
170  move_cup,
171 
176  move_stop,
177 
181  move_continue,
182 
186  move_cancel,
187 
191  terminate
192  };
193 
200 
204  virtual ~RobotController();
205 
210  RobotController(const RobotController& rc) = delete;
211 
216  RobotController(RobotController&& rc) = delete;
217 
223  RobotController& operator=(const RobotController& rc) = delete;
224 
230  RobotController& operator=(RobotController&& rc) = delete;
231 
237  RobotControllerState get_state() const;
238 
249  void pick_up_cup(std::uint32_t id);
250 
256  void move_stop();
257 
263  void move_continue();
264 
272  void move_cancel();
273 
280  void remove_object(const EnvironmentObject& obj);
281 
287  void add_object(EnvironmentObject&& obj);
288 
298  void set_error_callback(const std::function<void(ArmError)>& cb);
299 
300 private:
301  void set_state(RobotControllerState state);
302 
307  void position_reached();
308 
316  void move_to_position(const Matrix<double, 3, 1>& pos,
317  const Planners::Planner& planner,
318  double speed);
319 
324  void event_handler();
325 
329  void move_to_ready_handler();
330 
334  void pick_up_cup_handler();
335 
339  void pick_up_cup_stage1_handler();
340 
344  void pick_up_cup_stage2_handler();
345 
349  void move_cup_handler();
350 
354  void move_stop_handler();
355 
359  void move_continue_handler();
360 
364  void move_cancel_handler();
365 
369  const Matrix<double, 3, 1> target_position = {{0.2}, {0.0}, {0.4}};
370 
374  const Matrix<double, 3, 1> ready_pos = {{0.357}, {0.216506}, {0}};
375 
380  const double ground_level = 0;
381 
386  const double distance_from_cup = 0.12;
387 
391  const double angle_step_size = 360;
392 
396  const double euclidean_step_size = 0.05;
397 
402  std::function<void(ArmError)> error_callback;
403 
408  bool is_carrying = false;
409 
414 
418  mutable std::mutex state_m;
419 
423  Matrix<double, 3, 1> cup_position;
424 
428  std::unordered_map<std::uint32_t, EnvironmentObject> objects;
429 
433  mutable std::recursive_mutex objects_m;
434 
439  std::thread worker;
440 
444  ConcurrentQueue<Event> events;
445 
449  RobotDriverHandler& driver;
450 };
451 
452 } // namespace Kinematics
453 } // namespace HLR
454 
455 #endif
Matrix< double, 3, 1 > velocity
The velocity vector of the object.
Definition: RobotController.hpp:40
Robot arm is moving gripper to surround the cup.
Robot arm is moving to ready position,.
CGAL::Surface_mesh< CGAL::Simple_cartesian< double >::Point_3 > polyhedron
The CGAL polyhedron data. This can be used for collision checking.
Definition: RobotController.hpp:55
RobotControllerState
The current state of the robot controller.
Definition: RobotController.hpp:61
The arm has stopped due to a safety concern.
std::uint32_t id
The id of the object.
Definition: RobotController.hpp:30
Describes an object that is detected in the environment.
Definition: RobotController.hpp:25
This class contains the main logic of the robotic arm. It handles the calculation of robotic path and...
Definition: RobotController.hpp:138
Abstract class that forces.
Definition: Planner.hpp:17
The arm couldn&#39;t be moved because there is an underlying driver error.
Robot arm is currently stopped.
bool has_speed
Whether this object has a valid speed.
Definition: RobotController.hpp:50
The arm has stopped because no valid path was found to execute the given action.
Concrete handle on the robot using the ROS interface.
Definition: RobotDriverHandler.hpp:19
Event
Internal event class. These events are send to the worker thread and handled accordingly.
Definition: RobotController.hpp:145
bool is_cup
Whether this object is a cup.
Definition: RobotController.hpp:45
Is idle waiting to pick up a cup.
ArmError
Enum containing possible reasons for the robot arm not being able to succesfully execute the specifie...
Definition: RobotController.hpp:113
Matrix< double, 3, 1 > position
The position vector of the object.
Definition: RobotController.hpp:35