BoM (Bill of Materials) робота:
Arduino Mini Pro — 1 шт.
Мини-сервомашинка — 2 шт.
Держатель батареи — 1 шт.
Беспаечная макетная плата — 1 шт.
TSOP-датчик — 1шт.
Исходник:
/* [email protected] Rolly Robot Test Program IR table 16752735 16720095 16736415 16769055 16748655 16716015 16732335 16764975 16756815 16724175 16740495 16773135 16754775 16722135 16738455 16771095 16750695 16718055 16734375 16767015 16746615 16713975 16730295 16762935 repeat 4294967295 */ #include <IRLib.h> #include <Servo.h> #define MY_PROTOCOL NEC IRrecv My_Receiver(11); IRdecode My_Decoder; int IRin; // left servo details int servoLeftPin = 10; int servoLeftZero = 91; int servoLeftDirection = 1; int leftSpeed = 0; Servo servoLeft; // right servo details int servoRightPin = 9; int servoRightZero= 91; int servoRightDirection = -1; int rightSpeed = 0; Servo servoRight; // degree to which we move forward int forwardness = 0; int forwardSpeedMax = 20; //degrees from center int forwardSpeedMin = 20; // // degre to which we drift right int rightness = 0; int rightnessMax = 10; // user event to come to a hault softly int softStop = 0; // refresh rate for soft commands float updateLast = 0; int updateDelay= 100; void setup(){ servoRight.attach(servoRightPin); servoLeft.attach(servoLeftPin); My_Receiver.enableIRIn(); //debug Serial.begin(9600); //115200 } void loop(){ // start user input if (My_Receiver.GetResults(&My_Decoder)) { My_Decoder.decode(); if(My_Decoder.decode_type==MY_PROTOCOL) { IRin = My_Decoder.value; Serial.println(IRin); switch(My_Decoder.value) { case 16752735: // increase forward forwardness = forwardness+1; if (forwardness > forwardSpeedMax) forwardness = forwardSpeedMax; softStop = 0; break; case 16720095: // decrease forward forwardness = forwardness-1; if (forwardness < -forwardSpeedMax) forwardness = -forwardSpeedMax; softStop = 0; break; case 16736415: // hard stop forwardness = 0; softStop = 0; break; case 16769055: // soft stop softStop = 1; break; case 16748655: // decrease rightness rightness = rightness -1 ; break; case 16716015: // remove rightness rightness = 0 ; break; case 16732335: // increaee rightness rightness = rightness +1 ; break; } } My_Receiver.resume(); } // end user input // refresh for soft commands if (millis() >= updateLast + updateDelay) { updateLast = millis(); if (softStop == 1) { if (forwardness > 0) {forwardness = forwardness -1;} if (forwardness < 0) {forwardness = forwardness +1;} if (rightness > 0) {rightness = rightness -1;} if (rightness < 0) {rightness = rightness +1;} if (forwardness ==0 && rightness==0) softStop = 0; } } // update servos leftSpeed = forwardness+rightness; rightSpeed = forwardness-rightness; servoLeft.write(servoLeftZero + leftSpeed * servoLeftDirection); servoRight.write(servoRightZero + rightSpeed * servoRightDirection); }
Ссылки
Rolly Robot