So, time to buy the new Rover Car. On the shopping list:
– A Lego Technic 9398 4×4 Crawler
– Raspberry Pi bread board, jumpers, cobbler kits, resistors, LEDs, etc.
– Sensors: an ultrasonic sensor, an IR transmitter, accelerometer, compass.
Where does the Raspberry Pi fits in it? And what it the autonomous plan?
The Lego car engines are controlled by an IR receiver. This page has a thorough explanation of the Lego IR receiver contacts and the motor contacts, and how they operate. Basically, the IR receiver channels the 9V from the battery pack into the C1 and C2 channels of the engines, both servo and DC engines, thus making them rotate.
The first idea I had was to put the Raspberry Pi between the IR receiver and the engines. The advantage were:
– I could have a direct control of the engines, just like with the Mk. I Rover car.
yet, the disadvantages were higher:
– I had to cut the motor wires so I could add them into the bread board. I could order some extension wires from the Lego shop, nonetheless.
– We are dealing with 9 V here, and any mistake can cause me to ruin my Raspberry Pi, and I don’t want that.
– No idea on how to still make both manual and automatic controls work, that is, making the Raspberry Pi to contol the car, while still having manual control to override it.
There is a better solution: instead of cutting wires and using the bread board for engine control, why can’t I just use an IR transmitter?
The advantages are:
– No wire cutting. Raspberry Pi sends IR signals to control the engines.
– No need to modify the 4×4 crawler car. Everything stays there.
– Both the Lego controller and the Raspberry Pi controller can send IR signals, so they can both control the car at the same time.
– No risk on ruining the Raspberry Pi. Bread board stuff is only for the sensors, who use voltage that the Pi can handle, no need for 9 V.
The only disadvantage, so far, and not a big one, is that I have to teach the Raspberry Pi to speak “Legolese”, but since Lego kindly published the RC protocol, anyone can reproduce the IR codes.
The next thing is the sensors: how to detect the obstacles around the car? Th first idea was to buy 8 ultrasonic sensors, and placing them on the corners of the car, and on the sides. That idea was scrapped immediately, when I though that a cheap servo could do the trick.
This boebot shows what I have in my mind:
If I attach the ultrasonic sensor to a servo motor, and if I can control its angle, then I can do several measures per second, on a 180º range. That is more than enough to detect big obstacles such as walls or boxes, and it is fine for now.
This is good enough to make sure that the car can drive autonomously without hitting walls. Some Python code can ensure that he knows how to turn and reverse, if such obstacles are found. Yet, not good enough if we want the car to go from point A to point B.
Now, that is the core of Artificial Intelligence research, and that is basically given by whatever Python code I can put in the Raspberry Pi. So, let’s leave it there; in terms of hardware, I believe that an accelerometer and a compass are important, in order to provide a certain awareness of the whereabouts of the car (a GPS receiver wouldn’t be much help on a car that has a speed of 50 cm per second, operating inside buildings). If the car knows his speed and bearings, it can calculate its position from a reference point; given a destination point, he should at least know the bearings where he should be heading.
Now, it’s time to wait for the sensors and Pi accessories to arrive. The Lego car is here, and already assembled, waiting for some Pi sweetness.