yarp-devices
Loading...
Searching...
No Matches
LacqueyFetch.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __LACQUEY_FETCH_HPP__
4#define __LACQUEY_FETCH_HPP__
5
6#include <cstdint>
7
8#include <string>
9
10#include <yarp/conf/numeric.h>
11#include <yarp/conf/version.h>
12
13#include <yarp/dev/DeviceDriver.h>
14#include <yarp/dev/IAxisInfo.h>
15#include <yarp/dev/IControlMode.h>
16#include <yarp/dev/IPWMControl.h>
17
18#include "ICanBusSharer.hpp"
19#include "LacqueyFetch_ParamsParser.h"
20
21#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
22#define CHECK_JOINT(j) do { int n; if (getNumberOfMotorsRaw(&n), (j) != n - 1) return yarp::dev::ReturnValue_error_input_out_of_bounds; } while (0)
23#else
24#define CHECK_JOINT(j) do { int n; if (getNumberOfMotorsRaw(&n), (j) != n - 1) return false; } while (0)
25#endif
26
38class LacqueyFetch : public yarp::dev::DeviceDriver,
39 public yarp::dev::IAxisInfoRaw,
40 public yarp::dev::IControlModeRaw,
41 public yarp::dev::IPWMControlRaw,
44{
45public:
46 // --------- DeviceDriver declarations. Implementation in LacqueyFetch.cpp ---------
47
48 bool open(yarp::os::Searchable & config) override;
49 bool close() override;
50
51 // --------- ICanBusSharer declarations. Implementation in LacqueyFetch.cpp ---------
52
53 unsigned int getId() override;
54 bool notifyMessage(const roboticslab::can_message & message) override;
55 bool initialize() override;
56 bool finalize() override;
57 bool registerSender(roboticslab::ICanSenderDelegate * sender) override;
58 bool synchronize(double timestamp) override;
59
60 // --------- IAxisInfoRaw declarations. Implementation in IAxisInfoRawImpl.cpp ---------
61
62#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
63 yarp::dev::ReturnValue getAxes(std::size_t & ax) override;
64 yarp::dev::ReturnValue getAxisNameRaw(int j, std::string & name) override;
65 yarp::dev::ReturnValue getJointTypeRaw(int j, yarp::dev::JointTypeEnum & type) override;
66#else
67 bool getAxes(int * ax) override;
68 bool getAxisNameRaw(int j, std::string & name) override;
69 bool getJointTypeRaw(int j, yarp::dev::JointTypeEnum & type) override;
70#endif
71
72 // --------- IControlModeRaw declarations. Implementation in IControlModeRawImpl.cpp ---------
73
74#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
75 yarp::dev::ReturnValue getAvailableControlModesRaw(int j, std::vector<yarp::dev::SelectableControlModeEnum> & avail) override;
76 yarp::dev::ReturnValue getControlModeRaw(int j, yarp::dev::ControlModeEnum & mode) override;
77 yarp::dev::ReturnValue getControlModesRaw(std::vector<yarp::dev::ControlModeEnum> & modes) override;
78 yarp::dev::ReturnValue getControlModesRaw(const std::vector<int> & joints, std::vector<yarp::dev::ControlModeEnum> & modes) override;
79 yarp::dev::ReturnValue setControlModeRaw(int j, yarp::dev::SelectableControlModeEnum mode) override;
80 yarp::dev::ReturnValue setControlModesRaw(const std::vector<int> & joints, const std::vector<yarp::dev::SelectableControlModeEnum> & modes) override;
81 yarp::dev::ReturnValue setControlModesRaw(const std::vector<yarp::dev::SelectableControlModeEnum> & modes) override;
82#else
83 bool getControlModeRaw(int j, int * mode) override;
84 bool getControlModesRaw(int * modes) override;
85 bool getControlModesRaw(int n_joint, const int * joints, int * modes) override;
86 bool setControlModeRaw(int j, int mode) override;
87 bool setControlModesRaw(int * modes) override;
88 bool setControlModesRaw(int n_joint, const int * joints, int * modes) override;
89#endif
90
91 // ------- IPWMControlRaw declarations. Implementation in IPWMControlRawImpl.cpp -------
92
93#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
94 yarp::dev::ReturnValue getNumberOfMotorsRaw(int * number) override;
95 yarp::dev::ReturnValue setRefDutyCycleRaw(int m, double ref) override;
96 yarp::dev::ReturnValue setRefDutyCyclesRaw(const double * refs) override;
97 yarp::dev::ReturnValue getRefDutyCycleRaw(int m, double * ref) override;
98 yarp::dev::ReturnValue getRefDutyCyclesRaw(double * refs) override;
99 yarp::dev::ReturnValue getDutyCycleRaw(int m, double * val) override;
100 yarp::dev::ReturnValue getDutyCyclesRaw(double * vals) override;
101#else
102 bool getNumberOfMotorsRaw(int * number) override;
103 bool setRefDutyCycleRaw(int m, double ref) override;
104 bool setRefDutyCyclesRaw(const double * refs) override;
105 bool getRefDutyCycleRaw(int m, double * ref) override;
106 bool getRefDutyCyclesRaw(double * refs) override;
107 bool getDutyCycleRaw(int m, double * val) override;
108 bool getDutyCyclesRaw(double * vals) override;
109#endif
110
111private:
112 static constexpr unsigned int CAN_OP = 0x780; // keep in sync with firmware
113
114 bool send(unsigned int len, const std::uint8_t * msgData)
115 { return sender && sender->prepareMessage({CAN_OP + m_canId, len, msgData}); }
116
117 yarp::conf::float32_t refDutyCycles {0};
118 roboticslab::ICanSenderDelegate * sender {nullptr};
119};
120
121#endif // __LACQUEY_FETCH_HPP__
Definition LacqueyFetch_ParamsParser.h:43
Implementation for the Lacquey Fetch hand custom UC3M circuit as a single CAN bus joint (control boar...
Definition LacqueyFetch.hpp:44
unsigned int getId() override
Retrieve CAN node ID.
Definition ICanBusSharerImpl.cpp:9
bool finalize() override
Finalize CAN node communications.
Definition ICanBusSharerImpl.cpp:23
bool registerSender(roboticslab::ICanSenderDelegate *sender) override
Pass a handle to a CAN sender delegate instance.
Definition ICanBusSharerImpl.cpp:37
bool synchronize(double timestamp) override
Perform synchronized action on CAN master's request.
Definition ICanBusSharerImpl.cpp:45
bool notifyMessage(const roboticslab::can_message &message) override
Notify observers that a new CAN message has arrived.
Definition ICanBusSharerImpl.cpp:30
bool initialize() override
Perform CAN node initialization.
Definition ICanBusSharerImpl.cpp:16
Abstract base for a CAN bus sharer.
Definition ICanBusSharer.hpp:25
Implementation-agnostic consumer for TX CAN transfers.
Definition ICanSenderDelegate.hpp:22
virtual bool prepareMessage(const can_message &msg)=0
Register CAN message for write.
Proxy CAN message structure.
Definition CanMessage.hpp:20