etotheipi / creepy_face_oakd_clip

My 2022 Halloween creepy face that stares at you and guesses your costume
MIT License
3 stars 0 forks source link

Servo jittering #1

Open cody778 opened 1 year ago

cody778 commented 1 year ago

So I implemented the code into my project which only features an X axis JX Ecoboost servo. I modified the code to pin 25 and removed the audio configuration and modules. I ran the code and the facial detection and noise map were working fine as well as the coordinate calculation. But the servo would just move back and forth and jitter without actually following my face.

etotheipi commented 1 year ago

It's tough to tell for sure without seeing everything. How much does it overshoot? Does it ever finish settling on your face? I did have a problem after the pressure plate sequence that it would freakout (see the first minute of my video, after the dino ID). But it only did that AFTER the pressure plate sequence when the servos hadn't been updating. It would be completely dysfunctional to the point I'd have to hard reset after each costume ID. Never did it before the costume ID sequence, though.

One thing you can do is turn the visual output back on by uncommenting the couple lines at the end of the script. I had to disable them for headless operation, but for experimentation while the Pi is hooked up to a monitor, it's very useful.

One obvious thing to do is verify that your servo signal is not reversed (may not be an issue with servos, but definitely easy to mess up with steppers). Two things to look at

(1) There's a parameter that defines the center box of the image. The servos should not move if the center is in that box: top left of the image is (-1, -1), bottom right is (1, 1), the center box is (-0.15, -0.15) to (0.15, 0.15). Otherwise it will ALWAYS be adjusting. (2) There is a speed parameter that can be adjusted. Try making it really really slow.

cody778 commented 1 year ago

The angular velocity was lowered to 1.0, the center pan was lowered by 30 degrees and the center box was doubled in size to 0.30. The servo would turn to face the person detected but the it would immediately return to the center position. The jittering did not stop

etotheipi commented 1 year ago

Have you tested the gpiozero servo control with your particular servos? Are you sure you haven't swapped pan & tilt wires? Is it possible it's reversed from my servos?

There's some log output that you can probably use to help you figure out what the the servos and logic are trying to do. Just look in the code to see what all the vars mean. There's two different coord systems for servo angles ([-1, 1] and [0 deg, 180 deg]), and I matched up my servo directions to the coordinate directions through trial and error. Again, maybe yours is reversed for some reason.