IntroducTIOn

In tutorial #4, we saw a first example of tactile interaction with Robobo, that is, how the robot can react if we touch its face.

In this tutorial we will continue working on this aspect with Robobo, and you will now learn how to provoke a predefined response when we touch the face in a certain way.

The challenge is to create a Spinning Robobo!

pre-requisitEs

Before starting this challenge, we recommend that you read the following sections of the Robobo programming manual:

CHALLENGE: SPINNING ROBOBO

Creating a program that makes Robobo react to touches and gestures on its face (Smartphone screen). If you move your finger on the screen (fling) to the right or left, Robobo must turn its head to the right or left respectively and turn on the leds (one color to the right and a different color to the left).

SOLUTION

A possible solution to this challenge is the following, although there are many others. Which one is yours?

async function main(){
    var Robobo = require('./lib/robobo');
    robobo = new Robobo('10.113.36.163');

    await robobo.connect();

    robobo.resetFlingSensor();
    robobo.setEmotionTo('normal');
    robobo.setLedColorTo('all','off');
    await robobo.movePanToBLK(0,15);

    while (true) {
       await robobo.update();
       var angle = robobo.readFlingSensor();
       if (angle > 0) {
            console.log(angle);
            if ((angle<90)||(angle>270)) {
                robobo.setEmotionTo('surprised');
                robobo.setLedColorTo('all','blue');
                await robobo.movePanToBLK(-50,30);
            }else{
                robobo.setEmotionTo('surprised');
                robobo.setLedColorTo('all','magenta');
                await robobo.movePanToBLK(50,30);
            }
            await robobo.movePanToBLK(0,15);
            robobo.setEmotionTo('laughing');
            await robobo.pause(1);
            robobo.playSound('laugh');
            robobo.resetFlingSensor();
            robobo.setLedColorTo('all','off');
            robobo.setEmotionTo('normal');
        } 
    }
}
main()

SUPPLEMENTARY CHALLENGE

When you have completed the “Spinning Robobo” challenge we propose you a new one where we complicate a little the reaction of Robobo, are you prepared? The goal is to create a program in which Robobo moves its head forward/backward (TILT) or turns its body (moves the wheels) right/left (PAN) depending on the angle of the fling gesture you make on the screen of the Smartphone.