Omron HVC-P2 icon Omron HVC-P2 Omron HVC-P/HVC-P2 ARC plugin: Python-based camera integration for body, hand and face detection, gaze, age/gender, expressions and face recognition. 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

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!