Differential Drive

KD01 Side View

This is the first in the multi-part series about the KD01 Robot ( 1 | … ).

As I described in my series of posts on the KR01 robot, I got back into robotics after watching a YouTube video of the DPRG‘s David Anderson demonstrating his robots, talking about the details of their design and how they work. I’m very happy to say that David and I are now friends and he’s been mentoring me and answering some of my more tedious questions with the patience of a very good teacher.

The basic design of a differential drive robot

The KR01 robot uses a motor controller running a pair of motors on the port side and a pair of motors on the starboard side. The motors are wired up in parallel, so the four motors are treated (electrically) like a single pair of motors. But performance-wise they don’t act like two motors.

If I program the KR01 to rotate in place, how it performs depends a lot on what surface the robot is on, as with four motors the robot relies upon the slippage of its black silicon rubber wheels to permit it to rotate at all. And how the robot’s weight is distributed influences which wheels slip and which don’t. On a relatively sticky surface like a wood floor the KR01 visibly shudders as it tries to rotate in place. If it rotates continually it tends to move randomly across the floor.

All of this is due to those four wheels, which provide a lot of stability and are great for four-wheeling out on my front deck, but not so great for precise navigation, or rotating in place. The solution for this is a different robot design, called a differential drive robot.

At about 2:30 in David’s video he says:

“The advantage of differential drive is a zero turning radius. Zero turning radius is what we humans have, so if you want to build a robot that can run around in the same space as humans run around in, it’s a useful thing to do. And that means we can turn around pretty much in our own space. There’s some tremendous advantages to being able to do that. It greatly simplifies your navigation software if you don’t ever have to back up.”

David Anderson’s SR04 robot
(image used with permission)

The other part of the design requirement for a differential drive robot in being able to turn in place is that the full extent of the robot fit within a circle, with its tail wheel placed on the perimeter of that circle. If the tail wheel or the robot frame extends beyond that circle the robot won’t be able to turn in place without bumping its big bum into something.

Now, I’ll still be using the KR04 for many of my robotics experiments, but I wanted to try out a differential drive robot. I realised the design I now had in my head looked remarkably like something I’d seen before. David’s robots are typically differential drive designs, such as his SR04, the robot that inspired me to start building robots again, and it now seems a bit like the older brother to my new robot, which I’ve dubbed the KD01, where the “D” is for Differential. I stilll can’t think where the “K” came from…

KD01 Requirements

So in addition to desiring a differential drive robot, I thought the new robot should be able to re-use wherever possible the existing ideas, components and parts from the KR01, including its motor controller and drive train: the OSEPP 9V 185rpm motors, annodised aluminum wheels, silicon rubber tires, and Hall effect motor encoders. As the encoders are designed to be mounted on the same beam as the motors, this entailed even the same OSEPP/MakeBlock chassis components.

The KR01 and KD01 drive train showing motors and Hall effect motor encoders (click to enlarge)

The KR01’s four motors and four wheels permit a substantial carrying capacity, but its Makita 18v 6.0Ah power tool battery weighs 760g (1.7lb.). By comparison, the KD01 without batteries weighs 1525g; having a battery weight half that of the robot seems a bit extreme. Also, two drive wheels and half the number of motors doing all the work suggested something a bit lighter, perhaps the Makita 12v 2.0Ah power tool battery, which weights a 263g, some savings in both weight and size.

The Integrated Front Sensor

The KR01’s Integrated Front Sensor (IFS) supports five Sharp 10-150cm analog infrared sensors and three pairs of small lever switches attached to a clear polycarbonate plastic bumper. I definitely didn’t want to have to build this another time if I could reuse it.

To be able to mount the IFS requires chassis compatibility with the KR01. Thankfully this is simple, as the IFS is attached to the front of the robot with two 5mm stainless bolts and to the Raspberry Pi via a single five-wire I²C connector. With this hardware compatibility I can transfer the IFS between the two robots and use much of the same sensor software I’ve already developed. All this will save me a lot of time and trouble. Re-use is good.

The overall design is based around the existing drive train, with its 18cm (~7 1/8″) wheelbase.

I thought about buying a fancy German-made caster, but decided to build my own from a spare OSEPP wheel mounted with some the roller bearings (that came with their tank robot kit) to a commercial caster swivel mount, even using a pair of chrome guitar strap buttons as spacers. The end result is quite tall, but means that the KD01 will use three wheels of the same size, no small back caster that might reduce the floor clearance.

The tall back caster required a stepped platform with enough clearance for the caster to swivel 360 degrees. With the battery mounted just slightly behind the wheel axis, just getting everything onto the robot platform was a challenge. I ended up locating the ThunderBorg motor controller and the board holding the connections to the encoders underneath the battery, with the Raspberry Pi at the back of the robot, as was done with the KR01.

With all that I took to paper. Design is largely juggling all the requirements and constraints. and this was no exception.

The KD01 Differential Drive Robot

Things came together pretty quickly once I’d finalised the design on paper. I cut the two chassis pieces out of 3mm black Delrin plastic, using L-shaped aluminum for other parts of the frame and to provide a bed for the battery above some of the electronics.

The boards are held together using 3mm Lynxmotion anodised black aluminum hex standoffs. These are lightweight and strong, and permit the robot to be disassembled easily. I’ve been using M3 (3mm) stainless nuts and bolts for pretty much everything now.

The KD01 from above

The photo above shows the Raspberry Pi 3 B+ and a Pimoroni Breakout Garden hat at the rear (left), the Integrated Front Sensor at front (right), and the PiBorg ThunderBorg motor controller underneath where the battery sits. It’s currently sporting an Adafruit BNO085 IMU on a sparkly red nylon mast (made from a cutting board), and another Adafruit FXOS8700+FXAS21002 IMU mounted on a small black breadboard, affixed to the robot using small velcro dots. I’m currently doing some experiments with two IMUs. I also decided it was helpful to have a tiny Adafruit 135×240 Mini Pi TFT display screen as I had one in my inventory, so this was mounted on a 3mm Lynxmotion standoff using some bits of L-shape aluminum to provide a 3D swivel adjustment.

While the drive wheels and caster fit within a 212mm circle, the Integrated Front Sensor does extend outside of the circle, but not by much. This does mean that rotating in place could potentially catch the edge of the polycarbonate bumper on something as the robot turns. David’s SR04 is similar in this regard. He solved this in a later robot called the RCAT, which uses a curved plastic front bumper that fits within the extent of that circle. A great design.

Rotate in Place

Well, how did we do mechanically? I took the robot out onto the front deck and tried it out with a rotate-in-place.py test. On the deck the robot’s wheels hitting the spaces between its boards seemed a distraction, so I tried it again on a piece of smooth particle board. The result was posted to the NZPRG YouTube channel:

A Problem Exposed

Running a test sometimes exposed other problems. This was evident when running the KD01’s port wheels counter-clockwise: the encoder outputs were way out of range. Normally (such as on the two encoders of the KR01 or the starboard encoder of the KD01) there’d be almost exactly 494 steps per wheel rotation, but the port encoder on the KD01 was registering an inconsistent 337-342 steps per rotation but only when running counter-clockwise. I pulled out the trusty ol’ Iwatsu oscilloscope and wired it up to the encoder outputs with the robot on the bench.

Hardware debugging using the Iwatsu SS-5710 (circa 1991)

The only thing that seemed obviously different about this encoder is that the offset between the A and B waveforms’ falling edges was very close together.

The A and B waveforms before (left) and after (right)

In the image on the left you can see that the distance between the falling edge of the A (top) and B (bottom) waveforms almost coincides. This means that when the quadrature measurement occurs, the alternate waveform may not be in its opposite state and the tick count won’t change. On the other three encoders the two waveforms are significantly more offset.

It’s good to have some friends with experience. In this case, on today’s video conference with the DPRG I asked Carl, Doug, David and the other experts and they totally knew the problem was with that offset, or the lack thereof.

So I turned the KD01 upside down, pulled the little disk magnet off of the motor shaft, and very very carefully bent one of the tiny three-wire encoder sensors very very slightly, maybe a tenth of a millimeter. While its distance to the magnet seemed okay, it wasn’t quite parallel with the surface of the magnet. I then put everything back together, wired things up again and guess what? That fixed it. The image on the right shows the waveform after the adjustment. The offset between the two waveforms is now almost exactly 90 degrees, and the edge transitions now occur a long way from each other.

To check, I hand-rotated the port and starboard wheels while counting the encoder ticks with my motors_test.py program. The port encoder now turns -4941 ticks over ten clockwise turns of the wheel, and +4939 ticks over ten counter-clockwise rotations. Or 494 ticks per wheel rotation in either direction.

Success!

Big Things in Small Packages

Nuvoton 8051 NuTiny
The Pimoroni IO Expander, which uses a Nuvoton MS51 as its controller

My exposure to the Nuvoton MS51 microcontroller came about due to its use in a number of Pimoroni Breakout Garden products, initially their IO Expander board, which provides six PWM/digital and eight analog IO pins, programmed using a Python library on a Raspberry Pi using a single I²C connection. Very handy.

Part of this exploration has been mere curiosity about the MS51, which is essentially a 1980s-era technology still being used almost 40 years later. The Nuvoton MS51 is an MCS-51/8051-compatible microcontroller, using the same 8 bit architecture.

The bright red board shown at the top of the post is a bit misleading as it’s actually two boards: on the right is a USB linker board, which is used to connect to and program the MS51 microcontroller, which is on the left. These two boards can be cut apart and reconnected via the 10 pin connectors you can see in the middle. Many of the Nuvoton boards have made this even easier by perforating down the center so they can be easily broken apart. The MS51 processor itself is on the left side, that small surface mount black thing surrounded by pins labeled Nuvoton N79E85JALG, actually 4x6mm. On the IO Expander the MS51 processor is only about 3mm square. More on size below.

VL53L1X
(~3x mag.)

Now, I’m quite happy with continuing to program my robot in Python and wouldn’t want to go back to either C/C+ or assembly language, the latter I last touched in about 1981. But in my conversations with the DPRG we’ve talked about distributed processing for robots, that is, using something like a Raspberry Pi as a main brain, distributing the sensor and control tasks to various sub-processors. In a recent conversation this was likened to an octopus, which apparently has about two-thirds of its 500 million neurons in its arms. The sensor boards are generally small — about the size of a postage stamp — but the sensors on these boards often themselves also have a built-in microcontroller, like the ST VL53L1X, a Time-of-Flight sensor that’s about 5×2.5mm.

Last year Pimoroni released a pair products that internally use the MS51, both RGB LED knob controllers, a RGB Encoder and RGB Potentiometer. Recently they even added another MS51 implementation, a tiny Super Dinky Blinky (an LED blinker), even providing a github link with instructions on how to hack/reprogram the device. So it’s clear Pimoroni have some engineers on staff who like the MS51 as a general-purpose microcontroller.

The Pimoroni RGB Encoder, also using an MS51

Back in October 2020 I sent a message into the Pimoroni online forum regarding the use of the Nuvoton MS51 microcontroller on their IO Expander Breakout Garden board, asking if they might help me figure out how to hack it.

Well, nobody answered so I checked out the Nuvoton website and found a plethora of development boards, using ARM Cortex M0, M4, M23 and 8051-compatible processors in “Tiny” and “Maker” (Arduino UNO style) form factors. There’s also a suite of development tools.

Pimoroni Super Dinky Blinky, another MS51 implementation

It looks like both their hardware and software is quite well-documented, with a lot of PDFs on site. Each board is provided with a hardware specifications and information on their Software Development Kit or SDK (e.g. the one for the board shown at the top of this post, the NuTiny-SDK-N79E715). The Taiwanese-English is pretty good, and their product line looks to be very extensive. Not a small company.

Some of the Tiny-style boards are truly tiny, and their Maker-style boards (e.g., NuMaker-PFM-M2351) look like nice Arduino replacements, e.g., 64MHz, operating voltage 1.6-3.6v, memory up to 512kb RAM/ 96kb SRAM. Lots of pins and an UNO-compatible USB link connector. Even an on-board Wifi module. Like Arduinos, the processors themselves are typically surface-mounted but are also available in DIPP packaging should someone want to experiment with one on a breadboard.

A Nuvoton NuMaker MS51 board, pin-compatible with Arduino shields. The USB linker board is on the right.

The ARM Cortex-based processors would be Arduino-like, whereas the 8051 boards (e.g., NuTiny-N76e616) use the MS51/8051, back-to-the-future of the 1980s. Everything looks to be about US$25.00.

Software Development on the MS51

The link to the list of Nuvoton development tools includes IDEs for all of its Cortex M0/M4/M23 and 8051 controller boards. This does actually include a customised version of the Eclipse IDE called NuEclipse, with distributions available for both Windows or Linux. It’s based on a rather old (2015) version of Eclipse “Mars” but seems functional.

I downloaded and installed NuEclipse for Linux, which seems to be Eclipse customised for C/C++ development, comes with a GCC OpenOCD installer, code support for the 60-odd boards Nuvoton sells, user manuals and some sample files.

There are also three KEIL IDEs: one for US$395, one commercial, one free for the Cortex controllers, and two different IAR IDEs for the M0/M4/M23 and 8051 processors, resp. I downloaded the free version but it unfortunately won’t run on the only Windows machine I have available.

As I’m mostly interested in the 8051 I went to the IAR site, searched for the NuTiny-N76E885 board (which is currently on 90% discount for US$2.50!), then downloaded the IAR EW8051 Embedded Workbench IDE, available for either a free 30 day trial or a 4K code size-limited installation. When you first open the IDE you have a choice of registering online for the Evaluation Copy. It won’t operate until registered.

On starting the IAR IDE it looks a bit like an older, customised version of Eclipse, but basically functional. It doesn’t seem like there’s any way to connect it to the Pimoroni IO Expander that uses the Nuvoton MS51, so if I want to further investigate I’ll have to consider getting one of the Nuvoton controller boards.

I’ve also contacted their sales department to see about the price for purchase of the IAR IDE for a quantity of one. The installer included a “dongle driver” so I’m hoping they don’t use dongle-based license management (yuck). At least for the trial license there’s no dongle. If the commercial price of the KEIL IDE ($395) is any indication, the IAR one might be rather expensive. I hope to get a quote from their sales rep, otherwise I’ll be limited to 4K code files.

A Brief Review: Size Matters

I won’t pretend to be thorough here, as I don’t want to be unfair to Nuvoton. I received my order for the Nuvoton Tomato and NuMicro 8051 NuTiny boards. I also received a Nuvoton NuMaker-RTU-NUC980 Chili (on sale for US$14.50) which I may write about in the future.

This might have been a case where I hadn’t read the specifications very clearly, except there wasn’t anything specific on the product pages about size. One looks at photos online that don’t have a coin or a hand next to them for context and makes assumptions. My first impression on opening the packages is that the Nuvoton boards are hardly “tiny”. They seem overly large, with lots of empty space. Apparently the Nuvoton designers didn’t think size matters.

Clockwise from top left: Nuvoton Tomato, Raspberry Pi 3 B+, Itsy Bitsy M4 Express, Nuvoton 8051 NuTiny

The Nuvoton Tomato uses a single-core 32-bit ARM926EJ-S NUC976DK62Y microprocessor with a clock speed up to 300MHz. The ARM926EJ-S is circa-2001 technology, no longer under active development but still used in industry. By comparison, the circa-2016 Raspberry Pi 3 B+ has a much beefier four-core 64 bit ARM BCM2837B0 Cortex-A53 microprocessor running over four times faster at 1.4GHz. The Tomato is targeted at the Internet-of-Things (IoT) market, is a low-power device and has an embedded Linux OS which apparently has an optimised Java JVM. It also has the connectors to allow an Arduino shield to be plugged onto the top of it. Nice. It’s probably not fair to compare the Tomato and the Raspberry Pi. Apart from what’s on the boards, it’s impossible to ignore the fact that the Tomato is big at 67x120mm. But if I were thinking of building a Linux-based, Arduino-compatible robot using Arduino shields (like the Adafruit Motor/Stepper/Servo Shield), I’d certainly give it a whirl. It’s an interesting hybrid.

The bigger surprise was the 8051 “NuTiny”. Bad name really; it may be “Nu” but it’s by no means Tiny. The board is comprised of two parts: the 8051 processor board and a Nu-Link-Me (the Nu pun wears off quickly) board that’s used to connect and program the 8051 processor. But even with the Nu-Link-Me board broken off the 8051 board itself is still 35x52mm, compared with the Itsy Bitsy M4 Express at 18x36mm. If for convenience’ sake we leave the boards together the NuTiny is wider than a Raspberry Pi. Whereas the 8051 CPU chip is only 4x6mm (about half the size of the Itsy Bitsy’s ATSAMD51), the carrier board is over five times the size of the Itsy Bitsy, and doesn’t even come with any mounting holes, despite all that wasted PC board space. A bit of a shame, really. None of this hardly disqualifies it from use on a robot. And I am interested in playing with the 8051 processor, if doing so isn’t too inconvenient.

Summary

As I mentioned above, I have no plans to build a robot based upon one of these microcontrollers, though that’s perfectly feasible and indeed a pretty common approach. I’m mostly interested in distributing my robot’s tasks to sub-processors, with the Arduino compatibles (including Tiny, Trinket, Feather, Particle, Itsy Bitsy, etc.), the MS51-based Pimoroni IO Expander, and potentially any of the Nuvoton ARM Cortex or MSS51-based development boards are all suitable contendors for that purpose.

Odometry on a Mecanum Robot Using an Optical Flow Sensor

While I’ve lately been mostly focused on my KR01 robot, I’ve also been planning a Mecanum-wheeled robot to be called the KRZ02. I long ago decided my robots would incorporate odometry, counting the rotations of each motor in order to track the robot’s location. This is accomplished by either an optical or Hall-effect encoder connected to the left and right motor shafts. On the KR01, since I know the gear ratio of the motor, the size of the wheel (and that it travels 218mm per rotation), and that the encoder sends 494 steps per rotation of the wheel, I can calculate there’ll be 2262 steps per meter.

To be honest, I didn’t actually come up with such a formula but simply measured this by repeatedly having the robot move exactly one meter forward. In science this is called an observation. Observing is generally easier than calculating, but is still a valid means of finding things out. You can make calculations without having a robot, but if your calculation (the model) is flawed or incomplete it won’t be accurate, whereas careful observation of the robot while in the actual working environment can be quite accurate. My guess is that if I had gone to the trouble to develop an odometric formula I wouldn’t have ended up with a value of 2262 steps per meter, as somewhere in the mix a concrete, physical system often introduces variables that haven’t been accounted for in the model.

But back to the point. With knowledge of how many steps the motor encoders return I can calculate both the velocity and distance traveled for each motor, and therefore with a reasonable degree of accuracy where the robot is located from its starting location. David Anderson of the DPRG has made odometry into a fine art, and his robots can travel great distances in both complex indoor environments and even across difficult terrain up in the mountains and return to within inches of their starting locations. I find David’s work very inspiring.

But all this clever odometry falls apart when using Mecanum wheels, which have a series of rubber rollers that each have an axis of rotation at 45° to the wheel plane and at 45° to the axle line.

A Mecanum wheel with micro metal gearmotor and built-in Hall-effect encoder.

Whereas a traditional wheel translates its energy to the ground in a rather predictable way, the rotation of a Mecanum wheel interacts in complex ways with the other Mecanum wheels. I’m sure there’s a mathematical formula for this, one that would involve the direction and rotational velocity of each wheel, the total weight and weight distribution of the robot, the hardness of and therefore how much of each roller is in contact with the ground, the traction and rolling friction of the wheel rollers, the friction due to contact with the ground, roller slippage, and probably another half dozen unknowns. Call me lazy but my life is too short to even consider trying to create that formula and develop sensors for the various parameters of that equation. And we’re back to that abstract model versus concrete observation issue. If the goal is accurately tracking the robot’s movement over the ground (odometry), then we need to come up with another method.

Flying drones can’t do motor-based odometry but instead use a specialised camera called an optical flow sensor, something we might call a camera-as-sensor. An optical flow sensor’s camera looks down at the ground, generating a series of image frames, calculating the distance the drone has moved across the landscape by tracking the differences in position between image frames. This is returned as an x,y value at the frame rate of the camera. With both a GPS unit and a LiDAR providing a distance to ground measurement it’s possible to accurately perform odometry in mid-air.

PMW3901MB-TXQT
2x actual size

Now, my robot lives on the ground but there’s no reason we can’t try a similar trick. The actual sensor I’m using is from PixArt Imaging, designated the PMW3901MB-TXQT, and is all of 6 x 6 x 3 mm in size, using 6 milliamps of current. That’s including the camera and all of the electronics. This reminds me of the sensor used in the VL531LX Time of Flight sensor, which is a LiDAR the size of a grain of rice.

These sensors are generally sold on a carrier board so that they can be integrated into a commercial or hobbiest application. The carrier board I’m using is from Pimoroni, called the PMW3901 Optical Flow Sensor Breakout, part of their Breakout Garden series of sensors. The cost is about what we pay for two meals at a local Indian restaurant. You can solder a 7 pin header to the carrier board or simply plug it into an SPI socket on a Breakout Garden board.

The Pimoroni PMW3901 Optical Flow Sensor SPI Breakout

The PMW3901 has a frame rate of 121 frames per second and a minimum range of about 80mm. I’m hoping to mount it looking down from the underside of the robot’s upper board, which will be just above that 80mm minimum. The problem is twofold: how to provide the sensor’s camera with a clear view of the ground, and how to mount it in the center of the robot. This is necessary so that when the robot rotates around its center the sensor won’t register any absolute movement, just a rotational theta.

On the KRZ02 I’m using 48mm Mecanum wheels made by Nexus Robot. They’re a high quality steel framed wheel with some rather solid brass hubs and a load capacity of 3kg. When mounted on a Pololu Micro Metal Gearmotor the bottom of the robot’s 3mm thick Delrin plastic lower board is 30mm from the ground. This means the PMW3901 needs to be at least 47mm above that board.

I built a test rig frame out of a cheap nylon chopping board. A photo of the rig can be found at the top of this post. This holds the PMW3901 at a distance of 90mm from the ground, looking through a 50mm hole cut into a lower board. 50mm is the biggest hole cutter I have:

I used a Raspberry Pi Zero W and wrote a Python library and test file. In the test, the PMW3901 sensor returns positive and negative x and y values as it senses movement. Based on those values I’m setting the RGB LEDs to red for a movement to port, green for starboard, cyan for forward and yellow for aft/reverse.

The 5×5 RGB Matrix used to indicate direction.

My initial tests quickly proved faulty. The white plastic of the cutting board was providing all sorts of reflections of ambient light as well as the PMW3901’s illumination LEDs, and this confused the sensor to no end. Even at rest it would be indicating what seemed to be random motion. I taped some black matte paper to the board and this almost entirely eliminated the problem. I won’t be using white nylon on the robot but rather black Delrin plastic, which I can sand to a dull matte finish, so hopefully this will be sufficient. If not, there’s a rubberised black fabric used in photography that reflects almost no light.

The following video shows the test rig in operation.

As I noted in the video, the results indicate the test is a success, i.e., mounting a PMW3901 Optical Flow Sensor at about 90mm from the ground can provide odometry information for a ground-based robot.

With this important test out of the way I can now finish the plans and begin building the KRZ02 robot.

Credit where credit’s due: the beautiful fabric you can see in the photos and video is actually a reusable grocery bag designed by one of my favourite New Zealand artists, Michel Tuffery, as part of the Paper Rain Project.

The Four Corners Challenge

This is just a little ditty that I will update as things progress. It comes about from conversations on the DPRG mailing list about one of their commonly held robot contests, called the Four Corners Competition. Here’s the actual definition from April of 2018:

Objective: The robot will travel a rectangular path around a square course. The corners of the course will be marked with a small marker or cone. Before the robot makes its run, a mark or sticker will be placed on the center front of the robot and on the floor of the course. The objective is to minimize the distance between the two marks at the end of the run.

David Anderson pointed out that this contest goes back to a 1994 University of Michigan Benchmark (called UMBmark), “A Method for Measuring, Comparing, and Correcting Dead-reckoning Errors in Mobile Robots“, developed by J. Borenstein and L. Feng. As David describes it, the “concept is to drive around a large square, clockwise and counter-clockwise, while tracking the robot’s position with odometry, and stop at the starting point and measure the difference between the stopping point and the starting point. This shows how much the odometry is in error and in which direction, and allows calibration of the odometry constants and also the potential difference in size between the two wheels of a differentially driven robot. The DPRG uses this calibration method as a contest.” He even wrote a paper about it.

Well, I keep maintaining the purpose of my robotics journey is not to engage in competition (and I swear that I’m not a competitive person, I’m really not, no I am not), but I do think that this benchmark is a good exercise for fine-tuning a robot’s odometry. Nuthin’ to do with competition, nope, just a challenge.

The key to this challenge seems to be twofold: 1. getting the odometry settings correct; and 2. being able to accurately point the robot at that first marker. As regards the latter, the contest permits the robot to be aimed at the first marker using any method, so long as the method is removed prior to the contest starting. Over the years various approaches at this have been tried: ultrasonics, aiming the robot using a laser pointer, etc. I tried creating a gap between two boards and seeing if my existing VL53L1X sensor could see the gap, but then realised its field of view is 27°, so it’s not going to see a narrow gap at a distance of several meters. I then contemplated mounting a different, more expensive LiDAR-like sensor with a 2-3° field of view, but at 8-15 feet (the typical size of the course) that’s still not accurate enough.

Tactical Hunting Super Mini Red Dot Laser

This challenge has somehow lodged itself in the back of my head, the buzzing sound of a mosquito in a darkened bedroom. As I may resort to aiming the robot using a laser pointer I’ve put in an order from somewhere in China for a tiny “tactical hunting super mini red dot laser” (which kinda says it all). I’ll in any case definitely install the tactical hunting super mini red dot laser just ’cause it will look so cool and dangerous. But a laser pointer feels a bit like cheating: it’s not the robot doing the hard work, it’s like aiming a diapered, blindfolded child towards grandma’s waiting knees and hoping she makes it there. Hardly autonomous.

A Possible Solution: The Pi Camera

I’ve been planning to install a Raspberry Pi camera on the front of the KR01 robot for awhile, and since I was going to have a camera available I thought: heck, the robot will be at very least facing that first marker, so why not use its camera to observe the direction and let it try to figure its own way there? No hand-holding, no laser pointer aiming, no diapers, no grandma. Autonomous.

The Pink LED

So what would I use for a target? How about an LED? What color is not common in nature? What color LED do I have in stock? Pink (or actually, magenta). So I mounted a pink LED onto a board with a potentiometer to adjust brightness, using a 9 volt battery for the power source. Simple enough.

The Raspberry Pi camera’s resolution is 640×480. I wrote a Python script to grab a snapshot from the camera as an x,y array of pixels. I’m actually processing only a subset of the rows nearer the center of the image, since the robot is likely to be looking for the target of the Four Corners Challenge somewhat near the vertical center of the image, not closer to the robot or up in the sky.

The Four Corners Course with target LED at the 1st corner

I found an algorithm online to measure the color distance between two RGB values. The color distance is focused mostly on hue (the angle on the color wheel), so if that particular pink is sufficiently unusual in the camera image, the robot should be able to pick it out, regardless of relative brightness. I took a screenshot of the camera’s output, opened it up in gimp and captured the RGB color of the pink LED. I avoided the center of the LED, which showed up as either white (R255, G255, B255, hue=nil) or very close to white, and instead chose a pixel that really displayed the pinky hue (R151, G55, B180, hue= 286).

For each pixel in the array I calculated the color distance between its color and that of our target pink. To be able to see the results of the processing I then printed out not the pixel array of the original image but an enumerated conversion of the color distance — just ten possible values. So magenta is very close, red less close, yellow even less, et cetera down to black (not close at all). So the image is what we might call a “color distance mapping”. I just printed out each row to the console as it was processed, so what you’re seeing is just a screen capture of the console, not a generated image.

What the Rasbperry Pi camera sees (click to enlarge)

My first attempts were of just the LED against a dark background, enough to try out the color distance code. Since that seemed to work I tried it against a much more complicated background: the bookcase in my study (see photo). The distance from the camera to the pink LED was about 2 meters. Despite several objects on my bookcase being a fairly close match to the LED’s color, things seemed to still work: the LED showed up pretty clearly as you can see below:

The LED can be seen in the upper left quadrant on the bookcase shelf (click to enlarge)

That object just to the left of the LED with the 16 knobs is a metallic hot pink guitar pedal I built as a kit a few years ago. There’s another guitar pedal that same color on the shelf below. There’s enough difference between that hot pink and the magenta hue of the LED that it stands out alone on the shelf. Not bad.

Outdoors Experiments

So today, on a relatively bright day I tried this out on the front deck. There was a lot more ambient light than in my study and I was able to set the LED a full 3 meters (9 feet 10 inches) from the front of the robot. How would we fare in this very different environment?

The view from the robot

The 3mm LED I’d been using turned out to be too small at that distance, so replaced it with a larger pink LED and turned up the brightness. Surprisingly, the LED is clearly visible below:

This is a pretty happy result: the robot is able to discern a 5mm pink LED at a distance of 3 meters, using the default Raspberry Pi 640×480 camera. This required nothing but a camera I already had and less than a dollar’s worth of parts.

The Python code for this is called pink_led.py and is available in the scripts project on github.

Next step: figure out how to convert that little cluster of pixels into an X coordinate (between 0 and 640), then using that to set the robot’s trajectory. It could be that converting that trajectory into a compass heading and then following that heading might get the robot reliably to that first course marker.

But I’m still going to install that tactical hunting super mini red dot laser.

We’re Goin’ Mecanum!

Not that I’ve spent much time with my KRZ01 robot. I feel almost bad that I haven’t let the project develop much before making some significant changes. Like that high school girlfriend with braces.

Mecanum wheel with micro metal gearmotor and built-in rotary encoder

It’s just that my main project, the KR01 robot, is where I’ve been devoting most of my time and energy, and the KRZ01 isn’t frankly that different, despite being rather petite: about 1/4th the size and 6% of the weight (160g with its battery). Both are wheeled robots intended to operate using the Robot Operating System (ROS) I’m writing in Python.

So what made the KRZ01 the target of a redesign was the purchase of four Mecanum wheels. This post describes the beginning of this project — I’m only at the design stages right now.

What are Mecanum Wheels?

There’s a lot of descriptions (e.g., the YouTube video below) and demonstrations of Mecanum wheels on the web already (such as a Turkish Mecanum forklift!) so I won’t go into much detail here, suffice it to say that they allow a robot to travel in any direction without changing its compass heading. Well… not up or down. But crab travel, sure.

Just to mess with your head I’ll quote the description of how they work from the Wikipedia page on Mecanum wheels:

  • Running all four wheels in the same direction at the same speed will result in a forward/backward movement, as the longitudinal force vectors add up but the tranverse vectors cancel each other out;
  • Running (all at the same speed) both wheels on one side in one direction while the other side in the opposite direction, will result in a stationary rotation of the vehicle, as the transverse vectors cancel out but the longitudinal vectors couple to generate a torque around the central vertical axis of the vehicle;
  • Running (all at the same speed) the diagonal wheels in one direction while the other diagnoal in the opposite direction will result in a sideway movement, as the transverse vectors add up but the longitudinal vectors cancel out.

That kind of talk totally does my head in, but the concept obviously works, so I’m on board. When I get to the point of programming the motor controller for this I’m sure I’ll need a couple shots of good bourbon to focus my mind appropriately to the task.

The “Before” Photo (click to enlarge)

There are some design considerations regarding Mecanum wheels, and both David Anderson’s advice and my own experience with the KR01 suggest that I want the robot as balanced as possible, both in terms of weight and the position of the wheels relative to the center of the robot. With Mecanum wheels, weight distribution is even more critical than on a normal wheeled robot. Having too much weight on one wheel would significantly alter its behaviour, and not in a good way.

The Plans

So I have been planning this out. I can’t actually build anything just yet because I stupidly only bought two of the brass wheel hubs rather than four (“there were two in the photo” he says in his defense), so I’m waiting on another shipment from Canada.

Because it will be a fundamentally different robot the redesign will be called the KRZ02.

My plan for a Mecanum-equipped KRZ01 robot (click for larger view)

Update as of 2020-05-12: That first plan had a glaring error, in that while the centers of the wheels were on the circumference of a circle, that hardly meant they were equidistant, meaning their centers would fit on the four corners of a square. I’d drawn the diagram wrong. I tried a second time, this time also moving the motors as close towards the center of the robot as I dared, and including the positions of the Raspberry Pi Zero W, the two Picon Zero motor controllers, the Pimoroni Black Hat Hack3r expansion board, and the Breakout Garden Mini to hold one SPI and two I²C sensors . The robot got bigger but also more symmetrical. Witness version 2:

KRZ01 Mecanum Plan Plan 2

One thing seems pretty clear at the outset: the current KRZ01 has two “moon buggy” wheels and a ball caster, and its physical extent (i.e., how much space it takes up) is a circle 128mm in diameter — it’s a small robot. Plan 1 expands that to 210mm. Plan 2 above expands that extent to 227mm, almost double in size. It looks like it’d be a much larger robot than the KRZ01. Plan 1 used a 75mm chassis width, which is the current width of the KRZ01. Plan 2 has the motors as close together as seems reasonable but by fixing my design “bug” the robot is almost as big as David Anderson’s SR04 at 11″ (280mm). Not a small robot anymore.

I discussed the issue of symmetry with the guys at the DPRG and it seems that weight balance is critically more important than symmetry. I’m not happy with the Plan 2 being such a big robot, and from the plans there seems to be a fair bit of wasted space (i.e., it’s a lot longer than is strictly necessary) so I think I might try a third, shorter design.

More later…

Facilius Est Multa Facere Quam Diu

KR01 obstacle avoidance

This is another article in the series about the KR01 robot.

The title translates as “It is easier to do many things than one thing consecutively“, attributed to Quintilian, a Roman educator about two thousand years ago. It sounds curiously like a motto for either multi-tasking or multi-threaded processing. But also for how I’ve approached designing and building the KR01 robot.

One thing I’ve learned about building a robot is that, at least for me, the hardware and software is ever-changing. I guess that’s what makes the journey enjoyable. In my last post I ended up with too much philosophising and not enough about the robot, so this one makes up for that and provides an update of where things are at right now.

But before we get into the hardware and software I thought to mention that I’ve been quite happily welcomed into the weekly videoconferences of the Dallas Personal Robotic Group (DPRG) and about a week ago did a presentation to them about the KR01:

The DPRG is one of the longest-standing and most experienced personal robotics club in the US, with a great deal of experience across many aspects of robotics. They’re also some very friendly folks, and I’ve really been enjoying chatting with them. New friends!

Hardware

So… the biggest issue with the KR01 was imbalance. There was simply no room on the chassis for the big, heavy Makita 3.0Ah 18 volt power tool battery so I’d, at least temporarily, hung it off the back on a small perforated aluminum plate.

[You can click on any of the images on this page for a larger view.]

Earlier design: the black platform at the aft end held the Makita battery

The KR01 without a battery weighed 1.9 kilograms (4 lbs 3oz), so at 770 grams (1 lb 11 oz) the Makita battery and its holder comprised about 40% of the the robot’s total weight. By comparison, my little KRZ01 robot weighs 160 grams, including the battery. Since that photo was taken the robot has gained a bit of weight, now up to 2.1 kg. But that imbalance remained.

With the battery hanging off the back, when trying to spin in place the KR01 would typically sit on one back wheel and rotate around that wheel, but which wheel was almost arbitrary. I’d kinda knew something like this might happen but I was willing to keep moving forward on other parts of the robot (“facilius est…“), because fixing that problem meant making some big hardware changes.

Since I’d gotten to the point where I was actually testing the robot’s movement, I finally needed to bite the bullet and bought another piece of 3mm Delrin plastic. This time I positioned the battery as close to the physical center of gravity of the robot as possible. Then I spent a lot of time reorganising where things fit, as well as finally adding all of the sensors I’d been planning. I think I might have gone overboard a bit. The current design is shown below.

The redesigned KR01 with space for the battery closer to the center of gravity

The copper shielding is my attempt at cutting down on the amount of high-pitched ambient noise put out by the speaker (hidden underneath the front Breakout Garden Mini, next to the servo). This didn’t seem to make much difference but it looks kinda cool and a bit NASA-like so I’ll leave it for now. Yes, the KR01 can now beep, bark, and make cricket sounds. It also has a small 240 x 240 pixel display screen (visible at top center) and two wire feelers to theoretically protect the upper part of the robot, basically an emergency stop. I have no idea how well that will work. The inside of my house is pretty hazardous for a small defenseless robot.

Side view of the KR01 robot’s chassis, showing the power/enable switches and a Samsung 250gb SSD drive lodged underneath

Earlier versions of the robot had a 15cm range infrared sensor for the center, which being digital, replied with a yes or no. It worked as advertised, but 15cm wasn’t enough distance to keep the robot from running into things, even at half speed, so I’ve since replaced it with a longer range analog infrared sensor (the long horizontal black thing in the cutout in the plastic bumper, shown below) that I’ve coded to react to two separate ranges, “short” (less than 40cm) and “long” (triggered at about 52 cm). This permits the robot to slow down rather than stop when it gets within the longer range of an object.

The robot currently has a 15 cm range infrared sensor on each side but I’m planning to replace them with a pair of Sharp 10-150cm analog distance sensors, which hopefully will permit some kind of wall-following behaviour. I’m eagerly awaiting another package in the post…

Front view of the KR01 robot’s chassis, with polycarbonate bumper-sensor and infrared distance sensors

The KR01 now sports a variety of sensors from Adafruit, Pimoroni’s Breakout Garden, Pololu and others, including:

  • a servo-mounted 4m ultrasonic sensor, or
  • a servo-mounted Time of Flight (ToF) laser rangefinder with a range of 4m and accuracy of 25mm
  • four Sharp digital 15cm range infrared distance sensors
  • a Sharp analog 80cm infrared ranging sensor
  • an infrared PIR motion detector (for detecting humans and cats)
  • an X-Band Bi-Static Doppler microwave motion detector (for detecting humans and cats through walls)
  • a 9 Degrees of Freedom (DoF) sensor package that includes Euler and Quaternion orientation (3 axis compass), 3 axis gyroscope, angular velocity vector, accelerometer, 3 axis magnetometer, gravity vector and ambient temperature
  • a 6 channel spectrometer
  • two 5×5 RGB LED matrix displays
  • one 11×7 white LED matrix display
  • an HDMI jack for an external monitor (part of the Raspberry Pi)
  • WiFi capability (part of the Raspberry Pi)
  • a microphone
  • a speaker with a 1 watt amplifier

This is all powered by a Makita 18V power tool battery. The clear polycarbonate bumper (inspired by David Anderson’s SR04 robot) has six lever switches, with two wire feelers protecting the upper part of the robot.

All that just for the territory of my lounge. Or maybe my front deck.

Software

So while working on hardware I’ve also been working on the software. I’ve been writing a Behaviour-Based System (BBS) based on a Subsumption Architecture as the operating system for the KR01 in Python. The concept of a BBS is hardly new. Rodney Brooks and his team at MIT were pioneering this area of research back in the 1980s; it’s an entire field of research in its own right. Here’s a few links as a beginning:

The idea with a BBS is that each sensor triggers either a “servo” or a “ballistic” behaviour. Servo Behaviours (AKA “feedback and control systems”) immediately alter the robot’s movement or make a temporary change in its behaviour, such as speeding up or slowing down, in a relatively simple feedback loop. Ballistic Behaviours (AKA “finite state machines”) are small sub-programs that are (theoretically) meant to run from start to completion without interruption. The below video shows a ballistic behaviour that might occur should the robot find itself facing a wall: it backs up, scans the neighbourhood for a place where there’s no barrier, then attempts to drive in that direction. Yes, that is a sonar “ping” you hear.

This video shows a simple obstacle avoidance behaviour.

My understanding (i.e., the way I’m writing the software) is that for every sensor there is an associated servo or ballistic behaviour, and that each of these behaviours are prioritised so that the messages sent by the sensors contend with each other (in the subsumption architecture), the highest priority message being the one that the robot executes. It does this in a 20ms loop, with ballistic behaviours taking over the robot until they are completed or subsumed by a higher-priority ballistic behaviour. It’s the emergent behaviour as a consequence of these programmed behaviours that gives the robot its personality. When the robot has nothing to do it could begin a “cruising around” behaviour, whistle a tune, or go into standby mode awaiting the presence of a cat.

Not that my cat pays much attention to the robot. In the robot-plus-cat experiments that have been performed in our home laboratory he sniffs at the robot a bit and nonchalantly stays out of its way.

He wasn’t fooled for a moment by the barking.

From Failure, Success

KRZ-01 Robot

There’s been another mishap around here. I guess building robots has its ups and downs and last week was no different.

I’m kinda ashamed to say that while I was working on the KR01 robot I’ve now managed to burn out two Thunderborg motor controllers and one Ultraborg servo controller. Well, not quite “burn out”. The motor controller parts of the Thunderborgs still work but the RGB LED used to display the battery level has somehow gotten fried on both units, and the Ultraborg (which is used for sonar and servo control) seems to have died during the first Thunderborg catastrophe (sympathetic death). I have no idea really how this has happened, but of course the only real possibility is that I’ve done something wrong. I mean, I’ve been very careful with checking my wiring before applying the power, but at some point I must have got my wires crossed. The PiBorg folks who make these boards have been quite helpful and I’m sending them back to the UK to see if they can figure it out. But that will take awhile.

King Ghidorah anatomy by Shoji Phtomo
Not to be confused with Monster Zero 1

This means that for at least a few weeks I would be without a robot (the horror)! I really can’t have this happening just as I’m getting the robot operating system up and running. So last weekend I went ahead and built out one of my design prototypes, which I’ve been calling the KRZ-01 (Kiwi Robot Zero), as it’s based on a Raspberry Pi Zero W. It uses a Picon Zero for a motor controller, a Pimoroni Breakout Garden to mount some of its sensors, and a trio of infrared detectors rather than a front bumper.

Happily, the build posed only a few problems and I had it up and running rather quickly. I rewrote the Python modules that had been used to control the KR01’s motors to instead use the Picon Zero and I had it dancing around on the carpet today for the first time:

KRZ-01 Motor Control Demo

The KRZ01 is meant to be small and relatively cheap, but still have the ability to carry some impressive sensors. It actually isn’t a whole lot less capable than its larger sibling, the KR01. Without including shipping the parts come out around NZ$250, so it’s not the cheapest robot you could build but it’s got a lot of functionality2.

Side View of KRZ-01
Side View of KRZ-01

It’s based on a Raspberry Pi Zero W, which has 500MB of memory and supports both WiFi and Bluetooth. The OS is Raspbian Linux. The Picon Zero motor controller and a Breakout Garden Mini are both mounted on a Mini Black HAT Hack3r breakout board. This is an extremely compact setup. You can see this on the side view photo.

The sensors include: three Sharp infrared detectors; a VL53L1X Time of Flight (ToF) distance sensor mounted on a micro servo, which can measure distance up to about 4m with a 25mm accuracy (this is the same sensor I used on my night light); and two 298:1 ratio micro gear motors with encoders so we can measure how far we’ve travelled.

Bottom view of KRZ01
Bottom View Showing the Motors and Motor Encoders

There’s still two free I²C Breakout Garden sockets so additional sensors can be swapped in and out without any soldering. I added a couple of 11×7 LED Matrix boards as status displays but they’re hardly necessary. The whole thing runs on a common USB battery. The chassis is made out of 3mm Delrin plastic. For locomotion it uses a pair of Moon Buggy wheels, a lightweight plastic ball caster in the front, a heavier stainless ball in the back (so its balance is towards the back caster).

Since the robot supports WiFi I connect to it remotely using ssh, which is how I’ve been installing and loading its software, starting and stopping programs, and shutting it down 3. Remarkably, the Raspberry Pi W includes a tiny HDMI connector so I could plug it into a monitor, but that hardly seems necessary. This seems like a command line robot.

The chassis is 75mm wide and 120mm long. Without a battery the whole thing weighs 120 grams. For comparison, that’s 17 grams less than my iPhone 5. I have a 5200mAh battery that weighs 136 grams and a 4400mAh battery that only weighs 40 grams, so unless battery life is an issue I’ll probably use the smaller battery. I have a 10000mAh battery (200g) that would last many hours but I can’t imagine leaving the robot alone that long. What kind of trouble could it get into?

For more information about the KRZ01 Robot, visit its NZPRG wiki page.

Note: as of today the NZPRG has its own YouTube Channel.

Edit: after some back in forth in email and finally posting the boards back to PiBorg in the UK, I learned from them that what seemed to have happened was that the UltraBorg tested as faulty, and that was apparently what was burning out the LEDs on the ThunderBorgs. They’ve since sent me replacements for both and all is working well now. A well-deserved thank you to PiBorg for their patience and help!

After Despair, Some Joy

This article is the fourth in the multi-part series “Building the KR01 Robot” ( 1 | 2 | 3 | 4 ). Further articles can be found tagged “KR01“.

Hsü

Sometimes when you’re experimenting you fail. Sometimes over and over. I had two failures this week, one that had a solution and one that didn’t seem to. But as the I Ching says: perseverance furthers1.

Tank Treads

Celebration of a tank failure…

After some deliberation I’d decided to base my robot on a tank. I’d considered the benefits of a “dual-differential drive configuration, balanced by a non-driven tail wheel caster” on David Anderson’s SR04 robot and thought the OSEPP Tank Kit might be able to provide a suitable drive platform for my robot. One of the requirements of being able to determine the location of your robot is to accurately know how far its left and its right drive motors have traveled. This is necessary in order to perform odometry.

The SR04 has a left drive wheel and a right drive wheel and can rotate in place if the wheels turn in opposite directions (David’s robot impressively can spin in place on a table without changing position). A tank is able to do the same but requires a lot of tread slippage, and this “odometry error” would need to be accounted for somehow, perhaps using another type of locational awareness.

I hadn’t thought of the other problem, and there was a bit of delay in even finding out that there was another problem (one of those “unknown unknowns”). During the assembly of the robot I’d taken the silicon tank treads off a few times, and one morning one of the tread pieces had torn, and it’d been my last spare. I’d contacted OSEPP and they’d been very nice in sending out some replacements. Being this is New Zealand shipping things here from North America took awhile.

By the time the replacement treads arrived I’d gotten the robot to the point where it could perform its first test drive, so I put on the tank treads, wrote a quick Python program to move forward, turn around (do a 360 degree turn) and come back.

I put it down on the carpet and executed the program. The robot moved forward just fine (baby steps!), but as soon as it began to turn around, to my horror the treads slipped and twisted up, partly came off and then caught under the robot. I hit the kill switch (actually, Control-C from the ssh session), put the treads back on and tried it again. Same result. It was better on a wooden floor, but if the rotation was too fast it still sometimes did the same thing.

NZ Tomtit
New Zealand Tomtit
(image: Graham Commins (CC))

Now, I can’t blame the OSEPP people for this. I measured my robot and without a battery it weighs 1.7kg. With the smaller 12 volt Makita power tool battery it’s up to 1.92kg, and with the Makita 18v 3Ah battery2 it tops the scale at 2.35kg (5.2 lbs). If one watches the OSEPP Tank promo video on YouTube their little tank zips around with just an Arduino and a six AA cell battery pack, so it’s carrying nowhere near as much hardware. I’d be comparing a kererū with a tomtit. Unfair. I think a robot with a weight similar to the original kit would be fine.

The kererū, or New Zealand wood pigeon,
(image: NZ Forest and Bird)

My big fat kererū just couldn’t use the tank treads. I’d considered the tread slippage problem (but not the treads-falling-off-disaster) and ordered four of the OSEPP silicon wheels, and after some floor and carpet testing found that they would work. There’s enough slippage on wood floor or carpet that the four wheels do a reasonably good in-place rotation.

Thank goodness. I didn’t want to have to go back to the drawing board.

The Other, Seemingly Intractable Problem

OSEPP Motor Encoder: four connections!

The other problem was with the motor encoders. These are tiny Hall Effect sensors mounted to the motor shaft (before the gearbox) and are meant to provide a pair of waveforms (labeled A and B) that permit a determination of engine direction, speed and the number of times the shaft has rotated.

I’d spent days debugging this. I have this cool old Iwatsu SS-5710 oscilloscope I bought at a local pawn shop. It’s everything you want in an oscilloscope and more: complicated, mysterious, lots of knobs, bright image, nice lines, good coloring, even engages in scintillating dinner conversation. Okay, maybe not that last one.

I’d tried everything to get a usable waveform off of the sensors. Tantalisingly, I was able to get some tiny waveforms, similar to those NASA receives from Mariner 9 at the edge of the universe. But not enough to peg a Raspberry Pi GPIO pin. I’d disassembled the robot, adjusted the encoders, tried adding a 74HC14 Schmidt trigger circuit (forgetting that the encoders already do this), nothing worked. Ugh.

This morning I was reconnecting the 6 pin IDC cable I’m using between the chassis and the platform holding the Raspberry Pi, and I remembered that there were six pins. Six pins. The left and right motors each had an A and a B (i.e., A1, B1, A2, B2). What had I used the other two pins for?

Oh yeah… power.

I hadn’t provided power to the motor encoders. As soon as I connected ground and 5 volts to the encoders and fired up the robot while connected to the Iwatsu, lo and behold: I had some square waves. Success! If it’d been later in the day I would have cracked open a beer.

Motor Encoder Output
Finally, some square waves!

I then rummaged through all manner of half-completed Python scripts to find one that with some slight modification was able to count up and count down as the motor drove forward and back. So… the robot now functional motor encoders.

Next: to begin figuring out how to write a PID Controller.

The Wiring Begins

first KR01 prototype

This article is the third in the multi-part series “Building the KR01 Robot” ( 1 | 2 | 3 | 4 ), and describes beginning to design and build the hardware of the KR01 robot project.

With the robot chassis largely complete (at least for now) I began to plan out where I’d mount the Raspberry Pi, motor controller and other PC boards.

Shakey the Robot

Historically, robots seem to generally have mounted their drive systems on the bottom of a horizontal platform, with their control systems on the top. You can even seen this on Shakey, the first autonomous robot, which was developed back in the late 1960s at Stanford Research Institute (SRI).

My modified OSEPP Tank Kit provided a horizontal area to mount parts but I’d have to drill into the aluminum1 and that seemed rather inflexible, and the mounting holes of the various components didn’t match that of the OSEPP beams, which use a 16mm grid.

I wanted to mount my components on something lightweight and non-conductive, cheap, and easy to modify and/or replace. Some kind of plastic seemed right. I could have used used acrylic (called “perspex” here in New Zealand) but it tends to be rather brittle and easy to crack or split, so I settled on Delrin (a trade name for polyoxymethylene plastic), which is a bit softer, tougher, and almost indestructible. Delrin is often used for making bearings.

The Lower Bits

One thing I learned long ago: it’s all very well to be able to build something but you also need to be able to disassemble it easily. I figured that I needed some way to gather the various wires from the motors and motor encoders in such as way that I could use detachable cables to easily remove the top platform from the chassis. So one principle I’m using on the KR01 is to try to use jumper wires and single and dual header pins for the connections, so that things don’t have to be permanently soldered together.

chassis interface pinout
Chassis Interface Board pinouts

For what I decided to call the Chassis Interface Board I planned to use two 6 pin IDC cables for the connections to the upper part of the robot and one of the AdaFruit Perma-Proto boards to hold all the parts and organise the wiring, which just happened to fit into the area available. I mapped out the pin layout and then soldered some header pins to the board. I also cut a bit of 10mm aluminum “L” section to hold the SPST power switch, the DPDT motor kill switch, and a status LED (you can see this in the photo below).

chassis interface board
The Power Controls (left) and Chassis Interface Board (right)

I ended up drilling two small holes (the horror!) in the aluminum rails to hold some nylon standoffs, then mounted the Chassis Interface Board and wired things up.

Even with all my planning I didn’t get it right the first time and had made a wiring mistake. Apart from the mistake, now that I’m done with these components, the nice thing is that because I’ve not soldered everything together (except in creating the components themselves) I can take it all apart when I decide to make a design change. And that’s bound to happen.

The Platform

I decided to mount my components onto a black Delrin platform using nylon standoffs, so I bought an assortment of 2.5mm black nylon standoffs from Adafruit there’d be no issue with short circuits. A robot used for off-road or robot combat might need to use metal for strength, but the KR01 is strictly a domesticated house robot2

The closest plastics store in Petone didn’t carry sheet Delrin but Macplas up in Auckland did. After a brief phone conversation about which plastics were most appropriate for a small robot, I ordered some black 3mm Delrin for the platform and some clear 3mm polycarbonate for the front bumper. I find that when you involve people in the details of what you’re doing they can use their expertise to best help you.

component layout
Component Layout

Rather than start with the Delrin (which is kinda expensive) I prototyped the board first using a milky white nylon chopping board I bought at the Warehouse for $5. Yes, it occurred to me that I could have just used the nylon but the Delrin is thinner and much cooler. I mean, who makes a robot out of a chopping board?

I taped some paper to the plastic and laid out the various components, then drilled the holes. They say “measure twice, cut once” but I still made a mistake. So maybe it should be “measure thrice, cut once”, 3

Stuff Begins Arriving in the Post…

Early Prototype

This article is the second in the multi-part series “Building the KR01 Robot” ( 1 | 2 | 3 | 4 ), and describes beginning to design and build the hardware of the KR01 robot project.

Inspired by David Anderson’s SR04 robot (in particular, his YouTube video) I searched around for a suitable robot platform, the kind of chassis and motor that fit the scale of the design-in-my-head, and a few other factors. Having read David’s documentation of the project I rather liked his “very loose” design criteria:

  1. Survive in a wide range of (cluttered) human environments autonomously and continuously, without getting stuck.
  2. Provide a robust and reliable platform for developing navigation and behavior software.
  3. Be entertaining and aesthetic for the local human population.

I thought I’d have a go at updating what he’d done in 1998 to see what 22 years might have brought to progress in the world of “personal robots”. I’d been perusing the AdaFruit and Pimoroni websites and had seen all manner of pretty amazing sensors for prices I could afford. It was time to stop making Raspberry Pi night lights and try something more ambitious.

I admit to having strayed from one of David’s stronger design principles in the SR04, that being his “dual-differential drive platform with the geometry of an 11 inch circle” 1. That symmetry is valuable and I’m hoping that my tank-tread design (or four wheels if the treads don’t work out so well) won’t suffer. Watching the SR04 rotate continuously on a table without moving in place is pretty impressive. But I have to start somewhere. I can always modify the design…

OSEPP Tank Kit
The OSEPP Tank

So, I settled on an OSEPP Tank Kit. It’s a bit like Lego or Meccano in that the kit is provided as a set of red-anodised aluminum beams, some accessory plates and connector bits, using 4mm nuts and bolts to hold things together. There’s some flexibility in this, and OSEPP sells accessory kits. I bought an extra set of beams, as I knew of one deficiency in the Tank Kit I wanted to immediately change: it has four wheels but only two motors: the port motor at the front, the starboard motor at the rear.

Since David’s design uses a PID Controller I knew I’d need to use motor encoders, which was one of the reasons I chose the OSEPP kit: they offer a pair of motor encoders using Hall Effect sensors. I’d seen an image of two OSEPP motors and encoders mounted along a single beam, quite an elegant design. It seemed prudent to have both of the encoders on the same pair of motors (either the front or the rear). The Tank would have to be wider and I also wanted four drive motors, not just two. Using tank treads is not very efficient so I figured there’d be insufficient horsepower to drive a robot with only two.

In New Zealand orders from overseas can take anywhere from a few days to weeks in waiting, so I started making decisions and putting in orders. Locally I bought some stainless 4mm hardware from Mitre 10 and Coastal Fasteners. (See Vendors on the NZPRG wiki.)

The Kit Arrives

I’m not going to do one of those ridiculous unboxing videos. Yes, the box arrived. I opened it. I didn’t keep track much with videos or photos. I was playing, not performing.

prototyping in the kitchen
Playing on the Kitchen Table

The OSEPP kit is well-designed, though it’s impossible not to leave a bit of rash on the red anodisation. If you simply built the Tank Kit as intended this wouldn’t be an issue so much, but I tried at least four or five different permutations before settling on one design, and then had to modify it several times when I tried adding things like the front bumper supports and the mount for the power switches.

Beautifully Machined Wheels

The hardware is fun to work with. Not like Lego, where it can be a struggle to connect things securely, the OSEPP kit’s parts are held together by 4mm stainless steel nuts and bolts.

I locally sourced some stainless lock nuts (also called “nyloc nuts”) as I prefer them to the serrated flange nuts provided with the kit (though these work just fine too).

The Motor Encoder kit hadn’t arrived so I built it without remembering that photo I’d seen with the single beam holding both two motors and their encoders. The design as shown above on the kitchen table had no place to mount the encoders. The photo below shows each pair of motors mounted to a single beam, with the motor encoders attached to the front (top) pair.

Front and rear pairs of motors, you can see the encoders mounted on the motor shafts of the front pair. The left and right motors are wired together so they’ll appear as a left drive and a right drive.

When the motor encoders finally arrived I did another round of building and came up with what I thought was the final chassis, but even that had to change once I tried to mount the tank treads. As you can see, there’s not much clearance between the front bumper and the treads. And of course, the front bumper was only a stand-in until I could begin building the real bumper.

Next time: we begin the wiring and mounting the platform for the circuitry…