Robotic Arm With Zio Modules Part 2

by Alex_chu in Circuits > Remote Control

1001 Views, 5 Favorites, 0 Comments

Robotic Arm With Zio Modules Part 2

Robotic-Arm.png

In today’s tutorial, we will utilize all 4 servos and a PS2 wireless controller to control the robotic arm.

This blog post is part of the Zio Robotics Series.


Introduction

In our previous blog, we posted Part 1 tutorial on how to control a Robotic Arm using Zio modules. Part 1 mostly concentrated on automatically controlling your Robotic Arm’s Claw to open and close.

In today’s tutorial, we will notch it up a little by including a PS2 Wireless controller to control the Robotic Arm. For this project, we will be utilizing 4 servos.

Project Overview

Difficulty Level:

Zio Padawan

Helpful resources:

You should have a basic understanding of how to install Zio development boards. In this tutorial, we assume that your development board is already configured and is ready to be set up. If you haven’t configured your board yet check out our Zio Qwiic Start Guide tutorial below to get started:

Schematics

schematics1.jpg

Here is the Wiring Schematics of the Robotic Arm Part 2 Project as well as the PS2 Controller diagram needed to understand for your coding part.

PS2 Controller Diagram

PS2Lib_Control_Labels-600dpi.jpg

Zio Modules Connection Set Up

Below is the connection of our Zio modules to be set up with the Robotic Arm. Connecting all the modules together is pretty easy and will not take more than 10 minutes to set up.

Connect the Robotic Arm Servo to Zio 16 Servo Controller

WeChat Image_20190305123325.jpg

Connect Your 16 Servo to DC/DC Booster and Set It at 6.0V.

WeChat Image_20190305123319.jpg

We use a DC/DC Booster to boost and adjust the battery supply voltage to 6.0.

Use the potentiometer on the DC Booster to adjust the voltage until you get 6.0. Push the In/Out button until the display shows 6.0. You need to supply power (3.7V battery) first to your DC/DC Booster in order to adjust the voltage.

Connect Zuino M Uno to the Zio 16 Servo Controller

WeChat Image_20190305123305.jpg

Qwiic connect Zuino M Uno to the Zio Servo controller with qwiic cable.

Connecting Uno to the PS2 Receiver

uno-to-ps2-rcv.jpg

Here is a Pin Diagram of the Connections. You need 5 Male to Female Jumper Wires for this part.

Code for Robotic Arm

We will be using the PS2 Arduino Library to code our PS2 Wireless Controller to work with our Robotic Arm. You can find and download the source code for this Robotic Arm Part 2 project on our Github page.

Download and install the following libraries and save it on your local Arduino IDE libraries folder:

To install the libraries open your Arduino IDE, go to Sketch tab, select Include Library -> Add.Zip Library. Select the above libraries to be included on your IDE.

Arduino has a handy guide on how to install libraries to your Arduino IDE. Check them out here !

Run Your Code

QQ截图20190311160448.png

Open Arduino IDE. Under Files > Examples > PS2_Arduino_Library, Select PS2X_Servo

Note: Before you can control your Robotic arm with the PS2 Controller check the following steps: Switch on your PS2 Controller. Check that the Mode LED lights up. If it doesn’t, press the Mode button on your controller. After doing the above, you need to press the reset button on your Zuino M Uno for it to read your controller settings. You need to Press L1 and the Joystick to move your Robotic Arm.

  • Left Joystick controls the bending of the Arm upwards or downwards
  • Right Joystick controls the Claw to either open or close and rotating the claw to the left or right.

Code Explanation

Use of the PS2X Arduino library is simple, only requiring an initialization, a setup, and then a read command.

To set the connection for your PS2 Controller with your Uno, below are the pins you need to define in your code:

/**************************************************************** 
* set pins connected to PS2 controller:
* - 1e column: original
* - 2e colmun: Stef? * replace pin numbers by the ones youuse
****************************************************************/
#define PS2_DAT 13 //14
#define PS2_CMD 11 //15
#define PS2_SEL 10 //16
#define PS2_CLK 12 //17

We have replaced the pins with the ones that we use to connect to our Uno as outlined on the Pin Diagram above.

/***************************************************************** 
select modes of PS2 controller:
* - pressures = analog reading of push-butttons
* - rumble = motor rumbling
* uncomment 1 of the lines for each mode selection
****************************************************************/
//#define pressures true
#define pressures false
//#define rumble true
#define rumble false

Here we defined PS2 mode for pressures and rumble as false. We commented the ones we do not use.

We will only be using the Controller’s Joystick command and L1 to control the movement of our Robotic Arm.

void loop() {
/* You must Read Gamepad to get new values and set vibration values ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255) if you don't enable the rumble, use ps2x.read_gamepad(); with no values
You should call this at least once a second
*/
if(error == 1) //skip loop if no controller found
return;

else { //DualShock Controller
ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed

if(ps2x.Button(PSB_START))//will be TRUE as long as button is pressed
Serial.println("Start is being held");
if(ps2x.Button(PSB_SELECT))
Serial.println("Select is being held");
vibrate = ps2x.Analog(PSAB_CROSS); //this will set the large motor vibrate speed based on how hard you press the blue (X) button

if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) { //print stick values if either is TRUE

RY_Value=ps2x.Analog(PSS_RY);
RX_Value=ps2x.Analog(PSS_RX);
LY_Value=ps2x.Analog(PSS_LY);
LX_Value=ps2x.Analog(PSS_LX);

Serial.print("Stick Values:");
Serial.print(RX_Value);
Serial.print(" ");
Serial.print(RY_Value);
Serial.print(" ");
Serial.print(LY_Value);
Serial.print(" ");
Serial.println(LX_Value);

The code below is where we code our servos that control our robotic arm which we include in the function call under ps2x.button(PSB_L1)|| ps2x.button(PSB_R1).


You need to press L1 or R1 button together with the Joystick to control your Robotic Arm.

The Left Joystick control servos 2 and 3 for the Arm part - control the bending Up and Down of the arm respectively, while the Right Joystick control servos 0 and 1 of the Robotic Arm’s Claw to open or close, and to rotate left or right.

SERVO 0, 1 - Claw
SERVO 2, 3 - Arm

You can make changes to values in this section to control the degree of your Robotic Arm angle:

pulselen0=map(RY_Value,0,127,SERVOMIN0,SERVOMAX0);      
pulselen1=map(RX_Value,0,127,SERVOMIN0,SERVOMAX0);
pulselen2=map(LY_Value,0,127,SERVOMIN2,SERVOMAX2);
pulselen3=map(LX_Value,0,255,SERVOMIN3,SERVOMAX3);