I have an interesting problem,
I want to mount a camera on the front of a tractor(Sony RX0M2, similar to a gopro). The camera will eventually be used for image processing. A PQ-12 micro linear servo (see here) will be used to turn the camera on/off. It is being run by a Raspberry Pi 4B. All components in this project will be powered by the 12V tractor battery. I have the raspberry pi running my python code to control the servo at startup. I did this by editing the crontabs in the linux terminal. Thus when the tractor turns on-> Pi starts up->Servo extends/retracts pushing the camera power button-> Sony turns on.
However, when the tractor turns off the situation is more complicated. The camera will begin to use its own battery once the power source is removed. I would prefer the camera not drain its battery everytime the tractor is turned off. It would mean the tractor would have to run for 5-10mins next startup just to charge the camera back up to a battery level where it can operate.
I need some way to press that power button on the camera once the system power source is removed. I need to:
a) sense the battery is off. Maybe I could use a small microcontroller? I simple logic gate?
b) Something that charges up while the system has power and can temporarily power the servo during discharge. Perhaps a capacitor. But then again If I do use the Servo ill need a PWM signal. Would the PI zero work here. I think ill need something small since It'll need to be powered during this discharge time also.
Note: I think the Pi 4B can probably run code at shutdown but my assumption has been that this would be after a shutdown prompted by the user in GUI, not by shutting down the Pi via removing the power source. Perhaps this is an erroneous assumption.
Just a beginner here using my mediocre knowledge to develop half-brained solutions. Thanks for the help everyone. If I'm missing any important info just let me know.