Random Servo Movement

Joecolo

New Member
Please Help! I would like to move a servo randomly within a small parameter. I tried this but I get larger movements than 150 to 145, what am I doing wrong?

Thanks Joe

start:
servo 2,55
servopos 2,150
pause 1000

Random w0
w1 = w0 // 150 + 145

servo 2,55
servopos 2,w1
pause 1000

goto start
 

stan74

Senior Member
let w0=timer
start:
random w0
if b0>200 then let b0=200:endif
if b0<100 then let b0=100:endif
servopos 2,b0
pause 100
goto start
maybe
 

Joecolo

New Member
The program doesn't like timer? hmmmm

let w0 = Timer
^
Syntax error on line 3 at/before position 9

Error: Unknown symbol - Timer
 

erco

Senior Member
Did you want it to jerk from position to position or move smoothly?

Re: your original program, that second servo 2,55 is causing unnecessary roughness.

Untested mod to your program:

w0=time
servo 2,150
pause 1000

start:
Random w0
w1 = w0 // 150 + 75
sertxd (#w1,13,10)
servopos 2,w1
pause 1000
goto start
 
Last edited:

Joecolo

New Member
Erco

In a perfect world if I could get movement like this
servo 2,55
for b1 = 55 to 60
servopos 2,b1
pause 30
next b1

but small random positions

What is "sertxd (#w1,13,10)" ?

I tried your code but the movement was too great and exceed the servos range, how do I fine tune this?

Thanks Joe
 

westaust55

Moderator
In the line:
W1 = w0 // 150 + 145
The first part (w0 // 150) with give a value in the range 0 to 149.
Then you are adding the base value of 145 thus then entire range is 145 to 294.

If you only want the small/narrow range 145 to 150 then use
W1 = w0 // 6 + 145

Next remove the line:
Servo 2,55
From within the loop
 

erco

Senior Member
Joe: Servos often have extreme limits of 75 to 225, 150 being center. Figure out the range of values you want, min and max, by experimentation. Then use this formula in your program:

w1=w0//(max-min)+min
 

Joecolo

New Member
erco

this one is working, I have a narrow range of random movement between 150 and 165 using "w1 = w0 // 15+150"
w0=time
servo 2,150
pause 1000

start:
Random w0
w1 = w0 // 15+150
sertxd (#w1,13,10)
servopos 2,w1
pause 1000
goto start
and thank you for "sertxd (#w1,13,10)", I didn't know this was an option, 152
155
161
158
152
154
159
153
156
162
159
154
158
152
155
 

stan74

Senior Member
What's the servo connected to, curious. Sertxd ("variable= ",#variable,cr,lf) is less mysterious. I'm a newbie.
 

erco

Senior Member
@Joe:

Glad to hear that's working for you. 15 "servo" units isn't very much travel in the servo world, you either have a very sensitive mechanism or a very long arm!
 

eggdweather

Senior Member
The servo type makes a huge difference, using a Hitec or Futaba S-bus high resolution digital servo would enable the servo resolution (4096 or 0.03degrees) to exceed the PICAXE resolution.
 

erco

Senior Member
The servo type makes a huge difference, using a Hitec or Futaba S-bus high resolution digital servo would enable the servo resolution (4096 or 0.03degrees) to exceed the PICAXE resolution.
Aren't digital servos fully backward compatible with analog signals (i.e., the type of signals a Picaxe generates) and programmed to respond just as analog servos would?
 

stan74

Senior Member
Maybe they remember their position without constant pulses..or maybe not and they just don't use a pot..and they're digital. I bought 2 metal gear not micro servos and the are quieter than micro 9g. Chunky though.
 

erco

Senior Member
I just got some brand new supposedly digital 9g continuous rotation servos from FiTec to review. Same size, looks & tastes just like regular 9g servos and they work great using a regular analog servo tester. Will advise when I make a video.
 
Top