Monday, August 10, 2015

Almost mobile

 Previously I showed you how I built the lower chassis, which held the drive train components. Today, I am going to talk about the upper level, which holds the Raspberry Pi, temporarily, a camera, and, eventually, a battery.
Let us do this!
<!--more-->
 As you can see, the top is wider than the bottom. A full 1.5" wider to be exact. This is because I wanted to cover the tracks from above. The end project will have enclosed tracks, and this let me get a better feel for the space. The top is also an inch shorter. This is because, while I aligned the back, I wanted the front to sit back a little. This was a purely aesthetic choice, but it will allow me to place the distance sensor at the front and run the wires over, instead of through. The wires for the drive train run through a hole in the top center. That is the spaghetti mess you see on top. I am still waiting for my female to female and female to male connectors.

After I cut the top to size, I drilled holes in the bottom and top levels, through which I could run 2" bolts. I ran them nuts up to cut down on objects underneath that are likely to catch. I then made a space using some brass tubing. While doing this, keep in mind where your axles are and plan accordingly.
It is hard to see in this picture, but I also added a power switch to the battery pack for the drive train. Like I said last time, I wanted to have the motors and Pi powered separately. This switch lets me easily turn off the motor while I am just using the Pi, saving on my batteries. It also lets me quickly turn off the motor in the event of a program crash, which can tend to leave the motors running. More on that later.

 I also experimented with an old digital camera I had laying around. This thing has never been very useful. It was cheap, but never really worked real well. However, it seems to do alright as a webcam.

I stripped off the plastic case, keypad, and little screen. They won't be needed for this application, and they were just more weight and power draw. I did add its own two AA battery power supply. This only seems necessary when starting up the camera, as it will continue to run on just the Pi's power from the USB. I then plugged it into the USB, installed fswebcam, and took a couple pics.

However, when I tried to add it to my program, things failed. It seems PyGame won't read from the camera directly. It can't start the device. I found a work around by having fswebcam take new pictures continuously. As the goal was and is to only take pictures while it is moving, under the assumption that, while sitting still, new pictures aren't really needed, this is just an extra CPU tax. There is also a problem when the program grabs the picture. Sometimes it will grab partway through the snap, getting a partial image. Sometimes it will flat crash with a non-acceptable file error. At which point, the robot keeps doing whatever it was doing. Hence the usefulness of the motor power switch. Most of the time I just run it with the camera off or not even attached, just loading the image that was last taken. Not the coolest, but it works.

Next time I will have my battery to power my Pi and can finally be free. Currently, I am running with wall power and just hook up a keyboard directly. In this way, I have a keyboard cord and power cord hanging off, like some sort of umbilical. This seriously hampers movement. Many times the cords will just pull the Pi right off the top.

Until then, keep building!

No comments:

Post a Comment