Software
-
Obstacle Avoidance
The initial strategy when writing the code was to utilise a KBI interrupt which was triggered by the touch bars (which were normally open) when they closed. We experienced most difficulty initialising the KBI interrupt (KBIPE register in particular) due to a discrepancy between the pins labelled on our micro controller and how they are actually labelled on the data sheet. This confusion led us to load x8C onto the KBIPE instead of x60.
Furthermore, in the interrupt we tried to check which touch bar triggered the interrupt through polling which was completely the wrong strategy since the microcontroller was already in the subroutine and such a check could only take place in the main function. Instead we polled the touch bars in the main function and based on that we designed how the micro mouse reacted without the need of an interrupt.
Once this was done the IR sensor were integrated into our micro mouse code through polling as before and obstacles were avoided as expected.
The driving and Turning Algorithm
r and l are Boolean variables used to determine whether the micromouse should turn left or right.



-
White Line Following
As before the initial strategy was to design the if structure that would take care of all possible states coming from the three LDR sensors. This worked well because we could then write specific functions that would be called in each case such as our white line following function wlfollowing() and stop(). This was convenient and provided a simple means to diagnose problems and test specific functions by exposing the micro mouse to specific expected states of the LDR such as Black-white-black.
Having done that the next problem we encountered was minimising the jagged way the micro mouse was trying to maintain on the white line. Using a fixed correction distance proved futile and therefore we needed a dynamic correction distance as used earlier to keep the motors spinning at the same speed. Using that architecture the micro mouse was able to make large and small corrections automatously, in fact we only needed to modify this slightly to get the micro mouse to turn effectively at the 90 degree turns.

We further reduced the jagged turning by reducing the distance between the LDRs as shown below.
Doing this eliminated the micro mouse’s need to make large corrections to stay on the line; it also improved the responsiveness of the mouse to detect when it needed to turn
-
Combat
For combat an extra LDR was added to our design as shown below.


This change was important because to keep the mouse within the white box it needed to sense when it crossed the shite line in front and when it is being pushed behind. As for the code, a combination of code from obstacle avoidance and white line following were combined and merged. An if function checking the state of LDR4 encompassed all that code.