This project is an extension of my previous ARMin project. I decided to combine an old car kit to the mix. So I cobbled it together with the robot arm which brings us to ARMin v2! Here we go!
System OverviewThe project consists of the following:
- Raspberry Pi
- Arduino
- Robot Arm Kit
- Car Kit
- Wireless Xbox 360 dongle
- Xbox 360 controller
Again, the servos of the robot arm are connected to the the Arduino's GPIOs as detailed on the table below:
The car kit is connected the L298D motor driver as seen below:
If you look at the code, the ENA & ENB are coded but is not used hardware-wise. The ENA & ENB pins are tied to HIGH or 5v. These pins usually receive PWM signals to set the motor speed. Setting them constantly HIGH will set it to maximum speed.
The motors are connected to the L298D motor driver as seen on the diagram below:
The setup is primarily the same as ARMin v1 so I'm just linking it back: https://www.hackster.io/HyperChiicken/armin-simple-robot-arm-controller-using-python-33d165. But here's a summary of the steps:
- Upload the prototype.ino to your Arduino using the Arduino IDE
- Install and update your Raspberry Pi OS
- Install xboxdrv and Python 3.7+
- Install the pyserial 2.6 and arduino-python3 APIs
The original arduino-control.py script has been modified to incorporate the motor driver control. I decided to map the right trigger to move the car forward, left trigger to move the car back, left bumper to rotate left, and right bumper to rotate right. That means the claw code had to remapped to a different button, in my case button A.
# Move motors when right trigger is used
def rightTrigmove():
if int(joy.rightTrigger()) > 0:
board.digitalWrite(IN1,"LOW")
board.digitalWrite(IN2,"HIGH")
board.digitalWrite(IN3,"LOW")
board.digitalWrite(IN4,"HIGH")
# Move motors when left trigger is used
def leftTrigmove():
if int(joy.leftTrigger()) > 0:
board.digitalWrite(IN1,"HIGH")
board.digitalWrite(IN2,"LOW")
board.digitalWrite(IN3,"HIGH")
board.digitalWrite(IN4,"LOW")
# Move motors when left bumper is used
def leftBumper():
if int(joy.leftBumper()) > 0:
board.digitalWrite(IN1,"HIGH")
board.digitalWrite(IN2,"LOW")
board.digitalWrite(IN3,"LOW")
board.digitalWrite(IN4,"HIGH")
# Move motors when right bumper is used
def rightBumper():
if int(joy.rightBumper()) > 0:
board.digitalWrite(IN1,"LOW")
board.digitalWrite(IN2,"HIGH")
board.digitalWrite(IN3,"HIGH")
board.digitalWrite(IN4,"LOW")
This part of the code goes within the while loop
# Poll right trigger and move motors forward
rightTrigmove()
# Poll left trigger and move motors backward
leftTrigmove()
# Poll right bumper and turn right
rightBumper()
# Poll left bumper and turn left
leftBumper()
# Stop motors when nothing is pressed mapped to the motor controls
if (int(joy.rightTrigger()) | int(joy.leftTrigger()) | int(joy.rightBumper()) | int(joy.leftBumper()) == 0):
board.digitalWrite(IN1,"LOW")
board.digitalWrite(IN2,"LOW")
board.digitalWrite(IN3,"LOW")
board.digitalWrite(IN4,"LOW")
Launch at bootupI wanted to run the code at bootup so I can easily play with ARMin without having to SSH into my RPi and running the Python script. There are several different ways to do this, but I chose to use the rc.local route. Here we are adding a line to the rc.local file to have our Python script run at boot.
To do this, run the command
sudo nano /etc/rc.local
This will open a file containing this or some variation of this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
exit 0
What we need to do is append the following lines of code:
sudo python3 /home/pi/arduino-control-v2.py &
If you have a different username, the line of code should be like this:
sudo python3 /home/insertyourusernamehere/arduino-control-v2.py &
So we should have something like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
# Run robot and car control Python script at bootup
sudo python3 /home/pi/arduino-control-v2.py &
exit 0
Then reboot the system to apply the changes. Upon startup, we should be able to see the robot arm raise it's arm up when ready. Now we can play around with it without the hassle of manually running the Python script!
More to come...?I hope to add more or revise ARMin into something different. I would really like to create a robot assistant-like thing with him. Anyways, I hope this helps or inspires someone to create something!
Comments