Train Vision Object By Script icon Train Vision Object By Script Train camera vision objects via controlcommand(), attach camera, start learning, monitor progress, and return object name for scripts. Try it →

Counting Rotations Of A Parallax Feedback 360 Degree Servo

I thought this script might be useful for someone wanting to specify the number of rotations for a Parallax Feedback 360 degree servo. The servo is connected to port D0 and the 4th wire to ADC0.

#Rotate anti-clockwise for 5 rotations Servo(D0,80) $rotations = 0 $ADC = 999 $PreviousADC = 999 repeatwhile($rotations < 6) $ADC = GetADC(adc0) #Determine if value of ADC has increased significantly - If so, one rotation has occurred if ($ADC > $PreviousADC + 100) $rotations = $rotations + 1 endif print("Previous ADC " + $PreviousADC + " - Current ADC " + $ADC + " - Rotations: " + $rotations) $PreviousADC = $ADC sleep(10) endrepeatwhile Servo(D0,105) sleep(1000)

#Rotate clockwise for 5 rotations Servo(D0,130) $rotations = 0 $ADC = -1 $PreviousADC = -1 repeatwhile($rotations < 6) $ADC = GetADC(adc0) #Determine if value of ADC has decreased significantly - If so, one rotation has occurred if ($ADC < $PreviousADC - 100) $rotations = $rotations + 1 endif

print("Previous ADC " + $PreviousADC + " - Current ADC " + $ADC)

$PreviousADC = $ADC sleep(10) endrepeatwhile #ADC_Wait_Between(adc0,0,4,5) Servo(D0,105) sleep(1000)

By
afcorson
Australia

ARC Pro

Upgrade to ARC Pro

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro