
Foamtastic

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.
Code:
# move servo one direction at the speed of 120 (90 is the center point)
servo(d0, 120)
# wait 3 seconds
sleep(3000)
# stop the servo from moving
release(d0)
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
sleep(3000)
# stop the servo from moving
release(d5)
sleep(5000)
Servo(d5, 60)
Sleep(3000)
Release(d5)
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
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.
Will need some experimentation to determine what positions from EZ-B work.
Here is one, although you can probably find them cheaper.
https://www.amazon.com/Hitec-RCD-33785S-HS-785HB-Winch/dp/B000BOGI7E
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.
Alan