yarp-devices
Loading...
Searching...
No Matches
FakeJoint.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __FAKE_JOINT_HPP__
4#define __FAKE_JOINT_HPP__
5
6#include <string>
7
8#include <yarp/os/SystemClock.h>
9#include <yarp/dev/ControlBoardInterfaces.h>
10
11#include "ICanBusSharer.hpp"
12#include "FakeJoint_ParamsParser.h"
13
14constexpr auto JOINT_TYPE = yarp::dev::VOCAB_JOINTTYPE_REVOLUTE; // yarpmotorgui can't handle VOCAB_JOINTTYPE_UNKNOWN
15
26class FakeJoint : public yarp::dev::DeviceDriver,
27 public yarp::dev::IAmplifierControlRaw,
28 public yarp::dev::IAxisInfoRaw,
29 public yarp::dev::IControlCalibrationRaw,
30 public yarp::dev::IControlLimitsRaw,
31 public yarp::dev::IControlModeRaw,
32 public yarp::dev::ICurrentControlRaw,
33 public yarp::dev::IEncodersTimedRaw,
34 public yarp::dev::IImpedanceControlRaw,
35 public yarp::dev::IInteractionModeRaw,
36 public yarp::dev::IMotorRaw,
37 public yarp::dev::IMotorEncodersRaw,
38 public yarp::dev::IPidControlRaw,
39 public yarp::dev::IPositionControlRaw,
40 public yarp::dev::IPositionDirectRaw,
41 public yarp::dev::IPWMControlRaw,
42 public yarp::dev::IRemoteVariablesRaw,
43 public yarp::dev::ITorqueControlRaw,
44 public yarp::dev::IVelocityControlRaw,
47{
48public:
49 // --------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp ---------
50
51 bool open(yarp::os::Searchable & config) override;
52
53 bool close() override
54 { return true; }
55
56 // --------- ICanBusSharer declarations ---------
57
58 unsigned int getId() override
59 { return 0; }
60 bool notifyMessage(const roboticslab::can_message & message) override
61 { return true; }
62 bool initialize() override
63 { return true; }
64 bool finalize() override
65 { return true; }
67 { return true; }
68 bool synchronize(double timestamp) override
69 { return true; }
70
71 // --------- IAmplifierControlRaw declarations ---------
72
73 bool enableAmpRaw(int j) override
74 { return true; }
75 bool disableAmpRaw(int j) override
76 { return true; }
77 bool getAmpStatusRaw(int j, int * v) override
78 { *v = 0; return true; }
79 bool getAmpStatusRaw(int * st) override
80 { *st = 0; return true; }
81 //bool getCurrentRaw(int j, double * val) override;
82 //bool getCurrentsRaw(double * vals) override;
83 bool getMaxCurrentRaw(int j, double * v) override
84 { *v = 0.0; return true; }
85 bool setMaxCurrentRaw(int j, double v) override
86 { return true; }
87 bool getNominalCurrentRaw(int m, double * val) override
88 { *val = 0.0; return true; }
89 bool setNominalCurrentRaw(int m, double val) override
90 { return true; }
91 bool getPeakCurrentRaw(int m, double * val) override
92 { *val = 0.0; return true; }
93 bool setPeakCurrentRaw(int m, double val) override
94 { return true; }
95 bool getPWMRaw(int j, double * val) override
96 { *val = 0.0; return true; }
97 bool getPWMLimitRaw(int j, double * val) override
98 { *val = 0.0; return true; }
99 bool setPWMLimitRaw(int j, double val) override
100 { return true; }
101 bool getPowerSupplyVoltageRaw(int j, double * val) override
102 { *val = 0.0; return true; }
103
104 // --------- IAxisInfoRaw declarations ---------
105
106 bool getAxisNameRaw(int axis, std::string & name) override
107 { name = m_jointName; return true; }
108 bool getJointTypeRaw(int axis, yarp::dev::JointTypeEnum & type) override
109 { type = JOINT_TYPE; return true; }
110
111 // --------- IControlCalibrationRaw declarations ---------
112
113 bool calibrateAxisWithParamsRaw(int axis, unsigned int type, double p1, double p2, double p3) override
114 { return true; }
115 bool setCalibrationParametersRaw(int axis, const yarp::dev::CalibrationParameters & params) override
116 { return true; }
117 bool calibrationDoneRaw(int j) override
118 { return true; }
119
120 // --------- IControlLimitsRaw declarations ---------
121
122 bool setLimitsRaw(int axis, double min, double max) override
123 { return true; }
124 bool getLimitsRaw(int axis, double * min, double * max) override
125 { *min = *max = 0.0; return true; }
126 bool setVelLimitsRaw(int axis, double min, double max) override
127 { return true; }
128 bool getVelLimitsRaw(int axis, double * min, double * max) override
129 { *min = *max = 0.0; return true; }
130
131 // --------- IControlModeRaw declarations ---------
132
133 bool getControlModeRaw(int j, int * mode) override
134 { *mode = controlMode; return true; }
135 bool getControlModesRaw(int * modes) override
136 { return getControlModeRaw(0, &modes[0]); }
137 bool getControlModesRaw(int n_joint, const int * joints, int * modes) override
138 { return getControlModeRaw(0, &modes[0]); }
139 bool setControlModeRaw(int j, int mode) override
140 { controlMode = mode; return true; }
141 bool setControlModesRaw(int * modes) override
142 { return setControlModeRaw(0, modes[0]); }
143 bool setControlModesRaw(int n_joint, const int * joints, int * modes) override
144 { return setControlModeRaw(0, modes[0]); }
145
146 // --------- ICurrentControlRaw declarations ---------
147
148 //bool getNumberOfMotorsRaw(int * ax) override;
149 bool getCurrentRaw(int m, double * curr) override
150 { *curr = 0.0; return true; }
151 bool getCurrentsRaw(double * currs) override
152 { return getCurrentRaw(0, &currs[0]); }
153 bool getCurrentRangeRaw(int m, double * min, double * max) override
154 { *min = *max = 0.0; return true; }
155 bool getCurrentRangesRaw(double * mins, double * maxs) override
156 { return getCurrentRangeRaw(0, &mins[0], &maxs[0]); }
157 bool setRefCurrentRaw(int m, double curr) override
158 { return true; }
159 bool setRefCurrentsRaw(const double * currs) override
160 { return true; }
161 bool setRefCurrentsRaw(int n_motor, const int * motors, const double * currs) override
162 { return true; }
163 bool getRefCurrentRaw(int m, double * curr) override
164 { *curr = 0.0; return true; }
165 bool getRefCurrentsRaw(double * currs) override
166 { return getRefCurrentRaw(0, &currs[0]); }
167
168 // ---------- IEncodersRaw declarations ----------.
169
170 bool getAxes(int * ax) override
171 { *ax = 1; return true; }
172 bool resetEncoderRaw(int j) override
173 { return true; }
174 bool resetEncodersRaw() override
175 { return true; }
176 bool setEncoderRaw(int j, double val) override
177 { return true; }
178 bool setEncodersRaw(const double * vals) override
179 { return true; }
180 bool getEncoderRaw(int j, double * v) override
181 { *v = 0.0; return true; }
182 bool getEncodersRaw(double * encs) override
183 { return getEncoderRaw(0, &encs[0]); }
184 bool getEncoderSpeedRaw(int j, double * spd) override
185 { *spd = 0.0; return true; }
186 bool getEncoderSpeedsRaw(double * spds) override
187 { return getEncoderRaw(0, &spds[0]); }
188 bool getEncoderAccelerationRaw(int j, double * acc) override
189 { *acc = 0.0; return true; }
190 bool getEncoderAccelerationsRaw(double * accs) override
191 { return getEncoderAccelerationRaw(0, &accs[0]); }
192
193 // ---------- IEncodersTimedRaw declarations ----------
194
195 bool getEncoderTimedRaw(int j, double * enc, double * time) override
196 { *enc = 0.0; *time = yarp::os::SystemClock::nowSystem(); return true; }
197 bool getEncodersTimedRaw(double * encs, double * times) override
198 { return getEncoderTimedRaw(0, &encs[0], &times[0]); }
199
200 // --------- IImpedanceControlRaw declarations ---------
201
202 //bool getAxes(int * ax) override;
203 bool getImpedanceRaw(int j, double * stiffness, double * damping) override
204 { *stiffness = *damping = 0.0; return true; }
205 bool setImpedanceRaw(int j, double stiffness, double damping) override
206 { return true; }
207 bool setImpedanceOffsetRaw(int j, double offset) override
208 { return true; }
209 bool getImpedanceOffsetRaw(int j, double * offset) override
210 { *offset = 0.0; return true; }
211 bool getCurrentImpedanceLimitRaw(int j, double * min_stiff, double * max_stiff, double * min_damp, double * max_damp) override
212 { *min_stiff = *max_stiff = *min_damp = *max_damp = 0.0; return true; }
213
214 // ------- IInteractionModeRaw declarations -------
215
216 bool getInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum * mode) override
217 { *mode = interactionMode; return true; }
218 bool getInteractionModesRaw(yarp::dev::InteractionModeEnum * modes) override
219 { return getInteractionModeRaw(0, &modes[0]); }
220 bool getInteractionModesRaw(int n_joints, int * joints, yarp::dev::InteractionModeEnum * modes) override
221 { return getInteractionModeRaw(0, &modes[0]); }
222 bool setInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum mode) override
223 { interactionMode = mode; return true; }
224 bool setInteractionModesRaw(yarp::dev::InteractionModeEnum * modes) override
225 { return true; }
226 bool setInteractionModesRaw(int n_joints, int * joints, yarp::dev::InteractionModeEnum * modes) override
227 { return true; }
228
229 // --------- IMotorRaw declarations ---------
230
231 bool getNumberOfMotorsRaw(int * num) override
232 { return getAxes(num); }
233 bool getTemperatureRaw(int m, double * val) override
234 { *val = 0.0; return true; }
235 bool getTemperaturesRaw(double * vals) override
236 { return getTemperatureRaw(0, &vals[0]); }
237 bool getTemperatureLimitRaw(int m, double * temp) override
238 { *temp = 0.0; return true; }
239 bool setTemperatureLimitRaw(int m, double temp) override
240 { return true; }
241 bool getGearboxRatioRaw(int m, double * val) override
242 { *val = 0.0; return true; }
243 bool setGearboxRatioRaw(int m, double val) override
244 { return true; }
245
246 // --------- IMotorEncodersRaw declarations ---------
247
248 bool getNumberOfMotorEncodersRaw(int * num) override
249 { return getAxes(num); }
250 bool resetMotorEncoderRaw(int m) override
251 { return true; }
252 bool resetMotorEncodersRaw() override
253 { return true; }
254 bool setMotorEncoderCountsPerRevolutionRaw(int m, double cpr) override
255 { return true; }
256 bool getMotorEncoderCountsPerRevolutionRaw(int m, double * cpr) override
257 { *cpr = 0.0; return true; }
258 bool setMotorEncoderRaw(int m, double val) override
259 { return true; }
260 bool setMotorEncodersRaw(const double * vals) override
261 { return true; }
262 bool getMotorEncoderRaw(int m, double * v) override
263 { *v = 0.0; return true; }
264 bool getMotorEncodersRaw(double * encs) override
265 { return getMotorEncoderRaw(0, &encs[0]); }
266 bool getMotorEncoderTimedRaw(int m, double * enc, double * stamp) override
267 { *enc = 0.0; *stamp = yarp::os::SystemClock::nowSystem(); return true; }
268 bool getMotorEncodersTimedRaw(double * encs, double * stamps) override
269 { return getMotorEncoderTimedRaw(0, &encs[0], &stamps[0]); }
270 bool getMotorEncoderSpeedRaw(int m, double * sp) override
271 { *sp = 0.0; return true; }
272 bool getMotorEncoderSpeedsRaw(double *spds) override
273 { return getMotorEncoderSpeedRaw(0, &spds[0]); }
274 bool getMotorEncoderAccelerationRaw(int m, double * acc) override
275 { *acc = 0.0; return true; }
276 bool getMotorEncoderAccelerationsRaw(double * accs) override
277 { return getMotorEncoderAccelerationRaw(0, &accs[0]); }
278
279 // --------- IPidControlRaw declarations ---------
280
281 bool setPidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, const yarp::dev::Pid & pid) override
282 { return true; }
283 bool setPidsRaw(const yarp::dev::PidControlTypeEnum & pidtype, const yarp::dev::Pid * pids) override
284 { return true; }
285 bool setPidReferenceRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double ref) override
286 { return true; }
287 bool setPidReferencesRaw(const yarp::dev::PidControlTypeEnum & pidtype, const double * refs) override
288 { return true; }
289 bool setPidErrorLimitRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double limit) override
290 { return true; }
291 bool setPidErrorLimitsRaw(const yarp::dev::PidControlTypeEnum & pidtype, const double * limits) override
292 { return true; }
293 bool getPidErrorRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * err) override
294 { *err = 0.0; return true; }
295 bool getPidErrorsRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * errs) override
296 { return getPidErrorRaw(pidtype, 0, &errs[0]); }
297 bool getPidOutputRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * out) override
298 { *out = 0.0; return true; }
299 bool getPidOutputsRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * outs) override
300 { return getPidOutputRaw(pidtype, 0, &outs[0]); }
301 bool getPidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, yarp::dev::Pid * pid) override
302 { return true; }
303 bool getPidsRaw(const yarp::dev::PidControlTypeEnum & pidtype, yarp::dev::Pid * pids) override
304 { return true; }
305 bool getPidReferenceRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * ref) override
306 { *ref = 0.0; return true; }
307 bool getPidReferencesRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * refs) override
308 { return getPidReferenceRaw(pidtype, 0, &refs[0]); }
309 bool getPidErrorLimitRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * limit) override
310 { *limit = 0.0; return true; }
311 bool getPidErrorLimitsRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * limits) override
312 { return getPidErrorLimitRaw(pidtype, 0, &limits[0]); }
313 bool resetPidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j) override
314 { return true; }
315 bool disablePidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j) override
316 { return true; }
317 bool enablePidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j) override
318 { return true; }
319 bool setPidOffsetRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double v) override
320 { return true; }
321 bool isPidEnabledRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, bool * enabled) override
322 { *enabled = true; return true; }
323
324 // ------- IPositionControlRaw declarations -------
325
326 //bool getAxesRaw(int * ax) override;
327 bool positionMoveRaw(int j, double ref) override
328 { return true; }
329 bool positionMoveRaw(const double * refs) override
330 { return true; }
331 bool positionMoveRaw(int n_joint, const int * joints, const double * refs) override
332 { return true; }
333 bool relativeMoveRaw(int j, double delta) override
334 { return true; }
335 bool relativeMoveRaw(const double * deltas) override
336 { return true; }
337 bool relativeMoveRaw(int n_joint, const int * joints, const double * deltas) override
338 { return true; }
339 bool checkMotionDoneRaw(int j, bool * flag) override
340 { *flag = true; return true; }
341 bool checkMotionDoneRaw(bool * flag) override
342 { return checkMotionDoneRaw(0, flag); }
343 bool checkMotionDoneRaw(int n_joint, const int * joints, bool * flag) override
344 { return checkMotionDoneRaw(0, flag); }
345 bool setRefSpeedRaw(int j, double sp) override
346 { return true; }
347 bool setRefSpeedsRaw(const double * spds) override
348 { return true; }
349 bool setRefSpeedsRaw(int n_joint, const int * joints, const double * spds) override
350 { return true; }
351 bool setRefAccelerationRaw(int j, double acc) override
352 { return true; }
353 bool setRefAccelerationsRaw(const double * accs) override
354 { return true; }
355 bool setRefAccelerationsRaw(int n_joint, const int * joints, const double * accs) override
356 { return true; }
357 bool getRefSpeedRaw(int j, double * spd) override
358 { *spd = 0.0; return true; }
359 bool getRefSpeedsRaw(double * spds) override
360 { return getRefSpeedRaw(0, &spds[0]); }
361 bool getRefSpeedsRaw(int n_joint, const int * joints, double * spds) override
362 { return getRefSpeedRaw(0, &spds[0]); }
363 bool getRefAccelerationRaw(int j, double * acc) override
364 { *acc = 0.0; return true; }
365 bool getRefAccelerationsRaw(double * accs) override
366 { return getRefAccelerationRaw(0, &accs[0]); }
367 bool getRefAccelerationsRaw(int n_joint, const int * joints, double * accs) override
368 { return getRefAccelerationRaw(0, &accs[0]); }
369 bool stopRaw(int j) override
370 { return true; }
371 bool stopRaw() override
372 { return true; }
373 bool stopRaw(int n_joint, const int *joints) override
374 { return true; }
375 bool getTargetPositionRaw(int joint, double * ref) override
376 { *ref = 0.0; return true; }
377 bool getTargetPositionsRaw(double * refs) override
378 { return getTargetPositionRaw(0, &refs[0]); }
379 bool getTargetPositionsRaw(int n_joint, const int * joints, double * refs) override
380 { return getTargetPositionRaw(0, &refs[0]); }
381
382 // ------- IPositionDirectRaw declarations -------
383
384 //bool getAxesRaw(int * ax) override;
385 bool setPositionRaw(int j, double ref) override
386 { return true; }
387 bool setPositionsRaw(const double * refs) override
388 { return true; }
389 bool setPositionsRaw(int n_joint, const int * joints, const double * refs) override
390 { return true; }
391 bool getRefPositionRaw(int joint, double * ref) override
392 { *ref = 0.0; return true; }
393 bool getRefPositionsRaw(double * refs) override
394 { return getRefPositionRaw(0, &refs[0]); }
395 bool getRefPositionsRaw(int n_joint, const int * joints, double * refs) override
396 { return getRefPositionRaw(0, &refs[0]); }
397
398 // --------- IPWMControl declarations ---------
399
400 //bool getNumberOfMotorsRaw(int * number) override;
401 bool setRefDutyCycleRaw(int m, double ref) override
402 { return true; }
403 bool setRefDutyCyclesRaw(const double * refs) override
404 { return true; }
405 bool getRefDutyCycleRaw(int m, double * ref) override
406 { *ref = 0.0; return true; }
407 bool getRefDutyCyclesRaw(double * refs) override
408 { return getRefDutyCycleRaw(0, &refs[0]); }
409 bool getDutyCycleRaw(int m, double * val) override
410 { *val = 0.0; return true; }
411 bool getDutyCyclesRaw(double * vals) override
412 { return getDutyCycleRaw(0, &vals[0]); }
413
414 // ------- IRemoteVariablesRaw declarations -------
415
416 bool getRemoteVariableRaw(std::string key, yarp::os::Bottle & val) override
417 { return true; }
418 bool setRemoteVariableRaw(std::string key, const yarp::os::Bottle & val) override
419 { return true; }
420 bool getRemoteVariablesListRaw(yarp::os::Bottle * listOfKeys) override
421 { return true; }
422
423 // -------- ITorqueControlRaw declarations --------
424
425 //bool getAxesRaw(int * ax) override;
426 bool getRefTorqueRaw(int j, double * t) override
427 { *t = 0.0; return true; }
428 bool getRefTorquesRaw(double * t) override
429 { return getRefTorqueRaw(0, &t[0]); }
430 bool setRefTorqueRaw(int j, double t) override
431 { return true; }
432 bool setRefTorquesRaw(const double * t) override
433 { return true; }
434 bool setRefTorquesRaw(int n_joint, const int * joints, const double * t) override
435 { return true; }
436 bool getMotorTorqueParamsRaw(int j, yarp::dev::MotorTorqueParameters * params) override
437 { return true; }
438 bool setMotorTorqueParamsRaw(int j, const yarp::dev::MotorTorqueParameters params) override
439 { return true; }
440 bool getTorqueRaw(int j, double * t) override
441 { *t = 0.0; return true; }
442 bool getTorquesRaw(double * t) override
443 { return getTorqueRaw(0, &t[0]); }
444 bool getTorqueRangeRaw(int j, double * min, double * max) override
445 { *min = *max = 0.0; return true; }
446 bool getTorqueRangesRaw(double * mins, double * maxs) override
447 { return getTorqueRangeRaw(0, &mins[0], &maxs[0]); }
448
449 // --------- IVelocityControl declarations ---------
450
451 //bool getAxesRaw(int * ax) override;
452 bool velocityMoveRaw(int j, double spd) override
453 { return true; }
454 bool velocityMoveRaw(const double * spds) override
455 { return true; }
456 bool velocityMoveRaw(int n_joint, const int * joints, const double * spds) override
457 { return true; }
458 bool getRefVelocityRaw(int joint, double * vel) override
459 { *vel = 0.0; return true; }
460 bool getRefVelocitiesRaw(double * vels) override
461 { return getRefVelocityRaw(0, &vels[0]); }
462 bool getRefVelocitiesRaw(int n_joint, const int * joints, double * vels) override
463 { return getRefVelocityRaw(0, &vels[0]); }
464 //bool setRefAccelerationRaw(int j, double acc) override;
465 //bool setRefAccelerationsRaw(const double * accs) override;
466 //bool setRefAccelerationsRaw(int n_joint, const int * joints, const double * accs) override;
467 //bool getRefAccelerationRaw(int j, double * acc) override;
468 //bool getRefAccelerationsRaw(double * accs) override;
469 //bool getRefAccelerationsRaw(int n_joint, const int * joints, double * accs) override;
470 //bool stopRaw(int j) override;
471 //bool stopRaw() override;
472 //bool stopRaw(int n_joint, const int *joints) override;
473
474private:
475 int controlMode {VOCAB_CM_CONFIGURED};
476 yarp::dev::InteractionModeEnum interactionMode {yarp::dev::VOCAB_IM_UNKNOWN};
477};
478
479#endif // __FAKE_JOINT_HPP__
Definition FakeJoint_ParamsParser.h:42
Implementation for a fake joint (instant movement) as a single CAN bus joint (control board raw inter...
Definition FakeJoint.hpp:47
bool finalize() override
Finalize CAN node communications.
Definition FakeJoint.hpp:64
bool notifyMessage(const roboticslab::can_message &message) override
Notify observers that a new CAN message has arrived.
Definition FakeJoint.hpp:60
unsigned int getId() override
Retrieve CAN node ID.
Definition FakeJoint.hpp:58
bool initialize() override
Perform CAN node initialization.
Definition FakeJoint.hpp:62
bool synchronize(double timestamp) override
Perform synchronized action on CAN master's request.
Definition FakeJoint.hpp:68
bool registerSender(roboticslab::ICanSenderDelegate *sender) override
Pass a handle to a CAN sender delegate instance.
Definition FakeJoint.hpp:66
Abstract base for a CAN bus sharer.
Definition ICanBusSharer.hpp:25
Implementation-agnostic consumer for TX CAN transfers.
Definition ICanSenderDelegate.hpp:22
Proxy CAN message structure.
Definition CanMessage.hpp:20