Skynet watch out!

This is part 3 of my robot series.

Curiously enough, despite the fact that Claudia originally set this up to highlight my writing, I seem to be doing a robotics blog. Now if I were only a robotics expert, we’d be all set!

This update you will get two for the price of one. I will be adding a couple of cool flashy lights to my robot, and giving him a memory (of sorts).

Lets start with lights. Since he has an open source controller, we have the ability to add, remove, or swap bits and pieces. Kind of like Frankenstein’s monster, but without all the blood and grave-robbery. And hopefully I won’t attract angry villagers with torches and pitchforks. As he is set up for BYFR, there are still a couple of free pins on his controller board that are not used. So we could add either input or output devices. He doesn’t have any flashing lights yet, and any self respecting robot has to have those, so we’ll add a couple of LEDs first. For simplicity’s sake I will use the last two digital pins that don’t have any special functions; pins 8 and 11, and hook up red and green LEDs to them. Why red and green? That’s the proper color of navigation lights, of course (if you’ve been on a boat you’ll understand). Also red and green can work for yes and no, stop and go, all kinds of fun stuff.20140518-001

After wiring up the lights, I add a little bit of simple code to make sure they work. In this case when he hit hits his right whisker, I will have him flash his green light in addition to his beeping, reversing, etc. And when he hits left whisker, the red light will flash. Nifty, huh? That’s the beauty of open source!

Now l want to go back to the question in my “State the Purpose” post. What is the robot good for? Even with his cool flashy lights, the answer is still “not very much”. He runs around, bumping into stuff, making beeping noises, AND flashing light. If I want him to do anything useful, like fetch me a beer, he has to first learn to move about the house in a less random fashion. Not an easy task, due to his simplistic inputs. Before I try adding an ultrasonic rangefinder or something like that, let’s see what we have to work with now. He only knows when you order him about with the IR transmitter (remote control), and he knows when he bumps into something. Picture yourself in a dark house; you can’t see anything, can’t hear anything, and you only know when you’ve run into something. But even with these limitations, there is more we can do, and that is called learning. Teaching robots to learn is a very complicated topic that I can’t begin to do justice to. Lots of very well paid individuals with lab coats and fancy facilities have been working on this topic for decades.

But since my robot is starting with a completely pre-programmed response, (= I.Q. of 0.00) it’s possible to improve on this a little. The first part of learning is remembering. Lets go back to the dark house. Let’s say you bang into a wall a couple times: If you’re like me, you learn after the third or fourth time to do something different (and if you’re smarter than me, you only have to whack into something once 🙂 ) . However, the first part of learning is remembering; I have to remember that I whacked my head into a chandelier previously for me to even start to be able to learn to do something else. And this is what we’re going to give our robot – a memory.

If we take a look at the code below, I have now asked our robot to remember something, specifically how often he has bumped his right whisker, and how often he has bumped his left whisker (new code in green).

if (pbLeft == HIGH) { // If left whisker hit
left_whisker_count++; //NEW count bumps
digitalWrite(ledPinR, HIGH); //turn on red LED
int tones[] = {NOTE_C4, NOTE_B3, NOTE_C4};
int toneDurations[] = {4,4,4};
reverse();
makeTone(tones, toneDurations, sizeof(tones)/sizeof(int));
delay(500);
spinRight();
delay(1000); //turn less was 1500
digitalWrite(ledPinR, LOW); //turn off red LED
forward();
pbLeft = LOW;
Serial.println("pbLeft");

It’s not much, but it’s a start. With this information at your disposal, think of the possibilities. If you hit one bumper repeatedly, maybe it means you’re stuck in one spot, and maybe you need to change what you are doing to get unstuck. But figuring out what to do with this knowledge is a much bigger challenge for the future. For now let’s just check to see if he remembered what he has done. How do we do that? How about putting those cool new lights to a practical use! The next part of the code lets him tell you what he has remembered. Hit the “stop” button on the remote, and in addition to stopping, he also flashes the red and green lights to indicate the number of times he has hit the left and right bumpers (since the last reading).

case 0x210:
Serial.println("5"); // Stop
stopRobot();
makeTone(tones, toneDurations, sizeof(tones)/sizeof(int));// this is new to make tones on stop
delay(750); // need enough time for tones to play
while (left_whisker_count > 0) { //NEW
digitalWrite(ledPinR, HIGH); //NEW turn on red LED to count bumps
delay(175); // NEW
digitalWrite(ledPinR, LOW); //NEW turn off red LED
delay(200); // NEW
left_whisker_count--;
}
while (right_whisker_count > 0) { //NEW
digitalWrite(ledPinG, HIGH); //NEW turn on green LED to count bumps
delay(150); // NEW
digitalWrite(ledPinG, LOW); //NEW turn off green LED
delay(200); // NEW
right_whisker_count--;
}
break;

 

So I have flashing lights and a memory. I suppose the robo-apocolypse (a la Skynet) will take a while longer.

‘Till next time!

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.