Before I forget: Before a few days ago, I did imaging through the Raspberry Pi camera the following way:
I'd drive the robot a few feet. Then I'd send a command to take a picture. A picture would be sent back to me, and I'd take a look at it. Then I'd dismiss the picture, and drive the robot a little bit more. And so on.
Tedious.
The whole thing was done via Python. I couldn't figure out how to do streaming via Python. So, following streaming instructions here, I set up streaming video via the from the Raspberry Pi camera to a web page.
Now, I get a live stream of the camera as I drive the robot, making it a more fun driving experience.
Unfortunately, it seems to have hosed the picamera Python library, so I don't have access vi Python. Oh, well. For now, I don't need or want it. I'll have to see about reinstalling it or making it live side-by-side with streaming, if possible, if I want it back in the future.
Sunday, June 29, 2014
Wednesday, June 25, 2014
Stepper motor arrived
Okay, the new stepper motor finally arrived, and I tried out the sample code linked by one of the reviewers. It works fine, but some of the output pins used by the code are also used by the Arduino motor shield to control the motors. I'll have to find unused pins and rewrite the stepper motor code. I assume enough pins are available. If not...
Now that I have the stepper motor, I have to come up with a way of mounting the ultrasonic range sensor to the motor. First, I already attached the stepper motor to the top-front of the robot platform by reusing the long standoffs. I tried moving the Arduino and the Raspberry Pi to another location on the top plate, but the holes really don't seem ideal for anything. I wish the top plate had more holes for screws.
For attaching something to the stepper motor, I'll probably order this shaft coupler and this 1/4" rod. Then I'll have to find a flat platform or circuit board that can attach via 1/4" ID shaft collars or something similar, and I'll attach the range sensor to that board and wire it up to the Arduino stack.
I'm so used to looking through the McMaster-Carr catalog when ordering parts at work, but for this project, I'm looking through Amazon.com.
Now that I have the stepper motor, I have to come up with a way of mounting the ultrasonic range sensor to the motor. First, I already attached the stepper motor to the top-front of the robot platform by reusing the long standoffs. I tried moving the Arduino and the Raspberry Pi to another location on the top plate, but the holes really don't seem ideal for anything. I wish the top plate had more holes for screws.
For attaching something to the stepper motor, I'll probably order this shaft coupler and this 1/4" rod. Then I'll have to find a flat platform or circuit board that can attach via 1/4" ID shaft collars or something similar, and I'll attach the range sensor to that board and wire it up to the Arduino stack.
I'm so used to looking through the McMaster-Carr catalog when ordering parts at work, but for this project, I'm looking through Amazon.com.
Friday, June 20, 2014
Waiting
No, I haven't abandoned this blog. My next step was to add a stepper motor so I could sweep the ultrasonic sensor in a controlled fashion before the robot, in order to get a map of objects in the front.
I ordered a cheap stepper motor from Amazon.com some time ago, but the delivery time is very long. I should get it in a couple of days... I hope.
I ordered a cheap stepper motor from Amazon.com some time ago, but the delivery time is very long. I should get it in a couple of days... I hope.
Saturday, May 31, 2014
A new battery pack for my current robot.
I've been using the 6 AA battery holder that came with the Sainsmart 4WD robot platform for a few months now, and I've been wanting to get a beefier battery pack for more power. Based on a comment from an Amazon.com buyer of the platform, I ordered the True Energy 9.6 V battery pack and charger from Amazon.com, and it arrived earlier today. This evening, I went to Radio Shack and picked up a male/female pair of Molex connectors and a size M coax plug, so I could wire up the battery pack to feed through the shell of the robot platform for external recharging.
(I went by memory in selecting the size M coax plug, but fortunately, it's the right size.)
This is the top plate of the robot platform. An Arduino Uno with a motor shield is attached to the front (left) of the plate with short standoffs. The wireless SD shield (which I use mainly as a platform to hold a 16 pin socket) is not attached. On the right is a small circuit board attached to the top plate with longer standoffs. I usually velcro the Raspberry Pi and its battery pack here.
(I went by memory in selecting the size M coax plug, but fortunately, it's the right size.)
This photo shows the robot platform with the top taken off, showing the four motors attached to the wheels. The left motors are wired together, and the right motors are wired together.
This is the top plate of the robot platform. An Arduino Uno with a motor shield is attached to the front (left) of the plate with short standoffs. The wireless SD shield (which I use mainly as a platform to hold a 16 pin socket) is not attached. On the right is a small circuit board attached to the top plate with longer standoffs. I usually velcro the Raspberry Pi and its battery pack here.
Here's the bottom side of the top plate, showing the 6 AA battery pack attached to the plate and wired to a two-position switch. When the robot is jostled, sometimes a battery falls out of the holder. In any case, it doesn't provide a lot of power.
So, here's the new battery pack, shown in green lying on the bottom of the robot platform. The battery pack itself comes with a male molex connector that is used to attach to the charger. Because this molex connector isn't quite compatible with the male and female molex connectors I got from Radio Shack, I disconnected the original molex connector and attached the Radio Shack male connector. Then I wired the female molex connector to the coax socket and the two position switch (both of which were included with the Sainsmart 4WD robot platform). If you look closely, you can trace out the wiring.
The new battery pack is intended to power both the Arduino stack and the robot motors. In my initial test drive (without a full charge of the new battery), it's pretty swift.
Here's the top plate. On the right of the "On" label, you can see the newly installed coax socket.
On these two photos, you can see the newly assembled robot charging. On the left is the charger that came with the battery pack. I used the male molex connector that I disconnected from the battery, and I wired it to the Radio Shack size M coax plug with a black and red pair of wires.
The Arduino wireless SD shield is shown at the top of the Arduino stack, with the Radio Shack ultrasonic range sensor kind of looking like a pair of eyes. The Raspberry Pi and battery pack are velcro'd to the platform in back. Also of note is a Belkin Retractable High Speed USB 2 Cable connecting the Raspberry Pi to the Arduino stack as well as a short USB cable (half disconnected) between the Raspberry Pi and the battery pack velcro'd beneath it. I ordered both of these from Amazon.com to shorten cable length and reduce clutter.
This is a big thing to note: A variety of Raspberry Pi -- Arduino robots described on the web use the GPIO ports on the Raspberry Pi to communicate with the pins on the Arduino. To do so, since the two devices use 3.3 V and 5 V standard on their pins, the robot designers have to use an opto-isolator between the devices. I don't see the advantage to this over using the USB ports on both devices and then using the serial communications packages in the libraries on both platforms to handle the communications. It seems so much more straightforward to me to be able to send and receive ASCII code rather than control pins.
Finally, attached to the wireless SD shield by a standoff and encased in a clear plastic case behind the Radio Shack ultrasonic range sensor "eyes" is a Raspberry Pi Camera, attached also to the Raspberry Pi by its white flat ribbon cable.
-----
I still can't get the Raspberry Pi to act as a wifi access point to which I can log in. So, I'm still forced to use my home WiFi network for communications.
I still can't get the Raspberry Pi camera to display photos directly from Python using show() (or image.show()), either over SSH or via a VNC connection. (Actually, I'm not sure it works this way even when I use the Raspberry Pi directly connected to a monitor.) Instead, I have to capture an image to a .jpg file and then use Python to make an external call to Image Viewer. That works, but it feels pretty clunky.
Oh, yes, and I've also started using a VNC connection to the Raspberry Pi.
-----
My next project is to attach the Radio Shack ultrasonic range sensor to a swivel platform attached to a stepper motor controlled by the Arduino stack. Then I'll write an addition to the Arduino code to allow the range sensor to sweep in front of the robot and get a rudimentary range map of objects in front of the robot. I've been playing with the pylab library in python, and it seems promising for this project.
This is a big thing to note: A variety of Raspberry Pi -- Arduino robots described on the web use the GPIO ports on the Raspberry Pi to communicate with the pins on the Arduino. To do so, since the two devices use 3.3 V and 5 V standard on their pins, the robot designers have to use an opto-isolator between the devices. I don't see the advantage to this over using the USB ports on both devices and then using the serial communications packages in the libraries on both platforms to handle the communications. It seems so much more straightforward to me to be able to send and receive ASCII code rather than control pins.
Finally, attached to the wireless SD shield by a standoff and encased in a clear plastic case behind the Radio Shack ultrasonic range sensor "eyes" is a Raspberry Pi Camera, attached also to the Raspberry Pi by its white flat ribbon cable.
-----
I still can't get the Raspberry Pi to act as a wifi access point to which I can log in. So, I'm still forced to use my home WiFi network for communications.
I still can't get the Raspberry Pi camera to display photos directly from Python using show() (or image.show()), either over SSH or via a VNC connection. (Actually, I'm not sure it works this way even when I use the Raspberry Pi directly connected to a monitor.) Instead, I have to capture an image to a .jpg file and then use Python to make an external call to Image Viewer. That works, but it feels pretty clunky.
Oh, yes, and I've also started using a VNC connection to the Raspberry Pi.
-----
My next project is to attach the Radio Shack ultrasonic range sensor to a swivel platform attached to a stepper motor controlled by the Arduino stack. Then I'll write an addition to the Arduino code to allow the range sensor to sweep in front of the robot and get a rudimentary range map of objects in front of the robot. I've been playing with the pylab library in python, and it seems promising for this project.
Thursday, May 22, 2014
Tank code
Here's the Tank code, from when I used the Tamiya Tracked Vehicle Chassis as my platform. (The Blink comments at the top just mean I recycled the code from an earlier LED test and forgot to remove the comment...)
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup()
{
int i;
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
// Right motor (with gearbox on rear)
pinMode(3, OUTPUT); // PWM, HIGH=fast, LOW=slow or off
pinMode(9, OUTPUT); // Brake, HIGH=brake, LOW=coast when PWM low
pinMode(12, OUTPUT); // Direction, HIGH=forward, LOW=reverse
pinMode(8, OUTPUT); // Brake
pinMode(11, OUTPUT); // PWM
pinMode(13, OUTPUT); // Direction
//run_tank;
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(5000);
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(5000);
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(8,LOW);
delay(1000);
digitalWrite(11,HIGH);
delay(5000);
digitalWrite(8,HIGH);
delay(1000);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(8,LOW);
delay(1000);
digitalWrite(11,HIGH);
delay(5000);
digitalWrite(8,HIGH);
delay(1000);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
}
void loop()
{
}
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup()
{
int i;
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
// Right motor (with gearbox on rear)
pinMode(3, OUTPUT); // PWM, HIGH=fast, LOW=slow or off
pinMode(9, OUTPUT); // Brake, HIGH=brake, LOW=coast when PWM low
pinMode(12, OUTPUT); // Direction, HIGH=forward, LOW=reverse
pinMode(8, OUTPUT); // Brake
pinMode(11, OUTPUT); // PWM
pinMode(13, OUTPUT); // Direction
//run_tank;
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(5000);
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(5000);
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(8,LOW);
delay(1000);
digitalWrite(11,HIGH);
delay(5000);
digitalWrite(8,HIGH);
delay(1000);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(8,LOW);
delay(1000);
digitalWrite(11,HIGH);
delay(5000);
digitalWrite(8,HIGH);
delay(1000);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
}
void loop()
{
}
Nothing special, really. With the digital pinMode settings to output, I set up the Arduino Uno and Motor shield to control the outputs to the motors. After //run_tank, I turn on both brakes. Then the right motor is set to reverse, the brake is released, the right motor is run (in reverse), and then the brake is applied.
Next, the right motor is set to forward, the brake is released, the right motor is run (forward), and then the brake is reapplied.
And then I do the two steps on the left motor, before finally setting both brakes.
I suppose I could have put the same code in loop(). Mainly I put it in setup() out of habit.
However, I found this approach pretty unsatisfactory. Without sensors providing any feedback, there's no way for the robot to find its way around a room or other obstacle course, so all of the motion has to be preprogrammed. With the hardware I had available at the time, with no wireless communication to the Arduino, that writing a new program, picking up the tank and attaching the Arduino to the computer, and uploading the program before setting the tank back on the floor and pressing the button to restart the device.
There simply was no remote control or even limited robot intelligence and autonomy.
I needed something better.
(I'll put up a schematic of the wiring for this tank robot later, when I get around to it.)
Tuesday, May 20, 2014
The old robot platform and the new robot, as of 5/20/14
Here's a photo of the two platforms. On the right is the Tamiya tank platform (Tracked Vehicle Chassis kit) with the Tamiya Universal Plate and the Tamiya L/R Independent 4 speed Double Gearbox.
Previously, I had mounted the Arduino Uno and the Arduino Motor Shield on the Tamiya platform, along with a couple of 9V batteries in parallel. I'd then program the Arduino to drive the tank via the motor shield with a preset list of commands (forward, rotate left, rotate right, reverse, etc.).
When I later bought the Raspberry Pi, I thought of using the Raspberry Pi as the brains of the robot, with its larger memory potentially allowing more programming flexibility than is available on the Arduino as well as the fact that the RPi is an actual computer (if a small, cheap, and low-powered one) as opposed to a micro controller, like the Arduino. In order to do this, I needed a bigger platform to accommodate the additional parts.
So, on the left is my current robot. It uses a Sainsmart 4WD aluminum robot platform. The right and left side motors are connected in parallel on each side, so the four wheels aren't really independent. I use 6 AA batteries to provide the motor power. At the front of the robot (right, in the photo) is the Arduino Uno (mounted by standoffs to the top plate), an Arduino motor shield, and a wireless SD shield, on which is mounted a Radio Shack ultrasonic distance sensor.
At the end of the robot (left, in the photo), on a small platform attached by standoffs attached to the top plate, is the Raspberry Pi (model B) and Mophie Juicepack battery pack for iPhone that I use to power the Raspberry Pi. The RPi also has an Edimax USB WiFi adapter and a Raspberry Pi Camera Module, mounted in a case that is mechanically attached to the wireless SD shield on the Arduino stack. The RPi assembly is strapped with a velcro strap to the raised platform. The battery pack feeds power to the RPi via a USB-micro-USB cable, and the RPi talks to the Arduino Uno via a USB cable, rather than the GPIO RPi pins to the Arduino pins that several other people use.
I'll go into more detail later on the assembly and programming of this robot. For now, it's not autonomous.
However, as of this evening, I was able to sit at my MacBook Pro and use the WiFi network to drive the robot around my house by moving a little and then viewing the camera image after subsequent moves to see where the robot was located. So that was fun.
Starting the blog
I've been working on a robot hobby for about a year and a half. My inspiration has been the Mars rovers that JPL has successfully landed on Mars.
It started out as an Arduino stack running on a Tamiya tank platform, but it has recently evolved into a Raspberry Pi connected to an Arduino stack via USB and mounted onto a Sainsmart robot platform, all communicating with my MacBook Pro via my in home WiFi network.
This project has proceeded in fits and starts for over a year, mainly in a few minutes stolen here or there or an hour or so on an occasional weekend. It has been slow because I have a family and a job -- you know, a real life beyond the hobby. And it's not even my main hobby.
Actually, what is my main hobby? ...
Anyway, I thought I'd start recording my work on a blog, since I don't really have notes of my progress to date. And then -- and this is the important part -- I'd make this blog public, in case anyone stumbles across it, finds something useful, and maybe -- if I can figure this out -- leave some feedback.
It started out as an Arduino stack running on a Tamiya tank platform, but it has recently evolved into a Raspberry Pi connected to an Arduino stack via USB and mounted onto a Sainsmart robot platform, all communicating with my MacBook Pro via my in home WiFi network.
This project has proceeded in fits and starts for over a year, mainly in a few minutes stolen here or there or an hour or so on an occasional weekend. It has been slow because I have a family and a job -- you know, a real life beyond the hobby. And it's not even my main hobby.
Actually, what is my main hobby? ...
Anyway, I thought I'd start recording my work on a blog, since I don't really have notes of my progress to date. And then -- and this is the important part -- I'd make this blog public, in case anyone stumbles across it, finds something useful, and maybe -- if I can figure this out -- leave some feedback.
Subscribe to:
Comments (Atom)







