-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cpp
More file actions
32 lines (29 loc) · 991 Bytes
/
Copy pathController.cpp
File metadata and controls
32 lines (29 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "Controller.hpp"
namespace factoryflow {
Outputs Controller::scan(const Inputs& inputs) {
// Safety has priority over every sequence state, including COMPLETE.
// FAULT is latched: clearing an input must not restart machinery.
if (inputs.emergencyStop || inputs.motorFault) {
state_ = State::FAULT;
}
switch (state_) {
case State::IDLE:
if (inputs.entrySensor) state_ = State::TRANSPORTING;
break;
case State::TRANSPORTING:
if (inputs.sortingSensor) state_ = State::SORTING;
break;
case State::SORTING:
if (inputs.laneBSensor) state_ = State::COMPLETE;
break;
case State::COMPLETE:
case State::FAULT:
break;
}
// Rebuild the output process image each scan; inactive outputs stay safe.
Outputs outputs;
outputs.conveyorMotor = state_ == State::TRANSPORTING || state_ == State::SORTING;
outputs.diverterB = state_ == State::SORTING;
return outputs;
}
}