0

I Posted earlier about having problems with my servos that you guys helped me with and I'm really grateful for that. Now I'm facing an other issue with the servos:

I have put them on my "robot" that I can control with my phone using BlueDot but here is the problem, I have added the servo code so that when I press the middle of the blue dot it will activate the servos (attached to a claw) The first time it works, but if I press again it will not work the servos will again make that "can't move" sound" and only be quitting and restarting it will the bot work once again...

Does anybody have any idea of why that is?

#!/usr/bin/python3
from bluedot import BlueDot
import RPi.GPIO as gpio
from signal import pause
import time

try:

    gpio.setmode(gpio.BOARD)


    gpio.setup(31, gpio.OUT)
    gpio.setup(33, gpio.OUT)
    gpio.setup(35, gpio.OUT)
    gpio.setup(37, gpio.OUT)
    gpio.setup(3, gpio.OUT)
    gpio.setup(38, gpio.OUT)

    p2 = GPIO.PWM(38, 50)

    p = GPIO.PWM(3, 50)

    def dpad(pos):
        if pos.top:
            print("Forward")
            gpio.output(31, False)
            gpio.output(33, True)
            gpio.output(35, False)
            gpio.output(37, True)

        elif pos.bottom:
            print("Backing")
            gpio.output(31, True)
            gpio.output(33, False)
            gpio.output(35, True)
            gpio.output(37, False)


        elif pos.left:
            print("Turning left")
            gpio.output(31, True)
            gpio.output(33, False)
            gpio.output(35, False)
            gpio.output(37, False)




        elif pos.right:
            print("Turning right")
            gpio.output(31, False)
            gpio.output(33, False)
            gpio.output(35, True)
            gpio.output(37, False)

        elif pos.middle:
            print("activating claw!!!")
            gpio.output(31, False)
            gpio.output(33, False)
            gpio.output(35, False)
            gpio.output(37, False)
            p.start(2.5)
            p2.start(2.5)
            time.sleep(1)
            p2.ChangeDutyCycle(12.5)
            time.sleep(2)
            p.ChangeDutyCycle(7.5)  # turn towards 90 degree
            time.sleep(1)  # sleep 1 second
            p.ChangeDutyCycle(0.5)  # turn towards 0 degree
            time.sleep(1)  # sleep 1 second
            p2.ChangeDutyCycle(2.5)
            time.sleep(2)
            p2.stop()
            p.stop()


    def stop():
        gpio.output(31, False)
        gpio.output(33, False)
        gpio.output(35, False)
        gpio.output(37, False)



    bd = BlueDot()
    bd.when_pressed = dpad
    bd.when_released = stop
    pause()

except KeyboardInterrupt:
    print("Terminating program")
  • If that code is accurate you are driving one of your servos beyond its end stops. – joan Nov 15 '19 at 21:42
  • Are you talking about this line: p.ChangeDutyCycle(0.5) ??? – Kungbjucha Nov 16 '19 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.