You are on page 1of 28
Introduction to Robotics Lecture 8 - 2022 Arduino and practical Dr. Mohammed Marey - (MUST) Use servo motors with Arduino » Wiring: » Servo motors have three wires: GND/VCC/Signal, here in this case its powered using Arduino’s 5V, you can use 9V or 12V, » The Signal pin should be wired with one of Arduino’s PWM pins, they are marked with (~), the PWM signal will determine the Servo rotation angle. lowucrion 79 RosoTiCS Lec 08-2022 a ‘DR, MOHAMMED NAREY -(MUST) Code 1: Simple code on rotating the servo and keep that position, a pierce is to use a servo motor with Arduino board it rotate the servo from eto 00 /fand stops there while writing "ON" on the serial monitor /fYou wire GND VCC SIGNAI to GND 5V D6 from Arduino /SurtrTech #include Servo myservo; void setup() { Serial.begin(9600); myservo.attach(7); } void loop() { myservo.attach(7); Serial.printin("ON"); myservo.write(50); } INTRODUCTION To ROBOTICS -LEC. 08-2022 DR, MOHAMMED MAREY (MUST) #finclude Servo myservo; // create servo object to control a servo Ji twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { myservo.attach(6); // attaches the servo on pin 9 to the servo object } void loop() { for (pos = 0; pos <= 180; pos += 1) {// goes from 0 degrees to 180 degrees iin steps of 1 degree myservo.wite(pos); IItell servo to go to position in variable 'pos' delay(1 II waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos == 1) {// goes from 180 degrees to 0 degrees myservo.write(pos); //tell servo to go to position in variable ‘pos' delay(15); // waits 15ms for the servo to reach the position H } INTRODUCTION To ROBOTICS -LEC. 08-2022 DR MOHAWMED WAEY (MUST) |Code 3: How to use the function “detach” When you send a command to a servo motor it stays on that position until you move it by another command, but sometimes you need the servo to have some “free rotation”, this is where the function is handy, it stops the command signal and the servo can be rotated by 7ITHIS Code is 10 USE @ Servo Motor with Arduino board and the use of the function “detach” Jou wire GND VCC SIGNAI to GND 5V D6 from Arduino //SurtrTechi! #include i/ Servo library Servo myservo; //Declaring the Servo void setup() { Serial begin(9600); myservo attach(6); //Declaring on which pin the servo is connected F void loop() { myservo.attach(6); _//The first part until “delay’ it attach the servo = connect it, then write "ON" Serial printin("ON"); //on the serial monitor and rotate the servo to 90° myservo.write(90); delay(5000), myservo.detach(); _// In this part we detach the servo which means you can rotate it freely from 0 to 180° Serial printin("OFF"):!/ While writing "OFF" on the monitor delay(5000); } INTRODUCTION To ROBOTICS -LEC. 08-2022 E ‘DR, MOHAMMED NAREY -(MUST) |Code 4: Code to read the postion of the Servo motor, » The read function is important as well, sometimes you need to know the servo current position before proceeding to other actions, this function returns the servo current angle. IThis code is to use a servo motor with Arduino board and the use of the function "read" You wire GND VCC SIGNAI to GND 5V D6 from Arduino WSurtrTechi! Hinclude ‘Servo myservo; void setup) { Sorial.bogin(9600); myservo.attach(6); p void loop() { float a=myservo.read(); /! permits to read the position of the servo motor and show it on the serial monitor Serial printin(a), } INTRODUCTION To ROBOTICS -LEC. 08-2022 > ‘DR, MOHAMMED NAREY -(MUST) Pan-Tilt Mechanism » This pan/tilt bracket consists of two brackets and all the hardware you need to attach them to make a pan/tilt mechanism using two servo motors. » You can use it to mount your sensor or camera and move it in X,y,Z directions. ) lowucrion 79 RosoTiCS Lec 08-2022 2 ‘DR, MOHAMMED NAREY -(MUST) Code 5: to control 2 servo motors using joystick UTIs code is to use with dual axis pv camera cradle that uses two serves, adding a joystick module ‘/hwe contol the position of the cradle by moving the analog stick, the cradie follows the joystick movements WReter to surtrtech.com for more information include //Servos library and declaration ‘Servo myservot; Servo myservo2, int YAxis = 1; /Declaring where the X axis and Y axis of tho joystick pins are wired int XAxis = 0; /Of course analog inputs Void setup() ( Serial. begin(9600); //Setting the Serial monitor baude rate and launching pinMode(XAxis, INPUT), //Deciaring the pin modes and servo pins myservot attach) pinMode(YAxis, INPUT); myservo2 attach(9} ) void loopt) { int X=analogRead(XAxis);//Reading from the X axis potentiometer X=X*0.1756; //Converting the range of the potentiometer trom 0-1023 to 0-180 limits of the Servo you can change them if you have a 360 servos X2180-X;)/ This is used so the servo turn to exact positios otherwise it wil be inverted myservo1.wi A(X) WWAfter adapting we inject that value to the frst Serva int YsanalogRead(YAxis); e209 from the Y axis potentiometer Y=Y*0.1466; //Hore we did conversion that suits the Servo limits so we went from 0-1023 to 0-150 myservo2 write(Y),!/And we inject to our servo ? INTRODUCTION To ROBOTICS -LEC. 08-2022 DR, MOHAMMED MAREY (MUST) Joystick Module © CC BY-SA Dual Axis FPV Camera Cradle wpamcere sca [ Second servo moving vertically First servo (fixed on the stand) X axis on AO Y axis on At INTRODUCTION To ROBOTICS -LEC. 08-2022 7 ‘DR, MOHAMMED NAREY -(MUST) #include Servo horzServo; // Create a servo object for the pan (horizontal) servo Servo vertServo; (vertical) servo int horzPin = 0; axis int vertpin = 1; int vertval; int horzval; yee * Setup v void setup() { // Create a servo object for the tilt // Analog input for the joystick horizontal // Analog input for the joystick vertical axis // value read from the vertical axis // Value read from the horizontal axis horzServo.attach(9)+ | // Use pin 9 PWM output for horizontal servo vertServo.attach(10); // Use pin 10 PHM output for vertical servo + [ee * Main program loop 7s void loop() { horzval = analogRead(horzPin) ; horizontal position hor2Val = map(horzVal, 0, 1023, 0, 179)3 suit servo horzServo.write(horzVal); required position vertVval = analogRead(vertPin) ; vertical position vertVal = map(vertVal, 0, 1023, 0, 179); suit servo vertServo.write(vertVal); required position delay(15); time to settle , // Read joystick // Scale reading to // Move servo to // Read joystick // Scale reading to // Move servo to // Give the servos Direct kinematics » Forward (direct) Kinematics » Inverse Kinematics Joint Position and Orientation variables of the end-effector Direct Kinematics q = (0920 In Y=(.y,2.6.0) 44 INTRODUCTION To ROBOTICS -LEC. 08-2022 DR MOHAWMED WAEY (MUST) positioning/orienting Robotic Tasks force/moment exerted on environment Chain of rigid bodies connected by joints end-effector joints: power giving, performing J. sso connecting mechanisms robotic tasks * 3 Revolute Joints Joint 1 > Joint angle 6: the angle of rotation from the X;,, axis to the X;, axis about the Z,, axis. It is the joint variable if joint iis rotary. » Joint distance di: the distance from the origin of the (i-1) coordinate system to the intersection of the Z,, axis and the X;, axis along the Z,, axis. It is the joint variable if joint i is prismatic. » Link length a; the distance from the intersection of the Z,., axis and the X, axis to the origin of the ith coordinate system along the X; axis. > Link twist angle q@: the angle of rotation from the Z,, axis to the Z; axis about the X; axis. “1 Example 1 Ly Joint 1 , 1 |O,X, Joint 2 D-H Link Parameter Table Y2 Joint i) ay a; d 8; . a . ay 1 0 a 0 @t, | rotation angle from Z; to Z; about X; 2 | -90 | a | 0 G; ; distance from intersection of Z;_, & X, 3 0 o & to origin of i coordinate along X; St d, : distance from origin of (i-1) coordinate to intersection of Z,., & X, along Z,.; @, : rotation angle from X,, to X, about Z,.; Transformation between i-1 and i frames, i and i-7. —The position and orienta can be expressed in the Source coordinate a Ty = T(2,,.d,)R G{CO, -Ca,Sé@, Sé@, Ca,Cé, 0 Sa 0 0 »D-H transformation matrix for adjacent coordinate ion of the /-th frame coordinate (i-1)th frame by the following homogeneous transformation matrix: (2,4.8,)T (x,,4;)R(x;.@;) Sa,S0, a,Cé, -Sa,Cé@, a6, Ca, d, 0 1 » Forward Kinematics I =(G1 2499" In) —Given joint variables . —End-effector position & orientation Y=(,y,2.6,0,W) » Homogeneous matrix p» —specifies the location of the ith coordinate frame w.rt. the base coordinate system —chain product of successive coordinate transformation matrices of Ty nann..t, Be a ds 20 eee eee » Forward kinematics * Transformation Matrix 0, p 0, 9s => PSs 0, b 0, | 0 0 O\;1 0 0 0 O;}0 Cw -Sy 0 76 0|0 Sw Cy 90 0 0 o1 0 0 1ijj0 0 0 1 CECI CHS y—-SHCy CpSOCy+SéSy p, SHCA SPSASy+CHCy SpSECy—CoSw py ° “| -so casy cocy DP. 0 0 0 1 a, a, a. 0 Kinematics Equations: Yaw-Pitch-Roll representation for orientation » Yaw-Pitch-Roll representation for orientation GB cosasy spy cpsecy+SéSy_p, 1 S6CO SPSOSY+CHCY SASOCY-—CASY p, re ’ omy i 0 0 1 a, Py @=sin '(-n.) a. y Fy Py y =cos a (—~) . @>». was 0 1 ¢ = cos '(—*~) cos@ Problem? Solution is inconsistent and ill-conditioned!! 23 INTRODUCTION To ROBOTICS -LEC. 08-2022 DR, MOHAMMED MAREY (MUST) Kinematics Equations: Yaw-Pitch-Roll representation for orientation — Yaw-Pitch-Roll representation for orientation T=R.yRy Rey cé —-S¢ 0 0|| C@ O Se O}}1 O 0 0 So Cd 0 0}} O 1 0 O}}0 Cy -Sw 0 0 0 1 0||-S@ 0 C@ O||0 Sw Cy 0 0 0 o1 0 0 0 1|j0 0 0 1 CCS CHSBy-SoCy CPHSOCw+SpSy p, pa| SPC SPSByrcpcy spocy—CASy py ° “| -se casy cecy DP. 0 0 0 1 » Other representations — reference from, tool frame tool tool Lg = BY ,T,! i, 24 iC MOFAMED MAREY (MUST) » Steps to derive kinematics model: — Assign D-H coordinates frames — Find link parameters — Transformation matrices of adjacent joints — Calculate Kinematics Matrix — When necessary, Euler angle representation Example: Given D-H Link Parameter Table Calculate Kinematics Matrix Joint 1 Ly a ¢ , lob, Joint 2 Yo % a, Yomi] a, | a | & | 6 1 0 ao 8, 2 -90 ay 0 8, 5 0 0 dy 03 We have. C0, —CaS0, SaS0, a,CO, Ti =|5% CaC8, -Sa,C8, 4,86, 4 ° Sa, Ca, iy Joint i] a 4; dq 0; g s 9 1 1 0 ao 0 6, ‘cos8, -sin®@, 0 a,cosd Then : 1 sin@, c0s8, 0 ag sind 2 | -90) a | 0 | oo 08 48 o 0 o 48 3 0 0 d 83 The kinematic matrix : Ty = CCT») cosd, —sin®, 9 aCOS% | Toop, 0 —sin@, acosd,] [cos®, —sind, 0 0 3_| Sin®, €088, 0 asin@| | sino, 0 cosd, asind,|,/ sind, cos; 0 0 a) o 1 0 o 1 0 o 0 o 14 0 0 0 1 0 0 0 1 0 0 oi. Thank you Questions

You might also like