Friday 24 March 2017

Pi Wars 2017 - Scaling things up

Whilst the robot I posted about in my last blog entry is reasonably compact and contains most of the components I'll be needing for the PiWars 2017 challenges, in practice it feels a little bit sluggish and under powered, and not something I'd be confident entering into the Pi Noon challenge. So I decided what was need was a slightly bigger robot.

Now as the robot is 3D printed I can just scale it up to the size I want yes?  Well, unless you have a fully working replicator, its not quite that easy. The plastic parts scale up nicely the motors and other electronics don't. The weight increases, so you need bigger motors, then bigger, however the batteries, and possibly a higher rated motor controller. Then you need to make all these bigger components fit on the robot and suddenly it feels like you have less space than you did before!

I stripped all the parts from my PiWars 2015 entry and went through several revisions of the scaled up chassis, trying to work out how to make everything fix together.  Eventually I did a spot of rewiring on the controller, cut off some pins and finally came up with the following.

Old vs New

The new Pi Squared chassis is considerably larger than the previous variant, as well as gaining a rear wing, just fitting inside the maximum dimensions allowed for PiWars. The front wing is now removable, allowing the chassis a bit more space on my 3D printer, and can be swapped out for the various different challenges, although the only one I have prepped so far is for Pi Noon.
Removable front wings
The downside to the increased size is it takes a lot longer to print. The chassis takes just over 20 hours to print, the rear wing 5 and the front wing another 2...So my printer has been running almost constantly for the past week!

The control method is my usual PS3 controller, with a simple python script driving the motors, making use of pygame and the GPIOZero library to keep everything simple. In fact the entire code is rather small.

import pygame
import os
import time
import gpiozero

os.environ["SDL_VIDEODRIVER"] = "dummy"



# Wait for a joystick
while pygame.joystick.get_count() == 0:
  print 'waiting for joystick count = %i' % pygame.joystick.get_count()

j = pygame.joystick.Joystick(0)

print 'Initialized Joystick : %s' % j.get_name()

from gpiozero import OutputDevice
from gpiozero import Robot
EN1 = OutputDevice(17)
EN2 = OutputDevice(6)
r = Robot(left=(27,5), right=(13,4))

    # Only allow axis and button events
    pygame.event.set_allowed([pygame.JOYAXISMOTION, pygame.JOYBUTTONDOWN])
    left = 0.0
    right = 0.0

    while True:
        events = pygame.event.get()
        for event in events:
          UpdateMotors = 0

          if event.type == pygame.JOYAXISMOTION:
            left = j.get_axis(1)
            right = j.get_axis(3)

            r.value = (left, right)

except KeyboardInterrupt:
    # Turn off the motors

Finally here's a quick view of the new and improved Pi Squared running around.

With only a week left until PiWars I still have a lot to do, sensors to attach, code to write, practising driving.. So its going to be a busy weekend and evenings for the rest of the month!



  1. Looks like you've got the driving down pretty well in that video!

    Also, do you have a code repository on github or anywhere? You could then just link to it from here. But I appreciate the code, either way! :)

    1. I've got a couple of repositories up on GitHub ( although this variant of the code isn't up on there yet. In theory I'll tidy it up and upload whatever my final code ends up being after PiWars (And put the STLs up on Thingiverse

    2. That sounds really cool. I'll hope to see some code that you win with, then. 😎