I am currently creating a software model for controlling a simple (two-way) pneumatic cylinder. In essence, this controls just a movement from point A to point B. The controller has two outputs (OnMovingToA, OnMovingToB), which can be linked to a relay, valve, etc... to move the actuator to resp. A or B. The controller has two inputs (AtPositionA, AtPositionB) representing end-stops: a feedback mechanism that the position has been reached.
A user can interact with the controller/cylinder using commands/functions: MoveToA
and MoveToB
.
- Upon calling
MoveToA
, the cylinder should move toA
and stop whenA
has been reached (AtPositionA
is true). - Upon calling
MoveToB
, the cylinder should move toB
and stop whenB
has been reached (AtPositionB
is true).
Sometimes we also use 3-state valves to control the cylinder, where the cylinder can also be stopped halfway. Therefore the command Stop
is added as well.
- When
Stop
is called during a movement, the cylinder most likely will stop in an undeterminedintermediate position
. The system then waits for the nextMoveToA
orMoveToB
Inside the controller, I use a state machine. Initially, I had the state machine of the controller modeled like this:
some remarks:
- The rising edge of
AtPositionA
isA reached
- The falling edge of
AtPositionA
isA left
- The rising edge of
AtPositionB
isB reached
- The falling edge of
AtPositionB
isB left
- With A left, I mean: exit the A position.
- With B left, I mean: exit the B position.
- Output
OnMovingToA
is set to true whenMoving to A
is active. - Output
OnMovingToB
is set to true whenMoving to B
is active.
At least one issue I have with the above is that, since we are dealing with real-world applications, it is possible to be at position A and to move to B simultaneously. (the cylinder can be blocked, or the end-stop can have some off-delay. Naturally, this is not allowed within state machines, so we have to work around this.
After giving it some thought, I figured that position and movement are in fact 2 different - although connected - properties of a system. Hence, I split the state machine into movement and position states:
I feel that the second one is the way to go, but I fear that this is a bit unconventional.
What state machine would be preferred in this scenario? Is this a matter of taste, or is there a clear guideline that puts one above the other?