Asked — Edited
Resolved Resolved by thetechguru!

Question With A Piece Of Code

I have be scratching my head over this for several hours now and can not seem to figure out what is wrong or how to fix it. I have a piece of code that DJ sent me (thanks man) and it does what I want sort of.
Let me try and be as clear and give as much info as possible.

I am making a BB8 and want his arm to come out of his body and then go back in. I am using a continuous servo because a regular servo was not rotating enough to move the arm out fully. After 180 degrees the arm had only moved a very short distance so I am using a continuous servo so it can rotate enough times to move the arm out far enough. See pic 1.

What I have been trying to do is make a piece of code so that when a button is pressed on the mobile interface the arm rolls out pauses for a few seconds and then rolls back in.

The code Dj sent me is as follows.


move servo one direction at the speed of 120 (90 is the center point)

servo(d0, 120)

wait 3 seconds


stop the servo from moving


This works perfectly for bringing the arm out. So what I did was reverse this here is what I have to make the arm roll out/forward and then back in/reverse.

move servo one direction at the speed of 120 (90 is the center point)

servo(d5, 120)

wait 3 seconds


stop the servo from moving



Servo(d5, 60)



I have played around with the numbers and always end up with the same problem which is this. The arm rolls forward and then back Great!, however and this hard to explain, lets say the arm rolls forward 4 inches, it then rolls back 3 1/2, then when when I press the button again it rolls forward 4 inches and then back 3 /12 and keeps going like this, it never returns back to the same point. See pic 2

User-inserted image

User-inserted image


Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.


That's because a constant rotation servo has no POT (potentiometer has been removed) for position control... You are using timing (sleep commands) to position rather than absolute position (that a regular servo can give you because it has a POT)... Since timing is a very inaccurate way for motor control you are getting various start and stop positions every time you run it...

If you don't need any variable control you could maybe use a couple of limit switches. One at full extension and one at full retract of the arm... That way the arm always stops and starts at the same position.


Anything I can do to fix it? I need to use a continuous servo. I use a regular servo i would a giant cog wheel. Which there is no room for.


Like I said... you need a way to determine where the arm is... some sort of position control. Constant rotation servos can no longer do that... There are few ways to fix it, some more complicated some less complicated... Make a regular servo work for you or use 2 limit switches to determine beginning and ending stop points are the two least complicated ways to do it... A much more complicated method would be to use regular dc gear motors and a sabertooth/Kangaroo motor control setup...


You could also use a Sail Winch servo. They turn several times, but not unlimited times.

Will need some experimentation to determine what positions from EZ-B work.

Here is one, although you can probably find them cheaper.

The other option for what you are trying to do is a linear actuator. These push a rod straight out when receiving a signal, and many can be controlled like a servo. They tend to be expensive if you need more than a couple of inches of throw however.



Awesome thanks for info on a Sail Winch servo, I just ordered it. Thank you again, everyone.