kinematics-dynamics
KeyboardController.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __KEYBOARD_CONTROLLER_HPP__
4 #define __KEYBOARD_CONTROLLER_HPP__
5 
6 #include <string>
7 #include <vector>
8 #include <functional>
9 
10 #include <yarp/os/RFModule.h>
11 #include <yarp/os/ResourceFinder.h>
12 
13 #include <yarp/dev/PolyDriver.h>
14 #include <yarp/dev/IControlLimits.h>
15 #include <yarp/dev/IControlMode.h>
16 #include <yarp/dev/IEncoders.h>
17 #include <yarp/dev/IPositionControl.h>
18 #include <yarp/dev/IVelocityControl.h>
19 
20 #include "LinearTrajectoryThread.hpp"
21 #include "ICartesianControl.h"
22 #include "KinematicRepresentation.hpp"
23 
24 namespace roboticslab
25 {
26 
36 class KeyboardController : public yarp::os::RFModule
37 {
38 public:
39  ~KeyboardController() override
40  { close(); }
41 
42  // used for array indexes and size checks
43  enum joint { Q1 = 0, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, MAX_JOINTS };
44  enum cart { X = 0, Y, Z, ROTX, ROTY, ROTZ, NUM_CART_COORDS };
45 
46  bool configure(yarp::os::ResourceFinder & rf) override;
47  bool updateModule() override;
48  bool interruptModule() override;
49  double getPeriod() override;
50  bool close() override;
51 
52 private:
53  enum control_modes { NOT_CONTROLLING, JOINT_MODE, CARTESIAN_MODE };
54  enum joint_mode { POSITION, VELOCITY };
55 
56  static const std::plus<double> increment_functor;
57  static const std::minus<double> decrement_functor;
58 
59  template <typename func>
60  void incrementOrDecrementJointCommand(joint j, func op);
61 
62  template <typename func>
63  void incrementOrDecrementCartesianCommand(cart coord, func op);
64 
65  void toggleJointMode();
66  void toggleReferenceFrame();
67 
68  void actuateTool(int command);
69 
70  void printJointPositions();
71  void printCartesianPositions();
72 
73  void issueStop();
74 
75  void printHelp();
76 
77  int axes {0};
78  int currentActuatorCommand {VOCAB_CC_ACTUATOR_NONE};
79 
80  double jointPosStep {0.0};
81  double jointVelStep {0.0};
82 
84  std::string angleRepr;
86  control_modes controlMode {NOT_CONTROLLING};
87  joint_mode jointMode {VELOCITY};
88 
89  bool usingThread {false};
90  LinearTrajectoryThread * linTrajThread {nullptr};
91 
92  yarp::dev::PolyDriver controlBoardDevice;
93  yarp::dev::PolyDriver cartesianControlDevice;
94 
95  yarp::dev::IEncoders * iEncoders {nullptr};
96  yarp::dev::IControlMode * iControlMode {nullptr};
97  yarp::dev::IControlLimits * iControlLimits {nullptr};
98  yarp::dev::IPositionControl * iPositionControl {nullptr};
99  yarp::dev::IVelocityControl * iVelocityControl {nullptr};
100 
101  roboticslab::ICartesianControl * iCartesianControl {nullptr};
102 
103  std::vector<double> minPositionLimits;
104  std::vector<double> maxPositionLimits;
105  std::vector<double> maxVelocityLimits;
106  std::vector<double> currentJointVels;
107  std::vector<double> currentCartVels;
108 };
109 
110 } // namespace roboticslab
111 
112 #endif // __KEYBOARD_CONTROLLER_HPP__
Contains roboticslab::ICartesianControl and related vocabs.
constexpr int VOCAB_CC_ACTUATOR_NONE
No actuator or no action.
Definition: ICartesianControl.h:114
Abstract base class for a cartesian controller.
Definition: ICartesianControl.h:146
reference_frame
Lists supported reference frames.
Definition: ICartesianSolver.h:27
@ BASE_FRAME
Base frame.
Definition: ICartesianSolver.h:28
Sends streaming commands to the cartesian controller from a standard keyboard.
Definition: KeyboardController.hpp:37
Periodic thread that encapsulates a linear trajectory.
Definition: LinearTrajectoryThread.hpp:24
orientation_system
Lists available rotational representations.
Definition: KinematicRepresentation.hpp:36
@ AXIS_ANGLE
(axis_x, axis_y, axis_z, rotation angle) [axis needs not to be normalized]
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6