Modeling the elevator as a finite state machine

Thread Starter

rfdecker

Joined Nov 14, 2015
5
Hi, This is my first post here. Nice to meet you all!

The task:

There is a building consisting of 7 storeys (indexed 0-6). Design a system that controls the elevator in this building.

Design details:

1. There are navigation buttons in each floor (up / down).

2. Inside the elevator there are buttons to select the destination. (For simplicity, can I assume that only one destination can be selected)

3. Seven segment displays indicate the position of the lift. These are present in each floor and inside the elevator.

4. There are LEDs to indicate the direction of movement of the elevator in each floor. (arrows, I presume?)

5. There are buttons inside the elevator to control the fan and lights. (Fans and lights are OFF by default . They turn on automatically if the lift is in motion).

What I've done so far :

System #1: Controlling the seven segment display

Let the elevator be in floor 'x'.
For the destination selection (say y) from inside the elevator, we use an encoder to obtain the destination floor in binary. We then pass it on to the controller which compares x and y and decides the direction of movement. As it moves, keep updating x and send it to the seven segment displays in each floor and inside the elevator.

System #2: The main control unit (This is where I'm having issues):

Since we are modelling the elevator as a finite state machine, I have the following states.

1. Rest: (RST)

2. Moving up (UP)

3. Moving down (DOWN)

The following changes cause state transitions:

1.The elevator is called from one of the floors.

2.The destination has been reached.

3.The destination has been selected.

Case #1: The destination has been selected (y). If y > x (current floor) then UP. else DOWN. No disturbances here.

Case #2: The elevator is moving from say, the 3rd floor to the 6th floor. Someone at the 4th floor wants to go down. At the 5th floor, someone wants to go up. The obvious solution, halt at floor 5. go to floor 6 and then go to the 4th floor.

Issue #1: How do I handle the priorities ?

Issue #2: How do I store the information ? (I'm aware of flip-flops and related memory elements. Not sure about the finer implementation details)

Issue #3: How do I encode the states and create the state transition table ? (I'm not able to visualize it.)

PS: Since the question was worded ambiguously, I think it is safe to make some assumptions to simplify the problem.

Help would be greatly appreciated. Thanks in advance.
 

GopherT

Joined Nov 23, 2012
8,009
Hi, This is my first post here. Nice to meet you all!

The task:

There is a building consisting of 7 storeys (indexed 0-6). Design a system that controls the elevator in this building.

Design details:

1. There are navigation buttons in each floor (up / down).

2. Inside the elevator there are buttons to select the destination. (For simplicity, can I assume that only one destination can be selected)

3. Seven segment displays indicate the position of the lift. These are present in each floor and inside the elevator.

4. There are LEDs to indicate the direction of movement of the elevator in each floor. (arrows, I presume?)

5. There are buttons inside the elevator to control the fan and lights. (Fans and lights are OFF by default . They turn on automatically if the lift is in motion).

What I've done so far :

System #1: Controlling the seven segment display

Let the elevator be in floor 'x'.
For the destination selection (say y) from inside the elevator, we use an encoder to obtain the destination floor in binary. We then pass it on to the controller which compares x and y and decides the direction of movement. As it moves, keep updating x and send it to the seven segment displays in each floor and inside the elevator.

System #2: The main control unit (This is where I'm having issues):

Since we are modelling the elevator as a finite state machine, I have the following states.

1. Rest: (RST)

2. Moving up (UP)

3. Moving down (DOWN)

The following changes cause state transitions:

1.The elevator is called from one of the floors.

2.The destination has been reached.

3.The destination has been selected.

Case #1: The destination has been selected (y). If y > x (current floor) then UP. else DOWN. No disturbances here.

Case #2: The elevator is moving from say, the 3rd floor to the 6th floor. Someone at the 4th floor wants to go down. At the 5th floor, someone wants to go up. The obvious solution, halt at floor 5. go to floor 6 and then go to the 4th floor.

Issue #1: How do I handle the priorities ?

Issue #2: How do I store the information ? (I'm aware of flip-flops and related memory elements. Not sure about the finer implementation details)

Issue #3: How do I encode the states and create the state transition table ? (I'm not able to visualize it.)

PS: Since the question was worded ambiguously, I think it is safe to make some assumptions to simplify the problem.

Help would be greatly appreciated. Thanks in advance.

I think the direction of the elevator (up/down) should be initiated on a first come, first served basis but, as the car goes up, it should check the call button state on each floor as it approaches and stops as needed (easiest approach without requiring memory). As the car approaches, it has no way of knowing what floor the caller will actually request (up or down). The car needs to keep going in the initial direction until there are no more call buttons to address by people on those floors and no more floor buttons pressed on the lift for additional floors in the current direction.

Any more advanced priority system will require a Microcontroller. As I said, simply check if a stop is needed in the current direction as the lift approaches each floor.
 

Thread Starter

rfdecker

Joined Nov 14, 2015
5
I think the direction of the elevator (up/down) should be initiated on a first come, first served basis but, as the car goes up, it should check the call button state on each floor as it approaches and stops as needed (easiest approach without requiring memory). As the car approaches, it has no way of knowing what floor the caller will actually request (up or down). The car needs to keep going in the initial direction until there are no more call buttons to address by people on those floors and no more floor buttons pressed on the lift for additional floors in the current direction.

Any more advanced priority system will require a Microcontroller. As I said, simply check if a stop is needed in the current direction as the lift approaches each floor.
Thanks for your reply!. I understand this approach intuitively but I'm not sure how I implement this,
 

MikeML

Joined Oct 2, 2009
5,444
This project is frequently assigned as a learning exercise, and should have been posted in the homework forum. There have been thousands of posts about it just on these forums in the past few years; thousands more at other sites...

A bit of time spent searching previous posts might go a long way....
 

GopherT

Joined Nov 23, 2012
8,009
Thanks for your reply!. I understand this approach intuitively but I'm not sure how I implement this,

You need to define
- the available inputs at each call button on the floors (up and down)
- the available buttons on the lift (0-6)
- the communication from call buttons to lift
- a method for the car to determine which floor it is at (approaching)
- the reset mechanism to turn off 0-6 as the lift drops people off at each stop.
- the reset mechanism to turn off the call on each floor as the lift picks people up.

I see something like...


1. Start (no up/down call buttons pushed at a floor, no floor numbers pushed in the lift- doors open
A) someone enters and pushes a floor button
a) floor button on lower floor? Move elevator down (go to (2))
b) floor button on higher floor? Move elevator up (go to (2))

B) a call button is pressed on a floor
a) call button on lower floor? Move elevator down (go to (2))
b) call button on higher floor? Move elevator up (go to (2))

2) as car moves in a direction, it keeps moving in a direction until
A) it stops if a call button of the desired direction is pressed OR if floor is requested in lift
. a) stop, open doors, Check if any need to continue in current direction
. - if yes, close doors, continue in current direction (go to (2))
. - - if no, check if calls in reverse direction, close doors and travel (go to (2))
. - - - if no calls / floor requests active (go to (1))
 

Thread Starter

rfdecker

Joined Nov 14, 2015
5
You need to define
- the available inputs at each call button on the floors (up and down)
- the available buttons on the lift (0-6)
- the communication from call buttons to lift
- a method for the car to determine which floor it is at (approaching)
- the reset mechanism to turn off 0-6 as the lift drops people off at each stop.
- the reset mechanism to turn off the call on each floor as the lift picks people up.

I see something like...


1. Start (no up/down call buttons pushed at a floor, no floor numbers pushed in the lift- doors open
A) someone enters and pushes a floor button
a) floor button on lower floor? Move elevator down (go to (2))
b) floor button on higher floor? Move elevator up (go to (2))

B) a call button is pressed on a floor
a) call button on lower floor? Move elevator down (go to (2))
b) call button on higher floor? Move elevator up (go to (2))

2) as car moves in a direction, it keeps moving in a direction until
A) it stops if a call button of the desired direction is pressed OR if floor is requested in lift
. a) stop, open doors, Check if any need to continue in current direction
. - if yes, close doors, continue in current direction (go to (2))
. - - if no, check if calls in reverse direction, close doors and travel (go to (2))
. - - - if no calls / floor requests active (go to (1))
Thank you for the concise algorithm. Albeit, I have some doubts:

1. What if there are multiple requests ? My original idea was to use a 2-bit register to store the request. We need some kind of queuing mechanism to store the requests right?

2. Currently, I'm denoting the states by the direction of movement. How do I convert them/ draw the state diagram? I'm not sure how to handle interrupts (halts in intermediate floors)
 

Thread Starter

rfdecker

Joined Nov 14, 2015
5
This project is frequently assigned as a learning exercise, and should have been posted in the homework forum. There have been thousands of posts about it just on these forums in the past few years; thousands more at other sites...

A bit of time spent searching previous posts might go a long way....
Thanks for your reply. I did search the forums. None of the posts have the FSM approach.
 

GopherT

Joined Nov 23, 2012
8,009
Thank you for the concise algorithm. Albeit, I have some doubts:

1. What if there are multiple requests ? My original idea was to use a 2-bit register to store the request. We need some kind of queuing mechanism to store the requests right?
if there are multiple requests! just follow the logic on my algorithm. Keep going in the same direction, stop if a floor is called (if the car is going up, stop if the up button on the approaching floor is pressed) or stop if the current floor matches a requested floor in the car's panel (0-6). Once the elevator has no more call buttons above, and no floor requests at higher floors made, then the car can reverse directions (if any, or sit idle with doors open if no call buttons are pressed and no floor buttons are pressed.


There is no need for a priority system or optimized algorithm. Few elevators have this.



2. Currently, I'm denoting the states by the direction of movement. How do I convert them/ draw the state diagram? I'm not sure how to handle interrupts (halts in intermediate floors)
Make it simple (mindless). The only thing you have to 'remember' is the direction of the elevator, don't head for a particular floor, head a direction.

As you are at a floor, stop if a call button matches a direction OR stop if a floor matches a level selected by a user.

Ultimately, you have three major states (up, down, idle).
 

GopherT

Joined Nov 23, 2012
8,009
I imagine that the elevator shaft has some protrusions (rails) at each floor. Three rails would allow 8 unique binary) combinations that depress zero to three buttons (normally open) on the car as it passes.

Then some sort of system to indicate whether there is a call (up or down) from the floor to the car. I assume that the control panel (brain) is in the moving car.
 

Thread Starter

rfdecker

Joined Nov 14, 2015
5
if there are multiple requests! just follow the logic on my algorithm. Keep going in the same direction, stop if a floor is called (if the car is going up, stop if the up button on the approaching floor is pressed) or stop if the current floor matches a requested floor in the car's panel (0-6). Once the elevator has no more call buttons above, and no floor requests at higher floors made, then the car can reverse directions (if any, or sit idle with doors open if no call buttons are pressed and no floor buttons are pressed.


There is no need for a priority system or optimized algorithm. Few elevators have this.





Make it simple (mindless). The only thing you have to 'remember' is the direction of the elevator, don't head for a particular floor, head a direction.

As you are at a floor, stop if a call button matches a direction OR stop if a floor matches a level selected by a user.

Ultimately, you have three major states (up, down, idle).
Let's say the lift is moving from floor 1 to floor 5. If there's a UP request at floor 3, the lift will halt. The value of REQUEST in the register is overwritten. How does the lift then remember to go to floor 5?

Anyways. Here's my attempt at the state diagram: http://imgur.com/G4mRyce
 

GopherT

Joined Nov 23, 2012
8,009
Let's say the lift is moving from floor 1 to floor 5. If there's a UP request at floor 3, the lift will halt. The value of REQUEST in the register is overwritten. How does the lift then remember to go to floor 5?

Anyways. Here's my attempt at the state diagram: http://imgur.com/G4mRyce
Ok, if you want to do it with registers,

Option 1
why not make the elevator floor number the address of one of 7 registers and an up call can be bit 0 a down call bit 2, and bit 3 can indicate whether or not a button for that floor was pressed when can be t, down call. This situation can be used with more than one car in a bank of elevators when you don't want an ascending elevator to pick up someone who wants to go down.

Option 2 (easiest logic)
Use this if there is only one elevator and you pick people up as soon as the elevator passes their floor (regardless of direction - and there is no risk of elevator overcrowding.
Each but in a single 8-bit register represents a one of seven floors (bits 0-6) and the last bit represents the direction (up or down). Now, how would you solve this?
 

GopherT

Joined Nov 23, 2012
8,009
And a Option3

Like option 2 but there are two 8-bit registers.
A bit is placed in the appropriate down register if a down call is made or if a button is pressed that is below the elevator's current position.

A bit is placed in the right place of a the up register if an up call is made.

Use OR gates and shift registers at each floor to determine if additional need exists in the current direction. If so, keep going. If not, check other direction.
 
Top