yarp-devices
CanOpenNode.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __CAN_OPEN_HPP__
4 #define __CAN_OPEN_HPP__
5 
6 #include <cstddef>
7 #include <cstdint>
8 
9 #include "ICanMessageNotifier.hpp"
10 #include "ICanSenderDelegate.hpp"
11 #include "SdoClient.hpp"
12 #include "PdoProtocol.hpp"
13 #include "EmcyConsumer.hpp"
14 #include "NmtProtocol.hpp"
15 #include "DriveStatusMachine.hpp"
16 
17 namespace roboticslab
18 {
19 
34 class CanOpenNode final : public ICanMessageNotifier
35 {
36 public:
37  static constexpr double SDO_TIMEOUT = 0.1;
38  static constexpr double STATE_MACHINE_TIMEOUT = 2.0;
39 
41  CanOpenNode(unsigned int id, double sdoTimeout = SDO_TIMEOUT,
42  double stateTimeout = STATE_MACHINE_TIMEOUT, ICanSenderDelegate * sender = nullptr);
43 
45  CanOpenNode(const CanOpenNode &) = delete;
46 
48  CanOpenNode & operator=(const CanOpenNode &) = delete;
49 
51  ~CanOpenNode();
52 
54  void configureSender(ICanSenderDelegate * sender);
55 
57  unsigned int getId() const
58  { return _id; }
59 
61  SdoClient * sdo() const
62  { return _sdo; }
63 
65  ReceivePdo * rpdo1() const
66  { return _rpdo1; }
67 
69  ReceivePdo * rpdo2() const
70  { return _rpdo2; }
71 
73  ReceivePdo * rpdo3() const
74  { return _rpdo3; }
75 
77  ReceivePdo * rpdo4() const
78  { return _rpdo4; }
79 
81  TransmitPdo * tpdo1() const
82  { return _tpdo1; }
83 
85  TransmitPdo * tpdo2() const
86  { return _tpdo2; }
87 
89  TransmitPdo * tpdo3() const
90  { return _tpdo3; }
91 
93  TransmitPdo * tpdo4() const
94  { return _tpdo4; }
95 
97  EmcyConsumer * emcy() const
98  { return _emcy; }
99 
101  NmtProtocol * nmt() const
102  { return _nmt; }
103 
106  { return _driveStatus; }
107 
108  bool notifyMessage(const can_message & msg) override;
109 
110 private:
111  unsigned int _id;
112 
113  SdoClient * _sdo;
114 
115  ReceivePdo * _rpdo1;
116  ReceivePdo * _rpdo2;
117  ReceivePdo * _rpdo3;
118  ReceivePdo * _rpdo4;
119 
120  TransmitPdo * _tpdo1;
121  TransmitPdo * _tpdo2;
122  TransmitPdo * _tpdo3;
123  TransmitPdo * _tpdo4;
124 
125  EmcyConsumer * _emcy;
126  NmtProtocol * _nmt;
127  DriveStatusMachine * _driveStatus;
128 };
129 
130 } // namespace roboticslab
131 
132 #endif // __CAN_OPEN_HPP__
Wrapper for CAN protocol handles with handy accessors.
Definition: CanOpenNode.hpp:35
SdoClient * sdo() const
Retrieve handle of SDO client instance.
Definition: CanOpenNode.hpp:61
ReceivePdo * rpdo3() const
Retrieve handle of RPDO3 instance.
Definition: CanOpenNode.hpp:73
~CanOpenNode()
Destructor.
Definition: CanOpenNode.cpp:23
bool notifyMessage(const can_message &msg) override
Notify observers that a new CAN message has arrived.
Definition: CanOpenNode.cpp:52
void configureSender(ICanSenderDelegate *sender)
Pass sender handle to internal CAN protocol handles.
Definition: CanOpenNode.cpp:42
TransmitPdo * tpdo1() const
Retrieve handle of TPDO1 instance.
Definition: CanOpenNode.hpp:81
static constexpr double SDO_TIMEOUT
Timeout on SDO transfers (seconds)
Definition: CanOpenNode.hpp:37
TransmitPdo * tpdo4() const
Retrieve handle of TPDO4 instance.
Definition: CanOpenNode.hpp:93
ReceivePdo * rpdo1() const
Retrieve handle of RPDO1 instance.
Definition: CanOpenNode.hpp:65
ReceivePdo * rpdo2() const
Retrieve handle of RPDO2 instance.
Definition: CanOpenNode.hpp:69
CanOpenNode & operator=(const CanOpenNode &)=delete
Deleted copy assingment operator.
TransmitPdo * tpdo2() const
Retrieve handle of TPDO2 instance.
Definition: CanOpenNode.hpp:85
static constexpr double STATE_MACHINE_TIMEOUT
Timeout on state machine transitions (seconds)
Definition: CanOpenNode.hpp:38
TransmitPdo * tpdo3() const
Retrieve handle of TPDO3 instance.
Definition: CanOpenNode.hpp:89
CanOpenNode(const CanOpenNode &)=delete
Deleted copy constructor.
unsigned int getId() const
Retrieve CAN node id.
Definition: CanOpenNode.hpp:57
DriveStatusMachine * driveStatus() const
Retrieve handle of drive state machine instance.
Definition: CanOpenNode.hpp:105
CanOpenNode(unsigned int id, double sdoTimeout=SDO_TIMEOUT, double stateTimeout=STATE_MACHINE_TIMEOUT, ICanSenderDelegate *sender=nullptr)
Constructor, creates and configures all handles.
Definition: CanOpenNode.cpp:7
ReceivePdo * rpdo4() const
Retrieve handle of RPDO4 instance.
Definition: CanOpenNode.hpp:77
EmcyConsumer * emcy() const
Retrieve handle of EMCY instance.
Definition: CanOpenNode.hpp:97
NmtProtocol * nmt() const
Retrieve handle of NMT instance.
Definition: CanOpenNode.hpp:101
Representation of a CiA 402 state machine controller.
Definition: DriveStatusMachine.hpp:61
Representation of CAN EMCY protocol.
Definition: EmcyConsumer.hpp:33
Implementation-agnostic consumer for RX CAN transfers.
Definition: ICanMessageNotifier.hpp:22
Implementation-agnostic consumer for TX CAN transfers.
Definition: ICanSenderDelegate.hpp:22
Representation of NMT protocol.
Definition: NmtProtocol.hpp:45
Representation of RPDO protocol.
Definition: PdoProtocol.hpp:178
Representation of SDO client protocol.
Definition: SdoClient.hpp:32
Representation of TPDO protocol.
Definition: PdoProtocol.hpp:229
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6
Proxy CAN message structure.
Definition: CanMessage.hpp:20