Wednesday, September 19, 2012

The Robot Project!

It's Sep 19, 2012 - And it's been about 2 months since I started turning an electric chariot (A FAKE Segway) into a robot, this project started out to be a robotic lawn mower, and since it was started I got a real robot lawn mower, so I don't think I want to make this into one any more. I'm not really sure what it will become, but I thought it's been long enough and lots of stuff have happened I felt I needed to document the journey. So this is what I used as the base, mine was blue, and a slightly different model, but they are all pretty much the same. One of the first things that I wanted to do was do a tear down of the chariot and find out just what I was looking at to use. So below is the motor controller, made in China, but that is really about all we were able to find out about it, It's a single controller, but drives both wheels (I should that both wheels do the same thing, in other words, forward drives both wheels forward. there is no left or right control) With that being said, you can see the large relay in the middle, that is used for reverse, and to turn one or the other wheels off. Unfortunately, there is no way to make one wheel go forward and the other to go backward, at least with this controller. The wheels themselfs are the motors, simple 36v DC motor, they are regenerative motors, and it looked like they are setup to feed back into the battery if the break is engaged. Speaking of break, the motor control does have a full stuff electric break, which worked really well, almost too well when there is no weight on the frame. So here is the frame with the motors/wheels, and after I removed the steering off the back wheels and made them free spin (360 degree). And there are 2 or 3 videos of me getting the wheels working with out the "controls" that it came with, really it's a lot of simple switches, So I decided to go ahead and use the controller that it came with, and I wanted to keep the project "cheap" There are also a couple of video showing how I figured out how it did turn one or the other wheels on or off, if one of the wheels is off it becomes a free wheel, and depending on the surface it's sitting on depends on just how much that wheel turns My controller of choice was/is the Parallax Basic Stamp, If you go back and look at some of my video, you can see me playing around with the Stamp, it's easy to use, fairly low cost, and if used in quite a few robots, I also ordered a few arduino relays (12 total, even thou I really only need 6) These are coming from China, cost wise they were very cheap, time wise, they did take a while to get here. And I got extras because what if one failed, I would have to wait again for a replacement, no I have a replacement. Meanwhile I started to program the stamp, and do a basic lay-out of what and where things should be hooked up. The picture below shows the relays and the stamp on a board on the frame of the chariot. It was about this time thou that I came across an Ambrogio robotic lawn mower, and that is when this changed from a lawn mower to just a really cool robot to play with! In the picture above you can see the relays, (3 of which are no being using, more on this later), the basic stamp board, and a 2nd breadboard - the 2nd breadboard has a LM358A Dual Operational Amplifier, this when using a Pulse Width modulation signal from the stamp can be used to generate 5v which is used then to drive the motor controller - 5v will give max speed, the PWM can be adjusted and various voltages come out, 0v volt = stop, and anything between 0 to 5 will control the speed of the wheels. At this point, the LM358A circuit didn't work, and we finally decided that it really did need 12v like the diagram said it did, We did end up destroying one side of the Op Amp as well. A ping sensor was also added at some point with in this time frame. and a simple real word test was done, at this time I was using a weak battery, but was doing a test, things seemed to work, more or less, but once I put a good main battery on it - it was way too fast. During this test thou I decided that I might need to add a servo for the ping sensor to move, and get better detection. We also added some Voltage regulators at this time, a 12v, 9v and 5v were all added. The LM358A was placed on it's own breadboard, and piece of wood, it was mounted behind the stamp (Unfortunately I can't find any pictures of this, thou there are some videos with it in this configuration), Also mounted the USB connector for the stamp, and using a USB extension cable to program it now. At some point, we decided that we also needed more amperes to power everything, both the 9v and later the 5v had transistors added to them for just that reason. This ended up causing hugh problems thou, what my partner didn't realize is that the transistor where grounding out on one of the positive pins, And we went though many burt wires, and lots of archs and sparks. It took almost a week to get it back to "normal", and I ended up doing an almost complete rebuild. At one point I did think I fried the basic stamp board, but luckily it is working just fine. The above video was just after the rebuild. This was also after a rebuild, during the time of all the archs and sparks I beleive we ending up rebuilding this twice or more, I did move things around more thou, not really a complete rebuild. The above video shows a wheel/bench test this is after I got LM358A working, and again I moved some stuff around, removed the servo at this point, but later I moved the ping sensor again and put the servo back on. it was about this time that my Parallax LCD showed up, the LCD has backlight and speaker, this added the many possibility And my ADC0831 analog to digital converter showed up, and a very simple voltage meter was added, using a simple voltage divider. This was also the 2nd time during this project that I blow something up...Its a good thing I ordered two ADC0831, they really don't like having 36v applied to the input. I also mounted the LCD, and moved the board from behind the stamp, to ontop of the Stamp (For like a two layered effect), moved the Ping Sensor and added the servo again. I was having some issues with the servo, I thought it was a power issue, but turns out the basic stamp just didn't like a 25+ year old analog servo. At this point however I didn't fix that problem and just disconnected the servo again. I wrote some code for playing a "Battery Dead" and "Unknown Error" sounds using the LCD, and put those sounds into the robot code. About this time, My IR Obstacle Avoidance sensors showed up from China, I haven't added these into the bot yet, I did test them, they work great, are very simple on off switches (If it sees nothing it's on, if it sees something it's off, or is it just the opposite?) Either way I wrote some code, and I am planning on using these from drop off sensors, and yes they did work outside, quite happy with the results, but still need to get them mounted. Which finally brings us up to about last week, I added a Basic Micro Nano8 processor to control the servo, I setup the Stamp to send a high to the Nano8 when the Stamp wants the servo to move, the Nano8 is just will move the stamp to one of three spots, -45 degree, 90 degree, and 45 degree. It just counts the number of highs/low and decides where to move the servo, there is no feedback to the Stamp, the timing on this is a little off, but this is kind of a work in progress and it does work. The Nano8 has 4 I/O lines plus a serial port, the 4 I/O lines can be used for A2D, and 1 of the lines is capable of doing PWM. I have two analog sensors ordered a temperature and a humidity. I also order a couple of serial port buffers so the Nano8 can send the sensor information the Stamp, and the Stamp can decide what to do with it. But for now the Nano8 is only controlling the servo, added the Nano8 appears to have fixed the bouncing issue I was having using this servo with the Stamp. Of course this is still very much a work in progress, I have several things ordered that haven't arrived yet, an accelerometer, humidity and temp sensors. I did order a smaller relay board, and they arrived today, so I am going to replace one of the relay boards with the smaller board. I still need to figure out away to contain it within the yard, and work on getting better speed out of the wheels, or maybe just one speed at this point? Reverse goes at almost full speed, while forward is going to be very slow. I have a lot of videos of the progress on this, alot more then I posted here. http://www.youtube.com/kd8bxp That brings the project current as of Sept 19, 2012, I'll be doing more posts as it progresses, and of course a lot more videos to come! LeRoy, KD8BXP

Sunday, June 24, 2012

Controling the Kenwood TH-D7 from a PHP script

I was asked to write a blog post about the TH-D7 PHP script I wrote and posted about on twitter and youtube. One thing, all of my scripts were and are written for the command line, thou I see no reason why you couldn't use this script from a website, maybe with some slight modifications. You'll need to get the php_serial.class.php written by Rem Sanchez It can be found here: http://www.phpclasses.org/browse/file/17926.html This php script is the key to making the whole thing work, well at least it's one of the keys. The other the D7 and other Kenwood radios can be controlled from the serial port on the radio, you just need to know what to send to the port for the radio to do what needs to be done. For the command protocol you should look here: http://www.radiohound.com/command.htm So the basics: 1 include the php_serial.class.php 2 open the com port 3 send the command to the radio 4 Jump up and down because it worked! LOL It really is as simple as that thou. So, let look at my code, which is still very much a work in progress, sooner or later I will add/change the code so that it will ask the Freq or ask the message, at this time, it's hard written in the code, but it will give you an idea. CODE: D7.PHP require("php_serial.class.php"); $update = toserial($msg, "/dev/ttyUSB0"); function toserial($text, $comport) { //Initialize the class $serial = new phpSerial(); //Specify the serial port to use... in this case COM1 $serial->deviceSet($comport); //Set the serial port parameters. The documentation says 9600 8-N-1, so $serial->confBaudRate(9600); //Baud rate: 9600 $serial->confParity("none"); //Parity (this is the "N" in "8-N-1") $serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1") $serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1") $serial->confFlowControl("none");//Device does not support flow control of any kind, $serial->deviceOpen(); $serial->sendMessage($text); $serial->deviceClose(); return; } The above is will be called from the other scripts, it's meant to try and keep all the scripts small and easy to use, mainly what this script does is setup and send the command to the serial port. My FREQCHANGE.PHP $freq = '00144390000'; $msg = "FQ " . $freq . ",00" .chr(13) .chr(10); include ('d7.php'); OK, so here I set what Frequency I want to change to, you might notice how the frequency has leading zeros and trailing zeros, this is required by the radio, otherwise it's not going to work correctly. The $msg is what is passed to the D7.PHP script and is the command for the radio so if we look at the command protocol we will see that FQ is for setting the frequence and is in the form of FQ(space)FREQ,00 and a return and line feed need to both be sent I have two scripts setup for turning on and off the TNC of the radio as well, they are pretty much the same script: $msg = "TNC 1" .chr(13) .chr(10); //will turn TNC on $msg = "TNC 0" . chr(13) .chr(10); //will turn TNC off But again I refereed to the command protocol for those commands :-) of course the fun command is to send an APRS message! For that I wrote a short PHP script called: APRSMSGSEND.PHP $tocall = 'CALLSIGN-SSID'; $tomsg = 'Testing APRS Msg via script'; $msg = "AMSG 00," .$tocall . "," . $tomsg . chr(13) . chr(10); include ('d7.php'); SO as you can probably see by now, it's just setting the correct command to send to the serial port of the D7 $tocall call be a callsign or a callsign with SSID, and just remember the D7 is limited in how many characters it can send for the message SO, really the key to make this work is the serial port script! The D7 has a lot of other things that can be controlled via the serial port so I will refer you to the command protocol. My scripts are still very much a work in progress. Sooner or later I would like to make it look for key words off twitter probably just to change the freq, and I'll hook the audio up to a streaming service so people can listen in! :-) Other radios probably can also be controlled by this method as well, you just need to know the command protocol for your radio! Happy Radioing, and 73, LeRoy, KD8BXP

Thursday, March 15, 2012

How I did the Knight Rider Style LED Chaser using the basic stamp

So I was asked how I did the cyclon/knight rider stlye chasing LEDs using the basic stamp.
These two videos pretty much explain it, but I also said I would post the code, so here it is.






Cylon Chaser Lights:

' {$STAMP BS2}
' {$PBASIC 2.5}

HIGH 0
HIGH 1
HIGH 2
HIGH 3
HIGH 4
HIGH 5
HIGH 6
HIGH 7
HIGH 8
HIGH 9
PAUSE 500
LOW 0
LOW 1
LOW 2
LOW 3
LOW 4
LOW 5
LOW 6
LOW 7
LOW 8
LOW 9
DO

HIGH 0
HIGH 9
PAUSE 50
LOW 0
LOW 9
HIGH 1
HIGH 8
PAUSE 50
LOW 1
LOW 8
HIGH 2
HIGH 7
PAUSE 50
LOW 2
LOW 7
HIGH 3
HIGH 6
PAUSE 50
LOW 3
LOW 6
HIGH 4
HIGH 5
PAUSE 50

LOW 4
LOW 5
HIGH 3
HIGH 6
PAUSE 50
LOW 3
LOW 6
HIGH 2
HIGH 7
PAUSE 50
LOW 2
LOW 7
HIGH 1
HIGH 8
PAUSE 50
LOW 1
LOW 8
HIGH 0
HIGH 9
PAUSE 50

LOOP

Knight Rider Stlye Chaser LED:

' {$STAMP BS2}
' {$PBASIC 2.5}

HIGH 0
HIGH 1
HIGH 2
HIGH 3
HIGH 4
HIGH 5
HIGH 6
HIGH 7
HIGH 8
HIGH 9
PAUSE 500
LOW 0
LOW 1
LOW 2
LOW 3
LOW 4
LOW 5
LOW 6
LOW 7
LOW 8
LOW 9
DO

HIGH 0
HIGH 1
HIGH 2
PAUSE 50
LOW 0
HIGH 3
PAUSE 50
LOW 1
HIGH 4
PAUSE 50
LOW 2
HIGH 5
PAUSE 50
LOW 3
HIGH 6
PAUSE 50
LOW 4
HIGH 7
PAUSE 50
LOW 5
HIGH 8
PAUSE 50
LOW 6
HIGH 9
PAUSE 50

LOW 9
HIGH 6
PAUSE 50
LOW 8
HIGH 5
PAUSE 50
LOW 7
HIGH 4
PAUSE 50
LOW 6
HIGH 3
PAUSE 50
LOW 5
HIGH 2
PAUSE 50
LOW 4
HIGH 1
PAUSE 50

LOOP