Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
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.

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


User-inserted image


User-inserted image

AI Support Bot
Related Content
Synthiam
#1  
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.
#2  
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.
#3  
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...
#4  
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.

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
#5  
Awesome thanks for info on a Sail Winch servo, I just ordered it. Thank you again, everyone.