top of page

Software Design

The software for The Mystery Machine was designed to balance agility with power. The programming takes advantage of a State Machine approach, where a sensor being triggered or a timer expiring moves the robot from one set of actions to the next! For a high-level understanding of the software design, take a look at the state machine diagram! Interesting parts of the program are covered in more detail below, followed by a link to the code base. 

Finite State Machine Diagram

The states with black text and arrows are implemented in the loop, moving from one to the next according to the events that occur. The states and arrows in blue are checked in global events, and thus can be entered from any other state in the state machine. 

State MAchine.JPG

IR Sensing Self-Calibration

The software evolved over time with testing. Initially, the software used a hard-coded value for the IR sensor to determine when The Mystery Machine was oriented towards the beacons. After many rounds of testing and picking up on reflections of the IR Beacons when not facing the center, the software was updated to include a self-calibration. The Mystery Machine rotates 360 degrees at the beginning of game play and records the maximum signal detected, using an interrupt routine on the rising edge of a square wave signal. The software then detaches the original interrupt and attaches a new interrupt routine, which looks for a signal that is 80% of the original intensity to determine the location of the center of the playing field.

Getting In Position

After the IR Beacon is detected, The Mystery Machine rotates an additional 180 degrees using a timer, and then drives forward until a line is detected (see more on Line Sensing in the next section). When the line is detected, The Mystery Machine backs up, rotates 90 degrees, and then starts going forward, looking for the boundary line as it moves. This series of states allows The Mystery Machine to maximize torque and begin navigating the playing field in a relatively short amount of time. 

Line Sensing & Response

The line sensor returns a high value (1023) when no reflected light is detected, and a low value when the phototransistor senses the reflected LED light from the playing field. In the software, we used a hard-coded threshold of 1000, such that if most of the light was absorbed (but not necessarily all), the program determined that The Mystery Machine had reached a line, and responded.

 

Initially we tried to implement a line-following technique, where the robot would curve with the outer line. However, due to the limited turning ability of the robot, it proved more advantageous to simply back-up, rotate 30 degrees, and continue forward. To turn, the robot engages the caster wheel to pop up onto 2 wheels. The front two wheels then spin in opposite directions to rotate the Mystery Machine clockwise. Once the rotation timer expires, the caster wheel disengages, and The Mystery Machine continues forward on all four wheels. 

​

This behavior was captured in a nested-state-machine. As long as no IR beacon was detected and the limit switch was not activated, The Mystery Machine stayed in the line-following state. 

Limit Switch: Full Speed Ahead

In the case that The Mystery Machine was flesh against the wall, a normally open limit switch was activated, which is checked for in the Global Events. This puts the machine in the "Forward Only" state, where four wheel drive is engaged by disengaging the caster wheel. Until the limit switch is disengaged, The Mystery Machine will only go forward to maximize pushing power. The assumption was made that the robot will follow the wall naturally and not go out of bounds. This held true in the competition, as the robot stayed in bounds for all 4 rounds it competed in. If the limit switch is deactivated, The Mystery Machine reenters the line-following nested-state-machine. 

Game Timer

At the start of the program, a game timer is initiated such that all motors will stop after 130 seconds. The timer is checked once per loop in the Check Global Events function. The Mystery Machine lost the tournament on a technicality - The Mystery Machine motors stalled, drawing too much current and rebooting the program. Therefore, at the end of the game, the motors were still engaged, as the timer had restarted. To ensure victory, a 60 second timer likely would have sufficed. This could be updated in The Mystery Machine Version 2.0.

Full Code Located Here

View .cpp Version of Code Here:

https://github.com/danaekay/ME210

Special thanks    to our  friends, family  and the    ME210 teaching team!

bottom of page