0

How to get pan-tilt servos quiet forever after first adjustm
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

How to get pan-tilt servos quiet forever after first adjustm

by dstonek on Tue Feb 20, 2018 8:30 pm

This is a copy of this question https://raspberrypi.stackexchange.com/questions/79519/how-to-get-pan-tilt-servos-quiet-forever-after-first-adjustments?noredirect=1#comment125633_79519
Raspberry Pi 3
I have a camera mounted in an Adafruit pan-tilt mini kit with 2 servos (SG92R).
PCA9685 board.
Installed python-smbus and i2c-tools.
From raspi-config I enabled 5 Interfacing options P5 I2C.
Also installed Adafruit_Python_PCA9685.
Executing a python script I position the camera.

I only use pan-tilt to fine tune the camera position just at startup for timelapse.
I found that despite I added a @reboot line in crontab to run that script with the same two parameters (horizontal and vertical servo positions) I used the first time, just in case of restart after power failure or manual reboot, the position of the camera is slightly different than the original one.

I tried disabling I2C interface option but the result is far away the original position of the camera.

Then only way I guess I can accomplish that is to disconnect the power of the pan-tilt controller ( PCA9685 ) after getting the best position but this could be a mess for me.

I asked if is there another way to get servos quiet in case of reboot.

Here's the script to manage both servos.
Code: Select all | TOGGLE FULL SIZE
from __future__ import division
import time
import sys
import subprocess
import Adafruit_PCA9685

pwm = Adafruit_PCA9685.PCA9685()
servo_min0 = 160
servo_max0 = 166
servo_min1 = 444
servo_max1 = 450
if len(sys.argv)==1:
        servo_H = 360
        servo_V = 380
elif len(sys.argv)==2:
        servo_H = int(sys.argv[1])
        servo_V = 380
else:
        servo_H = int(sys.argv[1])
        servo_V = int(sys.argv[2])

def set_servo_pulse(channel, pulse):
    pulse_length = 1000000   
    pulse_length //= 60 
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096   
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

pwm.set_pwm_freq(60)
pwm.set_pwm(0, 0, servo_H)
pwm.set_pwm(1, 0, servo_V)

1) Is there something I can change here to get the servos fixed in the same position after rebooting?

2) An answer I got was to use "expensive" servos.
I found one larger assembly structure (metal) compatible with these servos: MG995 or HS322,HS422,Hitec,Parallax,Futaba, etc 40×20×36mm. I don't know if they would serve my needs (stay in a fixed position despite reboot). They also must be compatible with my PCA9685 module. Would they?
Thank you

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Tue Feb 20, 2018 9:05 pm

In my experence, most of the low-cost servos like the Towers are repeatable to within a couple of degrees. The Hitecs and Futabas for the most part are repeatable to within a degree. Part of that is due to the mechanical precision and residual backlash in the gear-train. And part of it is due to the tuning of the PID position control.

Some of the higher-end digital servos actually allow you to specify tuning parameters for the PID, including the positioning hysteresis.

The tradeoff there can be stability. If you get too aggressive with the proportional or integral terms and/or try to minimize the hysteresis, the servo may get jittery as it constantly tries to home-in on that perfect position.

For more precise positioning repeatability, stepper motors are a better option than servos.

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Wed Feb 21, 2018 7:35 am

Okay, I understand.
So would the simplest solution be to cut power to the controller after getting the best camera position?

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Wed Feb 21, 2018 7:56 am

Cutting power to the controller will cut power to the servos. Depending on the mass and orientation of your camera, there may not be enough resistance in the geartrain of the un-powered servo to maintain the current position.

It seems to me that the problem is caused be re-running the script and sending more commands to the board. Once the camera is in position, you just need to maintain power to the board and the servos. As long as everything is powered, nothing should change until you send more commands to the board. The PCA9685 will continue to generate the same control pulses for as long as it is powered.

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Wed Feb 21, 2018 8:32 am

It seems to me that the problem is caused be re-running the script and sending more commands to the board. Once the camera is in position, you just need to maintain power to the board and the servos. As long as everything is powered, nothing should change until you send more commands to the board. The PCA9685 will continue to generate the same control pulses for as long as it is powered.

I know that. I have the system powered on for a month and all photos are perfectly aligned.
My concern is about what's next a power failure.

Cutting power to the controller will cut power to the servos. Depending on the mass and orientation of your camera, there may not be enough resistance in the geartrain of the un-powered servo to maintain the current position.

Raspberry cameras are very lightweight. I have to care if I have to manipulate something inside the box where the RPi and other stuff is placed.
I already had tested the camera mounted on pan-tilt kit without power and it is firmly enough for my purposes.

So my next step would be to search about if it would be possible to cut power of only one RPi USB socket.
Thank you

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Wed Feb 21, 2018 8:53 am

So my next step would be to search about if it would be possible to cut power of only one RPi USB socket.

If you go that route, you probably only want to cut power to the servos (V+). Cutting power to the PCA9685 (VCC) will lock up your i2c bus.

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Wed Feb 21, 2018 10:06 am

If you go that route, you probably only want to cut power to the servos (V+). Cutting power to the PCA9685 (VCC) will lock up your i2c bus.

I only am using i2C bus for these two servos. Just in case, how can I only cut power to the servos?
Thank you

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Wed Feb 21, 2018 10:53 am

The PCA9685 is powered via the VCC pin. Servo power is supplied via either the V+ pin or the screw-terminals on the top edge of the board.

The simplest way to cut power is probably via a relay. The Feather Wing Mini Relay would handle the pan/tilt servos, and can be actuated from a 3.3v GPIO signal from the Pi:

https://www.adafruit.com/product/2895

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Wed Feb 21, 2018 12:42 pm

Sounds interesting. My knowledge on this matter is very basic. Not sure how to manage it from RPi. Latched or Non-Latched board?

I had a dumb idea: power the PCA9685 board from a small power bank I leave in the box until it is drained. Time enough to make servo adjustments. I know there are cons like leaving the powerbank depleted for a long time at low and high temperatures (0°C - 40°C)

Another idea is to see if power may be cut from a Witty Pi 2 card I ordered last week just to reduce Amp/day if a solar panel w/battery is required. If so, anyway it is a priced solution just to only power off servos

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Wed Feb 21, 2018 12:51 pm

You didn't say how you are powering the servos currently. But adding a non-latching relay would be fairly simple. You just connect the relay outputs in series with the servo power and connect a GPIO pin from the Pi to the control pin on the relay board. Setting the GPIO pin to HIGH turns the servo power on. Setting it LOW cuts the power.

Not familiar with the Witty board. But it sounds like you can script the power control, so that might be an option too.

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Wed Feb 21, 2018 2:08 pm

Now PCA9685 gets power from one RPi USB port but it can be taken from any other source.
Your relay seems to be the best option. So by software I can control it from Low to High.
Witty Pi customer service has responded that it is not possible with their board but they have a USB hub; their ports can be turned off from switch or software.
http://www.uugear.com/product/7-port-usb-hub-for-raspberry-pi/

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Mon Apr 02, 2018 5:45 pm

Hi Bill,

I need some help.
This is my present configuration
conexion controlador pan-tilt.jpg
conexion controlador pan-tilt.jpg (132.37 KiB) Viewed 409 times


1) How do I insert the non-latching relay?
conexion controlador pan-tilt-relay.jpg
conexion controlador pan-tilt-relay.jpg (154.46 KiB) Viewed 409 times


2) How to control it from software?

The Feather Wing Mini Relay would handle the pan/tilt servos

I see the relay has SDA and SCL pins.
3) Am I able to handle both servos and remove the PA9685?

Thank you

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Mon Apr 02, 2018 6:04 pm

To power the board, you need connections to GND and 3.3v from the Pi.

To control the relay, you need a connection from a GPIO pin to the "signal" connection on the relay board.
https://learn.adafruit.com/mini-relay-f ... ay-control
Image

Set the GPIO pin HIGH to energize the relay. Set it to LOW to de-energize.

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Re: How to get pan-tilt servos quiet forever after first adj

by dstonek on Mon Apr 02, 2018 6:44 pm

There's something I am missing, how does the PCA9685 get the power to be relayed?

conexion-controlador-pan-tilt-relay2.jpg
conexion-controlador-pan-tilt-relay2.jpg (161.53 KiB) Viewed 402 times

dstonek
 
Posts: 25
Joined: Tue Feb 20, 2018 8:00 pm

Re: How to get pan-tilt servos quiet forever after first adj

by adafruit_support_bill on Mon Apr 02, 2018 6:49 pm

The relay is just a magetically actuated switch. You connect your servo power via the relay contacts here:
https://learn.adafruit.com/mini-relay-f ... lay-output

Image

Both Wings have the same output, a 3-pin 3.5mm terminal block. The COM pin is what you should connect the signal you're planning to switch. If the relay is unset, the NC pin (Normally Connected) is mechanically connected to COM. NO (Normally Open) is mechanically disconnected.

When the relay is set, NC becomes disconnected from COM and NO is connected to COM

adafruit_support_bill
 
Posts: 80311
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.