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.