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
14
namespace
plcopen::core::adapters
15
{
16
17
enum class
Cia402State
: std::uint8_t
18
{
19
not_ready_to_switch_on
,
20
switch_on_disabled
,
21
ready_to_switch_on
,
22
switched_on
,
23
operation_enabled
,
24
quick_stop_active
,
25
fault_reaction_active
,
26
fault
,
27
};
28
29
// Controlword commands (bit patterns abstracted to their standard names).
30
enum 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
41
class
Cia402Machine
42
{
43
public
:
44
Cia402State
state
()
const
45
{
46
return
state_;
47
}
48
49
// Boot-up: the drive reports readiness after initialization.
50
void
initialize
()
51
{
52
if
(state_ ==
Cia402State::not_ready_to_switch_on
) {
53
state_ =
Cia402State::switch_on_disabled
;
54
}
55
}
56
57
// Drive-side fault event (any state except the fault ladder itself).
58
void
fault_event
()
59
{
60
if
(state_ !=
Cia402State::fault
&& state_ !=
Cia402State::fault_reaction_active
) {
61
state_ =
Cia402State::fault_reaction_active
;
62
}
63
}
64
65
// Fault reaction completed (controlled stop done inside the drive).
66
void
fault_reaction_complete
()
67
{
68
if
(state_ ==
Cia402State::fault_reaction_active
) {
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).
75
void
quick_stop_complete
()
76
{
77
if
(state_ ==
Cia402State::quick_stop_active
) {
78
state_ =
Cia402State::switch_on_disabled
;
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).
84
bool
command
(
Cia402Command
command
)
85
{
86
switch
(
command
) {
87
case
Cia402Command::shutdown
:
88
if
(state_ ==
Cia402State::switch_on_disabled
||
89
state_ ==
Cia402State::switched_on
||
90
state_ ==
Cia402State::operation_enabled
) {
91
state_ =
Cia402State::ready_to_switch_on
;
92
return
true
;
93
}
94
return
false
;
95
case
Cia402Command::switch_on
:
96
if
(state_ ==
Cia402State::ready_to_switch_on
) {
97
state_ =
Cia402State::switched_on
;
98
return
true
;
99
}
100
return
false
;
101
case
Cia402Command::enable_operation
:
102
if
(state_ ==
Cia402State::switched_on
||
103
state_ ==
Cia402State::quick_stop_active
) {
104
state_ =
Cia402State::operation_enabled
;
105
return
true
;
106
}
107
return
false
;
108
case
Cia402Command::disable_voltage
:
109
if
(state_ ==
Cia402State::ready_to_switch_on
||
110
state_ ==
Cia402State::switched_on
||
111
state_ ==
Cia402State::operation_enabled
||
112
state_ ==
Cia402State::quick_stop_active
) {
113
state_ =
Cia402State::switch_on_disabled
;
114
return
true
;
115
}
116
return
false
;
117
case
Cia402Command::quick_stop
:
118
if
(state_ ==
Cia402State::operation_enabled
) {
119
state_ =
Cia402State::quick_stop_active
;
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.
125
state_ =
Cia402State::switch_on_disabled
;
126
return
true
;
127
}
128
return
false
;
129
case
Cia402Command::disable_operation
:
130
if
(state_ ==
Cia402State::operation_enabled
) {
131
state_ =
Cia402State::switched_on
;
132
return
true
;
133
}
134
return
false
;
135
case
Cia402Command::fault_reset
:
136
if
(state_ ==
Cia402State::fault
) {
137
state_ =
Cia402State::switch_on_disabled
;
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
150
private
:
151
Cia402State
state_ =
Cia402State::not_ready_to_switch_on
;
152
};
153
154
}
// namespace plcopen::core::adapters
plcopen::core::adapters::Cia402Machine
定义
cia402.h:42
plcopen::core::adapters::Cia402Machine::initialize
void initialize()
定义
cia402.h:50
plcopen::core::adapters::Cia402Machine::fault_event
void fault_event()
定义
cia402.h:58
plcopen::core::adapters::Cia402Machine::command
bool command(Cia402Command command)
定义
cia402.h:84
plcopen::core::adapters::Cia402Machine::quick_stop_complete
void quick_stop_complete()
定义
cia402.h:75
plcopen::core::adapters::Cia402Machine::state
Cia402State state() const
定义
cia402.h:44
plcopen::core::adapters::Cia402Machine::fault_reaction_complete
void fault_reaction_complete()
定义
cia402.h:66
plcopen::core::adapters::Cia402Machine::operational
bool operational() const
定义
cia402.h:145
plcopen::core::adapters
定义
cia402.h:15
plcopen::core::adapters::Cia402State
Cia402State
定义
cia402.h:18
plcopen::core::adapters::Cia402State::fault_reaction_active
@ fault_reaction_active
定义
cia402.h:25
plcopen::core::adapters::Cia402State::switch_on_disabled
@ switch_on_disabled
定义
cia402.h:20
plcopen::core::adapters::Cia402State::fault
@ fault
定义
cia402.h:26
plcopen::core::adapters::Cia402State::not_ready_to_switch_on
@ not_ready_to_switch_on
定义
cia402.h:19
plcopen::core::adapters::Cia402State::ready_to_switch_on
@ ready_to_switch_on
定义
cia402.h:21
plcopen::core::adapters::Cia402State::switched_on
@ switched_on
定义
cia402.h:22
plcopen::core::adapters::Cia402State::quick_stop_active
@ quick_stop_active
定义
cia402.h:24
plcopen::core::adapters::Cia402State::operation_enabled
@ operation_enabled
定义
cia402.h:23
plcopen::core::adapters::Cia402Command
Cia402Command
定义
cia402.h:31
plcopen::core::adapters::Cia402Command::quick_stop
@ quick_stop
定义
cia402.h:36
plcopen::core::adapters::Cia402Command::shutdown
@ shutdown
定义
cia402.h:32
plcopen::core::adapters::Cia402Command::disable_operation
@ disable_operation
定义
cia402.h:37
plcopen::core::adapters::Cia402Command::disable_voltage
@ disable_voltage
定义
cia402.h:35
plcopen::core::adapters::Cia402Command::switch_on
@ switch_on
定义
cia402.h:33
plcopen::core::adapters::Cia402Command::enable_operation
@ enable_operation
定义
cia402.h:34
plcopen::core::adapters::Cia402Command::fault_reset
@ fault_reset
定义
cia402.h:38
core
adapters
cia402.h
制作者
1.15.0