yarp-devices
Loading...
Searching...
No Matches
EmulatedControlBoard.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __EMULATED_CONTROL_BOARD_HPP__
4#define __EMULATED_CONTROL_BOARD_HPP__
5
6#include <mutex>
7#include <vector>
8
9#include <yarp/os/PeriodicThread.h>
10
11#include <yarp/dev/DeviceDriver.h>
12#include <yarp/dev/IControlLimits.h>
13#include <yarp/dev/IControlMode.h>
14#include <yarp/dev/IEncodersTimed.h>
15#include <yarp/dev/IPositionControl.h>
16#include <yarp/dev/IPositionDirect.h>
17#include <yarp/dev/IVelocityControl.h>
18#include <yarp/dev/PolyDriver.h>
19
20#include "EmulatedControlBoard_ParamsParser.h"
21
22
33class EmulatedControlBoard : public yarp::dev::DeviceDriver,
34 public yarp::dev::IControlLimits,
35 public yarp::dev::IControlMode,
36 public yarp::dev::IEncodersTimed,
37 public yarp::dev::IPositionControl,
38 public yarp::dev::IPositionDirect,
39 public yarp::dev::IVelocityControl,
40 public yarp::os::PeriodicThread,
42{
43public:
44
45 // Set the thread period in the class constructor
46 EmulatedControlBoard() : yarp::os::PeriodicThread(1.0) {} // In seconds
47
48 // ------- IPositionControl declarations. Implementation in IPositionControlImpl.cpp -------
49
50 bool getAxes(int *ax) override;
51 bool positionMove(int j, double ref) override;
52 bool positionMove(const double *refs) override;
53 bool relativeMove(int j, double delta) override;
54 bool relativeMove(const double *deltas) override;
55 bool checkMotionDone(int j, bool *flag) override;
56 bool checkMotionDone(bool *flag) override;
57 bool setRefSpeed(int j, double sp) override;
58 bool setRefSpeeds(const double *spds) override;
59 bool setRefAcceleration(int j, double acc) override;
60 bool setRefAccelerations(const double *accs) override;
61 bool getRefSpeed(int j, double *ref) override;
62 bool getRefSpeeds(double *spds) override;
63 bool getRefAcceleration(int j, double *acc) override;
64 bool getRefAccelerations(double *accs) override;
65 bool stop(int j) override;
66 bool stop() override;
67 bool positionMove(int n_joint, const int *joints, const double *refs) override;
68 bool relativeMove(int n_joint, const int *joints, const double *deltas) override;
69 bool checkMotionDone(int n_joint, const int *joints, bool *flags) override;
70 bool setRefSpeeds(int n_joint, const int *joints, const double *spds) override;
71 bool setRefAccelerations(int n_joint, const int *joints, const double *accs) override;
72 bool getRefSpeeds(int n_joint, const int *joints, double *spds) override;
73 bool getRefAccelerations(int n_joint, const int *joints, double *accs) override;
74 bool stop(int n_joint, const int *joints) override;
75 bool getTargetPosition(int joint, double *ref) override;
76 bool getTargetPositions(double *refs) override;
77 bool getTargetPositions(int n_joint, const int *joints, double *refs) override;
78
79 // ------- IPositionDirect declarations. Implementation in IPositionDirectImpl.cpp -------
80
81 bool setPosition(int j, double ref) override;
82 bool setPositions(int n_joint, const int *joints, const double *refs) override;
83 bool setPositions(const double *refs) override;
84 bool getRefPosition(int joint, double *ref) override;
85 bool getRefPositions(double *refs) override;
86 bool getRefPositions(int n_joint, const int *joints, double *refs) override;
87
88 // ---------- IEncodersTimed Declarations. Implementation in IEncoderImpl.cpp ----------
89
90 bool resetEncoder(int j) override;
91 bool resetEncoders() override;
92 bool setEncoder(int j, double val) override;
93 bool setEncoders(const double *vals) override;
94 bool getEncoder(int j, double *v) override;
95 bool getEncoders(double *encs) override;
96 bool getEncoderSpeed(int j, double *sp) override;
97 bool getEncoderSpeeds(double *spds) override;
98 bool getEncoderAcceleration(int j, double *spds) override;
99 bool getEncoderAccelerations(double *accs) override;
100 bool getEncodersTimed(double *encs, double *time) override;
101 bool getEncoderTimed(int j, double *encs, double *time) override;
102
103 // --------- IVelocityControl Declarations. Implementation in IVelocityControlImpl.cpp ---------
104
105 bool velocityMove(int j, double sp) override;
106 bool velocityMove(const double *sp) override;
107 bool velocityMove(int n_joint, const int *joints, const double *spds) override;
108 bool getRefVelocity(int joint, double *vel) override;
109 bool getRefVelocities(double *vels) override;
110 bool getRefVelocities(int n_joint, const int *joints, double *vels) override;
111
112 // --------- IControlLimits Declarations. Implementation in IControlLimitsImpl.cpp ---------
113
114 bool setLimits(int axis, double min, double max) override;
115 bool getLimits(int axis, double *min, double *max) override;
116 bool setVelLimits(int axis, double min, double max) override;
117 bool getVelLimits(int axis, double *min, double *max) override;
118
119 // --------- IControlMode Declarations. Implementation in IControlModeImpl.cpp ---------
120
121 bool getControlMode(int j, int *mode) override;
122 bool getControlModes(int *modes) override;
123 bool getControlModes(int n_joint, const int *joints, int *modes) override;
124 bool setControlMode(int j, const int mode) override;
125 bool setControlModes(int n_joint, const int *joints, int *modes) override;
126 bool setControlModes(int *modes) override;
127
128 // -------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp --------
129
130 bool open(yarp::os::Searchable& config) override;
131 bool close() override;
132
133 // -------- PeriodicThread declarations. Implementation in PeriodicThreadImpl.cpp --------
134
135 bool threadInit() override;
136 void run() override;
137
138protected:
139
140 // ----- Shared Area Funcion declarations. Implementation in SharedArea.cpp -----
141
142 void setEncRaw(const int index, const double position);
143 void setEncsRaw(const std::vector<double> & positions);
144
145 double getEncRaw(const int index);
146 std::vector<double> getEncsRaw();
147
148 double getEncExposed(const int index);
149 std::vector<double> getEncsExposed();
150
151private:
152
153 enum jmc_state { NOT_CONTROLLING, POSITION_MOVE, RELATIVE_MOVE, VELOCITY_MOVE };
154 enum jmc_mode { POSITION_MODE, VELOCITY_MODE, POSITION_DIRECT_MODE, UNKNOWN_MODE };
155
156 bool setPositionMode(int j);
157 bool setVelocityMode(int j);
158 bool setTorqueMode(int j);
159 bool setPositionDirectMode(int j);
160
161 // General Joint Motion Controller parameters //
162 jmc_mode controlMode {UNKNOWN_MODE};
163 double lastTime {0.0};
164
165 std::mutex encRawMutex; // SharedArea
166
167 std::vector<jmc_state> jointStatus;
168
169 std::vector<double> encRaw;
170 std::vector<double> refAcc; // Exposed.
171 std::vector<double> targetExposed; // Exposed.
172 std::vector<double> velRaw;
173};
174
175#endif // __EMULATED_CONTROL_BOARD_HPP__
Definition EmulatedControlBoard_ParamsParser.h:58
Implements several motor interfaces.
Definition EmulatedControlBoard.hpp:42