This document discusses controlling a Robosapien toy robot from an Intel Edison board. An Arduino sketch runs on the Edison to communicate with a Firebase database and retrieve command integers. The Edison then converts the commands and uses infrared LED modulation to send signals to the Robosapien over infrared to control its movements and sounds.
2. ● 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...
3. ● 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
4. ● 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
5. ● 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
6. // 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
7. 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
8. 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
12. //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