Sharp Distance Sensors and Straight Line Challenge

We are using Sharp distance sensors on Mr. Bit which can read a distance around every 16-20ms, apparently slightly slower than digital sensors though we have the advantage of having a distance measured (our sensor actually the GP2Y0A41YK0F which has range 4cm – 30cm). To make use of them we are using a GrovePi+ which manages ADC for us, the GrovePi+ itself has no real controller code, it simply interprets commands sent from our Pi via python libraries over I2C and returns raw data to it. Here’s the simple class we’ve written to deal with this:

We’ve made some special wires that split a single 4-pin Grove JST socket (containing VCC, GND and two analog pins) to two 3-pin JST plugs for two sensors. Coupling them via header block and pins so we can easily detach them if needed.

robot with distance sensors attached

Sharp distance sensors positioned either side of Mr. Bit -ready for straight line

Our first implementation of the sensors has been for the Straight Line Speed Test. The Sharp sensors are positioned at each side of the front of Mr Bit so that the barriers of the track can be detected. We’re subtracting the distances as our measure and using a PID with a set-point of 0 to establish a straight line.

Testing for hours in our short hallway we’ve been able to get the PID to direct the robot to the centre even if at either side of the track. Setting off from the centre is best of course but we’ve proven that a straight-line can be maintained even when Mr Bit needs to centre itself on the track from the extremities of the course. So many tests, up and down and it’s very rewarding when things start working and the efforts put in are starting to pay off.

Our hallway not long enough and although that’s where we’ve done most of our testing we really wanted to test some full length runs.  We called some friends in our village and they offered to help us do some testing last Sunday in the local Scout and Guides hut.

two barriers of wood along length of a scout hut to create a straight line test track

An 8m(+) track for Mr Bit to run down – carefully constructed by Rebelle and crew

Mr. Bit has two sets of wheels, a small set and a large set. We have issues with both sets and that’s for another post… We have decided, however, to change wheels depending on the challenge. Using our bigger wheels on this challenge shaved a whole 2 seconds off the time! We are very pleased with the results. Take a look:

Again, we’ve learnt so much – PID is amazing though the tuning has taken hours and hours (not to mention the coding and learning etc). We are looking forward to the Straight Line challenge, it might be our best offering at the competition.  We’ve a button on the DS3 controller to start and stop though stopping distance has increased now – we’ll need a crash barrier so I’ll make sure my big coat and rucksack is there to catch Mr Bit on the day.

Leave a Reply

Your email address will not be published. Required fields are marked *