Shop OBEX P1 Docs P2 Docs Learn Events
Stingray Program — Parallax Forums

Stingray Program

jim N8RHQjim N8RHQ Posts: 85
edited 2012-01-11 06:12 in Robotics
Hi all

I'm hoping for some help with my stingray program. I have three LEDs wired to pins 3,4,5 via resistors to ground. The idea is the LED
indicates the most clear path and direction of travel, left, center, right. Sort of a debug function so the LCD doesnt need to be
connected all the time and still give an idea which direction it thinks is the most clear. I'm having some trouble getting the LEDs to
light (or more accurately, go off) when I think I'm telling them to.

I've done some static tests, with the LCD connected so I can know the distances to the targets.

Test 1

Left target 9 inches, trigger point < 8 inches
Center target 11 inches, trigger point < 10 inches
right target 9 inches, trigger point < 8 inches

reset processor, verify all target distances are the same, and only center LED comes on, great!
move any target to within trigger point, center LED goes dim (but still on) plus left AND right LEDs come on, not great.
then move any or all targets outside of trigger point, LED's stay the same, LCD verifies pings are reading change in distance, wtf?

Test 2
left target 9 inches
center target 9 inches
right target 11 inches
reset, verify targets at same distance, right LED comes on, great!
move left target to 17 inches, right LED stays on, left on stays off, bad
move center target to 14 inches, right LED stays on, center and left stay off, bad

A couple of other things. Except for the flaky LED operation, my program seems to run as intended. That is, put it on the floor, turn on
the motors and it seems to make the right choices for direction of travel and navigate pretty well. I just dont understand why the LEDs are
not displaying as intended. They seem to indicate properly the initial conditions, but when updated, things get ugly.

I'm using "outa[leftLED..rightLED] := xxx" to turn the LEDs on and off.

In some cases I do a compare, then outa, then begin a loop for movement. In other cases, I do a compare, then begin the loop for movement,
then outa. The idea being sometimes the LED would be on solid, and sometimes it would blink giving a visual indication of exactly which loop
was running.

It's my understanding that:
outa[leftLED..rightLED] := %010 would turn on the center led, and left and right would be off. Follow that with
outa[leftLED..rightLED] := %001 would turn off left and center led's and turn on right.

If that's the case, then I dont understand why the LEDs dont turn off when it seems like they should.

Does anybody have an idea where I might be going wrong?

jim

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-17 11:01
    Jim,

    You ought to display a character on the LCD to indicate which section of code is being executed. Each section of code should have a unique character which would be displayed with each "display" call.

    I see you use a ten element arrays for the ranges but only use two elements of the arrays. Is this left over from an earlier version of your code or part of a feature you plan to add?
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2011-12-17 21:14
    Duane Degn wrote: »
    Jim,

    You ought to display a character on the LCD to indicate which section of code is being executed. Each section of code should have a unique character which would be displayed with each "display" call.

    I see you use a ten element arrays for the ranges but only use two elements of the arrays. Is this left over from an earlier version of your code or part of a feature you plan to add?

    Hi Duane,

    Thanks for having a look and the suggestion.

    I think that's a good idea and I will try it tomorrow.

    As for the ten element arrays, the idea there was to save some short term history. When the robot is moving, the most current range and the oldest stored range should not be the same. When it's wedged into a corner, or stuck for some other reason, at some point the most current range and
    the oldest stored range become the same. That's when it's time to reverse and re-valuate.
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2011-12-29 21:00
    Problem Solved!

    Turned out to be a hardware issue.

    With big help from Phil Pilgrim, it turns out I was abusing the TXB0108 level shifters.

    Trying to drive LEDs directly with the levels shifters was a bad idea. Fortunately, I dont think I did any physical damage. Thanks to all who gave some input.

    Now I'm using the level shifters to switch transistors to control the LEDs. LEDs are much brighter now due to the increased current.

    Now its time to go abuse some IR leds.

    Updated code attached.
  • dmagnusdmagnus Posts: 271
    edited 2012-01-01 08:42
    I just finished putting my Stingray (with Pings) together and decided to try the Pings with Stingray demos that are out there. Not much luck. Seems they don't have a "stuck" routine. Then I found your code and really like the way you have put it together. I don't have a LCD and haven't hooked up any LED's yet, but I figured if I commented out that part of the code it should still work (probably should still work even without commenting it out - justt nothing hooked up).

    Well it's going somewhat nuts. It goes a short distance and then just spins in circles. I"ve tried switching the motors around and that just changes the direction of rotation. I have the pings plugged into the board at the proper 0,1,2 positions. Can't figure out what I'm doing wrong.

    I just ordered a LCD module and I think I'm going to go back and run all of the tests for the Stingray motors, etc. Meanwhile, I'll attach the TriPingRay.spin code (renamed TriPingRayDon) and would appreciate it if you would take a look at it. I haven't touched the other objects.

    Thanks,
    Don
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-01 12:37
    Hi Don,

    I had a lot of trouble with most of the other Stingray programs that are out there. Most of them caused my Stingray to just sit there and twitch. So I really do feel your pain. TriPingRay is the result of that frustration. It's really my first attempt at any thing complicated in Spin. While I do try to implement a routine to determine if I'm stuck, it still gets stuck sometimes. I'm currently playing with some IR leds and 38khz detectors to try to see some of the Ping blind spots a little better. I see my Stingray as a toddler who has just learned to stand, and now it wants to run. So dont turn it loose in a room full of your wife's best antique furniture. There will be crashes.

    I've had a look at the modified code. Looks to me like you may have accidently commented out setting wheel speed when the center distance is greater than 15. Those are the only two changes I've made and have attached the changed code.

    Apparently, there was a mix up in the early documentation for the Stingray motor wiring. On my bot, I have the left or port side motor connected to the Motor A connection and the right side motor connected to the Motor B connection. On the left motor, the green wire is connected to the postive terminal of the motor. On the right motor, I have the white wire connected to the positive terminal. According to my docs, I have the the connections reversed on the right motor. I dont remember why I did that or which is more correct.

    As for the LCD, the code runs equally well with or without the LCD. During testing, I set the chasis up on some Lego blocks to get the wheels off the ground, then move targets around in front of the pings and read the values off the LCD. Previously, I was using debug to send the values back to my PC. I mainly added the LCD so I didnt have to be tethered to the PC. I can help you with adding the debug output back in if you would like.

    If you have nothing connected to pins 3,4,5,or 15, you should be able to run my code without any changes. I would be very interested in hearing about your results and about how you have your motors wired.

    jim
  • dmagnusdmagnus Posts: 271
    edited 2012-01-01 15:28
    Yes, I caught the accidental commenting out of the wheel speed. Fixed that and did some more messing around this afternoon and I think I have a problem with the motor wiring - at the motors themselves. I'm going to set them up just like you have yours and then see what happens. Meanwhile, I hope to get my LCD early this week, so that will help, but it might be nice to do the debug output. If you have it handy, please attach it, but I can probably figure that out for myelf - just need to find the time, darn it!
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-01 17:08
    OK, my old code with debug was pretty ugly. Turns out it was easier to add the debug statements to the new code. Try this out.

    jim
  • dmagnusdmagnus Posts: 271
    edited 2012-01-02 09:32
    Thanks, Jim, I'll try it today.
  • dmagnusdmagnus Posts: 271
    edited 2012-01-06 14:51
    Hi again, Jim. Well, I think I must be pretty stupid, but I need your help again. I bought this Stingray kit (#28980) online from a dealer. The box was unopened and appeared to have everything in it. I discovered during assembly that I am missing one of the 2 small breadboard pieces (30 row X 2 col), but I don't think that is too big a deal. I also got a package of stuff that has jumper wires, switches, led's and ir stuff, transistors, resistors, diodes, speaker, etc (I think it's a PE Kit Project Parts - REV B. And, I'm using the Li-Ion rechargable battery pack to power the whole works.

    I got my 40X20 Serial Backlit LCD today and I thought I'd try to duplicate what you have with the three colored led's and the lcd. So, what I can't figure out is how the heck to 1.) mount the LCD - I don't see anyplace to put it; 2.) How to get power from the Parallax board to the breadboard; 3.) How to hook up to the pins (p0-23) on the Parallax board from the breadboard.

    I think I have some of it figured out: There is a set of headers on the right side forward of the parallax board that are VIN, 5V and 3.3V. They have what look like computer jumpers on them but I can stick a wire in one of the holes and run that to the (30X2) breadboard piece, then from that (in the same row) to a column (1-30) on the breadboard and that column has power (at least down to row f).

    If you could, I would really appreciate it if you could send me a diagram and/or a picture of how you have stuff mounted, powered and hooked to the signal pin. I suspect I need some different kind of jumper wires or something. Probably also have to re-engineer how to mount the LCD panel and still be able to get at stuff..

    Sorry I'm so dense. I have attached some pictures to show you what I have. 331-333 are what my board and breadboard look like. 334 is where I hooked up power to the breadboard from the power access headers.

    I really appreciate any help you can provide.

    As an aside, with the new code, my Stingray takes off like a bat out of hell - backwards. Sorta seems to turn in the right direction when you put somthing in the way of a ping, but I'm not sure. It turns, then takes off backwards again. I'm pretty sure I have the motors wired exactly as you do. Once I get the led's and lcd hooked up and working, it should be easier to debug.

    Thanks again.
    Don
  • ratronicratronic Posts: 1,451
    edited 2012-01-06 15:43
    dmagnus you can plug in your serial lcd into any of the servo headers labeled P0 thru P23. Which ever bank of eight you decide to plug into make sure the vin/5v jumper is set to 5v and observe wire polarity.
    Each plug is marked B R W which B = ground, R = 5volts, W = signal. Some of us have all kinds of things hooked to it.
    640 x 480 - 120K
    640 x 480 - 137K
  • dmagnusdmagnus Posts: 271
    edited 2012-01-06 16:24
    Yes, I see that. It looks like I need a whole bunch of servo leads. Might have to make a run to Radio Shack or the hobby store.
    Thanks.
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-06 23:43
    Hi Don, absolutely no worries, I am glad to help. Too bad about the missing breadboard, but I would bet if you contact customer service they will take care of it. Parallax is an amazing company in that respect. My nephew connected one of the three wire jumpers up backwards on a qti sensor for his boebot. I called customer service and tried to buy the silicon so I could replace it, and they sent me a new one at no charge. I was amazed.

    In your pic 334, the very top row along the black line is connected left to right all the way across. The second row along the red line is connected left to right but only part way across. On most of all my other boards, both rows are connected all the way across. That tripped me up when I put power at one end and was expecting to see it at the other end. I am using one of the blue jumpers that have a socket on one end and a pin on the other for power and ground. I think they were part of the same PE kit you mentioned. You will see it in my pics that I've pluged on to the MSR1 with the socket end at a random pin that I'm not using to pick up power from the column labeled R, and ground from the column B. At other times I have pluged wires in to the connectors you are using to get power.

    Speaking of jumper wires, you are going to need some. Order them from Parallax, scrounge them from anywhere you can. The more the merrier. I was going through some of my old computer parts boxes and found some four wire jumpers from cd drives. They work great too.

    It's a little hard to see in my pic 277, but the three wire jumper I have pluged into the large breadboard has been rotated 180 degrees when I pluged it in the column
    labeled W of P3..P5

    As for the LCD, mine usually dangles precariously off the back. I cut some half inch aluminum angle stock from Lowes drilled with some holes, but wasnt happy with the results so it remains unmounted. I pretty much only use it when I'm running static tests. I set the chassis up on blocks so the wheels are just off the desk, then move targets around the desk in front of the pings and read the display. With the wheels off the ground, the display mostly stays in place.

    edit: Dont forget to set the dip switchs on the LCD to 19200, or change the value for BAUD in the con section for what ever baud you have the LCD set for. BTW, which LCD did you say you have?

    It's interesting that yours runs backwards so much. That's part of the stuck routine which means you are getting the same reading for left or right distances for an extended period of time. Could be the environment, were you running in a big open space? Could be I need to make the array bigger so it takes longer to fill with the same value. I've been mostly running around the house and havent run with the stuck routine in a big open space yet.

    By the way, I loaded up the motor test programs from the assembly book. Written as they are, and wired the way I am, my left motor runs correctly, the right motor runs reversed.

    The transistors I'm using are 2N3904s from the PE kit. Radio Shack has 5 packs for $1.19 They are handy to have. I'm driving the base with a 10k resistor, and a 470 ohm on the leds. I've cleaned up the wiring the best I could, but let me know if something isnt clear. I dont usually wire that neatly, so I'm not that good at it. Especially since I dont like resistors with really short leads.
    1024 x 681 - 65K
    1024 x 681 - 69K
    1024 x 681 - 87K
  • dmagnusdmagnus Posts: 271
    edited 2012-01-08 13:53
    Hi Jim. Had a little time to play with the Stingray programming today. Also found another Ping I had and used the connector for that to hook up my 40X20 Serial Backlit LCD . Works just fine (after I set the baud rate ;-). It looked like everything was working properly execpt for the reverse instead of forward. It was also going way too fast, so I cut the motor speeds in half - later after messing around with it, I set a motor speed multiplier constant so I could vary the motor speed without a lot of editing. I had it working pretty well, but now it's going backwards again. Had a ball with it when I had it working right, though. I'm going back to the original program, put the multiplier in and reverse all of the signs on the forward/reverse routines for the motors. That should do it.
    I cleaned out my "man cave" and now have more room, but it doesn't seem to make much of a difference.
    I haven't tried to figure out the led's yet because I haven't found the transistors,etc. I need a magnifying glass to read the numbers on them (darn old eyes) and my third hand with magnifying glass isn't here yet. I bought a bunch of stuff - table, some tools, shrink tubing, etc. in anticipation of getting started on my ELEV-8 as soon as I have my ducks in a row.
    I'm curious, though, I don't understand the use of the transistors with the LED's. On the boe-bot they just used resistors. I'm ashamed to say, I'm not that up on the electronics (even though I have an amateur license) - just don't ever use it. But if you could give me a diagram or schematic, I'd love to see how it works.
    I'm also going to try to enlarge your pictures so I can see how you've got it wired up.
    Thanks, I'll let you know how it works out.
    Don (KC9FOM)
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-08 14:52
    Hey Don, that's good news. Although the backing up still has me a little puzzled. Does it start forward if you wave something in front of it? If your display is hooked up, are you in loop 6?

    I know what you mean about the eyes. I just got my first pair of bifocals last week. The magnifying glass still comes in handy. I picked up one of those map readers with the built in led.

    Not using transistors to drive the leds lead to a bunch of headaches. It mainly has to do with the level shifters. They would not shut off completly when they were told to. And the leds
    were trying to draw more current than the shifters are rated for. I think Phil said it best "Bidirectional level shifters are some of the most misunderstood ICs out there -- including by those who design them into a circuit." He was the one who helped me figure that one out. http://forums.parallax.com/showthread.php?136825-Question-about-outa

    The Stamp can source or sink something like 20 ma on a pin, I think the prop can too, but the level shifters on the MSR1 work a little differently. So I've found I should use transistors. I dont understand transistors as well as I should either, but I will share some notes. I've been working on getting max out from some ir leds. Their max current is 100 ma so I ran some experiments with my Quickstart board using 9v for Vin. Notes are attached.

    I use the same setup on the stingray with these values: R1 10k, R2 470 ohm (was wrong in previous post) and +5v instead of +9v.
    1024 x 1410 - 110K
  • TLCTLC Posts: 74
    edited 2012-01-09 07:22
    On the subject of mounting the LCD. Since the real estate on the Stingray is valuable I wanted something that I could easily attach when required and removed other times. I bought some lexan at Home Depot and built two supporting legs that held the display at an angle. I cut groves on the bottom of each leg and attached some of those powerful Alnico magnets from Harbor Freight. Since the chassis of the Stingray is aluminum I had to get some light gauge (maybe 30?) metal from Ace Hardware and glue it to the chassis. I used contact adhesive rather than epoxy in case I wanted to move it later. The only problem with the magnets could possibly be if you were going to use something like the HMC5883L compass module. I took a few quick shots to help explain. I've never tried to include thumbnails but I'll give it a try. If you have any questions please let me know and I can do a little better commentary.
    1024 x 685 - 81K
    1024 x 685 - 72K
    1024 x 685 - 77K
    1024 x 685 - 93K
  • dmagnusdmagnus Posts: 271
    edited 2012-01-09 10:57
    I'll get it working again. This week I hope to get my "shop" set up. I ordered a 30X40 drafting/hobby table because working on my desk just wasn't hacking it. I found a whole package (about 10) of those connectors you were talking about with a pin on one end and a socket on the other buried under a bunch of junk on my desk - so a cleanup is definitely needed as soon as I get the table. I also ordered another breadboard (actually a couple of them) and a package of those three pin connectors.
    Those notes will help and I also loaded your pictures into another viewer and can blow them up pretty large.
  • dmagnusdmagnus Posts: 271
    edited 2012-01-09 10:59
    I like the concept, although I might not use magnets - might try velcro or something. Thanks for the idea and the pictures. What's the other board you have mounted above the MSR1? Just curious...
  • PublisonPublison Posts: 12,366
    edited 2012-01-09 11:11
    dmagnus wrote: »
    I like the concept, although I might not use magnets - might try velcro or something. Thanks for the idea and the pictures. What's the other board you have mounted above the MSR1? Just curious...

    Looks like a standard Propeller Proto board, ( with some sockets installed)
  • TLCTLC Posts: 74
    edited 2012-01-09 11:14
    It's a Propeller Proto-Board which has a header that was a sort of short lived standard a while back. I am using it to connect an old Parallax eb500 Bluetooth module. The module is a pain and I'm going to update it to a Zigbee one of these days, however I have enough other work to do on the project that it isn't in the critical path.
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-09 18:35
    TLC, I really like your LCD bracket idea. I used some magnets to mount my LCD and Quickstart board to a protoboard. I used some washer type magnets mounted with screws and washers on the components and some larger magnets just stuck to the brackets on the proto board. The washers make the components not so "sticky" which works good on the proto board. I may have to re work that so it can move from the proto board to the stingray. I really like your lexan mounts, I think I'm going to try and make some.

    Don, the table sounds like a good idea. Put a good bright light over it. Sometimes I use a fluorescent on a goosneck. Some ziplock bags or some other divided storage would be a good idea.
    BTW, are you active on 80m? I hear some guys in Wisconsin at night. Maybe we could work each other.
    1024 x 681 - 56K
    1024 x 681 - 71K
    1024 x 681 - 75K
    1024 x 681 - 77K
  • dmagnusdmagnus Posts: 271
    edited 2012-01-10 06:05
    Yes, I have to come up with a good light. There is a 4' flourescent fixture pretty close, but not directly over the table, which is partially in front of a window, but I'm going to have to come up with something much better.
    I bought 3 of those semi-clear plastic divided boxes from Wal-Mart for about $3 each. I'm going to label the smaller one for all of the common resistor values, along with the transistors, diodes, LED's, etc. so I have them right at hand and easy to identify.
    My antenna got destroyed last summer in a windstorm just when I was getting started and I haven't replaced it yet. I'll bet you hear Rob K0CD a lot. He is a real pro and does a lot of very low power stuff on CW but I'm pretty sure he does voice, too. I never learned code and took advantage of the rule change to get my general. I'm going to put up a vertical on my roof next spring (as soon as I'm done spending money on Stingray, Quad, etc. - hmmmm, will that ever happen?), then I'm going to go over and have Rob teach me how to use my radio (Icom 706mk2g). I should be able to talk to you with that puppy if I can ever figure out how to use it properly. ;-)
    You are right on Lake Huron. I sold my sailboat to a guy who keeps it on Lake St. Clair, just a few miles south of you.
  • TLCTLC Posts: 74
    edited 2012-01-10 06:41
    Jim, That's a great idea regarding the protoboard. Being able to easily move modules from a stationary prototyping area to my Stingray "mobile" prototyping area would be handy. Where did you get the anodized (?) beveled washers? I really like the way they look. I met a really nice guy (Stephen, are you out there?) at the UPEC last summer and he had some black knurled screws that he used to replace the ones holding the top deck plate on the Stingray. Made it really simple to access and I'm still trying to remember where he got those from.

    dmagmus, do the boxes you found at Walmart hold the resistors with their leads straight? I've been looking for containers to help me organize my resistors by value but haven't found anything that works well. Vertical parts cabinets of various sizes work for everything else.
  • dmagnusdmagnus Posts: 271
    edited 2012-01-10 08:16
    Yes, I really like that cool looking hardware that Jim has. We need to source that. :smile:
    I don't think my containers will hold them with the leads straight out, but I think I can "lean" them in their individual compartments. Yes, the vertical parts cabinets with fairly long drawers would work but then you have to fiddle with the drawers - it's an idea, though.
    I found a color chart somewhere on the web that has the actual color code and value on a small square that I would be able to glue on the inside of the compartment. I haven't really tried to put any of it together yet, but when I do I'll take some pictures and post them here.
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-10 10:00
    Fastener Express is where I'm buying the anodized hardware. They have lots of sizes and colors. I'm using the purple #4 Countersunk Flat washer and blue #4 Flat heads. I bought some of the red and blue button 4-40 button heads to replace some of the original black hardware.
    http://www.fastener-express.com/countersunk-flat-washers-purple.aspx

    Hey Don, here is web page you might like.
    http://www.ealnet.com/m-eal/resistor/resistor.htm
  • dmagnusdmagnus Posts: 271
    edited 2012-01-10 10:30
    Funny, I was just looking at fastener-express... Here is the place where I downloaded the "drawer labels":
    http://usbmicro.com/documents/14E915BD78CB22AC079339E7E9ACF6FC5517814D.html
  • jim N8RHQjim N8RHQ Posts: 85
    edited 2012-01-10 13:34
    Those drawer labels are nice. Looks a lot more professional than my hand written labels.

    Yup, I live about 6 or 7 houses off Lake Huron, about 10 miles north of the Blue Water Bridge.

    Mother nature sure likes to mess with antennas, I took a direct lightning strike to my G5RV two years ago. I put the replacement in the exact same spot, banking on that lightning never strikes the same place twice :-)
    I was thinking just the other night, the ELEV-8 would make a great tool for putting up wire antennas. Maybe when you get yours flying you might try that.
  • dmagnusdmagnus Posts: 271
    edited 2012-01-11 06:12
    I had the same thought. You hook the wire on to the quad, fly it to where you need to and land. Beats shooting string around with a wrist rocket. I had 300' of copper mesh strung from a tree behind one outbuilding to a pole mounted on another. The wind kept blowing the wire into some trees along side, then the wind knocked the pole down. I've still got the copper, plus a bunch more, but I want to try one of the multiband verticals. I want to put the ham shack in the basement "man cave" and there is no way to get a wire antenna set up that would be convenient to the house. Just trying to decide whether to try to mount it on the roof (chimney) or on the ground next to the house. I think the ground would work out better for radials, but then I have to mow around it.
Sign In or Register to comment.