Leader PIC State Chart
The Leader state machine, referred to as LogicHSM, manages general logic of the software program. It processes input from phototransistors and the start button, controls all servo motors and the LED indicator. Through Leader SPI service, this machine posts command to and receives feedback from the motor PIC. LogicHSM receives events from CheckButtonStatus to monitor the start button status, and uses interrupt to detect beacons and ACORNs through phototransistors. The structure of the LogicHSM is illustrated in the following state chart figure. The top-level machine consists of four sub-systems: InitState, YardRecognition, Head2TreeSM and FreeRangeSM. In the first three sub-system, our SQRL will perfrom tasks to recognize its current yard, shoot the first ACORN placed near the starting point, and clean all the ACORNS in the two beacons. In the last State Machine, the SQRL will randomly search the ACORNs on the field and shoot them to the other yard. Additional currentstate-independent actions in response to ES_End event (e.g.,stopping the game at 2:18) are shown on the bottom right of the state chart figure.
Leader PIC Lower Level Machine: Head2TreeSM State Chart
In this state machine, the SQRL will first target at the beacon from the other yard and moves forward util the tape opto-reflective sensors detect that it has reached the middle of the yard. It then releases the gripper and shoots out the first ACORN. Next, the SQRL turns counterclockwise to locate the right beacon in its own yard and walks toward it using the tape-following strategy, guided by analog input from the tape reflective sensors. When the ACORN contact opto-reflective sensor indicates that the ACORN is within the range of our gripper, the SQRL stops and grasps the ACORN from the beacon. Then, the SQRL moves backward for a set time before repeating the entire process (i.e., realigning with the target beacon and moving to the beacon tree). After all five ACORNs from this beacon are shot to the other yard, the target beacon switches to the left beacon, and the process is repeated. The program exits this state machine and transition to FreeRangeSM when all ACORNs from the left beacon are cleaned.
Leader PIC Lower Level Machine: FreeRangeSM State Chart
In FreeRangeSM, the SQRL begins searching for ACORNs by rotating counterclockwise and waiting for signal from the ACORN detecting phototransistor. Upon finding an ACORN, the SQRL moves forward util the ACORN contact opto-reflective sensor indicates that the ACORN is within reach. It then closes the gripper and turns counterclockwise to target the beacon in the opponent’s yard and shoot out the ACORN. This process is repeated until Timer218 Timeout. If the opto-reflective sensors for checking obstacle distance are triggered while moving toward the found ACORN, the SQRL moves backward for a set time and returns to the state of looking for ACORN to restart the process.
Motor Control Service
The Motor Control Service is implemented on the motor PIC, which handles input from opto-reflective sensors and encoders. It uses PWM to control speeds of two DC motors by processing all the events posted from the event checkers (Check4Tape, and Check4AcornContact) and the Motor SPI service, which manages commands sent from the logic, or leader, PIC. The structure of this service is illustrated in the following figure.
SPI Services
The primary function of the two SPI services, one for the leader and one for the follower, is to communicate between the two PICs. The leader PIC can receive 8-bit feedback and send 8-bit commands to the follower PIC. Once one PIC receives a message from the other, its SPI service processes the message and converts it into the corresponding event, which is then posted it to LogicTopHSM or MotorControlService. The two SPI services also receive ES_NewMess2Send events from their respective state machines. Different 8-bit event parameters tell the SPI services the message to send to the other PIC. These tasks are executed through the SPI Interrupt.
Event Checkers for LogicPIC
The Event Checkers.c for LogicPIC handles input from the start button and two opto-reflective sensors. The CheckStartButton() function routinely monitors the value of pins connected to the start button and post ES_STARTBUTTON event to LogicPIC machine in time of pin value changes. The two opto-reflective sensors are used to detect obstacles taller than the ACORNs, such as walls. The CheckDistance() function posts ES_DistanceShort event to LogicTopSM, and down to FreeRangeSM, when the input from either opto-reflective sensors goes high. This triggers the CurrentState of the FreeRangeSM to transition to Avoidance to prevent collision.
Event Checkers for MotorPIC
The EventCheckers.c for MotorPIC manages input from opto-reflective sensors, handling tape detection, acorn contact detection. The Check4Tape() function regularly checks the analog inputs from three tape opto-reflective sensors, allowing MotorPIC to determine if it has deviated from the path. It posts ES_SpeedUpRight or ES_SpeedUpLeft event to MotorPIC when analog input of the right or left opto-reflective sensor exceeds the threshold . The Check4AcornContact() function routinely checks the digital inputs from the acorn opto-reflective sensor. It posts ES_AcornContact to MotorPIC in time of pin value rises, indicating contact with an acorn.
ServoService
This service uses PWM to control motion of all three servo motors: the gripper motor, the launching motor, and the yard indication motor. All three motors operates at the same frequency. The gripper motor can seal and open the gripper using a rack and pinion structure. The launching motor shoots the ACORN through an arm connected to a 1:5 planetary gearbox. The yard indication motor raises a flag with words “Ed” and “Karl” on the two ends.
LEDService
The LED service controls the red LED, which serves as a game status indicator. The LED is lit as the initial state. After the start button is pressed, the LED start toggling to indicate that the game is in progress. Since the longest timer duration is 46 seconds, the service runs Timer218 for three times. When Timeout, the service turns off the LED to indicate the end of the game.
Other Files