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.

Just Some Sun, Sea and Wind…

Sometimes we need a break from all the noise and confusion. Today we hiked up to the ridge overlooking the sea and Kapiti Island, looking north.

The track up to the ridge goes past a farm. Being New Zealand there are sheep. Always sheep.
The canopy where we’re often greeted by fantails. Today two came down and flew around us.
The view looking north towards Kapiti Island, with the next town, Paekakariki, just barely visible along the coast. Paraparaumu is in the distance (the long spit of land is actually the curve around its beach).
Looking northwest towards Australia…

Four minutes thirty-three seconds at the top of the ridge.

I hope you enjoyed this.

Best wishes to everyone!

Trial and Error. Lots of it.

[This post started as a progress report and ended up being more of a mental progress report. My next post will provide details about the current hardware and software of the KR01 robot.]

I just got another package in the mail. A couple of pieces of plastic. 3mm black Delrin. Very nice plastic.

While building the KR01 robot there’ve been a few lessons learned. One is that any notion of a “final design” was pretty foolish. If anything I’ve been constantly changing things. Donald Knuth, author of The Art of Computer Programming, famously wrote that “premature optimization is the root of all evil”, but we’re not talking here about optimisation: I’ve simply been trying to come up with functional hardware and software. Even for a small robot that’s proven to be anything but trivial. And the mistakes I’ve made have been due to both complicated and very trivial reasons.

ThunderBorg connections
What’s wrong with this picture?

Here’s a simple quiz (one that I’ve failed, twice):

Okay. You have a motor controller with connections labeled M1+ and M1-, M2+ and M2-. I’ve designated the port (left side) motor as M1 and the starboard (right side) motor as M2. You connect the white wire of the port motor to M1+, the black wire of the port motor to M1-, the white wire of the starboard motor to M2+ and the black wire of the starboard motor to M2-, just like in the photo. Correct? BZzzZZttt! Wrong. Can you guess why, or what will happen?
Answer: If you connect both motors to the controller in the same way (same polarity) and tell both motors to move forward, well, they will do exactly as you ask. Except that “forward” for the port motor means forward around the central axis of the robot, so the robot will spin counter-clockwise in place. Like many things this seems perfectly obvious, in retrospect. In retrospect.

I’ve been a software developer for many years, and iterative design is something I’ve long believed in, or at least have (by default) practiced. That is, you don’t get it right the first time, or the fifth. You keep hammering away until some portion of the work is done and then just move on to the next bit. Perseverance furthers. This isn’t that silly waterfall vs. Agile argument. It’s good to plan ahead. You need to plan, as much as you can. But at the beginning you can’t possibly see the road ahead. A hypothesis, a direction, yes.

Unlike software systems, with robots we have both hardware and software to deal with, and the entire approach is different, compared with say, a client-server infrastructure for a national weather service (which I have some experience with). The latter is enormously more complicated, but writing a robot operating system for a custom-built robot is just plain tricky, both getting the hardware functional and getting the software to do what you want. The hardware is a myriad of compromises of space, weight, cost; the software is reacting to an ever-changing series of sensor events, in real time. The more sensors, the more complicated things become. The motor controller softare can itself be quite a challenge.

It’s pretty tricky to create even a simple line-following behaviour, where there’s a single program that reads the values of two infrared sensors and alters the speed of two motors.

NASA’s Sojourner robot, which landed on Mars in 1997, sported an 8085 8 bit microprocessor with a 2 MHz clock (rated 100,000 instructions per second), addressing 64 KB1 of memory, 64 KB of RAM for the main processor, 16 KB of radiation-hardened PROM, 176 KB of non-volatile storage, and 512 KB of temporary data storage2. By comparison, the Raspberry Pi 3 B+ in the KR01 costs all of US$35 but is many orders of magnitude more powerful — somewhere over 200 million floating point instructions per second — with a 64 bit processor, a 1.4 GHz clock and 2 GB3 of memory. Rather than an SD card I’m using a Samsung 250 GB SSD for data storage, which costs about US$80. The Raspberry Pi is running a Linux operating system and I’m programming the robot in Python, not assembly language. So even if my budget is miniscule, I have some very significant advantages over NASA in the mid-1990s. The limitations of my project are entirely me.

I have no idea how difficult it must be to design an autonomous robot like NASA’s Perseverence robot, where there are seven large scale instrument systems, a five-jointed robotic arm and 23 cameras. It’s not a remote controlled robot (called telerobotics, basically a drone), as while it can be commanded, it’s autonomous: it can “think” for itself. It also weighs 1 metric ton, its power supply uses 5 kg of plutonium, and its mission has a budget of US$2.04 billion. Of course, it’s going to Mars. My KR01 only needs to navigate my lounge.

Perseverence would just fit in my lounge, if I moved my sofa (photo: NASA)

As is my nature, I jumped in headfirst and built a robot with quite a few sensors and hardware that I’ve been changing almost continually since I started. The photo at the top of this post is testament to the number of changes: it’s the “motherboard” of the robot that held the Raspberry Pi and all of the sensors that weren’t attached to the front bumper, and I’ve been almost continuously shifting things around both under and over that 3mm plastic boundary. Lots of holes.

While drilling all those holes, I learned a few things:

  • Everything is a compromise when it comes to the real world. Designs are abstract. Even if you know exactly what your goals are when designing a robot, the choice of materials, motors, batteries, sensors, and how they all fit together into a single hardware system, well, you’re not going to get it right the first time, and only by repeatedly failing will you arrive at a solution that kinda works. And it will only work some of the time. Then you go back and make some changes and try again. Repeat. And then once you’ve learned things by doing all that, your goals change.
  • You don’t know how things will go until you actually try it out. Design and its implementation are never the same. Robots and systems comprised of purely software are different in some rather profound ways. Rodney Brooks talked about two aspects of robots: situatedness and embodiment in his 1991 paper Intelligence Without Reason (see Some Notes on Artificial Intelligence ). This means that we’re not programming for an abstract system, we’re designing a control system for something that exists in the real world and has to deal with real world physical limitations and obstacles, where how long something takes to happen is affected by many factors, like floor surfaces, traction, and battery life. Things are often unpredictable. No two DC motors perform exactly the same, and are affected by things like heat and gear train friction. Sensors don’t perform exactly as we might think, and can be affected by bright lights, dust, radio frequency interference. There are wood floor to carpet transitions. Cat hair.
  • There’s going to be hardware and software bugs. I’m pretty meticulous, I like to think. But the number of mistakes I’ve made while building this robot, even after double- and triple-checking things, is rather humbling. To be fair, not everything was a mistake, sometimes it was trial and error, but there’ve been quite a few errors as well. For example, I’ve made mistakes creating wiring harnesses, forgot to provide power to sensors, drilled the holes for something and found it was too close to something else, and found a couple of push connectors that when pushed onto the connector pin just backed out of their housings and failed to make the connection. Sometimes these mistakes were obvious, some took awhile to discover and fix.
  • Things keep changing. Things wear out. You think you can bundle up those wires with a nylon wire tie? Think again. When you make a change tomorrow you’ll need to cut it off. This isn’t a reason to avoid the wire tie, just know that nothing is permanent, nothing lasts. This is also a central premise of Buddhism. Stay flexible, design for change.
  • Expect the unexpected. Robot hardware and software just doesn’t do what you think it’s going to do. It just doesn’t. Something always jumps up and grabs your ankle, and you’re sitting in your lounge with a mint julep, not prowling a desolate graveyard in a howling storm.
  • Learn from those who’ve gone before you. There’s little point in making mistakes others have already made. You can go it alone and make all those same mistakes, or do a bit of research to learn what to avoid, and also to seek inspiration.
  • Don’t be afraid to ask for help. Similar to that last item, there’s a lot of experience out there. If you’re polite people are usually happy to answer your questions, or point you at resources and documentation.
  • Try to stay organised. By this time I’ve got a lot of spare parts, nuts and bolts, sensors I haven’t yet tried out, or tried out and am not currently using. Just as in any shop, it’s smart to keep sort things out, keep things in divided containers, put your tools away when they’re not in use.
  • Stay within your budget. Have some idea of what you want to spend on your project, add a 20-50% percentage overrun, and design your robot to reasonably fit within that budget. All the miscellaneous adds up.
  • Be prepared. Make sure you have the right tools for the job. Have some spare parts handy. I’ve purchased extra 2.5mm, 3mm and 5mm nuts and bolts, washers, lock washers, nylon lock washers. A packaged set of 2.5mm nylon standoffs and a selection of LynxMotion 3mm aluminum standoffs in various lengths. I got a good quality soldering iron, and already had a multimeter and oscilloscope (the latter has proven pretty handy, if not strictly necessary). I have a well-lit, ergonomically-correct workspace. Power tools.

Hmm. I’m not sure if that list was really about building robots.

Here are some robot-specific ones (though suspiciously still generally-applicable):

  • Balance is important. You need to position the heavy objects (like batteries) so that the weight is over the center point of the robot, or if your robot is two wheeled with a trailing ball or wheel caster, low and slightly behind the main axle. If the weight is not on-center the robot’s motion will be affected.
  • Make sure you have enough power, and the right power. The Raspberry Pi needs a regulated 5 volt power supply: you’ll either need a USB “power bank” or a 5 volt regulator running off of a higher voltage battery. Your batteries might be lithium ion or lithium polymer supplying 3.7 or 7.4 volts, or nickel metal hydride (1.2 volts each) or alkaline AA batteries (1.5 volts each). An AA battery holder can hold four, six or more rechargeable or alkaline batteries supplying anywhere from 4.8 to 12 volts. Four AA rechargeable batteries provide 4.8 volts (not enough) and four alkaline AA batteries provide 6 volts (too much). Or like the KR01, you could use a power tool battery supplying 12 or 18 volts (which in reality seems to be around 20 volts). Your motors will likely need 6, 9 or 12 volts. Many of the motor controllers are configurable to handle a larger input voltage than the motors can handle, but this still requires care and proper configuration. Beyond voltage is current: how long your robot will run depends on the capacity (in amps or milli-amps) of your battery supply. Do you use a single battery for both the microcomputer/microcontroller as well as the motors? If you only want your robot to run for a few minutes at a time your battery capacity can be significantly lower.
  • Measure three times, cut once. Even with careful planning it’s easy to cut something the wrong size, or drill a hole in the wrong place. As you can see from the photo of the KR01, there’s not a lot of extra space anywhere on the robot, and I had to shift things around a lot to get things to fit. If there are any moving parts (like a servo-mounted ultrasonic sensor or camera), you need to be sure there’s enough clearance so that it won’t run into some other part of the robot.

Hmm. I might add to this list as time goes on but I can’t think of anything else right now. My beer is still cold, and only half full.

My next post will provide a progress report on the KR01 robot.

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…

Some Notes on Artificial Intelligence

[These are some still-disorganised notes on Robotics, Artificial Intelligence, and Knowledge Representation that will likely be moved over to the wiki once it’s up and running. Likewise, at the bottom are some references, which will also end up on the wiki…]

“SMPA: the sense-model-plan-act framework. See section 3.6 for more details of how the SMPA framework inuenced the manner in which robots were built over the following years, and how those robots in turn imposed restrictions on the ways in which intelligent control programs could be built for them.”

— Brooks 1985, p.2

From Brooks “Intelligence Without Reason” [Brooks 1991]:

“There are a number of key aspects characterizing this style of work.

  • Situatedness: The robots are situated in the world — they do not deal with abstract descriptions, but with the here and now of the world directly influencing the behavior of the system.
  • Embodiment: The robots have bodies and experience the world directly — their actions are part of a dynamic with the world and have immediate feedback on their own sensations.
  • Intelligence: They are observed to be intelligent — but the source of intelligence is not limited to just the computational engine. It also comes from the situation in the world, the signal transformations within the sensors, and the physical coupling of the robot with the world.
  • Emergence: The intelligence of the system emerges from the system’s interactions with the world and from sometimes indirect interactions between its components — it is sometimes hard to point to one event or place within the system and say that is why some external action was manifested.”

Brooks notes that the evolution of machine intelligence is somewhat similar to biological evolution, with “punctuated equilibria” as a norm, where “there have been long periods of incremental work within established guidelines, and occasionally a shift in orientation and assumptions causing a new subfield to branch off. The older work usually continues, sometimes remaining strong, and sometimes dying off gradually.”

He expands upon these four concepts starting on page 14:

  • The key idea from situatedness is: The world is its own best model.
  • The key idea from embodiment is: The world grounds regress.
  • The key idea from intelligence is: Intelligence is determined by the dynamics of interaction with the world.
  • The key idea from emergence is: Intelligence is in the eye of the observer.

I might note that Brooks’ criticisms of the field of Knowledge Representation reflect my own findings, observed during the four years of my doctoral research on KR at the Knowledge Media Institute.

It is my opinion, and also Smith’s, that there is a fundamental problem still and one can expect continued regress until the system has some form of embodiment.

— Brooks 1991

The lack of grounding of abstract representation is evident from the almost complete
lack of the KR researchers to even bother to definitively explicate the two terms in the field’s title: “Knowledge” and “Representation”. How can one rationally explore a field when one doesn’t yet know what knowledge is, or where there is no epistemologically-sound definition of the word representation? The greatest related advances in that field belong to the likes of C.S. Peirce, John Dewey, Wilfred Sellars, Richard Rorty and Robert Brandom, but this seems (at this point in time) to be still disconnected to the concept of “embodiment” as explored in robotics (but I’m hardly the person to judge that issue). So it’s grounded neither in mathematics 1 nor in the real world.

I must agree with Brooks, that embodiment is a necessary precondition for research into intelligence. Brooks’ paper was from 1991, my doctoral programme began in 2002. I wish I’d read his paper prior to 2002. I met Doug Lenat in 2000 and over dinner in Austin we discussed the idea of working for his company, Cycorp (the corporate home of the Cyc Ontology). The whole thing is a giant chess set, a massive undertaking that as of 2020 is still essentially doing what it did when I saw it for the first time at SRI in 1979; it’s as Brooks says, it’s just followed the advances in computing technology but not really provided any real breakthroughs.

Regarding scale or size:

“The limiting factor on the amount of portable computation is not weight of the computers directly, but the electrical power that is available to run them. Empirically we have observed that the amount of electrical power available is proportional to the weight of the robot.”

— Brooks 1991, p. 18

References