Python Forum
Robotic arm using raspberry pi 4
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Robotic arm using raspberry pi 4
#1
Question 
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
Larz60+ write Nov-12-2021, 10:07 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
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.
C3sarC likes this post
Reply
#3
(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
Reply
#4
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_q...+LESSON+27
https://www.youtube.com/watch?v=SGwhx1MYXUs
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020