Noise with PanTiltHat

Hi,

I bought a pantilthat et j’ai un petit problème.
When i import the library with python, one of the servo motor make noise like a vibration.
I can disable it but i prefer use the both.
Have you got any idea for help me to solve my problem ?

Thanks

This usually happens only when the servo is hitting the extreme of its movement and oscillating back and forth in an attempt to move into an impossible position. Or when the servo is overloaded and doesn’t have the torque to move.

If it’s happening for any other reason, you may have a faulty servo.

i have tried to connect only the fault motor and i have the same thing. The second motor doesn’t make any sound.
No problem for move, sound is the same at 90, 0, -90 and others between.
I must contact the shop support ?

Are you using a good quality power supply?

i have tested 2 different power supply. One of them can produce 2A. I will test another one this night.

I made a film : https://m.youtube.com/watch?v=amTAC0bvrSw

1 Like

Tested with 2 others power supply, same problem :(

Have you tried removing the servo from the pan tilt gimbal?

Does it do it when removed? If not then its prob crashing and pushing against an obstruction.

Just do a simple bit of code.

from pantilthat import *

pan(90) #change to -90 on next run
tilt(90) #change to -90 on next run

Might just be it was never zeroed right when assembled or if removed and its still doing it then its the servo.

But I may have problems with warranty :(

Cheap as chips those servo’s :)

http://www.ebay.co.uk/itm/12Pcs-SG90-9G-Micro-Servo-Motor-For-RC-Robot-Arm-Car-Helicopter-AirPlane-Boat-UK-/282216921320?hash=item41b57078e8:g:VIYAAOSwCGVX~fUU

You can get 12 of em for just over a tenner.

They don’t or the pantilthat doesn’t do 180 degrees though and which is which haven’t figured yet as need some feedback from you guys.
I am only getting 140 degrees approach, same on both servo’s no obstruction.

Sometimes there are dead zones at the end of travel and you just get jitter what happens if you send it to - 89 to 89 and -85 to 85?
Mine jitters just on one side for a couple of seconds and then stops, but the 180 degrees bugs me more. Or not having 180, I guess I could guestimate it and scale it, but still tryingto figure out if we are all the same.
Is this just a batch, is the pantilthat not giving 50-2400 micro second pulses or is it just me with two servos of the obstinate kind :)
Or guess you could return under warranty, give a shout to their.

Black Friday burned out my bank account :)

Ok try this code

[code]#!/usr/bin/env python

import cv2, sys, time, os
from pantilthat import *

servo_enable(1,1)
servo_enable(2,1)
pan(90)
tilt(90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)
servo_enable(1,1)
servo_enable(2,1)
pan(-90)
tilt(-90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)
servo_enable(1,1)
servo_enable(2,1)
pan(90)
tilt(90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)
servo_enable(1,1)
servo_enable(2,1)
pan(-90)
tilt(-90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)
servo_enable(1,1)
servo_enable(2,1)
pan(90)
tilt(90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)
servo_enable(1,1)
servo_enable(2,1)
pan(-90)
tilt(-90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)
servo_enable(1,1)
servo_enable(2,1)
pan(90)
tilt(90)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
time.sleep(5)

servo_enable(1,1)
servo_enable(2,1)
pan(-30)
tilt(0)
time.sleep(.7)
servo_enable(1,0)
servo_enable(2,0)
[/code]

I don’t really like the way its been implemented though as without the delay you will disable the servo before its finished the 1.6sec/60degree movement hence why I used .7.

It would be great if the pic had a register auto_shutoff_time where the pic would increment on each cycle and turn off the servo, also if zero then don’t turn off.
I have no idea how many registers that pic has or what can be done with it and how it could be flashed.

I found my problem about rotation but the whole pantilthad module is full of more arguments.
Easiest way is to sudo pcmanfm
Then navigate to /usr/local/lib/python2.7/dist-packages/pantilthat/pantilt.py and have look.

I sorted my rotation problem with

def __init__(self, enable_servo1 = True, enable_servo2 = True, enable_lights = True, light_mode = WS2812, servo1_min = 575, servo1_max = 2325, servo2_min = 575, servo2_max = 2325, address = 0x15, i2c_bus = None):

As you will see you are going from 800 to 2300 which aint 180 degrees servo’s have a little more than rated because they are analogue and you need to trim them.
The movement on the pan tilt is prob offset by 5 - 10 degrees physically and I have kept it as such so that its out of the dead zones as much as possible.
Its prob just a spline notch out of place or just sitting in a bad position and will have to trim back the rated minimium of 500 and knock the equivalent about off the top value.

doing the sudo pcmanfm will give you root access so you can edit the module but it will get overwritten on a lib upgrade from pimorini.
You can do the via python [code] def servo_pulse_min(self, index, value):
"""Set the minimum high pulse for a servo in microseconds.

    :param value: Value in microseconds

    """

    if index not in [1,2]:
        raise ValueError("Servo index must be 1 or 2")
    
    self._servo_min[index-1] = value

def servo_pulse_max(self, index, value):
    """Set the maximum high pulse for a servo in microseconds.

    :param value: Value in microseconds

    """

    if index not in [1,2]:
        raise ValueError("Servo index must be 1 or 2")
    
    self._servo_max[index-1] = value

[/code]

so

servo2 is servo_min(2…

I’ve been keeping my eye on all the PanTilt HAT feedback and will be rolling as much of this as possible into the library.

The firmware most likely wont change at this stage, but things like idle-timeout can be handled in Python by shutting down the servos with their enable bits.

I’ve pushed the values as suggested by @stuartiannaylor in this commit: https://github.com/pimoroni/pantilt-hat/commit/60558897f7731f9cf3ed9bd54cf05ac09b1faa21

I’ve also implemented an atexit handler, which turns off the servos when the Python script is exited to prevent any problems when they’re not being actively driven.

I will investigate an idle timeout which will disable a servo if it hasn’t been driven for X seconds, and re-enable it if any new PWM value is written. I realised this feature was implemented into servo blaster forever ago, I should have “drawn more inspiration” from that project ;D

Edit: https://github.com/pimoroni/pantilt-hat/commits/master

If you’re familiar with grabbing libraries from GitHub you can go right ahead and give that a try. It includes:

  • An integer number of degrees no longer required although the deadband of the servo means this probably wont make any difference
  • Servos now timeout by default after 2 seconds. You can change the timeout to 0 to prevent this.
  • The library turns off the servos upon exit

For some reason it also takes a moment to exit and I can’t seem to nail down why. It appears to be related to the Timeout. Apparently they suspend the main thread until they trigger, and atexit wont fire until they time out… I don’t even! This isn’t a huge problem, but it bugs me.

PS with docs I really like https://readthedocs.org/ really simple layout and great for us noobs

You mean like this? Welcome — PanTiltHAT 0.0.5 documentation

Look very similar :) was that always there as have honestly been doing this blind.

#!/usr/bin/env python

import time
from pantilthat import *


clockwise = False
x = 0
while True:
    
    if x == 90:
        clockwise = False

    if x == -90:
        clockwise = True


    if clockwise == False:
        x -= 1
    else:
        x += 1
        
    print(x, clockwise)
    pan(x)
    tilt(x)
    time.sleep(.01)

Its as smooth as you will get with this type of servo for me.

That’s how I’ve been testing mine out. Would love to see a video for comparison :-)

:D yes, sorry it was! Where did you go to hunt for documentation by the way? I’m hoping to get a nice boxout on our store pages with all the pertinent links so people can actually find this stuff, but that’s a work in progress!

Your example is purely linear with a constant rate of change, so it should be more consistent than my sin based example which gets slower towards the extremes.

For some reason maybe its the i2c delay but it wasn’t hitting the edges.
Also added trim methods currently going more than 180.
575 - 2325 seems about right to me.

#!/usr/bin/env python
import time
import pantilthat

print pantilthat.__file__


clockwise = False
x = 0

#500 - 2400 is max pulsewidth of sg90
pantilthat.servo_pulse_min(1, 500)
pantilthat.servo_pulse_min(2, 500)
pantilthat.servo_pulse_max(1, 2400)
pantilthat.servo_pulse_max(2, 2400)


while True:

    
    if x == 90:
        clockwise = False
        time.sleep(1)
    if x == -90:
        clockwise = True
        time.sleep(1)

    if clockwise == False:
        x -= 1
    else:
        x += 1
    
    #print(x, clockwise)
    pantilthat.pan(x)
    pantilthat.tilt(x)
    time.sleep(.01)

ps the forum has done it again and stripped tabs from the code you will have to indent the code.
Also the .file will display the location of the module

Nice, I’ll have to have a go at fiddling with the pulse widths, currently my tilt servo maxes out at -65.