Pi2go Automated Python Robot

The Pi2go Hardware & Goal

Our primary agenda for this college project was to make a robot that would complete a set course without user interaction. The Pi2go Automated Python Robot project required me to compile and build parts from a pi2go kit. This Raspberry Pi-based robot is powered by AA batteries and interfaces with the pi2go mainboard using the GPIO pins. Using the pi2go robots taught me how to program hardware to perform a function. With the pi2go I built, the final build had the following components:

  • 4 Ultrasonic Sensors (hc-sr04)
    • Front
    • Left Side
    • Right Side
    • Rear
  • 2 Motors with 2 wheels.
  • 1 Omnidirectional ball bearing which acted as a spherical front centre wheel.
  • 3 IR sensors (on pi2go board)
    • Front-middle
    • Front-left facing
    • Front-right facing
  • LEDs to indicate action and information upon event triggers.

In addition, the whole program was written using object-oriented programming. This used reusable methods that were imported into the core program. The whole program ran on a loop, constantly checking for updates to the sensors.

Unfortunately, I do not have any photos or videos of the robot in action, however, the code which I used to run the robot can be found here on GitHub.

pi2go raspberry pi automated python robot

Obstacles I overcame

Motors ran at different speeds while set to the same setting.

So for this, I had to identify which motor was slower, I tested this by running the robot at 100% speed and noting which direction it veered off to. In my case, it was to the right. meaning the right motor was slower. To combat this slight veering, I lowered the default speed of the left motor. Once I saw the pi2go travel in a straight line for more than 6 meters, I stopped reducing the left motor speed. This fixed the issue of it veering off to the right.

Ultrasonic sensors didn’t detect the correct distance when below 0.5ft.

I discovered this issue quite early on, this issue caused the robot to hit walls regularly. It either attempted to reverse into another wall or continue to roll forward. Furthermore, it was also not able to rotate the correct way to complete the course. To combat this, I made sure that if the robot was nearing a wall, it’d detect the distance on the side sensors. In addition, these values would then be checked to see which was smallest, and whatever side was the smaller value, that sides motor would speed up to allow the pi2go to fix its centre point.

Additionally, the robot didn’t detect when it collided with a wall, so I added an event that checked if the infrared sensors were triggered. 9/10 times they were sensing whenever they collided with a wall. These changes fixed the issues of crashing into obstacles, and misdirection.

Wi-Fi was the only form of connection to the device, locating the IP address every time we booted the robots was difficult.

The network I was on used DHCP to provide IP addresses to the Pi, which meant I couldn’t set a static or IP address for the Pi. I had to plug the Pi in via HDMI to a display, log in, check the connection status, and locate the IP address. Essentially, this whole process added unnecessary time to get on my Pi every day I worked on the project.

Therefore, to reduce this time, I added a script to the boot sequence which returned the IP address. This can be seen as a security flaw but seeing as the device was personal to me this wasn’t an issue. In other words, no one had access to this device except me. The feature was removed when I finished using the Pi for this project.

In conclusion, final Pi2go Automated Python Robot worked completely as expected! The full source code of my pi2go project can be found on my GitHub here

python code pi2go raspberry pi