top of page
Search
neil0064

Our Pi Wars Robot Moves!

Having spent the last couple of months getting the motors, wheels and Raspberry Pi 4 all assembled into a basic robot, it's time to test it out to ensure it can move and behaves as expected.

Connecting a PS4 Controller

For simple remote control of the robot, and also starting autonomous challenge runs, we need some form of controller. For this, we're going to use a Sony Playstation Dual Shock 4-compatible controller. These are available in many colours and options on Amazon, eBay etc, and conveniently connect wirelessly using Bluetooth to the Raspberry Pi 4.

Using the standard Raspberry PiOS, this can be connected easily by going to the desktop Bluetooth icon and selecting Add Device. If the icon is not shown, you may need to enable Bluetooth, but it is there by default normally.

Put the controller into "Pairing" mode by pressing the "share" and then "home" buttons together, and now both until it flashes double-beats every couple of seconds or so.

It should appear on the Raspberry Pi as "Wireless Controller" or similar, depending on brand.

Select the controller and click "Pair" and it should establish a connection and report success (you can ignore any second "Connection failed" message, this is a problem with some cheap controllers). This is all that is needed for most PS4 controllers (but older PS3 controllers are a lot more difficult to set up!).

Now we need some software to read the controller buttons and joysticks.

ApproxEng Input Software

We're going to be using Python to build our software, and by far the best library we've tried is the Approxeng Input Python library. This connects (and re-connects) reliably and provides a very convenient way of reading the state of the controller for use in the main software loop.

This was developed for an older version of the operating system, and has a slight issue currently when trying on the latest "Bookworm" version. For this, currently you need to install manually instead of through "pip".

Firstly, get the source code from GIT - open up a terminal window and type:

Then we need to adjust the dependencies to suitable versions for this operating system. Using your favouite editor, edit the setup file, e.g.

nano approxeng.input/src/python/setup.py

Change the versions of evdev to 1.6.1 and pyyaml to 6.0.1 and save the file.

We can now build and install the software using the commands

cd approxeng.input/src/python
python3 setup.py develop

This should build and install the necessary python packages.

Installing RedBoard+ Software

We're going to be using a Red Robotics RedBoard+, as this provides everything we need to drive and control our robot. The installation of this on the Pi4 is similar to the input library, and we're actually going to use the Approx Eng version of this as well.

Basic Software Control in Python

Time to write some simply test code. We're going "tank mode", i.e. one controller joystick will control the left motor and the other joystick the right. Here's the code


Test Run

Now we have everything in place, let's see how it behaves.



Not too bad, but I'd forgotten how difficult to control a 2-wheeled, large robot is. It swings, rocks and spins very easily.

Next Steps

We learnt in Pi Wars 2020 that the solution to making this hardware controllable was to add an Inertial Measurement Unit (IMU), which allows us to control direction, acceleration and rocking through software control. This will be covered in a later topic.




2 views0 comments

Recent Posts

See All

留言


bottom of page