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 toAand stop whenAhas been reached (AtPositionAis true). - Upon calling
MoveToB, the cylinder should move toBand stop whenBhas been reached (AtPositionBis 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
Stopis called during a movement, the cylinder most likely will stop in an undeterminedintermediate position. The system then waits for the nextMoveToAorMoveToB
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
AtPositionAisA reached - The falling edge of
AtPositionAisA left - The rising edge of
AtPositionBisB reached - The falling edge of
AtPositionBisB left - With A left, I mean: exit the A position.
- With B left, I mean: exit the B position.
- Output
OnMovingToAis set to true whenMoving to Ais active. - Output
OnMovingToBis set to true whenMoving to Bis 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?




