Skip to main content

Don’t reinvent the eel


Robots that don’t move around by themselves aren’t much fun.  Because you’d have to tie them to the back of a pterodactyl to fly them around.  Or attach them to the tail of a unicorn to make them hunt for pots of gold.

But don’t worry.  Humans have invented the wheel.  So let’s not reinvent it.

We’ll simply attach the wheels to Rosie’s plastic body and send instructions to the motor controller board that controls their motors using the Raspberry Pi.  Bit like how brains send signals to our legs through our nerves.

But let’s not get too scientific.  We just want to make some plastic boxes move around the floor to scare the cat - and the grandparents.  Or preferably both.  Now how hard could that be?

You will need to have these:

  • Raspberry Pi 3, and Raspbian running on SDHC card
  • A computer from which you are connecting to the Raspberry Pi remotely 
  • A robot / rover kit (which includes at a minimum: motors, motor controller board, wheels and some form of additional power supply, like a battery pack).  Exact contents will differ depending on the kit.  In this example, we have used a rover kit made by Monk Makes (https://www.monkmakes.com/pi-rover/).  Other varieties are available.
  • A 'body' to attach your wheels to, if you are not planning to use what's included with the kit.  We used a cheap plastic storage box for Rosie's chassis, the type sold in high-street discount stores (you know the ones!). 
  • Electric drill and screw driver (and suitable screws) if you intend to go off-piste with your robot chassis

You will need to have done these things:

  1. I’ve got Pi(3) brain
  2. Why-Fi-ght the Wi-Fi?
  3. Hurrah-ndom inventions

You will need to do this:

    • Assemble the kit and prepare the chassis.  This will basically involve attaching the wheels to the motors, attaching the motors to the motor controller board, and attaching the motor controller to the Pi.  An additional battery pack will be connected to the motor controller board as well.  Amidst the excitement, don't forget to attach the motors / wheels to the chassis.
    • Download (clone) the Python files from GitHub to your Pi that will allow you to control the motors using the motor controller board supplied with the kit
    • We like to move it, move it!

    What do you get after all this?

    After our frantic foray into Raspbian OS and Python programming, we finally get Rosie to do what robots are meant to do.  Yes, we'll get to move her around using all the things we've learnt so far.  Silly robot dancing, here we come!

    But before that, time for another introduction.  Budding roboticist - meet your new friend, GPIO, which stands for General Purpose Input / Output.  It's the bank of 40 pins mysteriously sticking out from one corner of your Pi 3.  And as its name suggests, it is how we get the Pi to talk to other bits of useful hardware.  And if you want to move a robot around, what could possibly be more useful than a motor, with a wheel attached to it.  In fact, two of those please so that we can make it turn around as well.

    And in order to claim swift victory, we will simply use whatever Python Libraries (a collection of software) that was provided with the kit to make the robot glide (un)gracefully across the floor.  There's plenty of time later to personalise our Rosie.  And to understand what's actually going on behind the scenes.  But for now, we just want to see a plastic storage box powered by a Raspberry Pi move across a garage floor.


    This is simply too much detail:

    Let's begin with the chassis.

    How you get your motors (and therefore your wheels) working will be different depending on the kit you have.  So it's best to be sensible for a change, and first read the manual that came with the kit.  But there's also nothing wrong with using only the bits from the kit that look useful, and improvising the rest.  And where better to start to ignore the instructions than when it comes to the robot's looks?

    Enter the... (audience pauses with excitement) plastic box.  It's extremely cheap.  It's lightweight.  And with a few unsightly holes drilled, we can attach anything to it (like sensors, cup holders, mosquito swatters, a spatula, etc, etc).  Let's then call this our prototype, as this makes it sound more acceptable.

    Next, let's attach the motors with the wheels in whatever position that will give our robotic friend the best balance.  I'm sure we could make use of some clever maths and science to advise us here, but where's the fun in that?  Eventually, we opted for two rear wheels, and a swivelling castor wheel at the front.  There's no right or wrong answer here.  Just trial and error.  Let's pray that Rosie will glide elegantly across the dance floor like a disco queen, and not stomp across like an angry teen.

    We also drilled holes by the wheels so that wires from the motors could be pulled up through and into the box... or the compartment (as this sounds more professional).  Direct Current (DC) Motors work by converting electrical current from a power source into rotational movement using a magnetic field, and these cables help carry this current.  But current from where?  A strange new device called the Motor Controller is introduced.  Not only does it provide power to the motors from a separate AA battery pack, but it helps the Pi communicate with the motors, almost like a little translator from the sophisticated and elegant language of Pi and Python, to the primitive signals understood by the motors.  The motor controller included in our kit was a RasPiRobot v3.

    Hey, look.  We now have a plastic box full of circuit boards and cables.  And some motors and wheels.  Now let's try to move it - not with the power of our mind, but with the power of our Pi.

    We should return to the Pi, or as we have been calling it - Rosie's brain.  Can you see that this is now a wannabe remote controlled robot?  That's why we'll need our SSH connection back from this point onwards.  No other cables are allowed.

    Now, we could just sit down for the next days / weeks / months working out how to program the motor controller to control the motors.  But technologists like to build on what others have already done.  And your kit should point you in the direction of some Python software already written for your motor controller that allows you to control the wheels using simple commands.  And quite often, these are shared on a site called GitHub which happens to be the most popular code sharing site on the planet.

    For our Monk Makes' Pi Rover Kit, the instructions inform us of some Python libraries (collection of Python software) that we can download.  These will allow our Python programs to interact with the motor controller in a way that we can easily understand.  Let's navigate to our 'rosie' folder and download (clone) the libraries from GitHub.

    pwd
    ...checks that we are still in the pi user's home folder (/home/pi)
    cd rosie
    ...let's continue to store all our files in the 'rosie' directory, including the files we are downloading
    pwd
    ...confirm that we are now in the rosie directory
    git clone https://github.com/simonmonk/raspirobotboard3.git
    ...this funny looking command allows us to clone (or download to you and me) the Python libraries for our motor controller (RasPiRobot v3) to the folder that we are currently in


    Providing that your home network has an Internet connection (which it should if you are reading this!), after a few seconds, it should tell you that it has completed.


    The installation instructions tell us that we should install the downloaded libraries so let's - for once - follow the instructions.

    cd raspirobotboard3/python
    ...Navigate to the 'python' folder in the 'raspirobotboard3' directory.  Why?  Because it tells us to.
    sudo python setup.py install
    ...Run setup.py using Python to install the motor controller files.  Why?  Because (again) it tells us to.

    It looks like the installation script has completed what it was doing.  Successfully.


    Finally, the instructions tell us that there are also some example programs available on GitHub that show us how to move a rover around.  Yes please!

    cd /home/pi/rosie
    ...goes back to the directory where we are storing our files
    git clone https://github.com/teknoteacher/raspirobot3
    ...download the example programs for our motor controller


    After all this, we should be all set to go.

    What were we doing?  Oh yes - we remember - we want to move a plastic box around the garage floor.  We want to be in total control when we do it, like a rock star.  We want to tell it where to go, and it needs to listen to us.  Thankfully, there is a sample program for that.  It's called '08_manual_robot_continuous.py' so let's copy it to our 'rosie' folder.

    cd raspirobot3
    ...changes directory to 'raspirobot3' folder containing all the sample Python programs
    cp 08_manual_robot_continuous.py ../rosie_wheels.py
    ...copies the '08_manual_robot_continuous.py' program up one folder above (/home/pi/rosie).  We are also renaming it to 'rosie_wheels.py', because we can!  We can safely edit it in the future now without affecting the original.
    cd .. 
    ...moves back up one folder to '/home/pi/rosie' 


    Now, are you ready to see a plastic box move?  Do you have your popcorn ready?  Do you have your sledgehammer beside you just in case your robot goes out of control and needs to be terminated?

    python rosie_wheels.py
    ...runs the 'rosie_wheels.py' Python program.

    The controls are very simple.  Use the 'up', 'down', 'left' or 'right' arrows to move the robot around.  Pressing any other key (we prefer the 'space' key) will stop the last movement.  If it all gets too much, you can exit the program by pressing 'control' and 'c' keys together (no sledgehammer required).


    Wasn't that worth all the work?  Now, have hours of fun (more like until the batteries run out) taking your cuddly plastic box on all kinds of journeys around the house.

    For now enjoy the small victory.  Feel proud of yourself that you are now a proud owner of a non-autonomous robot, which we will attempt to turn semi-autonomous.

    Even more reading:

    Raspberry Pi's official GPIO documentation can be found here:
    For this post, great deal of credit goes to Monk Makes (Simon Monk) and Teknoteacher (Alan O'Donohoe) whose excellent work we have referenced throughout:

    Comments

    1. Thanks for this fun "drive my bot around" test program. I learned a new way to access the key presses.

      Comment about rosie_wheels.py (08_manual_robot_continuous.py):
      1) there is a harmless duplicate elif keyp == LEFT: stanza
      2) for some reason the ord(keyp) == 3 did not catch cntl-c and quit. I had to kill the process.

      (Results from Rosie the Rug Warrior Pi https://flic.kr/p/Ur7JzW )

      ReplyDelete
      Replies
      1. Hello! We can't take credit for the RasPiRobot3 Python libraries as they have been created by Monk Makes (Simon Monk) and Teknoteacher (Alan O'Donohoe) especially for the board. Next step is to control your robot using a HTTP web interface perhaps? We do this later in Web of Pies and it makes a nice change to using your keyboard.

        Your robot looks cool in the picture!

        Delete

    Post a Comment

    Popular posts from this blog

    Tea minus 30

    We're fast approaching Christmas time.  And if robots were to make one simple observation about the human species during the Christmas festivities, it's that they watch a lot of TV.  A LOT.  Often, accompanied by an inappropriate amount of greenhouse gas-producing food.  Stuff you don't normally eat during the remainder of the year - for good reason.

    And most so-called shows on TV are boring to robots like Rosie.  After all, why watch a minor subspecies of the human race - celebrities - stumble awkwardly around the dance floor, dressed like a faulty, sparking circuit board?  Such branch of entertainment doesn't require robots to engage any of their proud circuitry.  Their processors remain idle.  Memory under-utilised.

    But if robots are to be part of people's homes (and blend in), they need to look at least a little interested in some of this irrational nonsense.  Nobody likes a party pooper.  A killjoy.  And this is where a certain subgenre of TV entertainment co…

    Beam me up, Rosie!

    How do you get from A to B?

    You can't, as As and Bs are just letters in the alphabet. But if A is your house, and B is a meerkat village at your favourite safari park, you'd probably use a device equipped with GPS.  Not to be confused with UPS, who will deliver you your chosen meerkat through the post. And why on Earth would Rosie Patrol need one? Precisely, it's because she is on Earth that she needs one. Because our planet is rather big. Big enough to get lost in. And we don't want to lose our friendly plastic boxes on wheels. And maybe, eventually when she's clever enough, she'll go and defeat baddies on her own. And return home afterwards for a well deserved Earl Grey tea.

    Besides, why wouldn't we want to add another three letter acronym to Rosie Patrol's repertoire?
    All superheroes need:One Raspberry Pi 3, running Raspbian OSComputer from which you are connecting to the Raspberry Pi Probably the most important bit: a GPS receiver thingmy. …

    Raspberry bye, hello

    Let us make this very clear from the onset of this exotic excursion.

    This is not a case of Raspberry Bye. Our relationship with our favourite single-board computer hasn't at all soured. In fact, we've become wholly inseparable. There's been many months of undeniable fun that's been had with the venerable computer strangely named after an edible fruit. To the extent that our relationship requires a healthy break. And quite frankly, our Pis require a well earned summer holiday to do whatever it is that robots and computers do during their time off. Crash. Burn. Refuel (with questionable toxins). Not at all unlike their human counterparts. And ultimately, it would be nice if they could return to a brand new, adorable pet waiting for them at home, a likeable little companion that they can just get along with.

    Well, we visited a pet shop, but couldn't find anything as small and smart as this adorable pup we stumbled up on while searching the Internet for a new, miniat…