Elevator Simulation - Matlab
I am doing a project about the simulation of an elevator and ran into this problem. I have a listbox for users to choose the floor that they want to go to but I don't know how to make the door of the elevator opens in the proper order.
For example, the first person want to go to the 1st floor and the second person wants to go to the 3rd floor. They would select 1 first and then 3, but when I do this Matlab always opens the 3rd floor first and then the 1st floor.
I am thinking about storing the value of the listbox in a matrix and then use for loop to open the elevator's door according to its floor in a correct order.
This is the GUI of my project. GUI
Under the listbox1_Callback . I tried to do this but my array only has one element.
A = ; listValue = get(handles.listbox1,'Value'); A = [A,listValue];
I want A to holds a sequence of values so that I could apply foor loop to A and execute element by element.
Thanks for your help.
Say, for example, that you have a function called open that takes one argument, the floor number, and opens that floor's elevator door. To loop over each selected floor, do:
handles.listbox1 = uicontrol('Style', 'listbox', ... 'String', [1 2 3 4], ... 'Position', [10 10 40 100], ... 'Max', 2); selectedFloor = get(handles.listbox1, 'Value'); for ii = 1:length(selectedFloor) open(selectedFloor(ii)); end
Your project is probably over, but I will nevertheless contribute something. Not about programming code per se, but about elevator principles, which may help you and others conceive the system correctly the next time.
Elevator doors only open at a specific floor when the cab is at or very near (< 8 cm typically) that floor. The reason is simple: the motor and mechanism to open the doors is on the cab. The landing door is actually moved by the cab door, using a clutch with skates and pick-up rollers. Therefore, what you have to be concerned about in you program is the position of the cab, which is a simple object that moves sequentially from floor to floor.
So, when calls are registered, you have to compare them to the position of the cab. Then you decide which way to go, up or down (or just open the door if the position is already right). You keep a preferred direction until you've reached the farthest call, then you change direction or wait for new calls. Simply add or subtract 1 from the actual position (let a few seconds elapse between each operation, to make look real), compare the position with the corresponding index of the call array, and then decide to stop and open the door (if a call exists) or continue (if none exists). Don't forget to stop at the extremities, even if for some reason no call exists.
If you want to introduce landing calls in the mix, you have to take into account if they are up or down calls. You stop only for up calls while going up, and only for down calls while going down.