Thursday, October 04, 2007

I doubled my encoder resolution.

I modified my interrupt code to switch interrupt levels. On the Mega128 external interrupts 0-3 don't have the option of setting the interrupt level to both. Both meaning low to hi and hi to low edges. You get either or. So in my encoder code, I added a state variable to tell which was the last state. I'm only interrupting on the A channel but now I get double the interrupts by detecting both edges.

The good news it my resolution has improved to .0047" per tick. The bad news it, I have to re-tune my PID loop :(

Last night I decided to modify my motor control code to take in account how fast the bot is traveling, and how far it has left to go. The results are good and it has smoothed the ramping I had coded earlier. In fact, in hindsight, the previous code was too restrictive ... now the control is more adaptive. I know I keep promising a video, but there's always something I want to fix before showing it off. I'll do it tonight first thing before I enter another 3 hour coding stint.

As for the PID, have a look at last night's capture.

The thick red is the left encoder measurement, the dashed pink is the right encoder. The yellow (click the image to see a bigger version) is the commanded left velocity. As you can see, I have a lot of oscillation now as well as an overdamped response. I need to go back and refresh my memory on PID tuning and what do I need to do to clean this up. One more thing, the instruction was to drive the robot forward 36". It took about 4.8 seconds.

Jay