yarp-devices
TechnosoftIposBase.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __TECHNOSOFT_IPOS_BASE_HPP__
4 #define __TECHNOSOFT_IPOS_BASE_HPP__
5 
6 #include <cstdint>
7 
8 #include <atomic>
9 #include <bitset>
10 #include <memory>
11 #include <string>
12 
13 #include <yarp/conf/numeric.h>
14 
15 #include <yarp/os/Timer.h>
16 
17 #include <yarp/dev/DeviceDriver.h>
18 #include <yarp/dev/IAxisInfo.h>
19 #include <yarp/dev/IControlLimits.h>
20 #include <yarp/dev/IControlMode.h>
21 #include <yarp/dev/ICurrentControl.h>
22 #include <yarp/dev/IEncodersTimed.h>
23 #include <yarp/dev/IImpedanceControl.h>
24 #include <yarp/dev/IInteractionMode.h>
25 #include <yarp/dev/IJointFault.h>
26 #include <yarp/dev/IMotor.h>
27 #include <yarp/dev/IMotorEncoders.h>
28 #include <yarp/dev/IPidControl.h>
29 #include <yarp/dev/IPositionControl.h>
30 #include <yarp/dev/IPositionDirect.h>
31 #include <yarp/dev/IRemoteVariables.h>
32 #include <yarp/dev/ITorqueControl.h>
33 #include <yarp/dev/IVelocityControl.h>
34 #include <yarp/dev/PolyDriver.h>
35 
36 #include "CanOpenNode.hpp"
37 #include "CommandBuffer.hpp"
38 #include "EncoderRead.hpp"
39 #include "ICanBusSharer.hpp"
40 #include "PdoProtocol.hpp"
41 #include "StateObserver.hpp"
42 
43 #define CHECK_JOINT(j) do { if (int ax; getAxes(&ax), (j) != ax - 1) return false; } while (0)
44 
45 #define CHECK_MODE(mode) do { if ((mode) != actualControlMode) return false; } while (0)
46 
47 namespace roboticslab
48 {
49 
54 class TechnosoftIposBase : public yarp::dev::DeviceDriver,
55  public yarp::dev::IAxisInfoRaw,
56  public yarp::dev::IControlLimitsRaw,
57  public yarp::dev::IControlModeRaw,
58  public yarp::dev::ICurrentControlRaw,
59  public yarp::dev::IEncodersTimedRaw,
60  public yarp::dev::IImpedanceControlRaw,
61  public yarp::dev::IInteractionModeRaw,
62  public yarp::dev::IJointFaultRaw,
63  public yarp::dev::IMotorRaw,
64  public yarp::dev::IMotorEncodersRaw,
65  public yarp::dev::IPidControlRaw,
66  public yarp::dev::IPositionControlRaw,
67  public yarp::dev::IPositionDirectRaw,
68  public yarp::dev::IRemoteVariablesRaw,
69  public yarp::dev::ITorqueControlRaw,
70  public yarp::dev::IVelocityControlRaw,
71  public ICanBusSharer
72 {
73 public:
74 
76  : can(nullptr),
77  iEncodersTimedRawExternal(nullptr),
78  iExternalEncoderCanBusSharer(nullptr),
79  monitorThread(nullptr)
80  {}
81 
82  // --------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp ---------
83 
84  bool open(yarp::os::Searchable & config) override;
85  bool close() override;
86 
87  // --------- ICanBusSharer declarations. Implementation in ICanBusSharerImpl.cpp ---------
88 
89  unsigned int getId() override;
90  std::vector<unsigned int> getAdditionalIds() override;
91  bool notifyMessage(const can_message & message) override;
92  bool initialize() override;
93  bool finalize() override;
94  bool registerSender(ICanSenderDelegate * sender) override;
95 
96  // --------- IAxisInfoRaw declarations. Implementation in IAxisInfoRawImpl.cpp ---------
97 
98  bool getAxisNameRaw(int axis, std::string & name) override;
99  bool getJointTypeRaw(int axis, yarp::dev::JointTypeEnum & type) override;
100 
101  // --------- IControlLimitsRaw declarations. Implementation in IControlLimitsRawImpl.cpp ---------
102 
103  bool setLimitsRaw(int axis, double min, double max) override;
104  bool getLimitsRaw(int axis, double * min, double * max) override;
105  bool setVelLimitsRaw(int axis, double min, double max) override;
106  bool getVelLimitsRaw(int axis, double * min, double * max) override;
107 
108  // --------- IControlModeRaw declarations. Implementation in IControlModeRawImpl.cpp ---------
109 
110  bool getControlModesRaw(int * modes) override
111  { return getControlModeRaw(0, &modes[0]); }
112 
113  bool getControlModesRaw(int n_joint, const int * joints, int * modes) override
114  { return getControlModeRaw(joints[0], &modes[0]); }
115 
116  bool setControlModesRaw(int * modes) override
117  { return setControlModeRaw(0, modes[0]); }
118 
119  bool setControlModesRaw(int n_joint, const int * joints, int * modes) override
120  { return setControlModeRaw(joints[0], modes[0]); }
121 
122  // --------- ICurrentControlRaw declarations. Implementation in ICurrentControlRawImpl.cpp ---------
123 
124  bool getCurrentRaw(int m, double * curr) override;
125 
126  bool getCurrentsRaw(double * currs) override
127  { return getCurrentRaw(0, &currs[0]); }
128 
129  bool getCurrentRangeRaw(int m, double * min, double * max) override;
130 
131  bool getCurrentRangesRaw(double * min, double * max) override
132  { return getCurrentRangeRaw(0, min, max); }
133 
134  bool setRefCurrentRaw(int m, double curr) override;
135 
136  bool setRefCurrentsRaw(const double * currs) override
137  { return setRefCurrentRaw(0, currs[0]); }
138 
139  bool setRefCurrentsRaw(int n_motor, const int * motors, const double * currs) override
140  { return setRefCurrentRaw(motors[0], currs[0]); }
141 
142  bool getRefCurrentRaw(int m, double * curr) override;
143 
144  bool getRefCurrentsRaw(double * currs) override
145  { return getRefCurrentRaw(0, &currs[0]); }
146 
147  // ---------- IEncodersRaw declarations. Implementation in IEncodersRawImpl.cpp ----------
148 
149  bool getAxes(int * ax) override;
150  bool resetEncoderRaw(int j) override;
151 
152  bool resetEncodersRaw() override
153  { return resetEncoderRaw(0); }
154 
155  bool setEncoderRaw(int j, double val) override;
156 
157  bool setEncodersRaw(const double * vals) override
158  { return setEncoderRaw(0, vals[0]); }
159 
160  bool getEncoderRaw(int j, double * v) override;
161 
162  bool getEncodersRaw(double * encs) override
163  { return getEncoderRaw(0, &encs[0]); }
164 
165  bool getEncoderSpeedRaw(int j, double * sp) override;
166 
167  bool getEncoderSpeedsRaw(double * spds) override
168  { return getEncoderSpeedRaw(0, &spds[0]); }
169 
170  bool getEncoderAccelerationRaw(int j, double * spds) override;
171 
172  bool getEncoderAccelerationsRaw(double * accs) override
173  { return getEncoderAccelerationRaw(0, &accs[0]); }
174 
175  // ---------- IEncodersTimedRaw declarations. Implementation in IEncodersRawImpl.cpp ----------
176 
177  bool getEncoderTimedRaw(int j, double * encs, double * time) override;
178 
179  bool getEncodersTimedRaw(double * encs, double * times) override
180  { return getEncoderTimedRaw(0, &encs[0], &times[0]); }
181 
182  // ---------- IImpedanceControlRaw declarations. Implementation in IImpedanceControlRawImpl.cpp ----------
183 
184  bool getImpedanceRaw(int j, double * stiffness, double * damping) override
185  { return false; }
186 
187  bool setImpedanceRaw(int j, double stiffness, double damping) override
188  { return false; }
189 
190  bool setImpedanceOffsetRaw(int j, double offset) override
191  { return false; }
192 
193  bool getImpedanceOffsetRaw(int j, double * offset) override
194  { return false; }
195 
196  bool getCurrentImpedanceLimitRaw(int j, double * min_stiff, double * max_stiff, double * min_damp, double * max_damp) override
197  { return false; }
198 
199  // ---------- IInteractionModeRaw declarations. Implementation in IInteractionModeRawImpl.cpp ----------
200 
201  bool getInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum * mode) override
202  { return false; }
203 
204  bool getInteractionModesRaw(int n_joints, int * joints, yarp::dev::InteractionModeEnum * modes) override
205  { return getInteractionModeRaw(joints[0], &modes[0]); }
206 
207  bool getInteractionModesRaw(yarp::dev::InteractionModeEnum * modes) override
208  { return getInteractionModeRaw(0, &modes[0]); }
209 
210  bool setInteractionModeRaw(int axis, yarp::dev::InteractionModeEnum mode) override
211  { return false; }
212 
213  bool setInteractionModesRaw(int n_joints, int * joints, yarp::dev::InteractionModeEnum * modes) override
214  { return setInteractionModeRaw(joints[0], modes[0]); }
215 
216  bool setInteractionModesRaw(yarp::dev::InteractionModeEnum * modes) override
217  { return setInteractionModeRaw(0, modes[0]); }
218 
219  // ---------- IJointFaultRaw declarations. Implementation in IJointFaultRawImpl.cpp ----------
220 
221  bool getLastJointFaultRaw(int j, int & fault, std::string & message) override;
222 
223  // --------- IMotorRaw declarations. Implementation in IMotorRawImpl.cpp ---------
224 
225  bool getNumberOfMotorsRaw(int * num) override;
226  bool getTemperatureRaw(int m, double * val) override;
227  bool getTemperaturesRaw(double * vals) override;
228  bool getTemperatureLimitRaw(int m, double * temp) override;
229  bool setTemperatureLimitRaw(int m, double temp) override;
230  bool getGearboxRatioRaw(int m, double * val) override;
231  bool setGearboxRatioRaw(int m, double val) override;
232 
233  // --------- IMotorEncodersRaw declarations. Implementation in IMotorEncodersRawImpl.cpp ---------
234 
235  bool getNumberOfMotorEncodersRaw(int * num) override;
236  bool resetMotorEncoderRaw(int m) override;
237 
238  bool resetMotorEncodersRaw() override
239  { return resetMotorEncoderRaw(0); }
240 
241  bool setMotorEncoderCountsPerRevolutionRaw(int m, double cpr) override;
242  bool getMotorEncoderCountsPerRevolutionRaw(int m, double * cpr) override;
243  bool setMotorEncoderRaw(int m, double val) override;
244 
245  bool setMotorEncodersRaw(const double * vals) override
246  { return setMotorEncoderRaw(0, vals[0]); }
247 
248  bool getMotorEncoderRaw(int m, double * v) override;
249 
250  bool getMotorEncodersRaw(double * encs) override
251  { return getMotorEncoderSpeedRaw(0, &encs[0]); }
252 
253  bool getMotorEncoderTimedRaw(int m, double * encs, double * stamp) override;
254 
255  bool getMotorEncodersTimedRaw(double * encs, double * stamps) override
256  { return getMotorEncoderTimedRaw(0, &encs[0], &stamps[0]); }
257 
258  bool getMotorEncoderSpeedRaw(int m, double * sp) override;
259 
260  bool getMotorEncoderSpeedsRaw(double * spds) override
261  { return getMotorEncoderSpeedRaw(0, &spds[0]); }
262 
263  bool getMotorEncoderAccelerationRaw(int m, double * spds) override;
264 
265  bool getMotorEncoderAccelerationsRaw(double * accs) override
266  { return getMotorEncoderAccelerationRaw(0, &accs[0]); }
267 
268  // --------- IPidControlRaw declarations. Implementation in IPidControlRawImpl.cpp ---------
269 
270  bool setPidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, const yarp::dev::Pid & pid) override
271  { return false; }
272 
273  bool setPidsRaw(const yarp::dev::PidControlTypeEnum & pidtype, const yarp::dev::Pid * pids) override
274  { return setPidRaw(pidtype, 0, pids[0]); }
275 
276  bool setPidReferenceRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double ref) override
277  { return false; }
278 
279  bool setPidReferencesRaw(const yarp::dev::PidControlTypeEnum & pidtype, const double * refs) override
280  { return setPidReferenceRaw(pidtype, 0, refs[0]); }
281 
282  bool setPidErrorLimitRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double limit) override
283  { return false; }
284 
285  bool setPidErrorLimitsRaw(const yarp::dev::PidControlTypeEnum & pidtype, const double * limits) override
286  { return setPidErrorLimitRaw(pidtype, 0, limits[0]); }
287 
288  bool getPidErrorRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * err) override
289  { return false; }
290 
291  bool getPidErrorsRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * errs) override
292  { return getPidErrorRaw(pidtype, 0, &errs[0]); }
293 
294  bool getPidOutputRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * out) override
295  { return false; }
296 
297  bool getPidOutputsRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * outs) override
298  { return getPidOutputRaw(pidtype, 0, &outs[0]); }
299 
300  bool getPidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, yarp::dev::Pid * pid) override
301  { return false; }
302 
303  bool getPidsRaw(const yarp::dev::PidControlTypeEnum & pidtype, yarp::dev::Pid * pids) override
304  { return getPidRaw(pidtype, 0, &pids[0]); }
305 
306  bool getPidReferenceRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * ref) override
307  { return false; }
308 
309  bool getPidReferencesRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * refs) override
310  { return getPidReferenceRaw(pidtype, 0, &refs[0]); }
311 
312  bool getPidErrorLimitRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * limit) override
313  { return false; }
314 
315  bool getPidErrorLimitsRaw(const yarp::dev::PidControlTypeEnum & pidtype, double * limits) override
316  { return getPidErrorLimitRaw(pidtype, 0, &limits[0]); }
317 
318  bool resetPidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j) override
319  { return false; }
320 
321  bool disablePidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j) override
322  { return false; }
323 
324  bool enablePidRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j) override
325  { return false; }
326 
327  bool setPidOffsetRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, double v) override
328  { return false; }
329 
330  bool isPidEnabledRaw(const yarp::dev::PidControlTypeEnum & pidtype, int j, bool * enabled) override
331  { return false; }
332 
333  // ------- IPositionControlRaw declarations. Implementation in IPositionControlRawImpl.cpp -------
334 
335  using yarp::dev::IPositionControlRaw::positionMoveRaw;
336 
337  bool positionMoveRaw(const double * refs) override
338  { return positionMoveRaw(0, refs[0]); }
339 
340  bool positionMoveRaw(int n_joint, const int * joints, const double * refs) override
341  { return positionMoveRaw(joints[0], refs[0]); }
342 
343  using yarp::dev::IPositionControlRaw::relativeMoveRaw;
344 
345  bool relativeMoveRaw(const double * deltas) override
346  { return relativeMoveRaw(0, deltas[0]); }
347 
348  bool relativeMoveRaw(int n_joint, const int * joints, const double * deltas) override
349  { return relativeMoveRaw(joints[0], deltas[0]); }
350 
351  using yarp::dev::IPositionControlRaw::checkMotionDoneRaw;
352 
353  bool checkMotionDoneRaw(bool * flag) override
354  { return checkMotionDoneRaw(0, flag); }
355 
356  bool checkMotionDoneRaw(int n_joint, const int * joints, bool * flag) override
357  { return checkMotionDoneRaw(joints[0], flag); }
358 
359  bool setRefSpeedsRaw(const double * spds) override
360  { return setRefSpeedRaw(0, spds[0]); }
361 
362  bool setRefSpeedsRaw(int n_joint, const int * joints, const double * spds) override
363  { return setRefSpeedRaw(joints[0], spds[0]); }
364 
365  using yarp::dev::IPositionControlRaw::setRefAccelerationRaw;
366 
367  bool setRefAccelerationsRaw(const double * accs) override
368  { return setRefAccelerationRaw(0, accs[0]); }
369 
370  bool setRefAccelerationsRaw(int n_joint, const int * joints, const double * accs) override
371  { return setRefAccelerationRaw(joints[0], accs[0]); }
372 
373  bool getRefSpeedsRaw(double * spds) override
374  { return getRefSpeedRaw(0, &spds[0]); }
375 
376  bool getRefSpeedsRaw(int n_joint, const int * joints, double * spds) override
377  { return getRefSpeedRaw(joints[0], &spds[0]); }
378 
379  using yarp::dev::IPositionControlRaw::getRefAccelerationRaw;
380 
381  bool getRefAccelerationsRaw(double * accs) override
382  { return getRefAccelerationRaw(0, &accs[0]); }
383 
384  bool getRefAccelerationsRaw(int n_joint, const int * joints, double * accs) override
385  { return getRefAccelerationRaw(joints[0], &accs[0]); }
386 
387  using yarp::dev::IPositionControlRaw::stopRaw;
388 
389  bool stopRaw() override
390  { return stopRaw(0); }
391 
392  bool stopRaw(int n_joint, const int * joints) override
393  { return stopRaw(joints[0]); }
394 
395  bool getTargetPositionsRaw(double * refs) override
396  { return getTargetPositionRaw(0, &refs[0]); }
397 
398  bool getTargetPositionsRaw(int n_joint, const int * joints, double * refs) override
399  { return getTargetPositionRaw(joints[0], &refs[0]); }
400 
401  // ------- IPositionDirectRaw declarations. Implementation in IPositionDirectRawImpl.cpp -------
402 
403  bool setPositionsRaw(const double * refs) override
404  { return setPositionRaw(0, refs[0]); }
405 
406  bool setPositionsRaw(int n_joint, const int * joints, const double * refs) override
407  { return setPositionRaw(joints[0], refs[0]); }
408 
409  bool getRefPositionsRaw(double * refs) override
410  { return getRefPositionRaw(0, &refs[0]); }
411 
412  bool getRefPositionsRaw(int n_joint, const int * joints, double * refs) override
413  { return getRefPositionRaw(joints[0], &refs[0]); }
414 
415  // -------- ITorqueControlRaw declarations. Implementation in ITorqueControlRawImpl.cpp --------
416 
417  bool getRefTorqueRaw(int j, double * t) override;
418 
419  bool getRefTorquesRaw(double * t) override
420  { return getRefTorqueRaw(0, &t[0]); }
421 
422  bool setRefTorqueRaw(int j, double t) override;
423 
424  bool setRefTorquesRaw(int n_joint, const int * joints, const double * t) override
425  { return setRefTorqueRaw(joints[0], t[0]); }
426 
427  bool setRefTorquesRaw(const double * t) override
428  { return setRefTorqueRaw(0, t[0]); }
429 
430  bool getTorqueRaw(int j, double * t) override;
431 
432  bool getTorquesRaw(double * t) override
433  { return getTorqueRaw(0, &t[0]); }
434 
435  bool getTorqueRangeRaw(int j, double * min, double * max) override;
436 
437  bool getTorqueRangesRaw(double * min, double * max) override
438  { return getTorqueRangeRaw(0, &min[0], &max[0]); }
439 
440  bool getMotorTorqueParamsRaw(int j, yarp::dev::MotorTorqueParameters * params) override;
441  bool setMotorTorqueParamsRaw(int j, const yarp::dev::MotorTorqueParameters params) override;
442 
443  // --------- IVelocityControlRaw declarations. Implementation in IVelocityControlRawImpl.cpp ---------
444 
445  using yarp::dev::IVelocityControlRaw::velocityMoveRaw;
446 
447  bool velocityMoveRaw(const double * sp) override
448  { return velocityMoveRaw(0, sp[0]); }
449 
450  bool velocityMoveRaw(int n_joint, const int * joints, const double * spds) override
451  { return velocityMoveRaw(joints[0], spds[0]); }
452 
453  bool getRefVelocitiesRaw(double * vels) override
454  { return getRefVelocityRaw(0, &vels[0]); }
455 
456  bool getRefVelocitiesRaw(int n_joint, const int * joints, double * vels) override
457  { return getRefVelocityRaw(joints[0], &vels[0]); }
458 
459 protected:
460 
461  enum report_level { NONE, INFO, WARN, FAULT };
462  enum limit_switch { POSITIVE, NEGATIVE, INACTIVE };
463 
465  {
466  const char * reg;
467  const std::bitset<16> & actual;
468  const std::bitset<16> & stored;
469  };
470 
471  bool reportBitToggle(report_storage report, int level, std::size_t pos, const char * msgSet, const char * msgReset = nullptr);
472 
473  virtual void interpretModesOfOperation(std::int8_t modesOfOperation) = 0;
474  virtual void interpretIpStatus(std::uint16_t ipStatus) {}
475  virtual void onPositionLimitTriggered() = 0;
476  virtual void reset() = 0;
477 
479  bool awaitControlMode(yarp::conf::vocab32_t mode);
480 
482  double degreesToInternalUnits(double value, int derivativeOrder = 0) const;
483 
485  double internalUnitsToDegrees(double value, int derivativeOrder = 0) const;
486 
488  std::int16_t currentToInternalUnits(double value) const;
489 
491  double internalUnitsToCurrent(std::int16_t value) const;
492 
494  double internalUnitsToPeakCurrent(std::int16_t value) const;
495 
497  double currentToTorque(double current) const;
498 
500  double torqueToCurrent(double torque) const;
501 
502  CanOpenNode * can;
503  CommandBuffer commandBuffer;
504 
505  std::unique_ptr<StateObserver> controlModeObserverPtr {new StateObserver(1.0)}; // arbitrary 1 second wait
506  std::unique_ptr<EncoderRead> lastEncoderRead {nullptr};
507 
508  // read/write, no concurrent access
509 
510  std::bitset<16> msr;
511  std::bitset<16> mer;
512  std::bitset<16> der;
513  std::bitset<16> der2;
514  std::bitset<16> cer;
515 
516  std::int8_t modesOfOperation {0};
517 
519 
520  bool configuredOnce {false};
521 
522  // read/write with atomic access
523 
524  std::atomic<std::int16_t> lastCurrentRead {0};
525 
526  std::atomic<yarp::conf::vocab32_t> actualControlMode {0};
527  std::atomic<yarp::conf::vocab32_t> requestedcontrolMode {0};
528 
529  std::atomic<double> tr {0.0};
530  std::atomic<double> k {0.0};
531  std::atomic<int> encoderPulses {0};
532 
533  std::atomic<double> maxVel {0.0};
534  std::atomic<double> min {0.0};
535  std::atomic<double> max {0.0};
536  std::atomic<double> refSpeed {0.0};
537  std::atomic<double> refAcceleration {0.0};
538 
539  std::atomic<double> lastHeartbeat {0.0};
540  std::atomic<std::uint8_t> lastNmtState {0};
541  std::atomic<std::uint16_t> lastFaultCode {0};
542  std::atomic<const char *> lastFaultMessage;
543 
544  std::atomic<limit_switch> limitSwitchState {INACTIVE};
545 
546  // read only after initial configuration, conceptually immutable
547 
548  yarp::conf::vocab32_t initialControlMode {0};
549 
550  double drivePeakCurrent {0.0};
551  double samplingPeriod {0.0};
552 
553  std::string axisName;
554  yarp::conf::vocab32_t jointType {0};
555 
556  bool reverse {false};
557 
558  PdoConfiguration tpdo1Conf;
559  PdoConfiguration tpdo2Conf;
560  PdoConfiguration tpdo3Conf;
561 
562  double heartbeatPeriod {0.0};
563  double syncPeriod {0.0};
564 
565  unsigned int canId {0};
566 
567 private:
568 
570  bool validateInitialState();
571 
572  void interpretMsr(std::uint16_t msr);
573  void interpretMer(std::uint16_t mer);
574  void interpretDer(std::uint16_t der);
575  void interpretDer2(std::uint16_t der2);
576  void interpretCer(std::uint16_t cer);
577  void interpretStatusword(std::uint16_t statusword);
578 
579  void handleTpdo1(std::uint16_t statusword, std::uint16_t msr, std::int8_t modesOfOperation);
580  void handleTpdo2(std::uint16_t mer, std::uint16_t der);
581  void handleTpdo3(std::int32_t position, std::int16_t current);
582  void handleEmcy(EmcyConsumer::code_t code, std::uint8_t reg, const std::uint8_t * msef);
583  void handleNmt(NmtState state);
584 
585  bool monitorWorker(const yarp::os::YarpTimerEvent & event);
586 
587  bool setLimitRaw(double limit, bool isMin);
588  bool getLimitRaw(double * limit, bool isMin);
589 
590  yarp::dev::PolyDriver externalEncoderDevice;
591  yarp::dev::IEncodersTimedRaw * iEncodersTimedRawExternal;
592  roboticslab::ICanBusSharer * iExternalEncoderCanBusSharer;
593 
594  yarp::os::Timer * monitorThread;
596 };
597 
598 } // namespace roboticslab
599 
600 #endif // __TECHNOSOFT_IPOS_BASE_HPP__
Wrapper for CAN protocol handles with handy accessors.
Definition: CanOpenNode.hpp:35
A buffer for periodic commands implementing linear interpolation.
Definition: CommandBuffer.hpp:16
std::pair< std::uint16_t, std::string > code_t
Emergency error code.
Definition: EmcyConsumer.hpp:35
Abstract base for a CAN bus sharer.
Definition: ICanBusSharer.hpp:25
Implementation-agnostic consumer for TX CAN transfers.
Definition: ICanSenderDelegate.hpp:22
Data-free state observer.
Definition: StateObserver.hpp:75
Base class for all proxied TechnosoftIpos implementations.
Definition: TechnosoftIposBase.hpp:72
unsigned int getId() override
Retrieve CAN node ID.
Definition: ICanBusSharerImpl.cpp:39
bool validateInitialState()
Make sure stored variables actually make sense.
Definition: TechnosoftIposBase.cpp:505
double internalUnitsToDegrees(double value, int derivativeOrder=0) const
Convert position, speed or acceleration to degrees.
Definition: TechnosoftIposBase.cpp:656
std::int16_t currentToInternalUnits(double value) const
Convert current to internal units.
Definition: TechnosoftIposBase.cpp:663
bool initialize() override
Perform CAN node initialization.
Definition: ICanBusSharerImpl.cpp:67
std::vector< unsigned int > getAdditionalIds() override
Retrieve more associated CAN node IDs, if any.
Definition: ICanBusSharerImpl.cpp:46
double currentToTorque(double current) const
Convert current (amperes) to torque (Nm).
Definition: TechnosoftIposBase.cpp:684
double internalUnitsToPeakCurrent(std::int16_t value) const
Apply internal iPOS conversion to express drive peak current in amperes.
Definition: TechnosoftIposBase.cpp:677
bool notifyMessage(const can_message &message) override
Notify observers that a new CAN message has arrived.
Definition: ICanBusSharerImpl.cpp:176
bool registerSender(ICanSenderDelegate *sender) override
Pass a handle to a CAN sender delegate instance.
Definition: ICanBusSharerImpl.cpp:58
double internalUnitsToCurrent(std::int16_t value) const
Convert current to amperes.
Definition: TechnosoftIposBase.cpp:670
bool finalize() override
Finalize CAN node communications.
Definition: ICanBusSharerImpl.cpp:134
double torqueToCurrent(double torque) const
Convert torque (Nm) to current (amperes).
Definition: TechnosoftIposBase.cpp:691
double degreesToInternalUnits(double value, int derivativeOrder=0) const
Convert position, speed or acceleration to internal units.
Definition: TechnosoftIposBase.cpp:649
bool awaitControlMode(yarp::conf::vocab32_t mode)
Wait with timeout for requested control mode change.
Definition: TechnosoftIposBase.cpp:642
NmtState
NMT state machine.
Definition: NmtProtocol.hpp:33
DriveState
CiA 402 drive states (associated to statusword).
Definition: DriveStatusMachine.hpp:22
@ NOT_READY_TO_SWITCH_ON
Not ready to switch on state.
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6
Definition: TechnosoftIposBase.hpp:465
Proxy CAN message structure.
Definition: CanMessage.hpp:20