From ae3bce643b3d88c9337c96c9b2085a05656cb00d Mon Sep 17 00:00:00 2001 From: LeeChuan2004 Date: Mon, 1 Apr 2024 10:32:56 +0800 Subject: [PATCH 1/4] Added "launcher_servo.py" --- launcher_servo.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 launcher_servo.py diff --git a/launcher_servo.py b/launcher_servo.py new file mode 100644 index 0000000..fcb1788 --- /dev/null +++ b/launcher_servo.py @@ -0,0 +1,70 @@ +import time +import RPi.GPIO as GPIO + +# Set pin numbering convention +GPIO.setmode(GPIO.BCM) + +# Choose appropriate pwm channels to be used to control the servos +import time +import RPi.GPIO as GPIO + +# Set pin numbering convention +GPIO.setmode(GPIO.BCM) + +# Choose appropriate pwm channels to be used to control the servos +cont_servo = 18 +half_servo = 20 + +# Configure the servo pins to output +GPIO.setup(cont_servo, GPIO.OUT) +GPIO.setup(half_servo, GPIO.OUT) + +# Initialise the servo pins to output pwm with 50 Hz frequency +cont = GPIO.PWM(cont_servo, 50) +half = GPIO.PWM(half_servo, 50) + +# For a continuous rotation servo, altering duty cycle / pulse width +# controls the speed of rotation of the servo, not the position of the shaft. + +# Both motors for cont and half are continuous rotation servos + +# SG92R 360 by Continental & FEETECH FS90R (cont) +# 100% counterclockwise speed = 1 ms pulse width = 5% duty cycle (for 50 Hz = 20 ms) +# Stop = around 1.5 ms pulse width = around 7.5% duty cycle (for 50 Hz = 20 ms) +# 100% clockwise speed = 2 ms pulse width = 10% duty cycle (for 50 Hz = 20 ms) +# May require some simple calibration: +# Output the desired stop duty cycle to the servo +# Then gently adjust the potentiometer in the recessed hole with a small screwdriver until the servo> + +# SPT5535LV-360W (half) +# 100% counterclockwise speed = 0.5 - 0.95 ms pulse width = around 2.5% - 4.75% duty cycle (for 50 H> +# Stop = between 1.45 - 1.55 ms pulse width = around 7.25% - 7.75% duty cycle (for 50 Hz = 20 ms) +# 100% clockwise speed = 1.95 - 2.5 ms pulse width = around 9.75% - 12.5% duty cycle (for 50 Hz = 20> + +half.start(7.25) # The pin starts to output PWM signals at 50 Hz with an initial duty cycle of 7.> +time.sleep(1) # The delay is to allow time for the servo to react +cont.start(7.5) +time.sleep(1) + +# Flip PVC pipe upright +half.ChangeDutyCycle(4.75) # slow counterclockwise +time.sleep(0.85) # Calibrated time to rotate approximately 180 assuming 61 RPM +half.ChangeDutyCycle(7.25) +time.sleep(2.5) + +# Flip PVC pipe back down test code +# half.ChangeDutyCycle(9.75) # slow clockwise +# time.sleep(0.5) # Calibrated time to rotate approximately 180 assuming 61 RPM +# half.ChangeDutyCycle(7.25) +# time.sleep(2.5) + +# Rotate the continuous rotation servo +cont.ChangeDutyCycle(10) # 100% clockwise +time.sleep(5) # Rotate for 5 sec +cont.ChangeDutyCycle(7.5) # Stop +time.sleep(2.5) + +# Cleanup +cont.stop() +half.stop() +GPIO.cleanup() From 19b1f18e785e07433219ae4092f017f7aa2f708a Mon Sep 17 00:00:00 2001 From: LeeChuan2004 Date: Tue, 2 Apr 2024 20:02:03 +0800 Subject: [PATCH 2/4] Calibrated --- launcher_servo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher_servo.py b/launcher_servo.py index fcb1788..0d03e13 100644 --- a/launcher_servo.py +++ b/launcher_servo.py @@ -47,8 +47,8 @@ time.sleep(1) # Flip PVC pipe upright -half.ChangeDutyCycle(4.75) # slow counterclockwise -time.sleep(0.85) # Calibrated time to rotate approximately 180 assuming 61 RPM +half.ChangeDutyCycle(6) # slow counterclockwise +time.sleep(3) half.ChangeDutyCycle(7.25) time.sleep(2.5) @@ -60,7 +60,7 @@ # Rotate the continuous rotation servo cont.ChangeDutyCycle(10) # 100% clockwise -time.sleep(5) # Rotate for 5 sec +time.sleep(4) # Rotate for 4 sec cont.ChangeDutyCycle(7.5) # Stop time.sleep(2.5) From 6d1c603352eabc778ddd9775f07294934c9515f3 Mon Sep 17 00:00:00 2001 From: LeeChuan2004 Date: Tue, 2 Apr 2024 22:24:10 +0800 Subject: [PATCH 3/4] Calibrated 2 + Uploaded test code (launcher_servo_reverse.py) --- launcher_servo.py | 4 ++-- launcher_servo_reverse.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 launcher_servo_reverse.py diff --git a/launcher_servo.py b/launcher_servo.py index 0d03e13..f70c03e 100644 --- a/launcher_servo.py +++ b/launcher_servo.py @@ -48,7 +48,7 @@ # Flip PVC pipe upright half.ChangeDutyCycle(6) # slow counterclockwise -time.sleep(3) +time.sleep(4) half.ChangeDutyCycle(7.25) time.sleep(2.5) @@ -60,7 +60,7 @@ # Rotate the continuous rotation servo cont.ChangeDutyCycle(10) # 100% clockwise -time.sleep(4) # Rotate for 4 sec +time.sleep(3.5) # Rotate for 4 sec cont.ChangeDutyCycle(7.5) # Stop time.sleep(2.5) diff --git a/launcher_servo_reverse.py b/launcher_servo_reverse.py new file mode 100644 index 0000000..7c50b63 --- /dev/null +++ b/launcher_servo_reverse.py @@ -0,0 +1,34 @@ +import time +import RPi.GPIO as GPIO + +GPIO.setmode(GPIO.BCM) + +cont_servo = 18 +half_servo = 20 + +GPIO.setup(cont_servo, GPIO.OUT) +GPIO.setup(half_servo, GPIO.OUT) + +cont = GPIO.PWM(cont_servo, 50) +half = GPIO.PWM(half_servo, 50) + +half.start(7.25) +time.sleep(1) +cont.start(7.5) +time.sleep(1) + +cont.ChangeDutyCycle(5) # 100% counterclockwise +time.sleep(3.25) +cont.ChangeDutyCycle(7.5) +time.sleep(2.5) + +#half.ChangeDutyCycle(8) # slow clockwise +#time.sleep(1.5) +#half.ChangeDutyCycle(7.25) +#time.sleep(2.5) + +cont.stop() +half.stop() +GPIO.cleanup() + + From a7d0b6c23d6c8c9eb7be9b060ed870febd3ad3b3 Mon Sep 17 00:00:00 2001 From: LeeChuan2004 Date: Thu, 4 Apr 2024 22:31:07 +0800 Subject: [PATCH 4/4] Calibrated 3 --- launcher_servo.py | 19 ++++++------------- launcher_servo_reverse.py | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/launcher_servo.py b/launcher_servo.py index f70c03e..0d7a4ee 100644 --- a/launcher_servo.py +++ b/launcher_servo.py @@ -4,13 +4,6 @@ # Set pin numbering convention GPIO.setmode(GPIO.BCM) -# Choose appropriate pwm channels to be used to control the servos -import time -import RPi.GPIO as GPIO - -# Set pin numbering convention -GPIO.setmode(GPIO.BCM) - # Choose appropriate pwm channels to be used to control the servos cont_servo = 18 half_servo = 20 @@ -34,21 +27,21 @@ # 100% clockwise speed = 2 ms pulse width = 10% duty cycle (for 50 Hz = 20 ms) # May require some simple calibration: # Output the desired stop duty cycle to the servo -# Then gently adjust the potentiometer in the recessed hole with a small screwdriver until the servo> +# Then gently adjust the potentiometer in the recessed hole with a small screwdriver until the servo stops moving. # SPT5535LV-360W (half) -# 100% counterclockwise speed = 0.5 - 0.95 ms pulse width = around 2.5% - 4.75% duty cycle (for 50 H> +# 100% counterclockwise speed = 0.5 - 0.95 ms pulse width = around 2.5% - 4.75% duty cycle (for 50 Hz = 20 ms) # Stop = between 1.45 - 1.55 ms pulse width = around 7.25% - 7.75% duty cycle (for 50 Hz = 20 ms) -# 100% clockwise speed = 1.95 - 2.5 ms pulse width = around 9.75% - 12.5% duty cycle (for 50 Hz = 20> +# 100% clockwise speed = 1.95 - 2.5 ms pulse width = around 9.75% - 12.5% duty cycle (for 50 Hz = 20 ms) -half.start(7.25) # The pin starts to output PWM signals at 50 Hz with an initial duty cycle of 7.> +half.start(7.25) # The pin starts to output PWM signals at 50 Hz with an initial duty cycle of 7.5% which corresponds to stop for a continuous rotation servo time.sleep(1) # The delay is to allow time for the servo to react cont.start(7.5) time.sleep(1) # Flip PVC pipe upright half.ChangeDutyCycle(6) # slow counterclockwise -time.sleep(4) +time.sleep(3.25) # Calibrated time to rotate approximately 180 assuming 61 RPM half.ChangeDutyCycle(7.25) time.sleep(2.5) @@ -60,7 +53,7 @@ # Rotate the continuous rotation servo cont.ChangeDutyCycle(10) # 100% clockwise -time.sleep(3.5) # Rotate for 4 sec +time.sleep(3.25) # Rotate for 3.25 sec cont.ChangeDutyCycle(7.5) # Stop time.sleep(2.5) diff --git a/launcher_servo_reverse.py b/launcher_servo_reverse.py index 7c50b63..105e8fe 100644 --- a/launcher_servo_reverse.py +++ b/launcher_servo_reverse.py @@ -23,7 +23,7 @@ time.sleep(2.5) #half.ChangeDutyCycle(8) # slow clockwise -#time.sleep(1.5) +#time.sleep(2) #half.ChangeDutyCycle(7.25) #time.sleep(2.5)