Friday, April 18, 2014

K9 Detects an Obstacle and Talks About It

This is very pre-mature but I have been working on generating events for the Raspberry PI which come from the Arduino as I have mentioned previously. Tonight was the first time I used one of these events. I have hooked up a temporary speaker and amplifier to the PI to allow it to play sounds. When the platform detects an obstacle using the Ping))) ultrasonic range finder, it stops the forward motor and sends an event to the PI. It responds by playing a sound. I thought the video was worth sharing.

video


The source for this interaction is available on my GitHub project but it has a long way to go.

Sunday, April 13, 2014

K9 Drive Base Demonstration

Things are progressing pretty well on the drive base. I have it configured to accept commands from both the on board Raspberry PI and an RC remote control. The remote control takes priority over any PI issued commands. This is useful if it should decide to do anything unexpected. When I first started testing it, I would put it up on blocks in case it decided to run away. Now I can flit the B switch on the remote control to stop it dead if this happens. Below is a picture of the current drive base with call outs that show what each component is.



It still looks like a bit of a rat's nest of wires but it is now capable of moving on its own and I can ssh over to the PI and give it commands like move forward or rotate around. Below is a video of my first tests. Excuse my weak voice, I have a bit of a cold.


As you can see it moves pretty fast. I have gone out of my way to restrict how fast it can go because when it is not carrying it external shell, it is far lighter than it will be when it is done. I already had one accident when my son was testing it out and he drove it hard into his own ankle and managed to hurt himself.

If you listen carefully you can also hear a high pitch noise whenever it moves. This is probably because the pulse width modulation frequency is too low and the motor itself is resonating in response to it. I will have to investigate changing that frequency to one outside the range of human hearing. Maybe, when I am done it will just annoy dogs.

Below is a head on shot. Here you can see the Parallax Ping))) sensor mounted on the front.


The speaker and microphone pair kind of look like eyes. If you look to the left you can see the RC receiver antenna which is being held on with a cable tie that looks a little like a sweat band. The ping sensor uses sound based radar to report obstacles up to 10 feet in front of it. These measurements are then passed on to the PI for further decision making.

At one point, I put the shell on and then got worried when the base refused to move forward. It would only go backward. Then I realized that when I had covered the Ping sensor, it was reporting that the shell was an obstruction in front of it and refused to move forward until the shell was removed.

Below is a shot of the two Razor scooters mounted to the bottom of the drive base. 



These scooter motors and rear wheels have been sawed off from the rest of the scooter. All that remains is the back 8 inches of the scooter. The rest was discarded. The frames are held to the mounting board with a U-bolt around the inner sides of the axels and three machine bolts that fit into the pre-drilled holes on the top of the frame and are very securely attached. There are also two wheels that spin freely and prevent the platform from tipping over.

You can also see that they are mounted in opposite directions. This is because the steel frames rapidly become wider than the base itself. If mounted in the same direction, they would be two wide to fit inside the shell. Having them face in opposite directions is not a problem because the DC motors can be rotated in either direction. If you look at the wiring diagram present in one of my previous posts, you will see that the left and right motors have their terminals reversed so as far as the controllers are concerned, they both move forward and backwards in unison.

Friday, April 11, 2014

Its Here! The new Printed Circuit Board Arrived.

You you may remember a few posts back, that the board I built to control the lights on the dorsal control panel on my K9 robot burned out because of a short. Well, the printed circuit board I designed to replace it has arrived. It took two weeks but for the price ($9.00 US) it was worth the wait for 5 copies of my design.


Thank you SeeedStudio. Yes, they have three eees in their name. Hopefully this weekend I can install the components and get it working.

Update: Here is a shot of it with all components installed.


This is the way to do it, all the holes were pre-tinned and all the traces are lacquered over. No more shorts.


Tuesday, April 8, 2014

Making K9 into a Pointer Dog - The HMC5883L Magnetometer

Real dogs have a breed called pointers which are also known as Gun Dogs bred to assist hunters in finding prey by pointing it out. I needed a similar capability to identify which direction the dive base is facing to stay on course while moving or for room mapping which is something I am interested in doing in the future.

I had never worked with a Magnetometer (Specifically the HMC5883L) and really did not know what to expect. They are fairly inexpensive to purchase. My first question was how to mount it. This may seem obvious but do you mount it flush or on its side? It turns out that the x-y plane provides the equivalent of a compass reading. If you look closely at your printed circuit board, there should be silk screened image of its three axis.
Your board may vary in size, color or number of pins but there should be an axis diagram. This one indicates that if you mount it flush with a horizontal surface and point the x-axis to the front, the angle between the vector formed by [x,y] and the centerline of your robot is the angle of your heading. I discovered this by reading the x and y values from the board as I rotated my robot base clockwise by hand. I graphed these points and repeated the process twice (the red and blue paths). 



The pink arrow represents the X axis and the direction of magnetic north which I found using a compass normal. As you can see, the points form an ellipse. I am no expert on this but I assume that the [x,y,z] vector represents the direction and the magnitude of the magnetic field at the point on Earth you are at. By looking at only the projection onto the x,y plane and then finding the center of the ellipsoid, you could calculate the angle between the x axis and the current [x,y] vector that points to magnetic north. Keep in mind all I know is what I have learned by experimenting with this board. If someone has any additional insight as to how this works, please pass it on. I am also ignoring any effects of tilting or z-axis data at this point. All I really wanted was my current angle from magnetic north but I was not getting this from the sample libraries a tried. I used the code at Adafruit to generate the x,y coordinates to create the graph above. You can see how its wired into my Arduino by looking at the diagram in my previous blog entry.

To calculate then center of this ellipse, I just placed a rectangle around it and then found the center of it as can be seen in the figure below. I calculated the center of the ellipse to be at (45,-360)
I don't know if this point will work for you or if this center will shift when I take the robot to new locations but for now I am using this as my center and I am getting fairly accurate readings on my heading relative to magnetic north.


Here, I calculate the angle between the current vector and the x axis which is the midline of my drive platform and then add or subtract from that angle to place it in the correct quadrant so so that I get the equivalent of a magnetic compass reading in degrees. My approach may be flawed as I mentioned above but I will update this post as I learn more about this device. The entire sketch that the gist above is taken from can be seen here. This sketch reads all the other devices listed in my previous blog entry and emits events over the USB bus to the Raspberry PI in JSON format indicating what the current heading is. I will talk about these events and the PI can send back to the Arduino in my next entry.

Monday, April 7, 2014

Making K9 Move - The motor base

I have been experimenting with building a base to sit my K9 outer shell on top of and things are really proceeding very well. For about $500.00 in parts I have created a platform that fits inside the shell that can be controlled either by a Raspberry PI or an RC remote control. Here is a picture of the platform with the parts I am planning on installing laid out on it but not yet connected. Here you can see the board that the scooters are attached two with plus shaped cut outs in the center to allow the wheels to pass through.


The platform consists of the following items.

1 1/4" Pine board with holes cut out for the wheels
2 Razor 24 Volt batteries (They come with the scooters, not shown above)
1 Terminal block
1 Raspberry PI
2  U-Bolts (1/4x1-1/8x3-1/2) used to attach the axel to the board
6 3/16x1 Washers
6 10-24 x3/4 Pan Phillips Machine screws which are the perfect size to screw through the wood into the steel frame.

Here is how the components are connected together.



If you look closely, you can spot that I have attached the scooters to the platform facing in opposite directions. This was to allow the steel frames to fit together closely enough to stay within the limits of the with of the board they were being mounted to. In the diagram above I have reversed the electrical connections to the motor to make both motors consistently move in the same direction. This could also be accomplished in code as well but this makes them both appear to be facing in the same direction as far as the controllers are concerned.

When working with high current systems it is a good idea to use heavier gage wire. I am using 18 gage stranded wire for all the motor connections which I am wiring into a terminal block for distribution. I have also wired the step down regulator into the terminal block to provide 3 amps of 5 volt service which should be enough to power two Ardunios and the PI.

Each scooter's specs state they can propel a child up to 10 mph for 40 minutes between charges. This platform packs two of them and will weigh far less so I am expecting really good performance. In addition the steel frames use a bicycle chain to transfer power from the motors to the polyurethane wheels. 

I put some thought into how I wanted the wheels arranged. I know I wanted four wheels, two powered and two idle to form a stable base that would not be easily tip-able. I also wanted the shortest possible turn radius as my goal was to develop autonomous navigation projects and having a near zero turn radius would allow the robot to maneuver in close quarters. This mean placing the wheels in the midsection of the body. By rotating them in opposite directions, the robot could literally spin around its z-axis, doing a complete 180° turn in place. I decided on a Hilare-type wheel arrangement which is a two wheeled differential drive with two additional passive points of contact (casters) was the way to make this happen.

After sawing away most of the scooter with a sawzall, only the back wheel and the motor remain. It turns out that using a combination of a large U-Bolt and 3 replacement screws listed above is all you need to anchor the scooter to the board. Here is a side shot of the mounted scooter frame.

I think I have been postponing posts because I want to put too much information into them so I am going to wrap this one up at this point and cover the communications protocol and how I am interpreting the sensor data as well as prioritizing remote control requests higher than PI requests in another post. I also want to talk about the power supply and how I want to manage battery charging. You can always look at the current state of my Arduino source code here. I have not yet started adding support for this peripheral to the PI daemon. It still has a long way to go.




Friday, March 28, 2014

A PCB for the K9 Dorsal Keyboard Driver

So, I mentioned that the driver board for controlling the dorsal keyboard panel shorted out on me. Well, I have decided to not rebuild it from a prototyping board but instead get a printed circuit board manufactured so this does not happen again. This way there is no chance of a home mead header pin folding over as the traces should be sealed and I will be using a real head block this time like the kind present on the Arduino.
I have only ever built home made printed circuit boards before. I have never used CAD software to create them and I have never designed a multi layer board before so this was quite an education. Here is a little bit about what I learned.

Seedstudio will manufacture five copies of a 2 layer 5x5cm board for around $10 by sending it out to China. I am in no hurry and this is a great price. Element 14 recommended  Sunstone Circuits who can do a single prototype for $40 and get it to you faster.

All of these manufacturing houses require something called Gerber Files which it turns out have nothing to do with baby food at all but are actually a set of documents that describe the layers of your board such as the silk screen, top layer, bottom layer, connections between layers (called vias) and where holes need to be drilled.

I needed a way to create these files and I discovered a free to use CAD program that will help you lay them our called Eagle. Eagle is not as simple to use as a lot of modern drawing software and harkens back to old unix workstation engineering packages a little bit but there are a great set of tutorials on how to use it by Jeremy Blum. This was pretty much all I needed to create the PCB board design shown above.

This board was pretty simple to design since all I really had to do was draw out the entire circuit diagram. 

From this, it created a sample PCB and I moved the components to where I wanted them to be located. Since this board does not carry any high frequency signals I did not really have to worry about shielding or bends in the tracing but the tutorial addresses these issues as well.  Next, it auto routed two layers of copper for me and then let me tweak the routes and add my own text to the silk screen layer. With the help of Jeremy's videos I rendered the gerber files and am about to place my order with Seedstudio. When the boards show up, I will talk more about how well the whole processes turned out.

I have placed my eagle project on git hub.

Monday, March 24, 2014

K9 Source Code Now Available

I have moved my source code from a private repository to a public on on github.com . Keep in mind that it is a work in progress and I think the most use it will have at this point is to provide me a way to link to source code I want to talk about in this blog. The source code can be found here.


What is currently in this repository is the Arduino code for the dorsal control panel and a Raspberry PI Python source for a daemon to control the Arduino and in turn the switches, light and LCD display. There is more than one way for a Raspberry PI to communicate with an Arduino (such as I2C) but I have chosen, at least initially, to use USB . The PI is the master decision maker based on messages it receives from the two Arduinos in the system. The Arduinos, in some cases, can simplify and filter the inputs into more meaningful messages to reduce traffic over the bus.

The format of the over the wire data is JSON. Even though there is no Javascript in use, I am just more comfortable reading and working with JSON. The Arduino has a JSON library (aJson by Marcus Nowotny) and so does Python so I am not in the business of parsing data, only interpreting it.

A simple set of commands and events has been created that allows the dorsal panel to be controlled and to emit keyup and keydown events. Here is an example.
{"lightcode":3} // Turns on the first two panel lights (ie 2^0+2^1 or 1+2)
{"backlighton":true} // Turns on the LCD backlight
{"line2":"Hello","line3":"World"} // Display the text hello on LCD display line 1 and world on line 2 
These commands can be typed to the Arduino's in the Serial Monitor for easy testing as well. You can take a look at the Arduino sketch in its current state here.

The Arduino emits JSON back to the PI to let it know when events such as key presses occur. Right now it generates events such as:
{"key8":"down"}
{"key12":"up"}
To process these events I am working on a python script that listens on the USB device representing the Arduino and connects the keydown events to light sequences on the control panel as a proof of concept. This script runs as a daemon started by the PI's init daemon when the PI boots up. Its job will be to coordinate button pushes with button lights and allow the user to make LCD menu choices.

Right now, individual buttons have been tied to lighting animations which makes for an interesting demo.

Alas, I demo-ed the light animations and had them trigger against different buttons on the keyboard a couple times but failed to make any videos.  I went to make a video just for this blog post and when a powered up the board, I had an expected short that seems to have burned out all the transistors. This is both a curse and a blessing. It is blessing because 1. it did not burn out the Arduino and 2. It gives me an excuse to create a PCB to replace it. I will talk about the PCB board creation process in a future entry and will update this entry in the future when I get the demo running again.