Nov-12-2021, 01:58 AM
Hey guys,
My name is Cesar Chavez I am a student at Bakersfield College. I am in my last year of the program (Industrial Automation) and I was assigned to a very cool project. Basically, programming a tank robot that has a arm built on arm. I was able to program the robot to move in all directions using bluedot library and I found a simple code for the arm. The problem I have is that the arm is not functioning properly. It uses servo motors with 3 wires (brown orange and yellow) powered by raspberry pi 4. It has an elbow, wrist, and gripper. The issue, when the function for the elbow sleeps for 2 seconds, the servo de-energizes and the elbow goes down. It wont hold its position. The same thing happens with the wrist. When the function for the wrist is over and sleeps for 2 seconds the wrist goes down and doesn't hold its position. I super new to python and coding so I have tried a few things like removing sleeping time but it didn't work, I tried adding GPIO.output(11, True) right after sleep(2) but it doesn't work. Any help would be much appreciated. This is the code I have for the arm:

My name is Cesar Chavez I am a student at Bakersfield College. I am in my last year of the program (Industrial Automation) and I was assigned to a very cool project. Basically, programming a tank robot that has a arm built on arm. I was able to program the robot to move in all directions using bluedot library and I found a simple code for the arm. The problem I have is that the arm is not functioning properly. It uses servo motors with 3 wires (brown orange and yellow) powered by raspberry pi 4. It has an elbow, wrist, and gripper. The issue, when the function for the elbow sleeps for 2 seconds, the servo de-energizes and the elbow goes down. It wont hold its position. The same thing happens with the wrist. When the function for the wrist is over and sleeps for 2 seconds the wrist goes down and doesn't hold its position. I super new to python and coding so I have tried a few things like removing sleeping time but it didn't work, I tried adding GPIO.output(11, True) right after sleep(2) but it doesn't work. Any help would be much appreciated. This is the code I have for the arm:
import RPi.GPIO as GPIO from time import sleeppython #funtion to control elbow def SetElbowAngle(angle): GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT) pwm=GPIO.PWM(11,50) pwm.start(0) duty = angle / 18 + 2 GPIO.output(11, True) pwm.ChangeDutyCycle(duty) sleep(2) GPIO.output(11, True) pwm.ChangeDutyCycle(0) def SetWristAngle(angle): GPIO.setmode(GPIO.BOARD) GPIO.setup(7,GPIO.OUT) pwm=GPIO.PWM(7,50) pwm.start(0) duty = angle / 18 + 2 GPIO.output(7, True) pwm.ChangeDutyCycle(duty) sleep(2) GPIO.output(7, True) pwm.ChangeDutyCycle(0) #funtion to control gripper def SetGripperAngle(angle): GPIO.setmode(GPIO.BOARD) GPIO.setup(3,GPIO.OUT) pwm=GPIO.PWM(3,50) pwm.start(0) duty = angle / 18 + 2 GPIO.output(3, True) pwm.ChangeDutyCycle(duty) sleep(2) GPIO.output(3, False) pwm.ChangeDutyCycle(0) #move to starting position SetElbowAngle(130) SetWristAngle(70) SetGripperAngle(0) #pick the object SetElbowAngle(110) SetGripperAngle(0) SetGripperAngle(130) #move back SetElbowAngle(150) SetWristAngle(50) #drop the object SetGripperAngle(130) SetGripperAngle(0) pwm.stop() GPIO.cleanup() GPIO.setwarnings(False)Thank you in advanced !!!
