yarp-devices
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 
12 #include <yarp/dev/DeviceDriver.h>
13 #include <yarp/dev/IAxisInfo.h>
14 #include <yarp/dev/IControlMode.h>
15 #include <yarp/dev/IPWMControl.h>
16 
17 #include "ICanBusSharer.hpp"
18 
19 #define CHECK_JOINT(j) do { int n; if (getNumberOfMotorsRaw(&n), (j) != n - 1) return false; } while (0)
20 
21 namespace roboticslab
22 {
23 
35 class LacqueyFetch : public yarp::dev::DeviceDriver,
36  public yarp::dev::IAxisInfoRaw,
37  public yarp::dev::IControlModeRaw,
38  public yarp::dev::IPWMControlRaw,
39  public ICanBusSharer
40 {
41 public:
42  // --------- DeviceDriver declarations. Implementation in LacqueyFetch.cpp ---------
43 
44  bool open(yarp::os::Searchable & config) override;
45  bool close() override;
46 
47  // --------- ICanBusSharer declarations. Implementation in LacqueyFetch.cpp ---------
48 
49  unsigned int getId() override;
50  bool notifyMessage(const can_message & message) override;
51  bool initialize() override;
52  bool finalize() override;
53  bool registerSender(ICanSenderDelegate * sender) override;
54  bool synchronize(double timestamp) override;
55 
56  // --------- IAxisInfoRaw declarations. Implementation in IAxisInfoRawImpl.cpp ---------
57 
58  bool getAxes(int * ax) override;
59  bool getAxisNameRaw(int j, std::string & name) override;
60  bool getJointTypeRaw(int j, yarp::dev::JointTypeEnum & type) override;
61 
62  // --------- IControlModeRaw declarations. Implementation in IControlModeRawImpl.cpp ---------
63 
64  bool getControlModeRaw(int j, int * mode) override;
65  bool getControlModesRaw(int * modes) override;
66  bool getControlModesRaw(int n_joint, const int * joints, int * modes) override;
67  bool setControlModeRaw(int j, int mode) override;
68  bool setControlModesRaw(int * modes) override;
69  bool setControlModesRaw(int n_joint, const int * joints, int * modes) override;
70 
71  // ------- IPWMControlRaw declarations. Implementation in IPWMControlRawImpl.cpp -------
72 
73  bool getNumberOfMotorsRaw(int * number) override;
74  bool setRefDutyCycleRaw(int m, double ref) override;
75  bool setRefDutyCyclesRaw(const double * refs) override;
76  bool getRefDutyCycleRaw(int m, double * ref) override;
77  bool getRefDutyCyclesRaw(double * refs) override;
78  bool getDutyCycleRaw(int m, double * val) override;
79  bool getDutyCyclesRaw(double * vals) override;
80 
81 private:
82  static constexpr unsigned int CAN_OP = 0x780; // keep in sync with firmware
83 
84  bool send(unsigned int len, const std::uint8_t * msgData)
85  { return sender && sender->prepareMessage({CAN_OP + canId, len, msgData}); }
86 
87  unsigned int canId {0};
88  std::string axisName;
89  yarp::conf::float32_t refDutyCycles {0};
90  ICanSenderDelegate * sender {nullptr};
91 };
92 
93 } // namespace roboticslab
94 
95 #endif // __LACQUEY_FETCH_HPP__
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.
Implementation for the Lacquey Fetch hand custom UC3M circuit as a single CAN bus joint (control boar...
Definition: LacqueyFetch.hpp:40
bool registerSender(ICanSenderDelegate *sender) override
Pass a handle to a CAN sender delegate instance.
Definition: ICanBusSharerImpl.cpp:37
unsigned int getId() override
Retrieve CAN node ID.
Definition: ICanBusSharerImpl.cpp:9
bool finalize() override
Finalize CAN node communications.
Definition: ICanBusSharerImpl.cpp:23
bool notifyMessage(const can_message &message) override
Notify observers that a new CAN message has arrived.
Definition: ICanBusSharerImpl.cpp:30
bool synchronize(double timestamp) override
Perform synchronized action on CAN master's request.
Definition: ICanBusSharerImpl.cpp:45
bool initialize() override
Perform CAN node initialization.
Definition: ICanBusSharerImpl.cpp:16
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6
Proxy CAN message structure.
Definition: CanMessage.hpp:20