Assembling a Robotic arm
Research
Now that we have a robotic car, I'm considering attaching more devices to it. What about attaching a robotic arm? The tutorial for the car has a section about controlling the robotic arm but unfortunately, my car didn't have one.
I started researching about robotic arms and learning what kind of servos they need. I found that any arm needs at least 4 servos to operate, I looked through dozens of arm models to find the best price/quality model. There are tons of cheap plastic arms but I wanted something more durable and also not expensive. I found one model named 6DOF Robot Mechanical Arm Clamp Claw Kit DOF Manipulator Industrial Robot Parts. It looks a little bit big for my car but I was willing to buy and assemble it. The learning experience is worth 37 bucks spent on the robotic arm :). Oh...the product description didn't say anything about instructions so I probably won't expect any assembling instructions. I found 6DOF Robotic Arm Assembly Tutorial which explains how to assemble the arm. Now I'm confident that my 37$ will not be wasted :)
Assembling
I started assembling the arm following the video tutorial and it went smoothly. The video tutorial is clear and simple to follow. Just until the first servo is installed. The problem is that we need to rotate this servo to 90 degrees.
Turn the servo to 90 degrees
Connect the servo to Port 1. See port numbers in the Motor HAT doc
Turn on the car, connect in VSCode and run this python program:
import Adafruit_PCA9685 # Import the library used to communicate with PCA9685
pwm = Adafruit_PCA9685.PCA9685() # Instantiate the object used to control the PWM
pwm.set_pwm_freq(50) # Set the frequency of the PWM signal
pwm.set_pwm(1, 0, int((540 + 72) / 2)) # range is between 72 and 539
What is PWM?
PWM - Pulse Width Modulation. There are plenty of videos about it. For example here.
Our servo MG996R has duty cycles 1-2ms where 1ms is 0 degrees, 2ms is 180 degrees.
To control the servo you need to send a "magic" number to the pwm object. Unfortunately, Adafruit_PCA9685 is an old and deprecated library which doesn't provide to set degrees 0-180. I played with the servo and found that the most left position is at 72 and the most right is at 539. Which probably corresponds to 0 and 180. Here is the article that explains what is a duty cycles and how to convert them to degrees.
Here is whole process in a few secs:
What is PWM?
PWM - Pulse Width Modulation. There are plenty of videos about it. For example here.Our servo MG996R has duty cycles 1-2ms where 1ms is 0 degrees, 2ms is 180 degrees.
To control the servo you need to send a "magic" number to the pwm object. Unfortunately, Adafruit_PCA9685 is an old and deprecated library which doesn't provide to set degrees 0-180. I played with the servo and found that the most left position is at 72 and the most right is at 539. Which probably corresponds to 0 and 180. Here is the article that explains what is a duty cycles and how to convert them to degrees.
Here is whole process in a few secs:
Connecting robotic arm to the car
I connected all 6 servos to the car:
import Adafruit_PCA9685 # Import the library used to communicate with PCA9685
pwm = Adafruit_PCA9685.PCA9685() # Instantiate the object used to control the PWM
pwm.set_pwm_freq(50) # Set the frequency of the PWM signal
#servo 2 - shoulder in almost open position (horizontal back) at 500
pwm.set_pwm(2, 0, 400) # ~45 degrees turned back
pwm.set_pwm(3, 0, 350) # ~60 degrees to shoulder
pwm.set_pwm(4, 0, 150) # ~100 degrees to elbow
pwm.set_pwm(5, 0, 300) # ~palm parallel to ground
pwm.set_pwm(6, 0, 250) # ~palm wide open
Resources
Tutorial: 6DOF Robotic Arm Assembly Tutorial
Another tutorial: How To Build 6 DOF Robot Arm Kit
No comments:
Post a Comment