Optical Flow Melty Brain Robot

I want to make a “melty brain”/translational drift battle robot using the OpenMV for optical flow stabilisation. To make this happen I want to:

  1. Receive a clock from each of my two brushless motor controllers that indicates wheel odometry.
  2. Every N pulses (where N is approximately 100 to 150) I want to quickly trigger a steering servo or solenoid (which will need to be clocked at 400Hz instead of the usual 50Hz) snap a photo and compare it to the photo taken on the previous cycle, computing the number of pixels of horizontal translation find_displacement() but only in the x direction).
  3. Use that optical flow displacement to modulate N.
  4. Have my robot rotate at approximately 1000rpm (approximately 16 frames per second) with extremely low frame jitter (something like 200us max) in the optical flow correction path.

OpenMV uses MicroPython, which can do many things. However it doesn’t seem to be able to:

  1. Configure servos to be clocked at a rate other than 50Hz.
  2. Support a counter that will interrupt every N cycles of an internal clock to trigger a snapshot.
  3. Run in hard realtime since it is a garbage collected language.

Am I right in assuming I can’t do those things in MicroPython?
I could probably add 1) and 2) to MicroPython by wrapping new C modules, but is 3) likely to be a killer in my application? What are peoples’ experience with frame jitter due to the interpreted and garbage collected nature of Python?
Better to remove python and program the OpenMV directly in C for this?

Thanks.

Hi, our servo module updates at 50 Hz because that’s what servos expect. However, its all based on general purpose timers so you can make the freq anything you want by using the TIM module directly.

As for tacking a snapshot every n cycles… You can configure a pin as an interrupt source and then interrupt on that to take a picture. You can’t take the picture during an interrupt but you can schedule the picture to be take later once the interrupt completes.

As for hard real-time, yeah, just call garbage collection in your main code loop to keep the amount of garbage produced low and then it will be hard real time more or less.

Cool, thanks for the advice!

I have read that many servos will operate at rates greater than 50 Hz as long as the pulse time is still between 1ms and 2ms. I need a high update rate for my application, so I plan to experiment until I find a servo that can do something quick. Many electronic speed controllers now officially support much faster update rates than 50Hz ( “OneShot125” ) for multi copter applications.

Thanks for the advice on this point. I will either directly configure a Timer to do PWM or I will hack the C implementation of the servo module to update faster.