Saturday, June 21, 2014

Pennybot finally makes it to the big time - sumobot finals


In order to get pennybot into the winner’s circle I needed to make a number of changes…

Realising that the rear IR sensor wasn’t really useful I unsoldered it and added it to the front of pennybot as a front sensor between the current left/right sensors.  This sensor was connected to the interrupt pin RB0.

I made a new metal scoop for the front with the bottom edge formed around a piece of wire for extra strength.  This scoop just scrapes the floor.  Great for lifting up opponents but terrible on the sumo ring paint job.

I went back to a much simpler code base for the IR detection function.  Firstly in the ISR section I check each interrupt flag to see what interrupt was triggered before calling that function.  Before I was running through all the sensor functions (line sensor/IR detectors) regardless.  Now with the direct front IR sensor being to RB0 I had three functions.  Firstly check the line sensors as staying within the ring is the most important behaviour.  Second check the direct front IR sensor (RB0) and go forward if that detects.  Once in this function skip the rest of the IR sensor checks before exiting the ISR code section.  This is to stop a false hit from making pennybot go left/right after a forward move.  Finally check the other IR sensors on RB4-7.

Also I removed all the loop and repeat checks.  Rather we go through the ISR code once and then out.  Previously I was getting stuck in function call loops that were going more than 8 deep and thus breaking as the stack would loop over itself.

Finally I changed the motor driving code for when there was a left front or right front detection.  Rather than turn on the spot we now do a slow right or left turn by braking one wheel (by making both motor inputs high) and only powering the other.  This results in a turn with the pivot point being the braked wheel rather than the centre of pennybot.

In previous bouts dumbbot was the winner 4 out of 5 matches.  The push strength dumbbot has was too much and it’s wheels too grippy for pennybot to push.  Now it was a different story.  Pennybot won every single match.  The new IR detection code worked great, the slow turns allow pennybot to track much better and the new scoop lifts up dumbbot slightly so it loses traction and can be pushed back.  Finally success.

The only minor points I’m considering to fix is the turn time on the line sensors.  Sometimes when there is line detection pennybot turns so far on the spot the other line sensor detects and we end up spinning on the spot.  The third IR emitter circuit (previously used for the rear IR emitter) is still on the board but unused.  Perhaps I will unsolder it but it seems more effort than it is worth.  Also I should add in a watchdog timer to get me out of unknown code failures.  The watchdog timer is one part of the pic programming I haven’t played with yet.

It’s been a long time but finally I can have a sumo battle.

No comments: