Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
cia402.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string_view>
5
15
17
33
35enum class OperationMode : int8_t {
36 kNoMode = 0,
39 kProfileTorque = 4,
40 kHoming = 6,
44};
45
57
63constexpr uint16_t kCommandMask = 0x008F;
64
66enum Command : uint16_t {
67 kCmdShutdown = 0x0006,
68 kCmdSwitchOn = 0x0007,
71 kCmdQuickStop = 0x0002,
72 kCmdFaultReset = 0x0080,
73};
74
79constexpr State decodeState(uint16_t statusword) {
80 // The two masks the standard uses: 0x4F distinguishes the states that ignore bit 5
81 // (quick stop), 0x6F the rest.
82 if ((statusword & 0x4F) == 0x40) {
84 }
85 if ((statusword & 0x6F) == 0x21) {
87 }
88 if ((statusword & 0x6F) == 0x23) {
89 return State::kSwitchedOn;
90 }
91 if ((statusword & 0x6F) == 0x27) {
93 }
94 if ((statusword & 0x6F) == 0x07) {
96 }
97 if ((statusword & 0x4F) == 0x0F) {
99 }
100 if ((statusword & 0x4F) == 0x08) {
101 return State::kFault;
102 }
104}
105
107constexpr bool isFaulted(uint16_t statusword) {
108 const State s = decodeState(statusword);
109 return s == State::kFault || s == State::kFaultReactionActive;
110}
111
113constexpr std::string_view toString(State state) {
114 switch (state) {
116 return "NotReadyToSwitchOn";
118 return "SwitchOnDisabled";
120 return "ReadyToSwitchOn";
122 return "SwitchedOn";
124 return "OperationEnabled";
126 return "QuickStopActive";
128 return "FaultReactionActive";
129 case State::kFault:
130 return "Fault";
131 }
132 return "Unknown";
133}
134
136constexpr std::string_view toString(OperationMode mode) {
137 switch (mode) {
139 return "NoMode";
141 return "ProfilePosition";
143 return "ProfileVelocity";
145 return "ProfileTorque";
147 return "Homing";
149 return "CyclicSyncPosition";
151 return "CyclicSyncVelocity";
153 return "CyclicSyncTorque";
154 }
155 return "Unknown";
156}
157
158} // namespace mm::node::cia402
Definition cia402.h:16
OperationMode
CiA402 operation modes (object 0x6060 / 0x6061 values).
Definition cia402.h:35
@ kCyclicSyncVelocity
CSV — interpolated cyclic velocity.
@ kCyclicSyncTorque
CST — interpolated cyclic torque.
@ kCyclicSyncPosition
CSP — interpolated cyclic position (the common SOMANET mode).
@ kHoming
HM — reference/homing run.
@ kProfileTorque
PT — profiled torque.
@ kProfilePosition
PP — trapezoidal point-to-point positioning.
@ kProfileVelocity
PV — profiled velocity.
Command
Canonical controlword command-bit patterns (the value of the bits in kCommandMask).
Definition cia402.h:66
@ kCmdShutdown
→ ReadyToSwitchOn (enable voltage + no quick stop).
Definition cia402.h:67
@ kCmdDisableVoltage
→ SwitchOnDisabled.
Definition cia402.h:70
@ kCmdFaultReset
Rising edge of bit 7 clears a fault.
Definition cia402.h:72
@ kCmdQuickStop
→ QuickStopActive.
Definition cia402.h:71
@ kCmdSwitchOn
→ SwitchedOn (also "disable operation" from OperationEnabled).
Definition cia402.h:68
@ kCmdEnableOperation
→ OperationEnabled.
Definition cia402.h:69
State
States of the CiA402 device control state machine (decoded from the statusword).
Definition cia402.h:47
@ kNotReadyToSwitchOn
Drive initialising; no clear state yet.
@ kQuickStopActive
Quick stop in progress.
@ kSwitchedOn
Switch-on command accepted; power stage on, no motion.
@ kReadyToSwitchOn
Shutdown command accepted.
@ kFaultReactionActive
A fault is being reacted to (e.g. controlled stop).
@ kOperationEnabled
Fully enabled; setpoints are followed.
@ kFault
Faulted and stopped; needs a fault reset.
@ kSwitchOnDisabled
Powered, holding; the resting state after init.
constexpr std::string_view toString(State state)
Human-readable name of a state (for logging / JSON). Never returns nullptr.
Definition cia402.h:113
constexpr uint16_t kCommandMask
Controlword (0x6040) command-bit mask — the state-machine bits a transition touches.
Definition cia402.h:63
constexpr State decodeState(uint16_t statusword)
Decodes the CiA402 state machine state from a statusword (0x6041) value.
Definition cia402.h:79
constexpr bool isFaulted(uint16_t statusword)
Whether the statusword's fault bit (bit 3) is set, gated to the faulted states.
Definition cia402.h:107
Object
Standard CiA402 object dictionary indices used by the drive profile.
Definition cia402.h:21
@ kPositionActualValue
INTEGER32, TxPDO — actual position.
Definition cia402.h:29
@ kStatusword
UNSIGNED16, TxPDO — reports the state machine.
Definition cia402.h:23
@ kTargetVelocity
INTEGER32, RxPDO — CSV/PV setpoint.
Definition cia402.h:27
@ kTorqueActualValue
INTEGER16, TxPDO — actual torque.
Definition cia402.h:31
@ kControlword
UNSIGNED16, RxPDO — commands the state machine.
Definition cia402.h:22
@ kVelocityActualValue
INTEGER32, TxPDO — actual velocity.
Definition cia402.h:30
@ kTargetTorque
INTEGER16, RxPDO — CST/PT setpoint (per-mille of rated).
Definition cia402.h:28
@ kModeOfOperationDisplay
INTEGER8, TxPDO — active operation mode.
Definition cia402.h:25
@ kTargetPosition
INTEGER32, RxPDO — CSP/PP setpoint.
Definition cia402.h:26
@ kModeOfOperation
INTEGER8, RxPDO — requested operation mode.
Definition cia402.h:24