Motion Master 6.0.0-alpha.86
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 <optional>
5#include <string_view>
6
16
18
23enum Object : uint16_t {
24 kErrorCode = 0x603F,
25 kControlword = 0x6040,
26 kStatusword = 0x6041,
34 kPositionWindow = 0x6067,
38 kVelocityWindow = 0x606D,
42 kTargetTorque = 0x6071,
43 kMaxTorque = 0x6072,
44 kMaxCurrent = 0x6073,
45 kTorqueDemand = 0x6074,
50 kTargetPosition = 0x607A,
52 kHomeOffset = 0x607C,
54 kPolarity = 0x607E,
55 kMaxMotorSpeed = 0x6080,
61 kTorqueSlope = 0x6087,
63 kGearRatio = 0x6091,
64 kFeedConstant = 0x6092,
65 kHomingMethod = 0x6098,
66 kHomingSpeeds = 0x6099,
68 kSiUnitVelocity = 0x60A9,
69 kVelocityOffset = 0x60B1,
70 kTorqueOffset = 0x60B2,
82 kControlEffort = 0x60FA,
85 kDigitalInputs = 0x60FD,
86 kDigitalOutputs = 0x60FE,
87 kTargetVelocity = 0x60FF,
89};
90
98enum class OperationMode : int8_t {
99 kNoMode = 0,
100 kProfilePosition = 1,
101 kVelocity = 2,
102 kProfileVelocity = 3,
103 kProfileTorque = 4,
104 kHoming = 6,
108 kCyclicSyncTorque = 10,
110};
111
115constexpr std::optional<OperationMode> toOperationMode(int value) {
116 // 0x6060 is an INTEGER8, so a value that does not fit int8_t is not a valid mode — reject it
117 // before the narrowing cast, or e.g. 264 would alias to 8 (CSP) and slip past validation.
118 if (value < INT8_MIN || value > INT8_MAX) {
119 return std::nullopt;
120 }
121 switch (static_cast<OperationMode>(static_cast<int8_t>(value))) {
133 return static_cast<OperationMode>(static_cast<int8_t>(value));
134 }
135 return std::nullopt;
136}
137
149
155constexpr uint16_t kCommandMask = 0x008F;
156
158enum Command : uint16_t {
159 kCmdShutdown = 0x0006,
160 kCmdSwitchOn = 0x0007,
163 kCmdQuickStop = 0x0002,
164 kCmdFaultReset = 0x0080,
165};
166
171constexpr State decodeState(uint16_t statusword) {
172 // The two masks the standard uses: 0x4F distinguishes the states that ignore bit 5
173 // (quick stop), 0x6F the rest.
174 if ((statusword & 0x4F) == 0x40) {
176 }
177 if ((statusword & 0x6F) == 0x21) {
179 }
180 if ((statusword & 0x6F) == 0x23) {
181 return State::kSwitchedOn;
182 }
183 if ((statusword & 0x6F) == 0x27) {
185 }
186 if ((statusword & 0x6F) == 0x07) {
188 }
189 if ((statusword & 0x4F) == 0x0F) {
191 }
192 if ((statusword & 0x4F) == 0x08) {
193 return State::kFault;
194 }
196}
197
199constexpr bool isFaulted(uint16_t statusword) {
200 const State s = decodeState(statusword);
201 return s == State::kFault || s == State::kFaultReactionActive;
202}
203
205constexpr std::string_view toString(State state) {
206 switch (state) {
208 return "NotReadyToSwitchOn";
210 return "SwitchOnDisabled";
212 return "ReadyToSwitchOn";
214 return "SwitchedOn";
216 return "OperationEnabled";
218 return "QuickStopActive";
220 return "FaultReactionActive";
221 case State::kFault:
222 return "Fault";
223 }
224 return "Unknown";
225}
226
228constexpr std::string_view toString(OperationMode mode) {
229 switch (mode) {
231 return "NoMode";
233 return "ProfilePosition";
235 return "Velocity";
237 return "ProfileVelocity";
239 return "ProfileTorque";
241 return "Homing";
243 return "InterpolatedPosition";
245 return "CyclicSyncPosition";
247 return "CyclicSyncVelocity";
249 return "CyclicSyncTorque";
251 return "CyclicSyncTorqueCommutationAngle";
252 }
253 return "Unknown";
254}
255
262 int bit = -1;
263 std::string_view abbreviation;
264 std::string_view label;
265};
266
275 {OperationMode::kNoMode, -1, "", "No mode selected"},
276 {OperationMode::kProfilePosition, 0, "pp", "Profile position mode"},
277 {OperationMode::kVelocity, 1, "vl", "Velocity mode (frequency converter)"},
278 {OperationMode::kProfileVelocity, 2, "pv", "Profile velocity mode"},
279 {OperationMode::kProfileTorque, 3, "tq", "Profile torque mode"},
280 {OperationMode::kHoming, 5, "hm", "Homing mode"},
281 {OperationMode::kInterpolatedPosition, 6, "ip", "Interpolated position mode"},
282 {OperationMode::kCyclicSyncPosition, 7, "csp", "Cyclic synchronous position mode"},
283 {OperationMode::kCyclicSyncVelocity, 8, "csv", "Cyclic synchronous velocity mode"},
284 {OperationMode::kCyclicSyncTorque, 9, "cst", "Cyclic synchronous torque mode"},
286 "Cyclic synchronous torque mode with commutation angle"},
287};
288
307constexpr bool quickStopHolds(int16_t optionCode) { return optionCode >= 5 && optionCode <= 8; }
308
310inline constexpr int kFirstManufacturerDriveModeBit = 16;
311
313constexpr std::optional<State> parseState(std::string_view token) {
317 if (token == toString(state)) {
318 return state;
319 }
320 }
321 return std::nullopt;
322}
323
329constexpr bool isCommandableState(State state) {
330 switch (state) {
336 return true;
339 case State::kFault:
340 return false;
341 }
342 return false;
343}
344
346enum class FsaAction : uint8_t {
347 kArrived,
348 kCommand,
349 kWait,
353};
354
360
390constexpr FsaTransition nextFsaTransition(State from, State target, bool allowQuickStopOverride) {
391 if (!isCommandableState(target)) {
392 return {FsaAction::kUnreachable, 0};
393 }
394 if (from == target) {
395 return {FsaAction::kArrived, 0};
396 }
397 switch (from) {
400 return {FsaAction::kWait, 0};
401
402 case State::kFault:
404
406 // The only way out is upward, whatever the target beyond it.
408
410 if (target == State::kSwitchOnDisabled) {
412 }
414
416 if (target == State::kSwitchOnDisabled) {
418 }
419 if (target == State::kReadyToSwitchOn) {
421 }
422 // Both kOperationEnabled and kQuickStopActive are reached through it.
424
426 if (target == State::kSwitchOnDisabled) {
428 }
429 if (target == State::kReadyToSwitchOn) {
431 }
432 if (target == State::kSwitchedOn) {
434 }
436
438 if (target == State::kOperationEnabled) {
439 return allowQuickStopOverride
442 }
443 // Everything else leaves through SwitchOnDisabled, which then continues the walk.
445 }
446 return {FsaAction::kUnreachable, 0};
447}
448
449} // namespace mm::node::cia402
Definition cia402.h:17
constexpr std::optional< OperationMode > toOperationMode(int value)
Maps a raw mode value (as written to 0x6060 / read from 0x6061) to a known operation mode....
Definition cia402.h:115
constexpr bool quickStopHolds(int16_t optionCode)
Whether a quick stop configured with optionCode leaves the drive in Quick Stop Active,...
Definition cia402.h:307
OperationMode
CiA402 operation modes (object 0x6060 / 0x6061 values).
Definition cia402.h:98
@ kNoMode
No mode assigned. Always legal; has no 0x6502 bit.
@ kInterpolatedPosition
IP — interpolated position.
@ kCyclicSyncVelocity
CSV — cyclic velocity.
@ kCyclicSyncTorque
CST — cyclic torque.
@ kCyclicSyncPosition
CSP — cyclic position (the common SOMANET mode).
@ kHoming
HM — reference/homing run.
@ kVelocity
VL — the frequency-converter velocity mode.
@ kCyclicSyncTorqueCommutationAngle
CSTCA — cyclic torque with commutation angle.
@ 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:158
@ kCmdShutdown
→ ReadyToSwitchOn (enable voltage + no quick stop).
Definition cia402.h:159
@ kCmdDisableVoltage
→ SwitchOnDisabled.
Definition cia402.h:162
@ kCmdFaultReset
Rising edge of bit 7 clears a fault.
Definition cia402.h:164
@ kCmdQuickStop
→ QuickStopActive.
Definition cia402.h:163
@ kCmdSwitchOn
→ SwitchedOn (also "disable operation" from OperationEnabled).
Definition cia402.h:160
@ kCmdEnableOperation
→ OperationEnabled.
Definition cia402.h:161
constexpr FsaTransition nextFsaTransition(State from, State target, bool allowQuickStopOverride)
One step of the walk from from toward target — the CiA402 state machine as a next-hop table.
Definition cia402.h:390
State
States of the CiA402 device control state machine (decoded from the statusword).
Definition cia402.h:139
@ 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 int kFirstManufacturerDriveModeBit
The first bit of 0x6502 that the profile leaves to the vendor (ETG.6010 Figure 15).
Definition cia402.h:310
constexpr std::string_view toString(State state)
Human-readable name of a state (for logging / JSON). Never returns nullptr.
Definition cia402.h:205
constexpr uint16_t kCommandMask
Controlword (0x6040) command-bit mask — the state-machine bits a transition touches.
Definition cia402.h:155
constexpr StandardOperationMode kStandardOperationModes[]
Every standard operation mode, with its 0x6502 bit — ETG.6010 §6.8.1, Figure 15.
Definition cia402.h:274
constexpr State decodeState(uint16_t statusword)
Decodes the CiA402 state machine state from a statusword (0x6041) value.
Definition cia402.h:171
constexpr std::optional< State > parseState(std::string_view token)
Parses a state name as toString spells it. std::nullopt for anything else.
Definition cia402.h:313
constexpr bool isFaulted(uint16_t statusword)
Whether the statusword's fault bit (bit 3) is set, gated to the faulted states.
Definition cia402.h:199
Object
Standard CiA402 object dictionary indices used by the drive profile, ordered by index.
Definition cia402.h:23
@ kFollowingErrorActualValue
INTEGER32, ro, TxPDO — live following error.
Definition cia402.h:81
@ kFollowingErrorTimeout
UNSIGNED16, rw, RxPDO — ms outside window before fault.
Definition cia402.h:33
@ kSupportedDriveModes
UNSIGNED32, ro — capability bit field of supported modes.
Definition cia402.h:88
@ kProfileDeceleration
UNSIGNED32, rw, RxPDO — profile deceleration.
Definition cia402.h:58
@ kPositionRangeLimit
2×INTEGER32, rw — position wrap range (min/max).
Definition cia402.h:51
@ kTouchProbe1PositiveEdge
INTEGER32, ro, TxPDO — position at probe 1 rising edge.
Definition cia402.h:73
@ kDigitalOutputs
2×UNSIGNED32, rw — physical outputs + enable mask.
Definition cia402.h:86
@ kQuickStopOptionCode
INTEGER16, rw — reaction to a quick stop.
Definition cia402.h:27
@ kPositionActualValue
INTEGER32, ro, TxPDO — actual position.
Definition cia402.h:31
@ kPositionDemandValue
INTEGER32, ro, TxPDO — trajectory generator demand.
Definition cia402.h:30
@ kHomingSpeeds
2×UNSIGNED32, rw — switch/zero search speeds.
Definition cia402.h:66
@ kStatusword
UNSIGNED16, ro, TxPDO — reports the state machine.
Definition cia402.h:26
@ kFeedConstant
2×UNSIGNED32, rw — feed per shaft revolutions.
Definition cia402.h:64
@ kTargetVelocity
INTEGER32, rw, RxPDO — CSV/PV setpoint.
Definition cia402.h:87
@ kVelocityThreshold
UNSIGNED16, rw, RxPDO — standstill velocity threshold.
Definition cia402.h:40
@ kGearRatio
2×UNSIGNED32, rw — motor/shaft revolutions.
Definition cia402.h:63
@ kMaxCurrent
UNSIGNED16, rw, RxPDO — current limit (per-mille).
Definition cia402.h:44
@ kHomeOffset
INTEGER32, rw, RxPDO — home offset from machine zero.
Definition cia402.h:52
@ kSiUnitVelocity
UNSIGNED32, rw — SI unit code of velocity objects.
Definition cia402.h:68
@ kFollowingErrorWindow
UNSIGNED32, rw, RxPDO — max tolerated following error.
Definition cia402.h:32
@ kHomingMethod
INTEGER8, rw, RxPDO — homing method number.
Definition cia402.h:65
@ kErrorCode
UNSIGNED16, ro, TxPDO — code of the last drive fault.
Definition cia402.h:24
@ kTouchProbeFunction
UNSIGNED16, rw, RxPDO — touch probe arm/config bits.
Definition cia402.h:71
@ kTorqueActualValue
INTEGER16, ro, TxPDO — actual torque.
Definition cia402.h:48
@ kTorqueProfileType
INTEGER16, rw, RxPDO — torque trajectory shape.
Definition cia402.h:62
@ kVelocityWindowTime
UNSIGNED16, rw, RxPDO — ms in window for target reached.
Definition cia402.h:39
@ kControlword
UNSIGNED16, rw, RxPDO — commands the state machine.
Definition cia402.h:25
@ kMotorRatedTorque
UNSIGNED32, rw — motor rated torque (mNm).
Definition cia402.h:47
@ kProfileAcceleration
UNSIGNED32, rw, RxPDO — profile acceleration.
Definition cia402.h:57
@ kVelocityActualValue
INTEGER32, ro, TxPDO — actual velocity.
Definition cia402.h:37
@ kTorqueOffset
INTEGER16, rw, RxPDO — torque feed-forward.
Definition cia402.h:70
@ kPositionDemandInternalValue
Definition cia402.h:83
@ kTargetTorque
INTEGER16, rw, RxPDO — CST/PT setpoint (per-mille).
Definition cia402.h:42
@ kPositionWindow
UNSIGNED32, rw, RxPDO — target-reached position window.
Definition cia402.h:34
@ kDigitalInputs
UNSIGNED32, ro, TxPDO — digital input bit field.
Definition cia402.h:85
@ kDcLinkCircuitVoltage
UNSIGNED32, ro, TxPDO — DC bus voltage (mV).
Definition cia402.h:49
@ kControlEffort
INTEGER32, ro, TxPDO — position loop output.
Definition cia402.h:82
@ kMotorRatedCurrent
UNSIGNED32, rw — motor rated current (mA).
Definition cia402.h:46
@ kQuickStopDeceleration
UNSIGNED32, rw, RxPDO — deceleration on quick stop.
Definition cia402.h:59
@ kPolarity
UNSIGNED8, rw, RxPDO — position/velocity polarity bits.
Definition cia402.h:54
@ kTouchProbeTimeStamp1NegativeValue
Definition cia402.h:78
@ kHomingAcceleration
UNSIGNED32, rw, RxPDO — homing acceleration.
Definition cia402.h:67
@ kTorqueDemand
INTEGER16, ro, TxPDO — control loop torque demand.
Definition cia402.h:45
@ kMaxMotorSpeed
UNSIGNED32, rw, RxPDO — motor speed limit.
Definition cia402.h:55
@ kMotionProfileType
INTEGER16, rw, RxPDO — trajectory shape.
Definition cia402.h:60
@ kTorqueSlope
UNSIGNED32, rw, RxPDO — PT torque ramp rate.
Definition cia402.h:61
@ kModeOfOperationDisplay
INTEGER8, ro, TxPDO — active operation mode.
Definition cia402.h:29
@ kVelocityOffset
INTEGER32, rw, RxPDO — CSP/CSV velocity feed-forward.
Definition cia402.h:69
@ kTouchProbe1NegativeEdge
Definition cia402.h:74
@ kTargetPosition
INTEGER32, rw, RxPDO — CSP/PP setpoint.
Definition cia402.h:50
@ kTouchProbeStatus
UNSIGNED16, ro, TxPDO — touch probe latch status.
Definition cia402.h:72
@ kVelocityWindow
UNSIGNED16, rw, RxPDO — target-reached velocity window.
Definition cia402.h:38
@ kMaxTorque
UNSIGNED16, rw, RxPDO — torque limit (per-mille).
Definition cia402.h:43
@ kProfileVelocity
UNSIGNED32, rw, RxPDO — PP cruise velocity.
Definition cia402.h:56
@ kVelocityThresholdTime
UNSIGNED16, rw, RxPDO — ms below threshold = standstill.
Definition cia402.h:41
@ kModeOfOperation
INTEGER8, rw, RxPDO — requested operation mode.
Definition cia402.h:28
@ kPositioningOptionCode
UNSIGNED16, rw, PDO — PP positioning options.
Definition cia402.h:80
@ kTouchProbeTimeStamp1PositiveValue
Definition cia402.h:76
@ kPositionWindowTime
UNSIGNED16, rw, RxPDO — ms in window for target reached.
Definition cia402.h:35
@ kVelocityDemandValue
INTEGER32, ro, TxPDO — ramp generator demand.
Definition cia402.h:36
@ kSoftwarePositionLimit
2×INTEGER32, rw — software end stops (min/max).
Definition cia402.h:53
constexpr bool isCommandableState(State state)
Whether a master can ask a drive to reach state.
Definition cia402.h:329
FsaAction
What a master should do next, having observed one state and wanting another.
Definition cia402.h:346
@ kCommand
Issue FsaTransition::command and look again.
@ kArrived
Already there; nothing to issue.
The next step of a walk toward a target state.
Definition cia402.h:356
FsaAction action
Definition cia402.h:357
uint16_t command
Meaningful only for FsaAction::kCommand.
Definition cia402.h:358
One row of the standard operation-mode table — a mode, the 0x6502 bit that advertises it,...
Definition cia402.h:258
std::string_view label
The profile's own wording, for a user-facing list.
Definition cia402.h:264
OperationMode mode
Definition cia402.h:259
std::string_view abbreviation
The profile's short form: "csp", "hm", …. Empty for kNoMode.
Definition cia402.h:263
int bit
Definition cia402.h:262