You are browsing as a guest. Sign up (or log in) to start making projects!

1h 12m 38s logged

Dual-motor…drive?

I added a second motor and added support for turning in the Pico’s firmware. The main challenge in this session was figuring out how the robot will turn. Since the entire purpose of the Pico is to be the Pi’s personal uber driver, it should have the ability to process almost every command on its own without reliance on the Pi. To put it simply, the Pi won’t say “hey, turn one motor this way and the other one in the opposite direction to create a torque to make the robot spin,”; instead, it will simply say something like “turn this way!” and the Pi will figure out the angle in which it should turn and it will internally compute how it should control the motors. The new command structure is now 2 bits for direction + 2 dummy bits + 4 control bits. Having the 2 bits for direction allows for 4 possible outputs. Since my histogram from the algorithm used intervals of 45 degrees, having 4 of those 45 degree chunks is enough to cover a 180 degree arc. With turning support in both the left and right direction using the command nibbles 0xD and 0xE, respectively, it is possible to complete a full rotation.

INFINITE RECURSIONNNNNN

Since the robot is supposed to only rotate for a little bit and then resume moving in whatever direction it was going in, I implemented this by using a recursive call to the control function itself and passing in the value of the old command as the new command to execute. This recursive behavior was only meant for turns, not straight movement. As you could guess from the header, this resulted in the program calling itself over and over if I did two turns (since the last command was a turn and it’s last command, by my stupid function call, is also a turn). I patched this by making the program only recall straight moves and not turns, that way it would never have a old_cmd encoding for another turn.

0
27

Comments 0

No comments yet. Be the first!