X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=elevator.hpp;h=a5b550060d9c193e7bd9270674e899292cfc7006;hb=2172ce055533d5865d58538ee00bf609e59b0f99;hp=cff643243535c2d759e146679518ab7c5d4e06a5;hpb=dd9988b5db6dc820c5fcd07f88513d126e926d22;p=cs356-p1-elevator.git diff --git a/elevator.hpp b/elevator.hpp index cff6432..a5b5500 100644 --- a/elevator.hpp +++ b/elevator.hpp @@ -8,85 +8,61 @@ #define ELEVATOR_HPP #include -#include -#include "position.hpp" +#include #include "direction.hpp" +#include "position.hpp" #include "stop.hpp" +typedef std::list StopList; -enum door_status { CLOSED, OPEN }; -const float elevator_step = 0.1; - -class bad_direction { }; +enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR }; +enum Event { EVT_IDLE, EVT_UP, EVT_DOWN, EVT_WAIT, EVT_OPEN_DOOR, EVT_CLOSE_DOOR }; class Elevator { public: - /* - * PURPOSE: Construct a new Elevator object - * - * REQUIRE: Nothing - * - * PROMISE: A new Elevator will be constructed - */ - Elevator (); - - /* - * PURPOSE: Tell the elevator to stop at the given floor, - * PURPOSE: going in the given direction. - * - * REQUIRE: floor is a valid floor - * REQUIRE: direction is either UP or DOWN - * - * PROMISE: The elevator will stop at the floor when it gets there - */ - void stop_at (int floor, enum direction _direction); - - /* - * PURPOSE: The elevator will move 1/10th of a floor in the current - * PURPOSE: direction. - * - * REQUIRE: Nothing - * - * PROMISE: The elevator will move if it has floors to stop at, otherwise - * PROMISE: it will sit idle at its current place. - */ - void move (); + Elevator (int elevator_number); + Elevator (int starting_floor, int elevator_number); - protected: - /* - * PURPOSE: Find the direction we should move in - * - * REQUIRE: _direction must be IDLE - * - * PROMISE: The best direction to move will be returned - */ - enum direction find_best_direction (); - - /* - * PURPOSE: Figure out if we are currently at a Stop in _stops - * - * REQUIRE: Nothing - * - * PROMISE: Return true if we are at a Stop in _stops, false otherwise - */ - bool currently_at_stop (); + void stop_at (Stop &stop); + float distance_from (Position& pos) const; + float distance_from (Stop& s) const; + void move (); + bool is_idle () const; private: - /* Storage for all of the places that we will be stopping */ - std::vector _stops; - /* Storage for the current elevator position */ - Position _pos; + /* State Machine: Helper Functions */ + Event find_next_event () const; - /* Stores the current direction */ - enum direction _direction; + /* State Machine: Transition Functions */ + void transition_move_up (); + void transition_move_down (); + void transition_move_idle (); + void transition_open_door (); + void transition_close_door (); + void transition_begin_wait (); + void transition_continue_wait (); - /* Stores the current door status */ - enum door_status _door_status; + /* Analyze the list of stops */ + bool currently_at_stop () const; + /* Elevator Status Variables */ + Direction direction_; + Position position_; + StopList stops_; + + /* State Machine */ + State state_; + int wait_; + + /* Elevator Number: Used to make calls into the GUI */ + int number_; + + static const float ELEVATOR_STEP = 0.1; }; + #endif /* ELEVATOR_HPP */ /* vim: set ts=4 sts=4 sw=4 noexpandtab textwidth=112: */