motion - focusrobotics/explorer GitHub Wiki
Parts Used
- Motors: https://www.pololu.com/product/4755
- Motor drivers: https://www.pololu.com/product/2507
- Motor mounts: https://www.pololu.com/product/1995
- Wheel mounts: https://www.pololu.com/product/2674
- Wheels: 98mm generic skate wheels like these: https://www.amazon.com/Razor-Scooter-Replacement-Wheels-Bearings/dp/B000FDFCPA/
PWM and PID
By default you can use the arduino analogWrite() function to set output PWM, but that gives a very low PWM frequency which is whiny. Setting up high frequency PWM varies a little by microcontroller.
- Setting up higher frequency PWM for STM32 microcontrollers:
- https://www.stm32duino.com/viewtopic.php?t=496
- https://github.com/stm32duino/STM32Examples/blob/master/examples/Peripherals/HardwareTimer/All-in-one_setPWM/All-in-one_setPWM.ino
- https://github.com/stm32duino/STM32Examples/blob/master/examples/Peripherals/HardwareTimer/PWM_FullConfiguration/PWM_FullConfiguration.ino
- https://github.com/stm32duino/wiki/wiki/API#core
- Setting up higher frequency PWM for Teensy microcontrollers
- Setting up higher frequency PWM for AVR (mega2560)
- I gave up on the mega because of low speed, poor floating point perf for PID, and poor interrupt resources for encoder support
Motors
Pololu 37mm metal gear motors: https://www.pololu.com/product/4755 6533 encoder counter per rev, or about 21 encoder counts per mm with the skate wheels I'm using voltage no-load performance stall extrapolation 12 V 100 RPM, 150 mA 34 kg⋅cm (470 oz⋅in), 5.5 A
Motor Drivers
I'm planning to drive it with this motor driver: https://www.pololu.com/product/2507 It will drive 12A continuous per channel. PWM up to 20KHz to limit noise. The library they supply only does the high speed PWM on an UNO (or a couple others) and I was going to use a mega2560
- Here's the pololu supplied control library: https://github.com/pololu/dual-vnh5019-motor-shield
- Here's info on fast PWM for the mega: https://forum.arduino.cc/index.php?topic=445178.0
- More mega PWM info: https://forum.arduino.cc/index.php?topic=72092.0 Holy crap! It's more complicated than I originally thought on the mega
- Here's a library which supports the mega and explains problems: https://github.com/photodude/DualVNH5019MotorShieldMod3
- The default connections and how to remap them are described in the pololu user guide for the shield
- It seems like maybe I want to user timer4 (pins 8,7,6) for pwm and remap the functions those pins currently use from the driver board
- https://arduinoinfo.mywikis.net/wiki/Arduino-PWM-Frequency has a table with all timers and prescaler values Giving up on the Mega! The stm32 or esp32 or Teensy can do this easily, but I'll have to use the driver as a separate board instead of a shield
Odometry
- 21 ticks per mm means 21000 ticks/sec if moving at 1m/s or 21 ticks/ms or ~50us per tick per wheel. Probably too fast of an interrupt rate for Arduino.
- Probably need FPGA to track odometry position and velocity. Might as well generate PWM from the FPGA as well, if it's going to be there.
- Actually, max speed is 100RPM or 1.6666 revs/sec so 10888 ticks/sec, so more like 100us per tick per wheel.
- But wait! It's not really 64 ticks per rev. It's 16 ticks per rev with quadrature encoders. They said 64 because they were counting both edges of both phases.
- The gear ratio is exactly 102.083:1 so at 16 ticks per motor rev it's 1633.328 ticks per output rev. That makes 612us per tick at max speed. Much more reasonable for an Arduino running at 16MHz.
- Of course that means it's more like 5 ticks per mm, but that should still be more than fine for odometer resolution.
- I can still switch to an FPGA solution in the future if I find limitations.
- The Arduino probably talks to a Raspberry Pi via a serial connection. That same Arduino or another one could handle bumpers and/or IR or sonar or other simple sensors.
Microcontroller(s)
- From the discussion above about odometry I can see that I might be processor limited with an 8 bit AVR so I'm looking at 32 bit microcontrollers
- ESP32 is very inexpensive and fast (240Mhz dual core) and I have bought a couple
- STM32 "blue pill" is quite fast and cheap and doesn't have the wifi that I probably don't need, the black pill (stm32F411) is even faster and I bought 10 from AliExpress
- Teensy 4.0 (or earlier) is very fast (up to 600Mhz) and not too expensive: $20. I bought two.