12
Intel IoT Webinar Tedison: Controlling a Robosapien from Edison

Intel IoT webinar #1 - Tedison presentation

  • Upload
    bemyapp

  • View
    155

  • Download
    1

Embed Size (px)

Citation preview

Intel IoT WebinarTedison: Controlling a Robosapien from Edison

● A low cost humanoid robot● ($62.99 on Amazon)● Bipedal walking motion● Infrared remote control● Hardware for

...Toy Story…...Child’s Play...

...Five nights at Freddies…

Robosapien...

● Robust Teddy Bear● Low cost● Large enough to hold a Robosapien● Stuffing in the head is too heavy, so…● Replace with packing peanuts

Ikea Vandring Bjorn Teddy Bear

● Edison with Arduino breakout board● Could now be done with SparkFun blocks● Keep the packing box as an enclosure!● No packing box● Infrared LED and resistor and jumper wires● NO SOLDER….

Intel Edison

● An “Arduino Sketch” that could never run on an arduino● Communicates using Firebase

○ A realtime cloud database with a REST API. Free for small users○ Backend doesn’t require any coding

● Front end saves a command integer to firebase● Intel Edison retrieves the events in the “arduino” event loop

Software

// the loop routine runs over and over again forever:

void loop() { // wait for a second

int maxfsize=500;

//Retrieve a command system("curl https://blazing-fire-1158.firebaseio.com/robosapien.json > /tmp/robocmd.txt");

char *cmdStr = (char*)malloc(maxfsize + 1);

FILE *lockFile = fopen("/tmp/robolock", "r");

if(!lockFile)

{

FILE *cmdFile = fopen("/tmp/robocmd.txt", "rb");

if(cmdFile)

{

Retreive a command

fseek(cmdFile, 0, SEEK_END);

long fsize = ftell(cmdFile);

if(fsize<3)

{

fclose(cmdFile);

Serial.println("File length too short. Size in bytes is: ");

Serial.println(fsize);

}

else

{

Check the response is valid

fseek(cmdFile, 1, SEEK_SET); //avoid leading quote

fread(cmdStr, fsize, 1, cmdFile);

fclose(cmdFile);

cmdStr[fsize] = 0;

cmdStr[fsize-1] = 0; //delete trailing quote

int cmdInt=atoi(cmdStr);

Serial.println("Command Number");

Serial.println(cmdInt);

Convert the command to an int

if(cmdInt>=0)

{

Serial.println("Executing Command");

sendCommand(cmdInt); //0x88 high5 0x8E fart

Serial.println("Command Executed, erasing command from firebase");

system("curl -X PUT -d '\"-1\"' https://blazing-fire-1158.firebaseio.com/robosapien.json");

Serial.println("Command erased");

}

}

}

}

}

Execute the command

void sendCommand(unsigned char cmdIn)

{

unsigned char cmd=cmdIn;

sendHeader();

for(int i=0; i<8; i++) {

if(cmd&128)

sendOne();

else

sendZero();

cmd=cmd<<1;

}

}

Sending command

void sendHeader()

{

sendPair(headerPulse, headerSpace, waitMS);

};

void sendOne()

{

sendPair(onePulse, oneSpace, waitMS);

};

void sendZero()

{

sendPair(zeroPulse, zeroSpace, waitMS);

};

Sending zeros, ones, headers

//VERY IMPORTANT NOTE delayMicros on an Edison will delay you a minimum of 90MS!!!!

void sendPair(int p, int s, int w){

int targetMicros=micros()+p; int micros2=micros();

while(micros()<targetMicros) { //Modulate at IR frequency for the “ON” pulse

int micros1=micros2;int microsTarget=micros1+w;

digitalWrite(led, HIGH); digitalWrite(boardLED, HIGH);

while((micros2=micros())<microsTarget){} //Waiting by spinning CPU with HIGH LED

int H=micros2-micros1; micros1=micros2;

digitalWrite(led, LOW); digitalWrite(boardLED, LOW);

microsTarget=micros1+w;

while((micros2=micros())<microsTarget){} //Waiting by spinning CPU with LOW LED

}

delayMicroseconds(s); //LED low only for “OFF” pulse

}

IR Modulation