semi automatic robot with precision manual control using arduino and ps2 controllerjoystick

6

Click here to load reader

Upload: vijay-raghav-varada

Post on 29-Jul-2015

91 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Semi Automatic Robot With Precision Manual Control Using Arduino and PS2 ControllerJoystick

Semi-Automatic Robot with Precision Manual Control using Arduino and Joystick

PLC Project

Vijay Raghav Varada- 50 Soumyo Sengupta- 51 Allister D’souza- 43

Page 2: Semi Automatic Robot With Precision Manual Control Using Arduino and PS2 ControllerJoystick

Semi-Automatic Robot with Precision Manual Control using Arduino and Joystick

Vijay Raghav Varada 50Allister D’souza 43

Soumyo Sengupta 51Mechatronics

Department of Mechanical and Manufacturing Engg.MIT, Manipal

Abstract- It is often required for a robot to accomplish complex tasks, which may be difficult to control manually alone. Incorporating an effective and precise control system along with the robot is the key to tackling this issue .This paper would help understand how to build a wireless/wired robot with multiple actuators that can perform complicated tasks with some amount of onboard processing capability. It would help one get through the basics of robot building, and at the same time help build a seemingly complex robot without the need to go into much detail of electronic circuits and indepth coding by modifying readily available components and utilizing inbuilt functions and libraries for the Arduino platform.

1 INTRODUCTION

The implementation of precise and effective control of robots and robotic platforms is a tedious work, no matter how well informed with robotics one is.

In competition oriented projects, not only the robotic platform, but also its manual control system would set one apart from the opposition. But building such a system usually costs both time and money, and at the same time makes the system complicated and hard to debug. Thus the answer lies with building a simple yet smart control system that is ergonomic to use and simple to implement into the robot.

The trick lies with the proper interpretation and processing of human input to perform the task. Most would go for a more direct approach for robot control, which would lack speed and human error can easily hamper the way one really wants the robot to function. As you will read further in the paper, one will see how to implement simple algorithms and code snippets, along with a few thumb rules to follow when designing, building and coding a robot for better control which will prove more effective than direct control.

Summary of Contributions: Interfacing a single Dual-Axis Potentiometer

Joystick with Arduino and coding it for speed controlled robot movement [section 2]

Proper implementation of PS2X library for Arduino for interfacing PS2 controller to drive

motors and actuators, and implementing code used for the potentiometer joystick for joysticks present on the PS2 controller

Thumb rules to follow while building easily controllable robots.

2. DUAL POTENTIOMETER JOYSTICK FOR ROBOT MOVEMENT

2.1 Interfacing Each potentiometer corresponding to one axis on the potentiometer has three pins. These pins are wired in such that the input voltage is divided at the center pin, i.e. as a voltage divider. Moving the joystick in turn rotates the potentiometer and changes he resistances of R’ and R.

Fig 2.1 potentiometer interfacing

Vx=Vcc.R (1) R+R’

The data pin, i.e. the pin at which the voltage is divided is given as input to microcontrollers Analog to Digital Converter (ADC). Since the input voltages should be between 0-5V for the input, the vcc of the potentiometer is set to 5V and the output will be a fraction of this voltage given by equation (1).

The Arduino had a 10-bit ADC, which will give a digital value of 0-1023 corresponding to the input voltages between 0-5v.

Vx (data)GND+Vcc

R’R

+Vcc

GND

Vx (data)R’

R

Page 3: Semi Automatic Robot With Precision Manual Control Using Arduino and PS2 ControllerJoystick

The two potentiometers are wired and the data pins corresponding to x and y axis’ are connected to who ADC pins of the Arduino.

2.2 Processing/Coding: AXIS MIXING The ADC values of the two input pins for each axis would read 0-1023 depending in the potentiometers and in turn depending on the joystick position. Our aim is to mix these two reading so as to get PWM(Pulse Width Modulation) values for left and right motors on a differential drive robot. This is achieved in by following steps:

2.2.1 Mapping ADC values:

The input is in 10-bit resolution, but the PWM output capable on the arduino is in 8-bit resolution. Thus the 10-bit has to be mapped to 8-bit.

This can be done by using the following equation:

# of states of PWM o/p * ADC i/p = Mapped i/p value (2)# of states of ADC i/p

Where # of states is determined by 2n ; n is the resolution.

Alternatively, the inbuilt “map” function of the arduino can also be used:

Mapped i/p=map(<ADC i/p>, 0, 1023, 0, 255);

Where 0,1023 corresponds to the lowest value and highest value respectively from which conversion is being done and 0,255 corresponds to the highest and lowest value respectively to which the quantity needs to be converted, in this case, 10 bit to 8 bit resolution.

2.2.2 Axis manipulation:Now that the inputs are properly taken as input and mapped to 8 bit, ordered pairs of x and y axis’ corresponding to the position of the joystick are taken for analysisThis can be done by serially outputting the axis values to the serial monitor of the arduino IDE.

Each axis would output values from 0-255 on going from one extreme joystick position to another and give an output of 128 at centered position.The values corresponding to the position to will be similar to Fig 2.2 for certain positions of the joystick. A mirrored output may be obtained by swapping Vcc and GND of the potentiometers.

Fig2.2 Input Axis values & corresponding positions

From now onwards, x and y are denoted as mapped inputs from potentiometers and X and Y as axis magnitude values.

To get full scale axis magnitude depending on the movement of the joystick, i.e. getting values from 0-255 from the potentiometers for each direction the joystick is moved and also separating the positive and negative axis’s, we use the following formulas:

X=(x*2)-256 (3) Y=(y*2)-256 (4)

The corresponding axis’s can be mirrored by multiplying the above equations by -1.Fig 2.3 shows how the processed axis values would look corresponding to the joystick positions.

Note: in case the joystick is not centered at 128 due to some error, a small threshold ranging from either directions of the input value at centered should be assigned to 128.

x=128; y=255

x=255; y=255

x=255; y=128

x=255; y=0

x=128; y=0

x=0; y=0

x=0; y=128

x=0; y=255

X=0; Y=256

X=256; Y=256

X=256; Y=0

X=256; Y= -256

X=0; Y= -256

X= -256; Y= -256

X= -256; Y=0

X= -256; Y=256

Page 4: Semi Automatic Robot With Precision Manual Control Using Arduino and PS2 ControllerJoystick

Fig 2.3 Processed axis values & corresponding positions

2.2.3 Axis Mixing:

Let us consider how the robot should behave when we give an input from the joystick, more specifically how the left and right motors would respond in a differential drive robot. Fig 2.4 shows joystick positions and how the robot kinematics, i.e. the left and right motor directions are expected to behave according to them.

X=-256 Y=256

Left 0 Right

Resultant= Left turn(forward)

X=0 Y=256

Left Right

Resultant=Forward

X=256 Y=256

Left Right 0

Resultant= Right turn(forward)

X=-256 Y=0

Left Right

Resultant=CCW rotation about center

X=0 Y=0

(centered)Left =0

Right =0

Resultant=Stationary

X=256 Y=0

Left Right

Resultant= CW rotation about center

X=-256 Y=-256

Left 0 Right

Resultant=left turn(reverse)

X=0 Y=-256

Left Right

Resultant=Reverse

X=256 Y=-256

Left Right 0

Resultant=Right turn(reverse)

Fig 2.4 Motor values and corresponding positions

Let’s assume a positive integer to write the speed of the motors in forward direction and negative for reverse. On examination and understanding of Fig 2.4, the following observations are made:

When X=0 and Y is changing, the Y axis decides the speed and direction of both the robot motors together

When Y=0 and X is changing, The X decides magnitude of speed one motor and the opposite direction (in sign of corresponding X value) is given to the other motor.

If X and Y are non-zero, Y axis decides speeds of both motors and the X increases and decreases speeds of opposite motors depending on its magnitude and direction. The magnitude of X is added or deducted from Y depending on its sign of X.

The following formulas are used to mix the X and Y value to get corresponding left and right motor speeds according to the above positional convention:

when Y is positive:LeftSpeed=Y+X RightSpeed=Y-X

Since Y becomes negative when joystick id pulled back, addition of subtraction to Y has to be reversed, thus:

When Y is negative:LeftSpeed=Y-XRightSpeed=Y+XNote: in case X axis is mirrored to the above used sign convention, the left speed and right speed are simply interchanged to get desired results.

The positive and negative integer obtained for speed will decide direction of motoring according to its sign. According to the above sign convention, we use positive for forward and negative for backward.

2.2.4 Thresholding speed:

Since speed values can go above 255, which is the max integer we can write for PWM output, the speed values we get from axis mixing have to be thresholded to the maximum possible magnitude for PWM and yet keeping the sign same, since it will decide the direction of rotating motors. This can be done by simple conditional statements in the code.e.g., for thresholding LeftSpeed, we use the following code fragment:if(LeftSpeed>255)LeftSpeed=255;If(Leftspeed<-255)LeftSpeed=-255);

2.2.5 Writing output to motors:

The magnitude of the left and right speeds are written to the corresponding motors and the sigh decides the direction. A conventional motor driver has two pins per motor channel. Giving voltage to one of these pins and keeping the other floating or ground makes the motor turn in one direction and interchanging the pins make the direction reverse.Two case statements are used to determine whether the speed magnitude must me written to the forward pin or the reverse pin of the motor driver.

Left forward motoring pin of the arduino be pin 9 and reverse motoring pin be 10 that are connected to the motor driver.e.g. for writing speeds to left motor, we use the following code fragment. if(LeftSpeed>0) analogWrite(9,leftspeed);

if(leftspeed<0) analogWrite(10,-leftspeed

Negative speed values written to the PWM pins are multiplied by -1.

In some motor drivers, each motor channel has one pin for direction and one pin for speed input. In such a case, HIGH or LOW is given to the direction pin depending on the direction

Page 5: Semi Automatic Robot With Precision Manual Control Using Arduino and PS2 ControllerJoystick

of motoring corresponding to the sign of the speed value, and its magnitude is given to the PWM pin.

Note: It is noticed that sometimes the motors might behave erratically even after proper coding, this may be caused due to many reasons such as, abruptly changing directions of the joystick, or some residual junk value remain in the variables used for speed . All this can be countered by resetting the speed values to zero and also setting PWM output to all the motor pins as zero if the joystick is in centered condition(X=0;Y=0). A simple ‘if” condition will suffice for this.

ACKNOWLEDGMENT

We would like to thank Mr.P.C. Sai Babu and Mr. Srinivasan C.R for their guidance through the course. We would also like to thank our fellow classmates for their moral support.

REFERENCES

[1] Bill Porter, “Interfacing PS2X library with arduino,”, www.mindfbillporter.com

[2] Micheal, Arduino Cookbook, 3rd ed., vol. 2, pp.68-73.[3] Information for libraries from www.arduino.cc