After a bit of a break, I have done some more work on Decimus, my DC micromouse. With all the peripherals tested and working, I have been concentrating on the motion controller or profiler. This has turned out to be harder than I expected. The basic idea is simple enough but the implementation turns out to be a bit tricky. Probably in part because I wanted it to be useable with Primus, the beginner’s stepper-driven micromouse.
Until I add the code into Primus, I am not going to know how successful I have been but I have a fair degree of confidence. the profiler only communicates with the hardware in two ways. One is to read the encoders to find out how far the mouse has moved since the last timer tick. Primus has no encoders but instead keeps a pair of counters exactly equivalent to the values maintained by the encoder hardware in Decimus.
The other communication is with the motor driver. It is the task of the profiler to generate speed profiles appropriate to a particular movement. Each movement generate two kinds of speed information – forward speed and rotational speed. These speeds are given to the motor controller where they get resolved into appropriate speeds for each wheel. The motor driver in Primus can only set the pulse rate for the steppers so the speeds are used directly. Since the steppers are open-loop it is sufficient to assume that pulses get turned into wheel movement unless we push the controller too far.
For Decimus, the wheel speeds are used to update the setpoint for each wheel. An error term is calculated which is the previous error plus a new component due to the speed term less the distance the wheel has actually moved. This error, for each wheel is used in two PD controllers to determine the power to each motor.
For initial testing, arbitrary values have been used for the P and D constants. These allow the mouse to work but some work now remains to determine the optimum values for these constants.
Although Decimus can steer off the walls and implements forward error correction by looking at wall trailing edges, the sensors have not yet been calibrated or properly aligned so the whole process is still a bit flaky. Still, results so far are quite promising: