Python Forum
Robotic arm using raspberry pi 4 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Robotic arm using raspberry pi 4 (/thread-35521.html)



Robotic arm using raspberry pi 4 - C3sarC - Nov-12-2021

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:

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 !!! Heart


RE: Robotic arm using raspberry pi 4 - Larz60+ - Nov-12-2021

Is the GPIO pin set for toggle?
if so, should lines 17-18, 29-30 be called here?

seems you need a release function (probably triggered by some event)
to call when you actually want to release the hold and not before.


RE: Robotic arm using raspberry pi 4 - C3sarC - Nov-13-2021

(Nov-12-2021, 10:18 AM)Larz60+ Wrote: Is the GPIO pin set for toggle?
if so, should lines 17-18, 29-30 be called here?

seems you need a release function (probably triggered by some event)
to call when you actually want to release the hold and not before.

Thank you for replying,

This is how I first had written the code GPIO.output(11, False) for line 17, and GPIO.output(7, False) for line 29. Later I decided to replace the work False for True thinking that by doing that my servo motor would stay energized after sleep function was over but that didnt solve my problem


RE: Robotic arm using raspberry pi 4 - Larz60+ - Nov-13-2021

C3sarC Wrote:This is how I first had written the code GPIO.output(11, False) for line 17, and GPIO.output(7, False) for line 29. Later I decided to replace the work False for True thinking that by doing that my servo motor would stay energized after sleep function was over but that didnt solve my problem

Watch these two videos, these are for raspberry-pi, but will work for other boards as is, or with reversed state:
https://www.youtube.com/results?search_query=Raspberry+Pi+LESSON+27
https://www.youtube.com/watch?v=SGwhx1MYXUs