yarp-devices
Loading...
Searching...
No Matches
DriveStatusMachine.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __DRIVE_STATUS_MACHINE_HPP__
4#define __DRIVE_STATUS_MACHINE_HPP__
5
6#include <cstdint>
7
8#include <bitset>
9#include <mutex>
10
11#include "PdoProtocol.hpp"
12#include "StateObserver.hpp"
13
14namespace roboticslab
15{
16
32
37enum class DriveTransition : std::uint16_t
38{
39 SHUTDOWN = 0x0006,
40 SWITCH_ON = 0x0007,
41 DISABLE_VOLTAGE = 0x0000,
42 QUICK_STOP = 0x0002,
43 ENABLE_OPERATION = 0x000F,
44 FAULT_RESET = 0x0080,
46};
47
61{
62public:
63 using word_t = std::bitset<16>;
64
66 DriveStatusMachine(ReceivePdo * rpdo, double timeout)
67 : rpdo(rpdo), stateObserver(timeout)
68 { }
69
72 { this->rpdo = rpdo; }
73
75 bool update(std::uint16_t statusword);
76
78 void reset();
79
81 word_t controlword() const;
82
84 bool controlword(const word_t & controlbits);
85
87 word_t statusword() const;
88
91
93 bool requestTransition(DriveTransition transition);
94
96 bool requestState(DriveState goalState);
97
99 bool awaitState(DriveState goalState);
100
102 static DriveState parseStatusword(std::uint16_t statusword);
103
104private:
105 word_t _controlword;
106 word_t _statusword;
107 ReceivePdo * rpdo;
108 StateObserver stateObserver;
109 mutable std::mutex stateMutex;
110};
111
112} // namespace roboticslab
113
114#endif // __DRIVE_STATUS_MACHINE_HPP__
Representation of a CiA 402 state machine controller.
Definition DriveStatusMachine.hpp:61
void reset()
Reset internally stored state.
Definition DriveStatusMachine.cpp:163
DriveStatusMachine(ReceivePdo *rpdo, double timeout)
Constructor, registers RPDO handle.
Definition DriveStatusMachine.hpp:66
word_t controlword() const
Retrieve stored controlword.
Definition DriveStatusMachine.cpp:169
bool awaitState(DriveState goalState)
Await until drive reaches given state, with timeout.
Definition DriveStatusMachine.cpp:234
DriveState getCurrentState() const
Parse stored bit representation of a statusword into a DriveState enumerator.
Definition DriveStatusMachine.cpp:193
static DriveState parseStatusword(std::uint16_t statusword)
Parse bit representation into a DriveState enumerator.
Definition DriveStatusMachine.cpp:244
std::bitset< 16 > word_t
Fixed-size sequence of 16 bits.
Definition DriveStatusMachine.hpp:63
bool requestState(DriveState goalState)
Request given drive state via object 6040h (blocking), update stored controlword.
Definition DriveStatusMachine.cpp:207
bool requestTransition(DriveTransition transition)
Request given drive transition via object 6040h (blocking), update stored controlword.
Definition DriveStatusMachine.cpp:198
void configureRpdo(ReceivePdo *rpdo)
Configure RPDO handle.
Definition DriveStatusMachine.hpp:71
bool update(std::uint16_t statusword)
Notify observers on a drive state change, if applicable.
Definition DriveStatusMachine.cpp:144
word_t statusword() const
Retrieve stored statusword.
Definition DriveStatusMachine.cpp:187
Representation of RPDO protocol.
Definition PdoProtocol.hpp:178
Data-free state observer.
Definition StateObserver.hpp:75
DriveTransition
CiA 402 drive transitions (associated to controlword).
Definition DriveStatusMachine.hpp:38
DriveState
CiA 402 drive states (associated to statusword).
Definition DriveStatusMachine.hpp:22
@ SWITCH_ON
Switch on command (xxxx.xxxx.0xxx.0111)
@ QUICK_STOP
Quick stop command (xxxx.xxxx.0xxx.x01x)
@ DISABLE_OPERATION
Disable operation command, alias for DriveTransition::SWITCH_ON.
@ FAULT_RESET
Reset fault command (xxxx.xxxx.1xxx.xxxx)
@ ENABLE_OPERATION
Enable operation command (xxxx.xxxx.0xxx.1111)
@ SHUTDOWN
Shutdown command (xxxx.xxxx.0xxx.x110)
@ DISABLE_VOLTAGE
Disable voltage command (xxxx.xxxx.0xxx.xx0x)
@ SWITCHED_ON
Switched on (operation disabled) state.
@ FAULT_REACTION_ACTIVE
Fault reaction active state.
@ QUICK_STOP_ACTIVE
Quick stop active state.
@ READY_TO_SWITCH_ON
Ready to switch on state.
@ OPERATION_ENABLED
Operation enabled state.
@ SWITCH_ON_DISABLED
Switch on disabled state.
@ NOT_READY_TO_SWITCH_ON
Not ready to switch on state.
The main, catch-all namespace for Robotics Lab UC3M.
Definition groups.dox:6