Diaľkový ovládač robota zo súpravy mBot Explorer Kit

Zdravím priateľov robotiky a programovania oboznamujúcich sa s robotom zo súpravy mBot Explorer Kit. Neodmysliteľnou súčasťou tejto súpravy je infračervený (skratka IR) diaľkový ovládač, slúžiaci nielen na odskúšanie predvoleného programu (nahraný výrobcom) pri prvom zapnutí spomenutého robota, ale aj umožňujúci rozvinutie vašich zručností pri jeho programovaní.

Diaľkový ovládač robota mBot

IR diaľkový ovládač robota zo súpravy mBot Explorer Kit disponuje programovateľnými tlačidlami (v počte 21) a ako zdroj energie mu slúži batéria CR2025. IR diaľkové ovládanie umožňuje IR dióda nachádzajúca sa na riadiacej doske mCore uvedeného robota.

Vysoký počet tlačidiel dáva priestor fantázii pri hľadaní odpovede na otázku aké funkcie majú plniť. Bolo tomu tak aj v mojom prípade, keď som dostal nápad vylepšiť výrobcom predvolený program tohto robota, pričom som sa zameral na aplikovanie častejšieho použitia zvukových a svetelných prejavov vychádzajúcich zo zmienenej dosky. Snažil som sa tiež vo väčšej miere využiť zobrazovaciu schopnosť displeja Me LED Matrix a optimalizovať funkcie tlačidiel opísaného ovládača. V texte nižšie môžete posúdiť, či a do akej miery sa mi to podarilo.

Alternatíva k predvolenému programu robota mBot vytvorená v mBlock 5

Predvolený program robota zo súpravy mBot Explorer Kit využíva IR diaľkový ovládač na spustenie rôznych módov (sledovanie čiary, vyhýbanie sa prekážkam, ovládanie smeru a rýchlosti pohybu). Tento program nebol vytvorený v platforme Makeblock mBlock 5 a jeho opätovné nahranie je možné len v staršej verzii (Makeblock mBlock 3), čo bolo hlavným dôvodom realizácie môjho nápadu spomenutého vyššie.

Najskôr som si zvolil ‚layout‘ portov konektorov RJ25 (6P6C) riadiacej dosky mCore (bez Bluetooth modulu):

  • Port 1 – displej Me LED Matrix
  • Port 2 – snímač čiary Me Line Follower
  • Port 3 – snímač vzdialenosti Me Ultrasonic Sensor

Potom som do piatej verzie uvedenej platformy pridal zariadenie mBot a začal som programovať využijúc programy z predošlého článku (sledovanie čiary a vyhýbanie sa prekážkam). Nasledovalo naprogramovanie ovládania smeru a rýchlosti pohybu, so zreteľom na optimalizáciu počtu použitých tlačidiel. Zvyšné nenaprogramované tlačidlá som použil na predvedenie displeja a RGB LED diódy riadiacej dosky zmieneného robota, pričom som nezabudol ani na ukážku nameraných hodnôt jeho snímačov.

Náročnosť vytvorenia programu pozostávajúceho až z piatich modulov sa prejavila aj na jeho dlhšom testovaní, ktoré postupne odhalilo viaceré nedostatky. Našťastie sa mi ich podarilo odstrániť, čo ma doviedlo k finálnej verzii môjho programu:

Program Arduino C – alternatíva k predvolenému programu

// generated by mBlock5 for mBot
// codes make you happy

#include <MeMCore.h>
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

MeRGBLed rgbled_7(7, 2);
MeBuzzer buzzer;
MeLEDMatrix ledMtx_1(1);
unsigned char drawBuffer[16];
unsigned char *drawTemp;
MeIR ir;
MeDCMotor motor_9(9);
MeDCMotor motor_10(10);
MeLineFollower linefollower_2(2);
MeUltrasonicSensor ultrasonic_3(3);
MeLightSensor lightsensor_6(6);

float tla_C4_8D_C3_ADtko = 0;
float r_C3_BDchlost_pohybu = 0;

void move(int direction, int speed) {
  int leftSpeed = 0;
  int rightSpeed = 0;
  if(direction == 1) {
    leftSpeed = speed;
    rightSpeed = speed;
  } else if(direction == 2) {
    leftSpeed = -speed;
    rightSpeed = -speed;
  } else if(direction == 3) {
    leftSpeed = -speed;
    rightSpeed = speed;
  } else if(direction == 4) {
    leftSpeed = speed;
    rightSpeed = -speed;
  }
  motor_9.run((9) == M1 ? -(leftSpeed) : (leftSpeed));
  motor_10.run((10) == M1 ? -(rightSpeed) : (rightSpeed));
}
void pohyb (){

  rgbled_7.setColor(0,255,246,0);
  rgbled_7.show();
  _delay(1);
  rgbled_7.setColor(0,0,0,0);
  rgbled_7.show();

  buzzer.tone(294, 0.5 * 1000);
  _delay(0.02);

  drawTemp = new unsigned char[16]{124,32,16,32,124,0,56,68,56,0,120,4,120,0,124,84};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{16,32,64,124,0,0,76,84,84,36,0,0,84,84,84,124};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  r_C3_BDchlost_pohybu = 0;
  while(!((ir.keyPressed(70))  ||  ((ir.keyPressed(71))  ||  ((ir.keyPressed(68))  ||  (ir.keyPressed(67))))))
  {
    _loop();
    if(ir.keyPressed(12)){

        drawTemp = new unsigned char[16]{36,120,44,64,0,56,12,0,24,36,24,0,36,8,16,36};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
        _delay(1);
        ledMtx_1.clearScreen();
        r_C3_BDchlost_pohybu = 40;

    }
    if(ir.keyPressed(24)){

        drawTemp = new unsigned char[16]{36,120,44,64,0,60,12,0,24,36,24,0,36,8,16,36};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
        _delay(1);
        ledMtx_1.clearScreen();
        r_C3_BDchlost_pohybu = 60;

    }
    if(ir.keyPressed(94)){

        drawTemp = new unsigned char[16]{36,120,44,64,0,48,60,0,24,36,24,0,36,8,16,36};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
        _delay(1);
        ledMtx_1.clearScreen();
        r_C3_BDchlost_pohybu = 90;

    }
    if(ir.keyPressed(64)){
        if(r_C3_BDchlost_pohybu == 0.000000){

            drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

            drawTemp = new unsigned char[16]{16,32,64,124,0,0,76,84,84,36,0,0,84,84,84,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

        }else{

            rgbled_7.setColor(0,255,255,255);
            rgbled_7.show();

            drawTemp = new unsigned char[16]{0,0,0,0,0,0,32,96,252,96,32,0,0,0,0,0};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

            move(1, r_C3_BDchlost_pohybu / 100.0 * 255);

        }

    }
    if(ir.keyPressed(25)){
        if(r_C3_BDchlost_pohybu == 0.000000){

            drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

            drawTemp = new unsigned char[16]{16,32,64,124,0,0,76,84,84,36,0,0,84,84,84,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

        }else{

            rgbled_7.setColor(0,255,0,0);
            rgbled_7.show();

            drawTemp = new unsigned char[16]{0,0,0,0,0,0,16,24,252,24,16,0,0,0,0,0};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

            move(2, r_C3_BDchlost_pohybu / 100.0 * 255);

        }

    }
    if(ir.keyPressed(7)){
        if(r_C3_BDchlost_pohybu == 0.000000){

            drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

            drawTemp = new unsigned char[16]{16,32,64,124,0,0,76,84,84,36,0,0,84,84,84,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

        }else{

            rgbled_7.setColor(2,255,161,0);
            rgbled_7.show();

            rgbled_7.setColor(1,0,0,0);
            rgbled_7.show();

            drawTemp = new unsigned char[16]{0,0,0,0,0,16,16,16,124,56,16,0,0,0,0,0};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

            move(3, r_C3_BDchlost_pohybu / 100.0 * 255);

        }

    }
    if(ir.keyPressed(9)){
        if(r_C3_BDchlost_pohybu == 0.000000){

            drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

            drawTemp = new unsigned char[16]{16,32,64,124,0,0,76,84,84,36,0,0,84,84,84,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

        }else{

            rgbled_7.setColor(1,255,161,0);
            rgbled_7.show();

            rgbled_7.setColor(2,0,0,0);
            rgbled_7.show();

            drawTemp = new unsigned char[16]{0,0,0,0,0,16,56,124,16,16,16,0,0,0,0,0};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

            move(4, r_C3_BDchlost_pohybu / 100.0 * 255);

        }

    }
    if(ir.keyPressed(21)){
        if(r_C3_BDchlost_pohybu == 0.000000){

            drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

            drawTemp = new unsigned char[16]{16,32,64,124,0,0,76,84,84,36,0,0,84,84,84,124};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            _delay(1);
            ledMtx_1.clearScreen();

        }else{

            rgbled_7.setColor(0,0,0,0);
            rgbled_7.show();

            drawTemp = new unsigned char[16]{0,0,0,0,0,0,68,40,16,40,68,0,0,0,0,0};
            memcpy(drawBuffer, drawTemp, 16);
            free(drawTemp);
            ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
            motor_9.run(0);
            motor_10.run(0);

        }

    }

  }

}

void senzor_sledov_C3_A1n_C3_AD__C4_8D_C3_A1ry (){

  rgbled_7.setColor(0,42,255,0);
  rgbled_7.show();
  _delay(1);
  rgbled_7.setColor(0,0,0,0);
  rgbled_7.show();

  buzzer.tone(330, 0.5 * 1000);
  _delay(0.02);

  drawTemp = new unsigned char[16]{0,24,36,66,129,129,66,36,24,24,36,66,66,36,24,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  while(!((ir.keyPressed(69))  ||  ((ir.keyPressed(71))  ||  ((ir.keyPressed(68))  ||  (ir.keyPressed(67))))))
  {
    _loop();
    if(linefollower_2.readSensors() == 0.000000){

        rgbled_7.setColor(0,0,0,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,120,252,252,120,0,0,0,0,120,252,252,120,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

        move(1, 40 / 100.0 * 255);

    }
    if(linefollower_2.readSensors() == 1.000000){

        rgbled_7.setColor(2,255,161,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,120,252,252,120,0,0,0,0,120,132,132,120,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

        move(3, 40 / 100.0 * 255);

        buzzer.tone(262, 0.2 * 1000);
        _delay(0.02);

    }
    if(linefollower_2.readSensors() == 3.000000){

        rgbled_7.setColor(1,255,161,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,120,132,132,120,0,0,0,0,120,252,252,120,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

        move(4, 40 / 100.0 * 255);

        buzzer.tone(494, 0.2 * 1000);
        _delay(0.02);

    }

  }

}
void ultrazvukov_C3_BD_senzor (){

  rgbled_7.setColor(0,0,242,255);
  rgbled_7.show();
  _delay(1);
  rgbled_7.setColor(0,0,0,0);
  rgbled_7.show();

  buzzer.tone(349, 0.5 * 1000);
  _delay(0.02);

  drawTemp = new unsigned char[16]{0,24,36,66,66,36,24,0,0,24,36,66,66,36,24,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  while(!((ir.keyPressed(69))  ||  ((ir.keyPressed(70))  ||  ((ir.keyPressed(68))  ||  (ir.keyPressed(67))))))
  {
    _loop();
    if(ultrasonic_3.distanceCm() < 12){

        rgbled_7.setColor(2,255,161,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,120,252,252,120,0,0,0,0,120,132,132,120,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

        move(3, 70 / 100.0 * 255);

        buzzer.tone(262, 0.5 * 1000);
        _delay(0.02);

    }else{

        rgbled_7.setColor(2,0,0,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,120,252,252,120,0,0,0,0,120,252,252,120,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

        move(1, 40 / 100.0 * 255);

    }

  }

}
void obr_C3_A1zky_a_barvy (){

  rgbled_7.setColor(0,212,0,255);
  rgbled_7.show();
  _delay(1);
  rgbled_7.setColor(0,0,0,0);
  rgbled_7.show();

  buzzer.tone(440, 0.5 * 1000);
  _delay(0.02);

  drawTemp = new unsigned char[16]{0,7,5,0,7,5,7,0,255,160,231,5,231,0,231,164};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{124,80,32,0,120,4,4,120,0,36,84,72,0,124,16,124};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{8,24,40,76,0,0,116,84,84,72,0,0,56,84,84,72};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{64,64,64,124,0,0,40,84,84,40,0,0,32,80,80,60};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  while(!((ir.keyPressed(69))  ||  ((ir.keyPressed(70))  ||  ((ir.keyPressed(71))  ||  (ir.keyPressed(68))))))
  {
    _loop();
    if(ir.keyPressed(8)){

        rgbled_7.setColor(2,255,0,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,16,48,48,48,48,16,0,0,16,48,48,48,48,16,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

    }
    if(ir.keyPressed(28)){

        rgbled_7.setColor(2,255,233,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,12,24,24,28,12,0,0,0,0,12,28,24,24,12,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

    }
    if(ir.keyPressed(90)){

        rgbled_7.setColor(2,42,255,0);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,24,28,28,24,0,0,0,0,24,28,28,24,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

    }
    if(ir.keyPressed(66)){

        rgbled_7.setColor(2,0,242,255);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,60,30,14,4,0,0,0,0,4,14,30,60,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

    }
    if(ir.keyPressed(82)){

        rgbled_7.setColor(2,255,0,220);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{0,0,54,62,28,62,54,0,0,54,62,28,62,54,0,0};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

    }
    if(ir.keyPressed(74)){

        rgbled_7.setColor(2,63,0,255);
        rgbled_7.show();

        drawTemp = new unsigned char[16]{16,60,62,62,62,62,60,16,16,60,62,62,62,62,60,16};
        memcpy(drawBuffer, drawTemp, 16);
        free(drawTemp);
        ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);

    }

  }

}
void hodnoty_senzor_C5_AF (){

  rgbled_7.setColor(0,55,0,255);
  rgbled_7.show();
  _delay(1);
  rgbled_7.setColor(0,0,0,0);
  rgbled_7.show();

  buzzer.tone(392, 0.5 * 1000);
  _delay(0.02);

  drawTemp = new unsigned char[16]{120,4,0,20,8,20,0,0,28,20,0,28,16,28,16,12};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  ledMtx_1.showNum(lightsensor_6.read(), 3);
  _delay(1);

  drawTemp = new unsigned char[16]{0,0,0,0,120,4,4,0,20,8,20,0,0,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(2);

  ledMtx_1.showNum(round(ultrasonic_3.distanceCm()), 3);
  _delay(1);

  drawTemp = new unsigned char[16]{0,0,0,0,28,20,20,0,28,16,28,16,12,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(2);

  ledMtx_1.showNum(linefollower_2.readSensors(), 3);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(1);

}

void _delay(float seconds) {
  long endTime = millis() + seconds * 1000;
  while(millis() < endTime) _loop();
}

void setup() {
  rgbled_7.fillPixelsBak(0, 2, 1);
  ledMtx_1.setColorIndex(1);
  ledMtx_1.setBrightness(6);
  ir.begin();

  _delay(1);

  drawTemp = new unsigned char[16]{124,32,16,32,124,0,56,68,56,0,120,4,120,0,124,84};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{0,0,0,0,0,0,60,80,80,80,60,0,0,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(1);

  drawTemp = new unsigned char[16]{0,24,36,66,129,129,66,36,24,24,36,66,66,36,24,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{0,0,0,0,0,0,124,84,84,84,40,0,0,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(1);

  drawTemp = new unsigned char[16]{0,24,36,66,66,36,24,0,0,24,36,66,66,36,24,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{0,0,0,0,0,0,56,68,68,68,68,0,0,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(1);

  drawTemp = new unsigned char[16]{124,4,0,20,8,20,0,0,28,20,0,28,16,28,16,12};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{0,0,0,0,0,0,124,68,68,68,56,0,0,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  _delay(1);

  drawTemp = new unsigned char[16]{0,7,5,0,7,5,7,0,255,160,231,5,231,0,231,164};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();

  drawTemp = new unsigned char[16]{0,0,0,0,0,0,124,84,84,84,84,0,0,0,0,0};
  memcpy(drawBuffer, drawTemp, 16);
  free(drawTemp);
  ledMtx_1.drawBitmap(0, 0, 16, drawBuffer);
  _delay(1);
  ledMtx_1.clearScreen();
  while(1) {
      if(ir.keyPressed(69)){

          rgbled_7.setColor(0,0,0,0);
          rgbled_7.show();
          ledMtx_1.clearScreen();
          motor_9.run(0);
          motor_10.run(0);
          pohyb();

      }
      if(ir.keyPressed(70)){

          rgbled_7.setColor(0,0,0,0);
          rgbled_7.show();
          ledMtx_1.clearScreen();
          motor_9.run(0);
          motor_10.run(0);
          senzor_sledov_C3_A1n_C3_AD__C4_8D_C3_A1ry();

      }
      if(ir.keyPressed(71)){

          rgbled_7.setColor(0,0,0,0);
          rgbled_7.show();
          ledMtx_1.clearScreen();
          motor_9.run(0);
          motor_10.run(0);
          ultrazvukov_C3_BD_senzor();

      }
      if(ir.keyPressed(68)){

          rgbled_7.setColor(0,0,0,0);
          rgbled_7.show();
          ledMtx_1.clearScreen();
          motor_9.run(0);
          motor_10.run(0);
          hodnoty_senzor_C5_AF();

      }
      if(ir.keyPressed(67)){

          rgbled_7.setColor(0,0,0,0);
          rgbled_7.show();
          ledMtx_1.clearScreen();
          motor_9.run(0);
          motor_10.run(0);
          obr_C3_A1zky_a_barvy();

      }

      _loop();
  }

}

void _loop() {
  ir.loop();
}

void loop() {
  _loop();
}

Program mBlock 5 – alternatíva k predvolenému programu

Video

Tlačidlá diaľkového ovládača robota mBot

Finálny program je príliš obsiahly, preto je nevyhnuté poznať ‚layout‘ funkcií tlačidiel opísaného ovládača:

  • A – mód ovládanie pohybu
  • 1 – nastavenie rýchlosti pohybu na 40%
  • 2 – nastavenie rýchlosti pohybu na 60%
  • 3 – nastavenie rýchlosti pohybu na 90%
  • Hore– pohyb dopredu
  • Dole – pohyb dopredu
  • Vľavo – otočenie vľavo
  • Vpravo – otočenie vpravo
  • Nastavenie – stop
  • B – mód sledovania čiary
  • C – mód vyhýbania sa prekážkam
  • D – mód zobrazenia nameraných hodnôt snímačov
  • E – mód zobrazenia rôznych obrázkov na displeji a rôznych farieb diódy riadiacej dosky
  • 4 až 9 – zobrazenie obrázku na displeji a farby diódy riadiacej dosky

Záver

Záverom chcem vyjadriť vďaku nielen za vytrvalosť, ale aj za čas strávený pri čítaní môjho článku. Musím sa priznať, že je to môj prvý komplexný program (pre robot), ktorý vystihuje reklamný slogan ‚all in one‘. Kto by bol povedal, čoho všetkého je schopný IR diaľkový ovládač s robotom zo súpravy mBot Explorer Kit, v kombinácii so správnym programom.

Mohlo by sa zdať, že tému diaľkového ovládania uvedeného robota som vyčerpal, avšak zdanie klame. Netreba zabúdať na Bluetooth modul riadiacej dosky mCore a zaujímavú Android aplikáciu Makeblock, ktoré vám predstavím nabudúce.

Eshop

E-shop

Makeblock Explorer Kit – mBot Bluetooth, modrý, verze 2

Modrý mBot Bluetooth vylepšený o LED matrix displej!


Makeblock mBot, 1800mAh Li-Pol baterie

Li-Pol baterie pro k napájení robota mBot nebo Vašich jiných projektů.




Leave a Reply