State Diagram Discussion:
The software was first
developed in the state diagrams shown below. Using this strategy allowed for a
relatively seamless transition into writing code using the state diagram
template provided in lecture. Our master state machine consisted of four
lower-level state machines that were executed in the order shown below.
The Starting Game state
machine contains two states: Waiting for Flash, and Rotating to 50. At the
entrance to Waiting for Flash, timer channel 0 is initialized and the overflow
interrupt for this timer is enabled. By counting the overflows (happening
approximately every 349 ms), various timers used throughout the game were
created, including the two-minute game timer. The Starting Game state machine
is exited when the 50 percent duty cycle beacon (over the ball dispenser) is detected.
The Driving to Dispenser
state machine consists of many states that are executed in series. Driving to
First Tape Hit is exited whenever a tape sensor is triggered for the first
time. If this first hit is on the right tape sensor, then the Setting Field Side
as Right state is entered, and a module-level variable is set to mark the field
side for use in navigation in subsequent states. The Driving to Dispenser SM is
exited once the front bump sensor is triggered on the ball dispenser.
The Driving to T state
machine handles the tape following required to drive straight to the dispenser.
The Driving to T state machine is exited once both the left and right tape
sensors are triggered, marking the arrival at the “T”.
The Sitting at Dispenser
state machine originally contained two parallel state machines: Getting Balls
and Sorting Balls. Due to strategic changes, Sorting Balls was removed but the
structure of Sitting at Dispenser SM was kept in this state to avoid software
changes. The Sitting at Dispenser state machine is exited when 10 balls have
been requested at the ball dispenser.
The Getting Balls state
machine handles the events required to request balls from the ball dispenser.
Three timers (based on the timer channel 0 overflow interrupt) are used. The
push timer dictates how long the robot drives forward into the ball dispenser
lever, the retract timer controls how long the robot backs away, and the 5
second timer creates the mandatory pause that must occur between 5 consecutive
ball requests.
The Dumping state machine
handles the navigation required to move the robot from the dispenser to goal
one as well as the motor controls necessary to dump balls into the goal. When a
drive timer expires, the Sitting at Goal state is entered. At that point the
dumping motor is turned on, releasing the balls towards goal one.
The original game strategy
and software design is shown above.
Inside the Sitting at Dispenser state machine were two parallel state
machines: Getting Balls and Sorting Balls. Sorting Balls would categorize balls
as they were received, and depending on their color or number, sort the balls
appropriately. The strategy was to store all black balls in the dump storage
(to be deposited in goal 3) as well as a predetermined number of yellow balls,
and to shoot the rest immediately into goal 2. After 15 balls had been
requested, the robot would move to goal 3 and deposit the stored balls, and
then move back to the dispenser to request and shoot the remaining 5 balls.