Sunday, February 24, 2013

ProtoCylon: It's ALIVE

ProtoCylon: It’s ALIVE

 

By Bobby Neal Winters
I wasn’t exactly in a laboratory over a cadaver coaxing the lightning to come it; I didn’t exactly have a hunchback named Igor by my side; but I do have some idea of the elation Dr. Frankenstein may have felt in those first few moments.
It he hadn’t been a fictional character, that is.
Along the way in this adventure, I continually referred to the simple-sounding model that organizes my thought so well: Input, Processing, and Output.  The processing consists of writing computer programs and that scares a lot of people, but throughout my adventure--for that is what is has been, an adventure--the Input and Output have been the most difficult. And of those two, Input has been by far the harder.
In Muscles on the Beast, I had put my robot body together and it would roll, but only with a preprogrammed script.  It had null input; it simply had processing and output.  At that time, I was debating whether to have it process input from ultrasonic sensors or to make it into a line following robot.
I decided to do the easiest; big surprise there.  I made into a bat.  It receives input from ultrasonic sensors.  The heuristic for this robot is for it to go straight ahead until it runs into a wall and then to turn until it gets free.  It tries turning one direction three times and if it is still caught it will try the other.  It will continue in this way until it is either free or its batteries run out.
#include
#define FULL_SPEED 256
#define TRAPPED_DIST 10

// motor pins
int speed1=3;
int speed2=11;
int direction1=12;
int direction2=13;

//distance Sensor pins
const int pingPin =4;
int inPin=2;

//variables concerning distance
int myDist;
boolean trapped;

void setup(){
setMotorPins();
setSensorPins();
}

void loop(){

 //How far is the next obstacle?
 myDist=getDistance();
 //If it is too close, I am trapped
 trapped=(myDist
 switch(trapped){
    case true:
     //If I am trapped, begin the struggle
     getFree();
    case false:
     //If I am not trapped, then quarter speed ahead
     goStraight(0.25,0.5);
     break;
 }

}

void setMotorPins(){

 pinMode(speed1,OUTPUT);
 pinMode(speed2,OUTPUT);  
 pinMode(direction1,OUTPUT);  
 pinMode(direction2,OUTPUT);
 return;
}

void setSensorPins(){
  pinMode(pingPin,OUTPUT);
  return;
}

long getDistance(){
 long duration, cm;

 digitalWrite(pingPin,LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin,HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin,LOW);  
 pinMode(inPin, INPUT);
 //How long does it take for my pings to get back.
 duration=pulseIn(inPin,HIGH);
 //How far is the next obstacle?
 cm=microsecondsToCentimeters(duration);
 return cm;
}  

void goStraight(float prop, float seconds){
 //prop is the proportion of full speed
 int rate=prop*FULL_SPEED;
 //Convert to microseconds
 int duration=1000*seconds;
 //Use both wheels  
 digitalWrite(direction1,HIGH);
 digitalWrite(direction2,HIGH);
 analogWrite(speed1,rate);  
 analogWrite(speed2,rate);  
 //Run awhile before we do anything else.
 delay(duration);
 return;
}

void goTurn(int dir, float seconds){
 //We will only turn at half speed
 float prop=0.5;
 int rate=prop*FULL_SPEED;
 //How long will we turn?
 int duration=1000*seconds;
 //Switch between the various directions.
 switch(dir){
    case 1:
     digitalWrite(direction1,HIGH);
     digitalWrite(direction2,LOW);
     analogWrite(speed1,rate);  
     analogWrite(speed2,0);     
    break;
    case 2:
     digitalWrite(direction1,LOW);
     digitalWrite(direction2,HIGH);
     analogWrite(speed1,0);  
     analogWrite(speed2,rate);
    break;
    default:
    return;
 }  
 delay(duration);  
 return;
}

void stopMotor(int seconds){
 analogWrite(speed1,0);
 analogWrite(speed2,0);  
 delay(1000*seconds);
 return;
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

void getFree(){
 //First try one direction
 int sense=0;
 int count=0;
 //Struggle until no longer trapped.
 while(trapped){
    ++count;
    goTurn(sense+1,1);
    if(count>3){
      count=0;
      //Struggle in one direction three times and then try the other.
      ++sense;
      sense=sense % 2;
    }
    myDist=getDistance();
    trapped=(myDist < TRAPPED_DIST);
 }
 return;
  
}

The Headless Pi-Man

The Headless Pi-Man

By Bobby Neal Winters
As those of you who have sampled this blog recently will be aware, lately I’ve been into building a robot.  I am progressing in that and will report on that shortly.  My account wouldn’t be complete if I didn’t share what got started on that was the Raspberry Pi.  I originally saw--was shown--Raspberry Pi on Facebook over Christmas Break.
I googled it.  Raspberry Pi was backordered, but the Arduino processor showed up on the search.  The rest is history, as they say.  
But I’m nothing if not stub..tenacious. I got my Raspberry Pi and have been trying to work it in amongst the Arduino/Robotics.  I may eventually try to marry them, but we have to see whether they get along first.
The Raspberry Pi is a computer based on an ARM chip...blah, blah, blah.  I’ve seen it described as the motherboard from a smartphone with some nice connectors glued to it.  They sell two varieties.  You want Model B and you can get it for $35 here.  You will also want to get the SD card with the operating system on it; that will cost you $13.
And you will need a TV at first.  It will have to have either an HDMI connector or a RCA jack connector.  These are the two ways that the Raspberry Pi connects directly with monitors.  The Pi was designed to appeal the the hacker mentality.  Since Christmas break, I’ve learned a lot about this psychology.  
There are folks who will spend hundreds of hours to find a way to do something outside of the constraints of the system.  (Be kind to them because you will want them to be your friends come the Zombie Apocalypse.) For these folks--and to make it as cheap as possible--the Pi has been designed so that you can make it work with things you might have laying around: keyboard, mouse, TV, ethernet hub, cell phone charger, etc.
I must confess that this peculiarity of working with anything BUT a computer monitor has cost me the most.  All of the TVs in my home are being watched by someone.  After a couple of misadventures with monitors designed for use with backup cameras and CCTV such as this. I got a cheap little TV for $100.  The bright side of this is that it can be used later for something else.  My youngest daughter is already lobbying for it.
This is all going to be filed under “I” for Irony in the Twilight Zone, however, because I believe I am going to be running my Pi headless.
That’s right, headless.
As it is a Linux box, you can use secure shell (SSH) to connect to it remotely.  As it is such a small little fellow, running a GUI on it makes it run slowly.  The light little browser that comes on it doesn’t do the things I like.
But it is a Linux box so I can put it on my network and set it up as a server.  The only thing I needed the monitor for was to get its IP address so I could connect to it remotely.
However, in the course of this, I have resurrected my Ubuntu box so I may put together a Linux network: A little computer farm in my own office.
There will be more entries as madness descends.

Thursday, February 21, 2013

Snow Day: Downton Abbey, Engineers, and a Chest Cold

Snow Day: Downton Abbey, Engineers, and a Chest Cold

By Bobby Neal Winters
You may recall the Multimedia PC I built one piece at a time.  I made a big deal about it.  I didn’t make such a big deal out of the fact that it suddenly stopped working.  (I now believe the power supply went out, but the truth of that remains to be seen.)  It turns out that building a video recorder isn’t such a big need when you’ve got Netflix.
In any case, it went out and I wasn’t in any hurry to get it fixed until a friend who’d loaned me the second season of Downton Abbey on DVD--before we discovered it was on Netflix--wanted his discs back.  It was then I remembered they were stuck in the Multimedia PC which couldn’t be opened because it was broken and which couldn’t be fixed because I didn’t have the time.  The solution at that point was to buy my friend a replacement set of DVDs and to wait until I had time to fix my Multimedia PC.
Summer came and went.  The wind whipped in flipping the days on my calendar.  Children dressed first in Halloween costumes and then as pilgrims came by.  A large man in a red suit struggled down a chimney and a naked baby in a top hat crawled by.
Then we got a snow day and I finally had time to mess with the computer.
It actually took less than half an hour to get the DVD out. All I had to do was take the DVD-Drive out of one and put it into another.  I pressed a button and out it popped.  I walked around the house with the DVD on my finger saying “Donna Noble has been saved.”  (It’s an obscure Dr. Who reference, okay, and not particularly germane to the event, but its obscurity covers that.)
Anyway, on the heels of that victory, I thought I would try to fix the Multimedia PC.  If I get it started, I think I might put Debian Linux on it so it can talk to my little Raspberry Pis.  The symptom that the PC exhibits is that you press the button and it won’t come on.  To me that suggests the power supply.  The reason I think this isn’t so much because I know a lot but because that would be the easiest and cheapest thing to fix.
In order to test this hypothesis, I thought I ought to plug it in. (Hey, I got a PhD, folks. The brilliance just flows.) I needed a power cord for that. (That PhD just keeps giving and giving.) I’d used the Multimedia PCs cord on another computer, so I borrowed one from my coffee pot.
Yes, you read that correctly. A computer uses the same power cord as a coffee pot. This is because good engineers, like Scotty said, are always just a wee bit conservative.  Wee bit, hell, once they have something that works they never change it.
I am old enough to remember the first printers for PCs.  You needed a screw-driver to hook them to the back of your computer.  It never occurred to the engineers who designed them that there would be offices without screwdrivers.  
Seriously.
Eventually we got the aptly named thumbscrews and those were around for years until they were replaced by USB printers.  This is because, like the coffee pot power cord, they worked.
I am sitting now at my Itty-bitty Ubuntu box tapping out this article after having fought with a chest cold for several days.  I am exhausted but my mind is somehow clear.  I am being battered by images around me.  USB printers, USB hard drives, USB thumb drives, my Arduino connected to the USB port, and a USB chargeable flashlight.  
The future is becoming clear to me.  I see it all.
One day I will awake to perk my coffee to a USB coffee pot.

Sunday, February 10, 2013

The Proto Cylon: Muscles on the Beast

The ProtoCylon: Muscles on the Beast

By Bobby Neal Winters
As I mentioned earlier, I am using Beginning Arduino by Michael McRoberts. It hasn’t failed me yet.  I’d also mentioned that my ProtoCylon’s robot body will be a car which will be run by a couple of motors.  In order to control the motors, transistors are required.  I wrote about using them in ProtoCylon: Control. There I used a temperature sensor to control the motor of an electric fan. Pretty cool. (Pun fully intended.)
I’d had visions of having to solder a couple of transistors to a pc board in order to control the motors on my robot.  That was before I learned about the Arduino Motor Shield.  The Arduino Motor Shield takes care of the transistors for you.  It also takes care of connectors for the power in and power out.
While an earlier version of myself would’ve insisted upon doing this the hard way, at 50 I am quite happy to use the scaffolding.  My skills soldering are steadily improving--not like they could get worse--and I am gaining confidence.  But I do like to be able to measure progress in visible ways, and today I did.  The robot moved.  See below:What you see there are motions that were pre-programmed.  I didn’t even write the code myself, though I did key it in.  While this is very fulfilling, I am not nearly done.  In order for this to really be a robot, it will have to be able to take input from the outside.  Remember the model: Input; Process; Output.  
I’ve got to decide on the mode of input.  There are two ways I am currently considering.  The first of these is to use my UltraSonic Sensors.  See ProtoCylon Senses.  These I could use to keep it from running into walls kind of like a bat.  The second model is that of the line following robot.  This would require light sensors.  It would have eyes.  I need to think on this a while.

Monday, February 04, 2013

An Interlude: Confronting Demons and Skeletons

An Interlude: Confronting Demons and Skeletons

By Bobby Winters
I may have shared with you before the brain block I have with regard to soldering.  When I was a kid, I’d gotten a computer kit that required soldering.  I made a mess of it and it wouldn’t work. It cost a lot of money, and we didn’t have all that much.  So, in my shame, I put it aside.
Since I’ve begun playing with microcontrollers, it’s become clear to me that beyond a certain point I will need to know how to solder.  Breadboards are nice, but anything that’s not going to be taken apart eventually will need to be soldered together.  I’ve taken to a program of learning the manly skill of soldering.  I’ve confronted the soldering demon.
I will never be an artist.  Heck, I may never actually solder anything that works.  But I am beyond the “Oh my gosh, what a mess” stage.  It boils down to those three words people have been telling me all my life: “Take your time!” Yes, that’s it.  That’s the secret.  One must decide that soldering is a thing that one must do and then set out the preparations to do it.  
The first thing is to prepare a place.  You’ve got to have a place to do your work.  The second is to have all of your materials around you.  You need your soldering iron, its stand, a little wet sponge to clean your tip on, and--this helped me a lot--a desoldering iron complete with attached desoldering bulb.  I always do a better job writing when I have an eraser, so it figures I do a better job soldering when I have a desoldering iron.
All of that having been said, I’ve not been able to solder a heat sensor to the pc board yet.  I think that I’m frying them.  I hook them to my thermometer program and they read -196.6. I tried three times and got this result three times with three different ruined sensors--and I’ve tried using a alligator clip as a heat sink.  In the world of digital thermal sensors, I am now known as He-who-brings-hot-death.  I am now looking for conductive glue on Amazon.
On other news, I’ve gotten a skeleton for my ProtoCylon.  There’s a picture below.  My experience in opening the box and thinking about putting it together made me think of building the pyramids.  I knew it could be done, but thousands might die in the process. There were parts--nuts, bolts, wheels, motors, plates--but no directions.  I have got something screwed--such a versatile word--together, but it was interesting.  I suppose they thought it would be more interesting without the directions.




Friday, February 01, 2013

Reconciliation

Reconciliation

By Bobby Neal Winters

The more I know, the less I understand
And all the things I thought I figured out, I have to learn again
I've been tryin' to get down to the Heart of the Matter
But my will gets weak
And my heart is so shattered
But I think it's about forgiveness
--Don Henley, Mike Campbell, and J.D. Souther

My father loved women.  And he was the sort of man who believed that there wasn’t a woman so beautiful that she couldn’t be made more beautiful with a two-year-old child tagging along behind her. As a truck driver, he viewed the world through his windshield and often created opinions of people from what he saw.  I remember of him speaking of a young woman who lived on the 19-mile stretch of road between Ada and Asher (Oklahoma).  He’d only knew her from from these glimpses along the road, but he admired her because she was so frequently outside and was working every time he saw her.
That is something I do too.  I create my own people by my glimpses of what I see.  There might be very little to go on.  I might only see them in public occasions when they are putting out what they want to be seen.  And it has been my habit to create an idealized version of them.  This means I admire a lot of people--and that makes me happy--but it also means that I am frequently disappointed.  One nasty side-effect of this is I am becoming more cynical as I grow older.
Those who watch this space may recall that a while back wrote that my father had committed suicide because of having cancer and that, after all these years, I was finding it difficult to really forgive him for it.  It was one of those things that in my youth I had forgiven, but as I grew closer to the age he’d been when I’d known him, I found forgiveness to be more difficult.
I got letters about that which doesn’t happen often.  They were very thoughtful, and though I have answered them all personally, I want to acknowledge them here. Thank you.
The Lord’s Prayer--the Our Father--asks that we be forgiven as we forgive others, so I’d better forgive.  But it is a process.
When the Presbyterians say the Lord’s Prayer, they say forgive us our debts.  We owe something.  It makes it almost a financial transaction.  That brings up another financial term: reconciliation. When you look up reconciliation in the dictionary, it brings of the image of two parties, each  bringing out accounts of their mutual transactions to see whether they line up.
When I’ve reconciled my bank account--my records versus the bank’s--there have been times when the two accounts didn’t line up exactly.  Mathematics dictates that I am wrong or the bank is wrong or that both of us are wrong.  There is a certain amount of good faith searching that must take place on the part of each of us.  How much depends upon the size of the difference. After that good faith effort, there comes a time when the difference must be acknowledge and each party must proceed.
Most of the time this ends with me admitting that I must have made a mistake.  But the search is not wasted because sometimes banks do make mistakes and because I gain greater insight to the sorts of mistakes I make.  If I follow the procedures that Mr. Scott taught me in high school bookkeeping, then there is a trail of what I’ve done that I can look back on.
This is what I’ve been doing in reconciling with my father.  There comes a point where the accounts don’t match up and if the relationship is to continue somebody has to let the difference go.  
And Dad’s been gone for nearly three decades, but there is still a relationship.  He’s not around to state his case, so I’ve just got to let the difference go.
But in the process, I’ve recalled all the good about him. I’ve discovered the things about him--good and bad--that live on in me. And I’ve let go of my anger.
(Bobby Winters, a native of Harden City, Oklahoma, is Assistant Dean of the College of Arts and Sciences and Professor of Mathematics at Pittsburg State University. He blogs at redneckmath.blogspot.com and okieinexile.blogspot.com. You may contact him at okieinexile@gmail.com. )