Embedded Programming
A first attempt

The Idea:

I've wanted to play with embedded systems for a long while. While embedded systems programming is not my favorite branch of Computer Science, the things you can make with a micro-controller have a certain flash to them that most other programming projects lack. So, when I had the opportunity to work on an embedded systems project for a class, I decided I wanted to make something flashy. My original idea was to make a remote controlled unicycle, but it rapidly became evident that such a contraption would be well beyond my abilities to fabricate, let alone control. Instead, I decided to give my device two wheels, side by side like a Segway so that it would only have to balance in one dimension at once.

The biggest question I had to answer before I could put anything together was how sense the tilt of the device. I decided the coolest method to try, and also the least expensive, would be to use a pendulum. In practice, the pendulum would be a lead fishing weight attached to a potentiometer. As the weight rotated the shaft of the potentiometer, it would change the voltage and through analog to digital conversion, provide an integer value that reflected the tilt of the pendulum. This could then be used to calculate an appropriate response. For example, if the device tilted forward, the pendulum would tilt forward, and the controller would instruct the device to speed up.

For propulsion, I used two DC motors with feedback attached to small wooden wheels and powered by Digilent HB-5 H-bridges. The potentiometer I used was a 5kΩ liner potentiometer from Radio Shack. For a controller I decided to use a Digilent Cerebot PIC32MX. Originally I started playing with a PIC32 starter kit that I used previously in an embedded systems class. Unfortunately it soon became clear that the layout of the pins made wireing up any motors an absolute mess. The layout of the Cerebot works very well, with several connectors containing all of the proper pins to drive a motor with Pulse Width Modulation and feedback. As an added benefit, the two boards shared the same processor and debug module, and so all of the code I had already written transferred straight across.

Here is my robot in completed form:
The Robot

The Problem:

For some, a little thought would be all it takes to understand why this design would not work. For me, it took a bit of experimentation, but I came to the same conclusion. The first thing to notice is how much this setup resembles a chaotic pendulum. This in itself should be enough reason to suspect controlling the system would be very difficult. However there is a single situation that I believe shows that this control scheme is impossible. If you imagine the system completely stationary and upright, and then it begins to fall forward, the device is counting on the pendulum to swing out in front to indicate the tilt. However, because of the inertia of the pendulum, it actually swings the opposite direction, causing the device to accelerate away from the direction it is tilting. This causes it to fall faster until it slams into the ground.

The project was not a total loss however. For one, I have a much better understanding of how use A to D conversion, and how to control the motors on the robot effectively. I also think the pendulum sensor still has some potential. If the pendulum was hung from the same point of rotation as the wheels, it would behave as a normal pendulum rather than as a chaotic double pendulum. It would still have some interference from movement forward and backwards, but because that is mostly under the control of the motors I can have the controller account for it. Whether this eventually proves to be a viable control method or not is yet to be seen, but I hope to keep working on this as I have time.

Comments: