After quite a bit of my favorite activity, soldering, I was able to get to a point where I could test how the rpi would control a motor. Here's a idea of the test desk:
After a stupid mistake wasted a few hours of my time, I was able to rotate a motor both ways using the pretty nice gpiozero library. I'm not going to go in details about the code, it's going to be on github at some point. Due to under investigation (bad wiring?) I burned the onboard rpi. This pushed me back a few days and I focused on the interior layout.
This diagram is the pinout of the rpi zero and comes from https://pinout.xyz/. I was very useful figuring out where to connect each motor and the battery.
Once ordered, received, & soldered a new pi and a (few) new motor drivers, I was ready to test things again and got all 3 motors to work!
Depth Control
Translation & rotation are simpler than depth control, since all we expect from a translating / rotational motor is to turn until we tell it to stop doing so. With depth, the way we designed it, the motor has to respect 2 physical limits, ie both end states of the syringe: empty (going up) and full (going down). Our simple motor:
- doesn't know how its rotation speed
- doesn't know how many rotations it made so far
- can't tell us anything about its state, although we know when it's running and how much of our max available current we're giving it, scaled within [0, 1].
The solution I came up with is to multiply its scaled input current by an arbitrary time duration, à la Riemann integral. When the motor is turned on, I call a function at an arbitrary frequency (~12Hz), that calculates this so-called energy as
E = motor.value * time_delta
I then proceed to a manual calibration the motor, activating it to one limit to another, saving each time the energy as threshold.
The last two steps are to persist those limits and load them at startup, and stop the motor whenever the next delta
would move the motor's energy past either threshold.
Add a little progress bar on the side of those buttons and the feedback is complete!
Actually now I want to replace both buttons and the progress bar with a single Depth Motor Slider, and let the code handle the rest. Maybe a feature for the shrimp-deck?