I am trying to control a servo on my BB Blue with the rcpy library with the following script but the simple set servo1.set(duty) does not move the servo but the clock instruction does. I am sure it’s something obvious but I can’t see why it doesn’t work. Any suggestions greatly appreciated. The rc_test_servos -c 1 -p 1.5 bash script works on the servo.
bash script works
import rcpy
import time
import rcpy.clock as clock
import rcpy.servo as servo
from rcpy.servo import servo1
state = rcpy.get_state()
print("state is ", state)
run = rcpy.run()
print("run is ", run)
rcpy.idle()
print("State is ", rcpy.get_state())
rcpy.run()
print("State is ", rcpy.get_state())
servo.enable()
duty = -1.5
# Send the servo to -1.5
print("Duty is ",duty)
servo1.set(duty)
time.sleep(2)
# Send the servo to 1.5
duty =1.5
print("Duty is", duty)
# Use period option to move the servo
period =0.1
clk = clock.Clock(servo1, period)
clk.start()
time.sleep(2)
print("Finish")
servo.disable()
rcpy.exit()
print("Good bye")