yarp-devices
Loading...
Searching...
No Matches
CanBusBroker.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __CAN_BUS_BROKER_HPP__
4#define __CAN_BUS_BROKER_HPP__
5
6#include <vector>
7
8#include <yarp/dev/ControlBoardInterfaces.h>
9#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
10
11#include "DeviceMapper.hpp"
12#include "SingleBusBroker.hpp"
13#include "SyncPeriodicThread.hpp"
14#include "CanBusBroker_ParamsParser.h"
15
16#define CHECK_JOINT(j) do { int n = deviceMapper.getControlledAxes(); if ((j) < 0 || (j) > n - 1) return false; } while (0)
17
38class CanBusBroker : public yarp::dev::DeviceDriver,
40 // control board interfaces
41 public yarp::dev::IAmplifierControl,
42 public yarp::dev::IAxisInfo,
43 public yarp::dev::IControlCalibration,
44 public yarp::dev::IControlLimits,
45 public yarp::dev::IControlMode,
46 public yarp::dev::ICurrentControl,
47 public yarp::dev::IEncodersTimed,
48 public yarp::dev::IImpedanceControl,
49 public yarp::dev::IInteractionMode,
50 public yarp::dev::IJointFault,
51 public yarp::dev::IMotor,
52 public yarp::dev::IMotorEncoders,
53 public yarp::dev::IPidControl,
54 public yarp::dev::IPositionControl,
55 public yarp::dev::IPositionDirect,
56 public yarp::dev::IPWMControl,
57 public yarp::dev::IRemoteVariables,
58 public yarp::dev::ITorqueControl,
59 public yarp::dev::IVelocityControl,
60 // multiple analog sensors interfaces
61 public yarp::dev::IContactLoadCellArrays,
62 public yarp::dev::IEncoderArrays,
63 public yarp::dev::IOrientationSensors,
64 public yarp::dev::IPositionSensors,
65 public yarp::dev::ISixAxisForceTorqueSensors,
66 public yarp::dev::ISkinPatches,
67 public yarp::dev::ITemperatureSensors,
68 public yarp::dev::IThreeAxisGyroscopes,
69 public yarp::dev::IThreeAxisLinearAccelerometers,
70 public yarp::dev::IThreeAxisMagnetometers
71{
72public:
73 // -------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp --------
74
75 bool open(yarp::os::Searchable & config) override;
76 bool close() override;
77
78 // ---------- CONTROL BOARD INTERFACES ----------
79
80 // --------- IAmplifierControl declarations. Implementation in IAmplifierControlImpl.cpp ---------
81
82 bool enableAmp(int j) override;
83 bool disableAmp(int j) override;
84 bool getAmpStatus(int j, int * v) override;
85 bool getAmpStatus(int * st) override;
86 //bool getCurrent(int j, double * val) override;
87 //bool getCurrents(double * vals) override;
88 bool getMaxCurrent(int j, double * v) override;
89 bool setMaxCurrent(int j, double v) override;
90 bool getNominalCurrent(int m, double * val) override;
91 bool setNominalCurrent(int m, double val) override;
92 bool getPeakCurrent(int m, double * val) override;
93 bool setPeakCurrent(int m, double val) override;
94 bool getPWM(int j, double * val) override;
95 bool getPWMLimit(int j, double * val) override;
96 bool setPWMLimit(int j, double val) override;
97 bool getPowerSupplyVoltage(int j, double * val) override;
98
99 // --------- IAxisInfo declarations. Implementation in IAxisInfoImpl.cpp ---------
100
101 bool getAxisName(int axis, std::string & name) override;
102 bool getJointType(int axis, yarp::dev::JointTypeEnum & type) override;
103
104 // --------- IControlCalibration declarations. Implementation in IControlCalibrationImpl.cpp ---------
105
106 bool calibrateAxisWithParams(int axis, unsigned int type, double p1, double p2, double p3) override;
107 bool setCalibrationParameters(int axis, const yarp::dev::CalibrationParameters & params) override;
108 bool calibrationDone(int j) override;
109
110 // --------- IControlLimits declarations. Implementation in IControlLimitsImpl.cpp ---------
111
112 bool setLimits(int axis, double min, double max) override;
113 bool getLimits(int axis, double * min, double * max) override;
114 bool setVelLimits(int axis, double min, double max) override;
115 bool getVelLimits(int axis, double * min, double * max) override;
116
117 // --------- IControlMode declarations. Implementation in IControlModeImpl.cpp ---------
118
119 bool getControlMode(int j, int * mode) override;
120 bool getControlModes(int * modes) override;
121 bool getControlModes(int n_joint, const int * joints, int * modes) override;
122 bool setControlMode(int j, const int mode) override;
123 bool setControlModes(int n_joint, const int * joints, int * modes) override;
124 bool setControlModes(int * modes) override;
125
126 // --------- ICurrentControl declarations. Implementation in ICurrentControlImpl.cpp ---------
127
128 //bool getNumberOfMotors(int * ax) override;
129 bool getCurrent(int m, double * curr) override;
130 bool getCurrents(double * currs) override;
131 bool getCurrentRange(int m, double * min, double * max) override;
132 bool getCurrentRanges(double * mins, double * maxs) override;
133 bool setRefCurrent(int m, double curr) override;
134 bool setRefCurrents(const double * currs) override;
135 bool setRefCurrents(int n_motor, const int * motors, const double * currs) override;
136 bool getRefCurrent(int m, double * curr) override;
137 bool getRefCurrents(double * currs) override;
138
139 // ---------- IEncoders declarations. Implementation in IEncodersImpl.cpp ----------
140
141 bool getAxes(int * ax) override;
142 bool resetEncoder(int j) override;
143 bool resetEncoders() override;
144 bool setEncoder(int j, double val) override;
145 bool setEncoders(const double * vals) override;
146 bool getEncoder(int j, double * v) override;
147 bool getEncoders(double * encs) override;
148 bool getEncoderSpeed(int j, double * spd) override;
149 bool getEncoderSpeeds(double * spds) override;
150 bool getEncoderAcceleration(int j, double * spds) override;
151 bool getEncoderAccelerations(double * accs) override;
152
153 // ---------- IEncodersTimed declarations. Implementation in IEncodersImpl.cpp ----------
154
155 bool getEncoderTimed(int j, double * encs, double * time) override;
156 bool getEncodersTimed(double * encs, double * times) override;
157
158 // --------- IImpedanceControl declarations. Implementation in IImpedanceControlImpl.cpp ---------
159
160 //bool getAxes(int * ax) override;
161 bool getImpedance(int j, double * stiffness, double * damping) override;
162 bool setImpedance(int j, double stiffness, double damping) override;
163 bool setImpedanceOffset(int j, double offset) override;
164 bool getImpedanceOffset(int j, double * offset) override;
165 bool getCurrentImpedanceLimit(int j, double * min_stiff, double * max_stiff, double * min_damp, double * max_damp) override;
166
167 // -----------IInteractionMode declarations. Implementation in IInteractionModeImpl.cpp --------------
168
169 bool getInteractionMode(int axis, yarp::dev::InteractionModeEnum * mode) override;
170 bool getInteractionModes(yarp::dev::InteractionModeEnum * modes) override;
171 bool getInteractionModes(int n_joints, int * joints, yarp::dev::InteractionModeEnum * modes) override;
172 bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode) override;
173 bool setInteractionModes(yarp::dev::InteractionModeEnum * modes) override;
174 bool setInteractionModes(int n_joints, int * joints, yarp::dev::InteractionModeEnum * modes) override;
175
176 // --------- IJointFault declarations. Implementation in IJointFaultImpl.cpp ---------
177
178 bool getLastJointFault(int j, int & fault, std::string & message) override;
179
180 // --------- IMotor declarations. Implementation in IMotorImpl.cpp ---------
181
182 bool getNumberOfMotors(int * num) override;
183 bool getTemperature(int m, double * val) override;
184 bool getTemperatures(double * vals) override;
185 bool getTemperatureLimit(int m, double * temp) override;
186 bool setTemperatureLimit(int m, double temp) override;
187 bool getGearboxRatio(int m, double * val) override;
188 bool setGearboxRatio(int m, double val) override;
189
190 // --------- IMotorEncoders declarations. Implementation in IMotorEncodersImpl.cpp ---------
191
192 bool getNumberOfMotorEncoders(int * num) override;
193 bool resetMotorEncoder(int m) override;
194 bool resetMotorEncoders() override;
195 bool setMotorEncoderCountsPerRevolution(int m, double cpr) override;
196 bool getMotorEncoderCountsPerRevolution(int m, double * cpr) override;
197 bool setMotorEncoder(int m, double val) override;
198 bool setMotorEncoders(const double * vals) override;
199 bool getMotorEncoder(int m, double * v) override;
200 bool getMotorEncoders(double * encs) override;
201 bool getMotorEncoderTimed(int m, double * enc, double * stamp) override;
202 bool getMotorEncodersTimed(double * encs, double * stamps) override;
203 bool getMotorEncoderSpeed(int m, double * sp) override;
204 bool getMotorEncoderSpeeds(double *spds) override;
205 bool getMotorEncoderAcceleration(int m, double * acc) override;
206 bool getMotorEncoderAccelerations(double * accs) override;
207
208 // --------- IPidControl declarations. Implementation in IPidControlImpl.cpp ---------
209
210 bool setPid(const yarp::dev::PidControlTypeEnum & pidtype, int j, const yarp::dev::Pid & pid) override;
211 bool setPids(const yarp::dev::PidControlTypeEnum & pidtype, const yarp::dev::Pid * pids) override;
212 bool setPidReference(const yarp::dev::PidControlTypeEnum & pidtype, int j, double ref) override;
213 bool setPidReferences(const yarp::dev::PidControlTypeEnum & pidtype, const double * refs) override;
214 bool setPidErrorLimit(const yarp::dev::PidControlTypeEnum & pidtype, int j, double limit) override;
215 bool setPidErrorLimits(const yarp::dev::PidControlTypeEnum & pidtype, const double * limits) override;
216 bool getPidError(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * err) override;
217 bool getPidErrors(const yarp::dev::PidControlTypeEnum & pidtype, double * errs) override;
218 bool getPidOutput(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * out) override;
219 bool getPidOutputs(const yarp::dev::PidControlTypeEnum & pidtype, double * outs) override;
220 bool getPid(const yarp::dev::PidControlTypeEnum & pidtype, int j, yarp::dev::Pid * pid) override;
221 bool getPids(const yarp::dev::PidControlTypeEnum & pidtype, yarp::dev::Pid * pids) override;
222 bool getPidReference(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * ref) override;
223 bool getPidReferences(const yarp::dev::PidControlTypeEnum & pidtype, double * refs) override;
224 bool getPidErrorLimit(const yarp::dev::PidControlTypeEnum & pidtype, int j, double * limit) override;
225 bool getPidErrorLimits(const yarp::dev::PidControlTypeEnum & pidtype, double * limits) override;
226 bool resetPid(const yarp::dev::PidControlTypeEnum & pidtype, int j) override;
227 bool disablePid(const yarp::dev::PidControlTypeEnum & pidtype, int j) override;
228 bool enablePid(const yarp::dev::PidControlTypeEnum & pidtype, int j) override;
229 bool setPidOffset(const yarp::dev::PidControlTypeEnum & pidtype, int j, double v) override;
230 bool isPidEnabled(const yarp::dev::PidControlTypeEnum & pidtype, int j, bool * enabled) override;
231
232 // ------- IPositionControl declarations. Implementation in IPositionControlImpl.cpp -------
233
234 //bool getAxes(int * ax) override;
235 bool positionMove(int j, double ref) override;
236 bool positionMove(const double * refs) override;
237 bool positionMove(int n_joint, const int * joints, const double * refs) override;
238 bool relativeMove(int j, double delta) override;
239 bool relativeMove(const double * deltas) override;
240 bool relativeMove(int n_joint, const int * joints, const double * deltas) override;
241 bool checkMotionDone(int j, bool * flag) override;
242 bool checkMotionDone(bool * flag) override;
243 bool checkMotionDone(int n_joint, const int * joints, bool * flag) override;
244 bool setRefSpeed(int j, double sp) override;
245 bool setRefSpeeds(const double * spds) override;
246 bool setRefSpeeds(int n_joint, const int * joints, const double * spds) override;
247 bool setRefAcceleration(int j, double acc) override;
248 bool setRefAccelerations(const double * accs) override;
249 bool setRefAccelerations(int n_joint, const int * joints, const double * accs) override;
250 bool getRefSpeed(int j, double * spd) override;
251 bool getRefSpeeds(double * spds) override;
252 bool getRefSpeeds(int n_joint, const int * joints, double * spds) override;
253 bool getRefAcceleration(int j, double * acc) override;
254 bool getRefAccelerations(double * accs) override;
255 bool getRefAccelerations(int n_joint, const int * joints, double * accs) override;
256 bool stop(int j) override;
257 bool stop() override;
258 bool stop(int n_joint, const int *joints) override;
259 bool getTargetPosition(int joint, double * ref) override;
260 bool getTargetPositions(double * refs) override;
261 bool getTargetPositions(int n_joint, const int * joints, double * refs) override;
262
263 // ------- IPositionDirect declarations. Implementation in IPositionDirectImpl.cpp -------
264
265 //bool getAxes(int * ax) override;
266 bool setPosition(int j, double ref) override;
267 bool setPositions(const double * refs) override;
268 bool setPositions(int n_joint, const int * joints, const double * refs) override;
269 bool getRefPosition(int joint, double * ref) override;
270 bool getRefPositions(double * refs) override;
271 bool getRefPositions(int n_joint, const int * joints, double * refs) override;
272
273 // --------- IPWMControl declarations. Implementation in IPWMControlImpl.cpp ---------
274
275 //bool getNumberOfMotors(int * number) override;
276 bool setRefDutyCycle(int m, double ref) override;
277 bool setRefDutyCycles(const double * refs) override;
278 bool getRefDutyCycle(int m, double * ref) override;
279 bool getRefDutyCycles(double * refs) override;
280 bool getDutyCycle(int m, double * val) override;
281 bool getDutyCycles(double * vals) override;
282
283 // ----------- IRemoteVariables declarations. Implementation in IRemoteVariablesImpl.cpp --------------
284
285 bool getRemoteVariable(std::string key, yarp::os::Bottle & val) override;
286 bool setRemoteVariable(std::string key, const yarp::os::Bottle & val) override;
287 bool getRemoteVariablesList(yarp::os::Bottle * listOfKeys) override;
288
289 // -------- ITorqueControl declarations. Implementation in ITorqueControlImpl.cpp --------
290
291 //bool getAxes(int * ax) override;
292 bool getRefTorque(int j, double * t) override;
293 bool getRefTorques(double * t) override;
294 bool setRefTorque(int j, double t) override;
295 bool setRefTorques(const double * t) override;
296 bool setRefTorques(int n_joint, const int * joints, const double * t) override;
297 bool getMotorTorqueParams(int j, yarp::dev::MotorTorqueParameters * params) override;
298 bool setMotorTorqueParams(int j, const yarp::dev::MotorTorqueParameters params) override;
299 bool getTorque(int j, double * t) override;
300 bool getTorques(double * t) override;
301 bool getTorqueRange(int j, double * min, double * max) override;
302 bool getTorqueRanges(double * min, double * max) override;
303
304 // --------- IVelocityControl declarations. Implementation in IVelocityControlImpl.cpp ---------
305
306 //bool getAxes(int * ax) override;
307 bool velocityMove(int j, double spd) override;
308 bool velocityMove(const double * spds) override;
309 bool velocityMove(int n_joint, const int * joints, const double * spds) override;
310 bool getRefVelocity(int joint, double * vel) override;
311 bool getRefVelocities(double * vels) override;
312 bool getRefVelocities(int n_joint, const int * joints, double * vels) override;
313 //bool setRefAcceleration(int j, double acc) override;
314 //bool setRefAccelerations(const double * accs) override;
315 //bool setRefAccelerations(int n_joint, const int * joints, const double * accs) override;
316 //bool getRefAcceleration(int j, double * acc) override;
317 //bool getRefAccelerations(double * accs) override;
318 //bool getRefAccelerations(int n_joint, const int * joints, double * accs) override;
319 //bool stop(int j) override;
320 //bool stop() override;
321 //bool stop(int n_joint, const int *joints) override;
322
323 // ---------- MULTIPLE ANALOG SENSORS INTERFACES ----------
324
325 // --------- IContactLoadCellArrays declarations. Implementation in IContactLoadCellArraysImpl.cpp ---------
326
327 std::size_t getNrOfContactLoadCellArrays() const override;
328 yarp::dev::MAS_status getContactLoadCellArrayStatus(std::size_t sens_index) const override;
329 bool getContactLoadCellArrayName(std::size_t sens_index, std::string & name) const override;
330 bool getContactLoadCellArrayMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
331 std::size_t getContactLoadCellArraySize(std::size_t sens_index) const override;
332
333 // --------- IEncoderArrays declarations. Implementation in IEncoderArraysImpl.cpp ---------
334
335 std::size_t getNrOfEncoderArrays() const override;
336 yarp::dev::MAS_status getEncoderArrayStatus(std::size_t sens_index) const override;
337 bool getEncoderArrayName(std::size_t sens_index, std::string & name) const override;
338 bool getEncoderArrayMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
339 std::size_t getEncoderArraySize(std::size_t sens_index) const override;
340
341 // --------- IOrientationSensors declarations. Implementation in IOrientationSensorsImpl.cpp ---------
342
343 std::size_t getNrOfOrientationSensors() const override;
344 yarp::dev::MAS_status getOrientationSensorStatus(std::size_t sens_index) const override;
345 bool getOrientationSensorName(std::size_t sens_index, std::string & name) const override;
346 bool getOrientationSensorFrameName(std::size_t sens_index, std::string & frameName) const override;
347 bool getOrientationSensorMeasureAsRollPitchYaw(std::size_t sens_index, yarp::sig::Vector & rpy, double & timestamp) const override;
348
349 // --------- IPositionSensors declarations. Implementation in IPositionSensorsImpl.cpp ---------
350
351 std::size_t getNrOfPositionSensors() const override;
352 yarp::dev::MAS_status getPositionSensorStatus(std::size_t sens_index) const override;
353 bool getPositionSensorName(std::size_t sens_index, std::string & name) const override;
354 bool getPositionSensorFrameName(std::size_t sens_index, std::string & frameName) const override;
355 bool getPositionSensorMeasure(std::size_t sens_index, yarp::sig::Vector & xyz, double & timestamp) const override;
356
357 // --------- ISixAxisForceTorqueSensors declarations. Implementation in ISixAxisForceTorqueSensorsImpl.cpp ---------
358
359 std::size_t getNrOfSixAxisForceTorqueSensors() const override;
360 yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(std::size_t sens_index) const override;
361 bool getSixAxisForceTorqueSensorName(std::size_t sens_index, std::string & name) const override;
362 bool getSixAxisForceTorqueSensorFrameName(std::size_t sens_index, std::string & frameName) const override;
363 bool getSixAxisForceTorqueSensorMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
364
365 // --------- ISkinPatches declarations. Implementation in ISkinPatchesImpl.cpp ---------
366
367 std::size_t getNrOfSkinPatches() const override;
368 yarp::dev::MAS_status getSkinPatchStatus(std::size_t sens_index) const override;
369 bool getSkinPatchName(std::size_t sens_index, std::string & name) const override;
370 bool getSkinPatchMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
371 std::size_t getSkinPatchSize(std::size_t sens_index) const override;
372
373 // --------- ITemperatureSensors declarations. Implementation in ITemperatureSensorsImpl.cpp ---------
374
375 std::size_t getNrOfTemperatureSensors() const override;
376 yarp::dev::MAS_status getTemperatureSensorStatus(std::size_t sens_index) const override;
377 bool getTemperatureSensorName(std::size_t sens_index, std::string & name) const override;
378 bool getTemperatureSensorFrameName(std::size_t sens_index, std::string & frameName) const override;
379 bool getTemperatureSensorMeasure(std::size_t sens_index, double & out, double & timestamp) const override;
380 bool getTemperatureSensorMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
381
382 // --------- IThreeAxisGyroscopes declarations. Implementation in IThreeAxisGyroscopesImpl.cpp ---------
383
384 std::size_t getNrOfThreeAxisGyroscopes() const override;
385 yarp::dev::MAS_status getThreeAxisGyroscopeStatus(std::size_t sens_index) const override;
386 bool getThreeAxisGyroscopeName(std::size_t sens_index, std::string & name) const override;
387 bool getThreeAxisGyroscopeFrameName(std::size_t sens_index, std::string & frameName) const override;
388 bool getThreeAxisGyroscopeMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
389
390 // --------- IThreeAxisLinearAccelerometers declarations. Implementation in IThreeAxisLinearAccelerometersImpl.cpp ---------
391
392 std::size_t getNrOfThreeAxisLinearAccelerometers() const override;
393 yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(std::size_t sens_index) const override;
394 bool getThreeAxisLinearAccelerometerName(std::size_t sens_index, std::string & name) const override;
395 bool getThreeAxisLinearAccelerometerFrameName(std::size_t sens_index, std::string & frameName) const override;
396 bool getThreeAxisLinearAccelerometerMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
397
398 // --------- IThreeAxisMagnetometers declarations. Implementation in IThreeAxisMagnetometersImpl.cpp ---------
399
400 std::size_t getNrOfThreeAxisMagnetometers() const override;
401 yarp::dev::MAS_status getThreeAxisMagnetometerStatus(std::size_t sens_index) const override;
402 bool getThreeAxisMagnetometerName(std::size_t sens_index, std::string & name) const override;
403 bool getThreeAxisMagnetometerFrameName(std::size_t sens_index, std::string & frameName) const override;
404 bool getThreeAxisMagnetometerMeasure(std::size_t sens_index, yarp::sig::Vector & out, double & timestamp) const override;
405
406private:
407 roboticslab::DeviceMapper deviceMapper;
408
409 std::vector<yarp::dev::PolyDriver *> busDevices;
410 std::vector<yarp::dev::PolyDriver *> nodeDevices;
411 std::vector<roboticslab::SingleBusBroker *> brokers;
412
413 roboticslab::SyncPeriodicThread * syncThread {nullptr};
414};
415
416#endif // __CAN_BUS_BROKER_HPP__
Definition CanBusBroker_ParamsParser.h:43
CAN-oriented control board that implements all YARP motor interfaces.
Definition CanBusBroker.hpp:71
Exposes raw subdevice interface handles on a per-axis manner.
Definition DeviceMapper.hpp:65
Periodic SYNC signal emitter.
Definition SyncPeriodicThread.hpp:29