Program In Words
If there has been no summons or floor requests for the last 7.5 seconds, travel to the ground floor as your home base.
When there’s a window of inactivity on a floor (<7.5seconds) or when at home base, detect if a Up or Down summons button is used, go to the floor correspondent to that button.
Upon arrival to any floor, apply this rule: The doors will be always be automatically opened for 5 seconds. After that time has passed, use the motion sensors between the doors to detect movement. Only close the doors if there has been no movement between the motion sensors for 3 seconds.
If a floor request button inside the elevator is pressed, travel to correspondent floor number. Prioritize this over summon requests. However if a summon request is detected mid-travel, apply the two rules below.
When traveling Up due to a summon/floor request, detect if a floor on the way has used a Up summon request, if it is detected then stop on that floor first. Otherwise, travel to the original summon/request.
When traveling DOWN due to a summons/floor request, detect if a floor on the way has used a down summon request, if it is detected then stop on that floor first. Otherwise, travel to the original summon/request.
When all previous steps are complete and no activity has occurred for 7.5 seconds, travel to the ground floor to idle. If there is a floor request from inside the elevator, proceed to that floor.
There’s lots of beautiful work here, ChefRat, and some that could use re-thinking.
My first reaction to your early instructions:
“remain idle” assumes that instructions begin with an elevator on the ground floor. Maybe that could be handled by instruction that tells the elevator to proceed to the ground floor after 7.5 seconds of inactivity. As long as that’s not contradicted by any other instruction, the elevator would always end up at the ground floor without knowing it’s “home base.”
Unless the building has floors below the ground floor, this instruction about ground floor idling is again a little imprecise. Does the elevator respond to Up or Down summons buttons ONLY WHEN idling at the ground floor?
This is really tricky, but a downbound elevator should ignore an UP summons request but stop for a DOWN summons request, right?
I will delay grading these assignments for awhile to give everyone a chance to revise their first drafts. DON’T POST A NEW VERSION. Just open this post in Edit and make improvements.
Optional, of course.
Most of this is fabulous, ChefRat.
I have a quibble with this:
Maybe coders use the ONLY IF command as a default, in which case I need to be educated. My impulse would be to default to DO THIS UNLESS.
My version would read:
I don’t think you need the last sentence at all if my version makes sense.
Graded.
Regrade is always available following significant improvements.