Asked — Edited

Servo Rotation

Does anyone have any code they could share that would turn a servo from side to side. I need it to move the servo from position 50 to position 80 and back again not exceeding those positions but I cant seem to figure out the logic to make it happen. Any examples?


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

#1  

Seriously?


servo(D0,50) #set servo to position 50
sleep(1000)
servo(D0,80) #move servo to position 80
sleep(1000)
servo(D0,50) #move servo back to original position 50

#2  

The important thing in tjat script is the sleep steps. servo positions are absolute, so if you tell it to go to a position it will. However, servos don't give feedback back to ARC to say when they have reached the position. Therefore, as soon as ARC gives the command, it assumes it is complete and moves on to the next step. Without the sleep steps, it will head back to position 50 before ever reaching position 80.

You can enhance this is with the addition of a servospeed command if you want to slow it down (but will need to use a longer sleep).

If you want it to repeat you can use a label and goto, or if you want it to repeat until some condition is met you could use repeat until or repeat while commands.

Alan

PRO
USA
#3  

Ok, what I mean is I want it to slew back and forth not exceeding the position. I can move the servo. I'm trying to set the code up to check the position of the servo, the slew to the side it is further away slowly and then back again. If I use those commands, it very fast and abrubt. something more smooth. I was trying to use a counter and add 1 to the counter to move it that way. But I couldn't get the logic down.

#4  

So then use servospeed(D0,2) command in conjunction with sleep commands to slow things down... Picking the right servo speed and the right sleep commands should get you what you want...

PRO
USA
#5  

I am not at a place I can check the code. So are you suggesting something like this:

Servo(d1,50) sleep (600) Servo(d1,60) sleep (600) servo(d1,70) sleep (600) servo(d1,80)

#6  

More like this... This will execute much smoother and slower (sweeping back and forth like radar)


Servo(d1,50)
servospeed(D1,2) #may need adjusting slows the servo down
:top
servo(d1,50)
sleep(2000) #may need adjusting
servo(d1,80) 
sleep(2000) #may need adjusting
goto(top)

PRO
USA
#7  

Ok, will give it a try tonight. Movement like Radar is what I am looking for not the jerky movement I've experienced. Thanks

#8  

You may need to adjust the sleep commands to maybe sleep(1000) and if it is too slow speed it up using servospeed(D1,1) instead ofservospeed(D1,2)... FYI servospeed(D1,3), servospeed(D1,4) etc.. would be even slower...