Projektas #6: Valdykite „Arm Robot“ roboto rank? 2 vairasvirt?mis
Po to kai sukonstravote „Arm Robot“ roboto rank? ir atlikote 1-5 pratimus, atlikite š? galutin? projekt?, nor?dami valdyti roboto rankos judesius naudodami 2 vairasvirtes. Su vairasvirte Nr. 1 judinsite rieš? (S3) ir griebtuv? (S4), o su vairasvirte Nr. 2 judinsite rank? (S2) ir pagrind? (S1).
SUD?TINGUMO LYGIS: Pažengusiems.
PRATIMO TRUKM?: 60 min.
MEDŽIAGOS:
- „Arm Robot“ roboto ranka
- USB - USB B tipo kabelis
- Kompiuteris
JUNGTYS:
Šio projekto ?gyvendinimui, „Arm Robot“ roboto ranka turi b?ti sukonstruota pagal instrukcijas (nuorod? ? vadov?). Atlikite veiksmus ir sujunkite atitinkamas jungtis.
PROGRAMOS KODAS
Galite atlikti š? projekt? naudodami „Arduino“ program? arba suderinam? vaizdin? programavimo programin? ?rang?, naudojan?i? blokus. Toliau pateikiamas reikiamas kodas.
„Arduino“ kodas
- Parsisi?skite ir ?diekite „Arduino IDE“ program?. Ji si?loma „Windows“, „Mac OS“ ir „Linux“.
- Paleiskite „Arduino“ program? ir nukopijuokite ? j? toliau pateikt? kod?:
#include <Servo.h> int valueX = 0; // J2 X-AXIS READING int valueY = 0; // J2 Y-AXIS READING int valueX2 = 0; // J1 X-AXIS READING int valueY2 = 0; // J1 Y-AXIS READING /*-----------------------------------------------------------------------------------------*/ int pinJX = A1; // A1 X-AXIS ANALOG PIN int pinJY = A0; // A0 Y-AXIS ANALOG PIN int pinJX2 = A2; // A2 X2-AXIS ANALOG PIN int pinJY2 = A3; // A3 Y2-AXIS ANALOG PIN /*-----------------------------------------------------------------------------------------*/ Servo motor1; // DECLARE S1 // SERVO MOTOR 1 Servo motor2; // DECLARE S2 // SERVO MOTOR 2 Servo motor3; // DECLARE S3 // SERVO MOTOR 3 Servo motor4; // DECLARE S4 // SERVO MOTOR 4 /*-----------------------------------------------------------------------------------------*/ int degree1 = 0; // S1 DEGREES int degree2 = 0; // S2 DEGREES int degree3 = 0; // S3 DEGREES int degree4 = 0; // S4 DEGREES /*-----------------------------------------------------------------------------------------*/ float tiempo; void setup() { // put your setup code here, to run once: motor1.attach (6); // DIGITAL PIN PWM 6 WHERE S1 IS CONNECTED motor2.attach (9); // DIGITAL PIN PWM 9 WHERE S2 IS CONNECTED motor3.attach (10); // DIGITAL PIN PWM 10 WHERE S3 IS CONNECTED motor4.attach (11); // DIGITAL PIN PWM 11 WHERE S4 IS CONNECTED /*-----------------------------------------------------------------------------------------*/ // ARM ROBOT INITIAL POSITION degree1 = 20; //S1 degree2 = 70; //S2 degree3 = 80; //S3 degree4 = 90; //S4 /*-----------------------------------------------------------------------------------------*/ } void loop() { // put your main code here, to run repeatedly: Motor1(); Motor2(); Motor3(); Motor4(); for (tiempo = 0; tiempo < 2500; tiempo++) { if (tiempo >= 2500) { tiempo == 0; } } } void Motor1 () { valueX = analogRead ( pinJX); // STORES THE READINGS OF THE Y-AXIS OF THE ANALOG PORT A1 // INCREASE MOTOR 1 DEGREES if ( (valueX > 520) && (valueX <= 1023) && (degree1 < 170) ) // INCREASE THE DEGREES WHEN THE X-AXIS READING IS HIGHER THAN THE CALIBRATION OR LOWER/EQUAL TO 1023 { degree1 = degree1 + 5; // +5 degree } // DECREASE MOTOR 1 DEGREES else if ( (valueX >= 0 ) && (valueX < 480)&& (degree1 > 20) ) // DECREASE DEGREES WHEN THE X-AXIS READING IS LOWER THAN THE CALIBRATION OR HIGHER / EQUAL TO 0 { degree1 = degree1 - 5; // -5 degree } motor1.write (degree1); // SEND DEGREES TO SERVO 1 } void Motor2 () { valueY = analogRead ( pinJY); // STORES THE READINGS OF THE Y-AXIS OF THE ANALOG PORT AO // INCREASE MOTOR2 DEGREES if ( (valueY > 530 ) && (valueY <= 1023) && (degree2 < 140) )// INCREASE THE DEGREES WHEN THE Y-AXIS READING IS HIGHER THAN THE CALIBRATION O LOWER / EQUAL TO 1023 { degree2 = degree2 + 5; // +5 degree } // MOTRO2 DECREASE DEGREES else if ( (valueY >= 0 ) && (valueY < 480) && (degree2 > 70) ) // DECREASE DEGREES WHEN THE Y-AXIS LECTURE IS LOWER THAN THE CALIBRATION OR HIGHER/EQUAL TO 0 { degree2 = degree2 - 5; // -5 degree } motor2.write (degree2); // SEND DEGREES TO SERVO 2 } void Motor3 () { valueX2 = analogRead ( pinJX2); // STORES THE READINGS OF THE X2-AXIS OF THE ANALOG PORT A2 // MOTOR3 DEGREES INCREASE if ( (valueX2 >= 0 ) && (valueX2 < 480) && (degree3 < 155) ) // INCREASE DEGREES WHEN THE X2-AXIS READING IS HIGHER THAN THE CALIBRATION OR LOWER/EQUAL TO 1023 { degree3 = degree3 + 5; // +5 degree } // MOTOR3 DEGREE DECREASE if ( (valueX2 > 530 ) && (valueX2 <= 1023) && (degree3 > 80) ) // DECREASE DEGREES WHEN THE X2-AXIS READING IS LOWER THAN THE CALIBRATION OR HIGHER/EQUAL TO 0 { degree3 = degree3 - 5; // -5 degree } motor3.write (degree3); // SEND DEGREES TO SERVO 3 } void Motor4 () { valueY2 = analogRead ( pinJY2); // STORES THE READINGS OF THE Y-AXIS OF THE ANALOG PORT A3 // MOTOR4 INCREASE DEGREES if ( (valueY2 >= 0 ) && (valueY2 < 480) && (degree4 < 125) ) // INCREASE DEGREES WHEN Y2-AXIS READING IS HIGHER THAN THE CALIBRATION OR LOWER/EQUAL TO 1023 { degree4 = degree4 + 5; // +5 degree } // MOTOR4 DEGREE DECREASE else if ( (valueY2 > 530 ) && (valueY2 <= 1023) && (degree4 > 90) ) // DECREASE DEGREES WHEN THE Y2-AXIS READING IS LOWER THAN THE CALIBRATION OR HIGHER/EQUAL TO 0 { degree4 = degree4 - 5; // -5 degree } motor4.write (degree4); // SEND DEGREES TO SERVO 4 }
- Sukonfig?ruokite ir ?kelkite kod? vadovaudamiesi instrukcijomis pateiktomis „Arm Robot“ roboto rankos pirm?j? veiksm? vadove
Kodas vaizdinio programavimo programinei ?rangai naudojan?iai blokus
- Parsisi?skite ir ?diekite program?
- Paleiskite program? ir nukopijuokite toliau pateikt? kod?:
- Sukonfig?ruokite program? ir ?kelkite j? ? „Arm Robot“ roboto rank?. Instrukcijos pateikiamos „Arm Robot“ roboto rankos vadovo pirmuosiuose veiksmuose.
PRATIMO REZULTATAS:
Suk?rus program? gal?site valdyti „Arm Robot“ roboto rank? naudodami dvi vairasvirtes. Su vairasvirte Nr. 1 judinsite rieš? (S3) ir griebtuv? (S4), o su vairasvirte Nr. 2 judinsite rank? (S2) ir pagrind? (S1).