Another Servo Jitter Issue

I have gone through many posts that claim to have servo jitter problems, and even though I did find some solutions, none seemed to work for me. My particular problem can be seen here.

My circuit is composed of:
-Picaxe 18X in a breadboard.
-A hacked 2 axis analogue joystick.
-2 Futaba S3003 servos.
-(I was wondering if adding capacitors somewhere would help my problem. My experiments turned out useless.)

The pots in the joystick get 5VDC and 0VDC in each end and each wiper is fed via 330 ohm R to 2 ADC pins. That value is mathematically translated to servo values in the code and then fed to the 2 servos. They have their own PS.

Here´s the code:

init:
servo 4,75
servo 5,75

main:
readadc 1,b1
readadc 0,b0
let b2=b0/2+75
let b3=b1/2+75
servopos 4,b2
servopos 5,b3
goto main

As far as I can tell, the jitter is caused by the instability of the ADC reading coming from the joystick, even when I don´t touch it. The best I can think of, is writing code to round up the values. According to the debug screen, my instability is smaller than value 5 (inside of the 0-255 range).

Any ideas, community? H-E-L-P!
 
I have tried to filter out some of the jitter with the code, like so:

init:
servo 4,75
servo 5,75
symbol TOLERANC = b13
toleranc = 9

main:
readadc 0,b0
readadc 1,b1
let b12=b0+toleranc
let b11=b0-toleranc
let b10=b1+toleranc
let b9=b1-toleranc
readadc 0,b2
readadc 1,b3
if b2>=b0 and b2<=b12 then main
if b2<=b0 and b2>=b11 then main
if b3>=b1 and b3<=b10 then main
if b3<=b1 and b3>=b9 then main
let b4=b0/2+75
let b5=b1/2+75
servopos 4,b4
servopos 5,b5
goto main

No luck.
 

KingsJester89

New Member
I've previously attempted something similar see here: http://www.youtube.com/watch?v=PPu70X8AKqM
In my case the jitter was caused by the servos drawing too much current, overheating and thus shutting down the 7805 I was using as a power supply and resetting the Picaxe variables to zero. The picaxe would then read ADC values from potentiometers and attemt to move the servos only to overheat the 7805 once more. I solved it by using a 7805 for each servo as they can each source 1 amp of current. I'm not sure if this is the problem in your case though, but it's worth a look.
 
Last edited:

boriz

Senior Member
Where is your Pause?

Servo command uses background timer to update servo position every 20mS. Your loop takes much less time than that, continually resetting the servo command system. Try adding PAUSE 100.
 
KingsJester89,
I don´t think that is the problem here. However, I appreciate your feedback and will power one servo from an alternative source to rule that out.

BTW, very cool robot arm experiment. How did you control the 3rd axis? The shot of the joystick is not very clear.

Cheers,
Andrés
 
The pause is not on the transcripted code, as you have noticed, Boriz. I did experiment with different lengths. It was placed right after the first 2 readadc commands. I´ll give it another go tonight. Would you place it there? Or somewhere else?
Thanks for your feedback!

Andrés
 

KingsJester89

New Member
BTW, very cool robot arm experiment. How did you control the 3rd axis? The shot of the joystick is not very clear.
Andrés,
The Picaxe 18m2 is reading the ADC values from 3 potentiometers. I made the joystick myself from a scrap peice of metal and some plastic. Here it is before I wired it up:
http://www.flickr.com/photos/63002868@N03/5951393367
And after:
http://www.flickr.com/photos/63002868@N03/5951979972
http://www.flickr.com/photos/63002868@N03/5951980044
 
Last edited:

boriz

Senior Member
I would probably put the pause here:
Code:
servopos 4,b4
servopos 5,b5
[COLOR="#FF0000"]Pause 100[/COLOR]
goto main
 
Here are your suggestions and what I´ve found right next to them.

1.- (Dan M. and KingsJester89) Find out if either current or tension is the problem. Nope it isn´t. I have to admit that the original power supply was somehow more marginal than what I expected, so I did two things. One) I left only one servo hooked up (half the current draw) and it still shook. Two) I used a lead/acid 12VDC 4Ah battery (properly regulated) as my power source and the shake was still there. Different frequency. But still there. By the way, I´ve added Dan`s trick to my code (MIN 75, MAX 225).

2.- (Rick100) Change the pots in the vintage joystick. I simply unplugged the joystick from the breadboard and the shake was still there.

3.- (Boriz) Add pause 100 to the code, because it was cycling faster than the refresh rate. Didn´t solve it either.

4.- (Ignoblegnome) Add caps as described in the forum topic he linked to. Didn´t get to the shop on time. I´ll try again tomorrow.

Thanks to all who participated. Stay tuned for more updates!

Cheers,

Andrés
 
I would probably put the pause here:
Code:
servopos 4,b4
servopos 5,b5
[COLOR="#FF0000"]Pause 100[/COLOR]
goto main
Hey Boriz,
The pause did not solve the problem. I have tried it where I originally had it and also where you suggested. I came to believe that it didn´t matter where it was located, anyway.

Code:
init:	
servo 4,75
servo 5,75
symbol TOLERANC = b13
toleranc = 4

main:
	readadc 0,b0
	readadc 1,b1
[COLOR="#FF0000"]pause 100[/COLOR] ´tried it here
	let b12=b0+toleranc
	let b11=b0-toleranc
	let b10=b1+toleranc
	let b9=b1-toleranc
	readadc 0,b2
	readadc 1,b3
if b2>=b0 and b2<=b12 then main
if b2<=b0 and b2>=b11 then main
if b3>=b1 and b3<=b10 then main
if b3<=b1 and b3>=b9 then main
let b4=b0/2+75 max 225 min 75
let b5=b1/2+75 max 225 min 75
servopos 4,b4
servopos 5,b5
[COLOR="#FF0000"]pause 100[/COLOR] ´and tried it here too
goto main
 

MartinM57

Moderator
^^^^^ agree

...and then add a loop that moves b0 from 0 to 255 so that the servo moves under simple program control rather than as a result of readadc readings
Code:
init:	
servo 4,75
servo 5,75
symbol TOLERANC = b13
toleranc = 4

main:
	;readadc 0,b0
	readadc 1,b1
        [B][COLOR="#FF0000"]for b0 = 0 to 255[/COLOR][/B] 
pause 100 ´tried it here
	let b12=b0+toleranc
	let b11=b0-toleranc
	let b10=b1+toleranc
	let b9=b1-toleranc
	readadc 0,b2
	readadc 1,b3
if b2>=b0 and b2<=b12 then main
if b2<=b0 and b2>=b11 then main
if b3>=b1 and b3<=b10 then main
if b3<=b1 and b3>=b9 then main
let b4=b0/2+75 max 225 min 75
let b5=b1/2+75 max 225 min 75
servopos 4,b4
servopos 5,b5
pause 100 ´and tried it here too
        [COLOR="#FF0000"][B]next b0[/B][/COLOR]
        goto main
 
Last edited:

boriz

Senior Member
Are the Picaxe and servos driven from the same voltage source? Try splitting it. IE: 5v regulator for Picaxe, 4AA batteries for servos.

Note. A single servo can draw as much as an amp or more.
 
Have you checked if the adc values is stable? Try reading the pots and sertxd them back to the computer. I`m thinking if the adc values is not clean, then the servo output could be affected.
 
Have you checked if the adc values is stable? Try reading the pots and sertxd them back to the computer. I`m thinking if the adc values is not clean, then the servo output could be affected.
Yep. I have tried that with the debug command. They are reasonably stable. I get a +/-5 reading all the time. Let´s say that the joystick is not being touched and in the middle of its travel. The content of the readadc variable would be at (let´s say) 128 and oscillate +/-3 typically and +/-5 as peaks.
Reagrdless, I remove the joystick connections from the breadboard and it still shakes. I like what they have suggested about isolating the readadc commands and swapping them with a for next loop.

Thanks, Balderbraa!
 
Are the Picaxe and servos driven from the same voltage source? Try splitting it. IE: 5v regulator for Picaxe, 4AA batteries for servos.

Note. A single servo can draw as much as an amp or more.
I have tried it with separate PSUs. But I am not happy with their current capabilities. Only last night I bought a 3A PS. I hope to be able to test it tonight. I´ll let you know how it went, Boriz. Thanks,
Andrés
 

hippy

Ex-Staff (retired)
A +/- 5 variation on READADC would be far from what most would call stable and this would seem to be the primary source of the jitter. Test as has been suggested without the READADC and the variable set to a known value and it should hopefully be jitter free.

100K is possibly high for a potentiometer used with a PICAXE and 10K would likely be a better value. Simply removing the pots won't necessarily cure instability as you likely then have the ADC input floating.
 
A +/- 5 variation on READADC would be far from what most would call stable and this would seem to be the primary source of the jitter. Test as has been suggested without the READADC and the variable set to a known value and it should hopefully be jitter free.

100K is possibly high for a potentiometer used with a PICAXE and 10K would likely be a better value. Simply removing the pots won't necessarily cure instability as you likely then have the ADC input floating.
Thanks for bringing a fresh perpective into my headaches, hippy! You are right when you assume that when I lifted the pots from the breadboard, I forgot to tie the pins down. (Embarrased). As I have mentioned before, I need to finish my new 3A power supply to be able to test this experiment again. I will update when I do so.

Thanks for your input.

Andrés
 
Last edited:
Here are all the things that I have tried:
-I´ve run the servos and the logic from the same power supply and from different ones. The last one I´ve used for the servos alone was 3A properly regulated.
-I have made sure that, if using 2 PS, that the GNDs were common.
-I have switched the pots from the hacked joystick from 100K&#937; to brand new and noiseless 10K&#937;.
-I have tied all unused inputs from the Picaxe down via 10K&#937; resistors.
-I have tried to implement filtering in the code.

...all those solutions produced this result. The jitter has diminished considerably... but it is still there. I don´t think it is going to get any better than this, so I´ll move on to other things.

I want to express my most heartfelt gratitude to all those who took the time to read the thread and chime in ideas.

Cheers,
Andrés
 

flyingnunrt

Senior Member
Don't give up yet ypu should be able to get better than that.
I don't know what the futaba servos are like but I used JR and that worked fine with an 18X.
I only had one servo though. Have you tried it with just the one servo?
I used Nicads, one pack for the picaxe and one for the servo, with the grounds commoned, that worked fine for me.
Have you isolated the + supply to the servo from that supplying the picaxe chip?
try adjusting the pause time say to 30ms or even 15ms for example, or even try changing the servopos command to just servo as the servopos command may be leaving the servo with an indeterminate signal for too long.
 
Last edited:

Bill.b

Senior Member
using the AXE091 development board, I duplicated the two servo control.
using an 18m2, two DGS S03NF servos from a common supply.
with the following program -

Symbol SERVO1 = b.4
Symbol SERVO2 = b.5
init:
servo SERVO1,75
servo SERVO2,75

main:
pause 100
readadc 0,b0
let b2=b0/2+75
readadc 1,b1
let b3=b1/2+75
servopos SERVO1,b2
servopos SERVO2,b3
goto main

when a DEBUG was insterted after the main - no jittering of the servos was detected.
removed the DEBUG and noted a small amout of jitter.
as the DEBUG command inserts a coms delay in then program, I added a PAUSE 100 before the READADC command
this removed the jitter.

hope this helps.
 
Don't give up yet ypu should be able to get better than that.
Hey, Flyingnunrt!
I HATE giving up on something. I´ll follow your advice and work on it some more.

Have you tried it with just the one servo?
Indeed I have. And that did not solve the problem. BTW: my current type and amount of jitter can be seen here: (video).

I used Nicads, one pack for the picaxe and one for the servo, with the grounds commoned, that worked fine for me.
Have you isolated the + supply to the servo from that supplying the picaxe chip?
Yup. I have used them from a common power supply and from different ones (with both GNDs commoned). I have done a number of experiments with capacitors trying to filter out the noise on the line.

...try adjusting the pause time say to 30ms or even 15ms for example
I´ve also experimented with different lengths of pauses here and there.

...or even try changing the servopos command to just servo as the servopos command may be leaving the servo with an indeterminate signal for too long.
This one thing I haven´t tried. I said I was going to, but I forgot. I will try the servo command instead. I seem to remember that the manual favoured servopos for some reason, but I will give it a go.

THANKS, flyingnunrt!

Andrés
 
using the AXE091 development board, I duplicated the two servo control.
using an 18m2, two DGS S03NF servos from a common supply.when a DEBUG was insterted after the main - no jittering of the servos was detected.
removed the DEBUG and noted a small amout of jitter. As the DEBUG command inserts a coms delay in then program, I added a PAUSE 100 before the READADC command
this removed the jitter. Hope this helps.
Hello Bill.b and thanks for your interest. Unfortunately I don´t have an AXE091 board. I did try with different lengths of pauses in different locations with no luck. At least, if you got it working, that means that the reasoning behind this project is solid. Regardless if I can get it to work or not.

Cheers,
Andrés
 

boriz

Senior Member
Jitter is caused by noise. Find the noise. Use a 'scope. Otherwise you'll just have to use trial and error.

A PAUSE is required. Not optional. PAUSE 100 is a good place to start.

Something else to think about:

When a servo goes from still to moving, there is a current surge close to the stall current of the motor. This can be significant if brief. It will definitely put a dip (inverted spike) on your supply voltage. If you operate two servos, where the commands are so close together, this effect can be doubled. So consider a small pause between servo commands. There may also be a back-emf spike. If so, consider diodes.

Dirty (noisy) voltage supply will cause jitter. This is why separate battery supply for servos is good. Also the lower the internal resistance of the batteries, the better. So re-chargeables are better. Also, decent decoupling near the servo is recommended.

With a clean V+ supply and a noise free servo signal, you will have no jitter.

Maybe the noise is on the servo signal? Maybe the output you are using has a high impedance and EM noise is getting onto the line? Maybe a pullup or pulldown resistor will help?

Lot's of maybes.

Please show us an accurate circuit diagram.
 
Last edited:

Lord Grezington

New Member
Hi There

I have had some similair problems in the past. I think your probem is caused by noise (perhaps from your servo's), I would assume your Jitters are reduced if your wires between the pots and the analogue inputs were shortend.

With my project i used different software (not basic coding), but the solution should be very similair. I had 2 DC motor's on gearboxes (roughly 80W each) on the output shafts of the gearboxes i had mounted some pots (to use for absolute positioning). I used these pots as potential dividers (0-5V) and fed these into the pic. the noise was caused by the pot wires being too close to the dc motors.

To overcome this issue i took an average of the analogue input signal, ie, take one analogue reading, save as variable A, wait 1ms, take another reading, Save Variable as B, again wait 1ms, take another reading and save as C. Now calculate Variable D as the average of all A,B and C. Use D as your variable to work your calculations.

I found this to be a good solution on the bench, when moved into a noisier envoroment (to be fair, this was bewteen 2 1.5 Hp AC motors) i still got very small Jitters. So, the my next solution to make the analogue inputs completly noise proof was to take 5 readings (and save as variables with 1ms between them), then filter (disregard) out the highest reading and the lowest reading, then you should take an average of the remaining 3 values.

This solution will slow your system down, but if you think of the responce time of the servo's it should be too bad. Also, you can probably increase the frequency up to 32Mhz on the new M2 Chips.

Hope this makes sence

Graham
 
Last edited:

flyingnunrt

Senior Member
Andrés thats a fair length of unshielded cable from the pot to the picaxe you've got there.
Tried connecting a shield to ground yet?
 

Judson

New Member
I know how to round the variables to the nearest value, and you can make it less or more sensitive.

Here is the code. I originally used it on a robot for light sensing, but with small modifications, it should work for you. Variable b3 is the sensitivity variable, so the higher number you put in, the less sensitive your joystick will become.

I hope this helps!

Main:
readadc ?, b0
readadc ?, b1
readadc ?, b2
let b3 = 1
let b4 = b0 + b3
let b5 = b1 + b3
let b6 = b2 + b3

`rest of program

goto main
 
Top