Translate

Writing The Software To Control The Raspberry RedBot



18 September 2016


Now that the hardware has been completed and is in place, it is time to start writing the software. When working on a new project I like to take a "Mise en place" approach - that is getting everything organized and in place and ready to go. First I create a Github page for the project and update the Wiki pages as the project progresses. For this project, I created a Github repository called razmq

Next, I identify any additional software packages I might need and install them. The additional software requirements for razmq are identified here

After that, I  write a set of routines to exercise the hardware.- a hardware baseline so to speak. In this way, I am able to verify hardware functionality at any time.

An Experimental Software Architectural Approach

As I have done in several of my previous projects, Python 3 will be used. I believe it is better to look towards the future of the language rather than have to worry about maintaining the legacy of Python 2. 

I will still maintain an asynchronous event driven design approach, however, I would like to simplify things and provide concurrency without the use of either the Python asyncio module or the threading module. To do this, I will be dividing support for a given hardware functionality into 2 separate processes. The first process will present a "user" view of the hardware. For example, for motor control, this process will describe motor motion in abstractions such as direction and speed. These abstractions will be translated into MessagePack messages and then "published" using the ZeroMQ publisher/subscriber pattern. Another process will be created and it will be a subscriber for these messages. It will translate the abstractions into pigpio calls to directly control a motor controller device. In this way, I can maintain an abstract view of the world and swap in specific hardware at any time to implement that abstraction.

To simplify the networking connections between all of these processes, a ZeroMQ forwarder will be used. The forwarder uses a "well-known" IP address/port for all publishers to publish their messages, and another "well-known" IP address/port for subscribers to subscribe to receive messages. There are no configuration files to maintain and each process uses a consistent methodology to both publish and subscribe to messages. To make the coding easier, a base class will be provided to encapsulate many of the ZeroMQ and MessagePack details. This base class can be inherited by the classes that provide either the user or hardware view of the system. 

The experimental part of this exercise is to determine if the memory and CPU utilization is viable while having multiple concurrent processes running.

If this all seems a little abstract, in my next posting I will be describing the details of supporting a simple hardware device, the LED, using these methods. Hopefully that will demystify the described approach. It really is simpler than it sounds and provides a very flexible development environment.

Until next time ....
9 September 2016

It's Alive!

Brain Transplant A Success.

I've successfully replaced the original Arduino based processor board that comes with the RedBot with a Raspberry Pi 3.

It looks like a chaotic mess of wires, but is actually quite organized, and no GPIO pins were harmed in the process. A Pi Ez-Connect was used so that I can easily remove the Pi and use it in another project at any time. All solder connections were made on a solderable breadboard, so the Ez-Connect can be reused as well.




All of the original RedBot connectors were maintained so that the Arduino board can be restored if need be. The new brain supports all of the original features:
  • Dual Motor Drive
  • Encoders for each motor
  • Left and right mechanical bumpers.
  • On board LED.
  • On board push button switch
  • Piezo buzzer
  • Line followers
  • Accelerometer
In addition a 5 volt regulator was added to keep the Raspberry Pi 3 happy for as long as possible when running on battery power.

Current limiting resistors were also added to the bumper and push button switches. This helps protect the Pi's GPIO pins.

All in all, I am quite pleased with the outcome. 

Next up, the software!

2 September 2016

I'm Back!


I haven't posted anything in a while and thought would do a quick post about what I have been up to and what I will be posting about in the coming days and weeks.

I have been working on replacing the Arduino based controller board on my RedBot with a Raspberry Pi. Yeah, I know, RPi based robots are nothing new and maybe even boring at this point in time, but my focus has always been on software, and a RedBot with a Linux powered brain gives me the perfect platform for me to try out my software musings.

Whatever happened to Wire Wrapping?            #bringBackWireWrap

Back in the late 1970's, when I did a lot of hardware prototyping, a prototyping technique that was all the rage was wire wrapping. It seems to have disappeared off the face of the earth and I have no idea why. For those not familiar with this technique, it predated wireless breadboards and allowed one to connect components together without soldering. You simply placed a wire wrap terminal or socket on a perf board, and then using a special tool, wrapped a lead around the terminal. The connection was easy to make, easy to remove, and gave great conductivity. Here is a picture:


There is a great article on makezine.com about the technique.

Now don't get me wrong, for quick a proof of concept, a wireless breadboard can't be beat, but when it comes to actually building a board that is not a printed circuit board, transferring the prototype to working design can be a challenge.

For the RedBot Raspberry Pi brain transplant, I decided to use a solder-able breadboard. Sounds like a great idea in theory, and I am using it, but for my needs it is far from perfect. First, you need to solder. The solder holes are getting smaller and my eyes are getting weaker - not a great combination. When I first started prototyping back in the vacuum tube days - 100 watt irons, massive connectors with equally massive connection points, which were all the rage, soldering was really simple. Not so today.

Also, using a wireless breadboard layout is not ideal. There is a lot of wasted real estate on the board to accommodate the connection redundancy. Again great when testing out a design or creating a temporary one, but horrible for a real world permanent solution.

In addition, I am a software guy. When I screw up the software, I rewrite a few lines and fix the problem. When I solder something incorrectly or decide there is a better way to do things, I need to find my solder sucker and pray I don't destroy the board or components.

Wire wrapping alleviated all these problems. It was simple and quick to do and just as easy to remove an errant connection. Sparkfun, Adafruit I am calling on you to  #bringBackWireWrap.

RedBot Brain Surgery


Here is a picture of my creation taken about a week ago. I have since added an LED and push button switch.



I will be connecting to the RPi using a Pi EZ-Connect.



Why a Pi?

The Raspberry Pi 3 is a cost effective platform for me to play with. First it offers a mainstream Linux OS (Debian). It has integrated WiFi and bluetooth, a fairly hefty 4 core processor, and plenty of room for additional software on the SD card.

The stability of the Pi, and its community support in my opinion, is unsurpassed. 

Using a Pi allows me to write everything in Python 3, my language of preference.

GPIO Support

I have selected the pigpio library to be the basis of low level GPIO control. This may be controversial, but I think pigpio is the best RPi GPIO control library available for Python. It supports Python 3 (as well as 2), is actively supported by its author (joan - your the best!), and its API is concise and simple to understand (even for a simpleton like me.)

RedBot Supported Features and Hardware Improvements

I will be maintaining the features of the Arduino based RedBot. I decided not to reuse the RedBot accelerometer board since that device requires a fairly complicated i2c solution. Instead, I am using the ADXL345, which allows for much simpler software.

By creating my own interface board, I also added some hardware "improvements". For example, I have added current limiting for both the push button switch and bumpers.

ZeroMQ Pub/Sub Based software Modules

The software will revolve around a ZeroMQ Pub/Sub communication pattern. This effort will not be using Python asyncio, but instead a simpler multi-process approach that uses custom protocols implemented in MessagePack- stay tuned and all will be revealed. 

A Kivy GUI

Eventually, when all else is working I will be implementing a Kivy based GUI. Kivy is a Python based GUI library that I found compelling both visually and from a programming standpoint.
Currently, I have Kivy working with ZeroMQ for the PC.


Kivy comes with a sophisticated tool called Buildozer, that ports the GUI to an Android .apk file.
Unfortunately, I have not been able to get ZeroMQ and Buildozer to play nice together. Hopefully that will be solved in the near future. 

More To Come Later ...