windy54
Posts: 95
Joined: Sat Dec 29, 2012 3:37 pm

Voice HAT Version 1 - servo constantly jitters

Tue Aug 04, 2020 7:48 am

Hi,
I have got my voice HAT V1 working again on a PI B2 And am trying to control a servo.

With no voice hat software running and using the simple GPIO zero servo example, ( please ignore any typos in the code snippet below, my IPad keeps putting in capitals etc)

Code: Select all

From gpio zero import Servo
Import time

Myservo = Servo(21)

While True:
    Myservo.min()
    time.sleep(10)
    Myservo.max()
    time.sleep(10)
    
The servo moves between the two positions but there is a lot of jitter when supposedly stationary.

I am powering the servo from its own PSU, with a 0v connection between PSU and PI, with servo signal connected to PI.

If I repeat the experiment using a PI with no voice HAT there is no jitter in the servo, so I believe it is not the servo itself or wiring.

Has anyone else experienced this problem?

I have also tried using pigpio, servo still jitters but I get a buzzing from the loudspeaker, possibly because pigpio uses the DMA and PCM (audio chip?) to generate the PWM signals.

Cheers
Steve

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Voice HAT Version 1 - servo constantly jitters

Tue Aug 04, 2020 12:43 pm

Posts I made in thsi thread may help: viewtopic.php?f=32&t=279684
Arguing with strangers on the internet since 1993.

User avatar
8BitsAndAByte
Posts: 4
Joined: Fri Aug 24, 2018 1:50 pm
Contact: Twitter

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 05, 2020 7:59 am

Hi Steve,

This stops the jittering in our projects:

Code: Select all

Myservo.detach()
Hope it helps!

Cheers,
8 Bits
We’re Dane & Nicole, two makers that create tremendously terrible tech!

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 05, 2020 4:03 pm

8BitsAndAByte wrote:
Wed Aug 05, 2020 7:59 am
Hi Steve,

This stops the jittering in our projects:

Code: Select all

Myservo.detach()
Hope it helps!

Cheers,
8 Bits
Doesn't that stop the servo being driven thus preventing any self correction should external input cause it to move?
Arguing with strangers on the internet since 1993.

User avatar
8BitsAndAByte
Posts: 4
Joined: Fri Aug 24, 2018 1:50 pm
Contact: Twitter

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 05, 2020 4:37 pm

thagrol wrote:
Wed Aug 05, 2020 4:03 pm
8BitsAndAByte wrote:
Wed Aug 05, 2020 7:59 am
Hi Steve,

This stops the jittering in our projects:

Code: Select all

Myservo.detach()
Hope it helps!

Cheers,
8 Bits
Doesn't that stop the servo being driven thus preventing any self correction should external input cause it to move?
Jup, you're spot on. We're not sure if that would be an issue for Steve :)
We’re Dane & Nicole, two makers that create tremendously terrible tech!

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 05, 2020 4:46 pm

8BitsAndAByte wrote:
Wed Aug 05, 2020 4:37 pm
thagrol wrote:
Wed Aug 05, 2020 4:03 pm
8BitsAndAByte wrote:
Wed Aug 05, 2020 7:59 am
Hi Steve,

This stops the jittering in our projects:

Code: Select all

Myservo.detach()
Hope it helps!

Cheers,
8 Bits
Doesn't that stop the servo being driven thus preventing any self correction should external input cause it to move?
Jup, you're spot on. We're not sure if that would be an issue for Steve :)
Using the pigpio pinfactory (and the underlying library/daemon) would seem a better solution then as in my experience it's jitter free without needing to be disconnected or the power being tunred off.

Bu yeah, we don't know what the original use case is.
Arguing with strangers on the internet since 1993.

windy54
Posts: 95
Joined: Sat Dec 29, 2012 3:37 pm

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 05, 2020 5:17 pm

Thanks for the responses, I will try them out and get back to you, had to stop This project for the moment.

What my grandson has asked for is a robot that responds to him, so I am putting the PI, speaker and microphone in the body, and use the servo to rotate the robot head backwards and forwards.

I can control the servo but with a stationary demand the servo is jittering all the while.

Steve

windy54
Posts: 95
Joined: Sat Dec 29, 2012 3:37 pm

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 12, 2020 5:48 pm

I have been investigating, thagrol's suggestion "Posts I made in thsi thread may help: viewtopic.php?f=32&t=279684" did seem to stop the jitter and I briefly managed to control the servo between min and max angles.

However the servo then stopped working, I have been looking at the servo signals using a simple logic analyser and a very simple program

Code: Select all

pi=pigpio.pi()
pi.set_PWM_frequency(12,50)
pi.set_servo_pulsewidth(12,1500)
and on my PI with the voice HAT installed I always seem to get half the demanded frequency i.e. demand 50Hz and get 25Hz, the pulse widths are then too large for the servo. The servo_demo program prints out the widths and they are off the order 1.8 msecs, I am measuring 3 msecs.

The same software on a PI4 with no voice HAT operates correctly.

So still confused, back to Google I think.

Steve

trejan
Posts: 2240
Joined: Tue Jul 02, 2019 2:28 pm

Re: Voice HAT Version 1 - servo constantly jitters

Wed Aug 12, 2020 6:17 pm

It has nothing to do with the Voice HAT itself. The servo pins are connected to the GPIO header through a current limiting resistor. There is no other circuitry attached to those pins. See https://github.com/google/aiyprojects-r ... ce_hat.pdf

If you're seeing a difference then it is the Pi you're using it on.

windy54
Posts: 95
Joined: Sat Dec 29, 2012 3:37 pm

Re: Voice HAT Version 1 - servo constantly jitters

Thu Aug 13, 2020 8:35 pm

I will stop posting under this thread because the title no longer applies.

Using pigpio to control the servo rather than gpiozero I can move the servo and maintain a position without any jitter .

However I am convinced that with the latest google image when you use the pigpio servo commands the frequency is halved, it should be 50Hz but is actually 25Hz.

I have proved this by replacing the SD card with a standard raspbian build and the servo frequency is 50Hz, measured with a logic analyser, full range of movement is achieved with values between 500 and 2400.

When I run the same script with the latest google image the servo moves for values between 500 and 1200, I am measuring a frequency of 25Hz.

This means I cannot move the servo to the minimum position.

I will raise an issue with google and see what happens.

Steve

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Voice HAT Version 1 - servo constantly jitters

Thu Aug 13, 2020 8:46 pm

If you can have a look at the signal on piscope. It will clarify whether the timing is faulty or not.

http://abyz.me.uk/rpi/pigpio/piscope.html

windy54
Posts: 95
Joined: Sat Dec 29, 2012 3:37 pm

Re: Voice HAT Version 1 - servo constantly jitters

Thu Aug 20, 2020 7:39 pm

This script works

Code: Select all

import pigpio
import time

def main(args):
    servoPin = 24
    sleepTime = 2
    pig = pigpio.pi()
    pig.set_PWM_frequency(servoPin,100) # this will give 50Hz
    print( pig.get_PWM_frequency(servoPin))
    print(pig.set_PWM_range(servoPin,500))
    pig.set_PWM_dutycycle(servoPin,30)
    mina = 14
    maxa = 63
    mid = (mina+maxa)/2
    for angle in range(mina,maxa,1):
        #angle = 25 + index * 2.5
        print(angle)
        pig.set_PWM_dutycycle(servoPin,angle)
        time.sleep(sleepTime)
    pig.set_PWM_dutycycle(servoPin,mid)
    return 0

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

Note the comment against setting the frequency, actual frequency is half the demand.
With this script my servo moves smoothly between min and max positions and then moves to mid-position and stays there with no jitter.

The same script on Buster results in a frequency of 100Hz and the servo does not move until the count reaches 26.

I have had to burn a new image, and now I have got a smooth servo but some of the example programs, e.g assistant_library_with_local_demands.py results in a segmentation fault....

Steve

Return to “AIY Projects”