Showing posts with label Mindstorms NXT. Show all posts
Showing posts with label Mindstorms NXT. Show all posts

Friday, January 24, 2014

Lego Segway with minimal-order observer control

Self-balancing Lego robots are nothing new, but everyone uses PID controllers. I wanted to implement an observer controller to do something new and flex my controls muscles. 

I built a Mindstorms robot that uses a light sensor to measure light reflected off the floor and thereby the robot's tilt. This turned out to be finicky since I had to set the zero point manually, and ambient light variations screwed things up fairly often. It worked well enough in the end though.


Controller Design
A full-order observer controller uses a model of the system in the control loop, which allows us to observe state information that would otherwise be hidden in the actual system. We can then use that state info in the feedback to reduce the error, which now incorporates both the system and model outputs. This can be a robust way to control high-dimensional systems while also being able to inspect the (estimated) states for useful insights.

However, we may not actually need all the state information. A minimal-order observer (aka functional observer) still uses a model, but requires fewer poles to be chosen than a full-order controller. That simplifies design and eliminates the need to calculate and compute state-space transformation matrices.

The figure shows the minimal-order observer, with the controller elements labeled as psi 0 and psi 1. In the lower diagram, psi 0 is algebraically combined with the summation block to simplify coding. As noted, each psi function is a ratio of (simple) Z-domain transfer polynomials.

Minimal-order diagram in Simulink. In the actual system, the real robot takes the place of the "Linearized Model".
Results
I coded the observer controller in RobotC with the help of a couple of Matlab scripts to choose poles and calculate the coefficients of the transfer polynomials. I could have put more work into accurately modeling the robot (weighing it properly, etc.), but as you can see, it works well enough.


The video's a bit long, to show the balancing stability - skip to 1:30 to see me driving the robot with a joystick over Bluetooth. Driving could use some smoothing, but it's fun.

Code is here.
            

Friday, September 30, 2011

Microchip ICD adapter -> NXT port breakout board

Lego Mindstorms NXT kits are great for robotic prototypes and experiments. The computer brick and sensors communicate over I2C, which is great for DIY expansions. Unfortunately they also use nonstandard RJ connectors. (You can now buy the connectors, but that's no fun.)

The NXT's RJ port with offset connector lock.


I wanted to access the I2C, so I hacked up my "sound sensor" (microphone) to add a standard 0.1" header. But even as hacks go, it was ugly and only allowed access to 5 of the 6 pins.

However, a while ago the ECE department was getting rid of surplus parts, and among the reels of SMD resistors were a handful of header-to-RJ45 adapter boards that come with Microchip ICD programmers.

Microchip, on the other hand, make this handy board with a normal RJ45 port.
One day I happened to look at one and realize the RJ port on the Microchip board had the same pin spacing as the NXT ports. I cracked open my earlier hack, did a bit of soldering and desoldering, and boom - I had a small, clean NXT-port-to-header breakout board.

The connector lock may be shifted, but the footprint is the same as RJ45.
Mind you, I haven't actually coded up an I2C interface yet. But I can have a lot of lovely continuity beeps between NXT ports and a breadboard now. :)

     

Monday, September 12, 2011

Particle filters in real time

I love class projects, because it's great to make something that works amidst the theory and pure math. For one of my robotics classes, my team decided to code up a particle filter.

Actually, our plan was to have a Lego Mindstorms NXT robot localize itself (figure out its initially unknown position in a known environment), then navigate to a sound source while avoiding obstacles. We couldn't get the physical robot to cooperate, so we did the localization piece in simulation.

We got the particle filter working, and made some nice videos of the particles in action. Those and more info after the jump.