plcopen 0.22.0
载入中...
搜索中...
未找到
cia402.h
浏览该文件的文档.
1#pragma once
2
3// BS6.2: CiA 402 (IEC 61800-7-201) drive state machine — pure software, no
4// bus I/O. plcopen-fieldbus (B5) reuses this against real slaves; here a
5// mock slave exercises every transition. Command and state names follow the
6// standard's power state machine; the fault reaction path is modeled as an
7// explicit state so the full ladder is test-coverable.
8//
9// Contract: no allocation, no exceptions; transition() is a pure function of
10// (state, command/event).
11
12#include <cstdint>
13
15{
16
28
29// Controlword commands (bit patterns abstracted to their standard names).
30enum class Cia402Command : std::uint8_t
31{
32 shutdown, // -> ready to switch on
33 switch_on, // -> switched on
34 enable_operation, // -> operation enabled
35 disable_voltage, // -> switch on disabled
36 quick_stop, // -> quick stop active
37 disable_operation, // -> switched on
38 fault_reset, // fault -> switch on disabled
39};
40
42{
43public:
45 {
46 return state_;
47 }
48
49 // Boot-up: the drive reports readiness after initialization.
51 {
54 }
55 }
56
57 // Drive-side fault event (any state except the fault ladder itself).
59 {
62 }
63 }
64
65 // Fault reaction completed (controlled stop done inside the drive).
67 {
69 state_ = Cia402State::fault;
70 }
71 }
72
73 // Quick stop ramp completed: per 605Ah option code 1-4 the drive lands
74 // in switch on disabled (the modeled default).
76 {
77 if(state_ == Cia402State::quick_stop_active) {
79 }
80 }
81
82 // Host command; returns false when the transition is not defined by the
83 // standard's table (the state does not change).
85 {
86 switch(command) {
89 state_ == Cia402State::switched_on ||
92 return true;
93 }
94 return false;
98 return true;
99 }
100 return false;
102 if(state_ == Cia402State::switched_on ||
105 return true;
106 }
107 return false;
109 if(state_ == Cia402State::ready_to_switch_on ||
110 state_ == Cia402State::switched_on ||
114 return true;
115 }
116 return false;
118 if(state_ == Cia402State::operation_enabled) {
120 return true;
121 }
122 if(state_ == Cia402State::ready_to_switch_on ||
123 state_ == Cia402State::switched_on) {
124 // Below operation enabled, quick stop acts as disable voltage.
126 return true;
127 }
128 return false;
130 if(state_ == Cia402State::operation_enabled) {
132 return true;
133 }
134 return false;
136 if(state_ == Cia402State::fault) {
138 return true;
139 }
140 return false;
141 }
142 return false;
143 }
144
145 bool operational() const
146 {
147 return state_ == Cia402State::operation_enabled;
148 }
149
150private:
152};
153
154} // namespace plcopen::core::adapters
bool command(Cia402Command command)