Oh dear... I may be in over my head.

Tim M.Tim M. Posts: 26
edited 2004-10-30 - 22:05:02 in Robotics
Well, I may be in over my head when it comes time for the coding, to say the least...· I recently purchased an Epilog Laser Cutter/Engraver to work with Lexan.· I've been working on a robot chassis design in a CAD program for about 6 months, and I finally got build it out of Lexan.· I knew what all electronics i wanted to use, so I went ahead and bought them too.· I'm just now getting everything hooked up, and it dawned on me that i'm in trouble...· I'm no master programmer like some of you guys on here are, I'm just good at designing.· I can program the BS2, but I think my project may be a little too advanced for me.
Here's some of the parts that I'm using, and some goals that I would like to accomplish.· I would appreciate your input on as to whether a novice/intermediate programmer, such as myself, could tackle this project.
I'm using a BS2, and a BS2 carrier board
2x SRF08 Ultrasonic sensors mounted on servo turrets at the front of the bot
4x servos for driving.· skid steer.
Pololu 8 serial servo controller
1x servo with a wireless video cam on it, just so i can see what it sees.
7 servos total.

Here's what i would like it to do.· Drive around not running into anything, and if it comes to something such as a doorway, to navigate itself through the middle of the doorway.· Choose the best path around an object.
Now at first, all that sounded simple to me, but then it hit me.· There's gonna be SOOO many variables, especially since the sensors are mounted on turrets that can rotate and check in different directions.
Am I right about this?· I'm having doubts as to whether I can finish this, though i would really like to.· Are my choice in parts a good combination to resolve my goals?· I appreciate any feedback you guys may have on this.
Thanks a lot
-Tim

Comments

  • cabojoecabojoe Posts: 72
    edited 2004-10-25 - 08:35:59
    Looks like you have some studying to do. I think a good thing for you to do first would be to study the "what's a microcontroller" text available here. Another good thing to do would be to learn to write a program for each individual component that you have... i.e. take the 08 ranger for example...take the programs that came with it and make the stamp·run one ranger. Save that program and back it up. Then figure out how to run two rangers. Do the same with your servo controller, using the simple programs that came with it to run one servo, then try two...etc. In time you will have a library of programs for all the components you have. From there it's all about integrating all those individual programs into a full program that will control your robot to make it do what you have designed it to do.

    Some of us around here can help out on individual components, but in the end it's up to you to put it all together. Sounds like you have some good gear. I have a folder full of 08 ranger stuff (running two at a time, etc.) that might help you out. Boy I'd kill for a laser cutter for lexan...I do all my plastics with my saws...lol.

    Remember...master one component at a time, understand it, save those programs and backup like crazy. I think this is a better approach than slapping it all together and expecting to program it all at once.

    Good luck with your bot! Let me know how it's going.cool.gif

    PS...Here's my bot http://www.lynxmotion.com/images/html/proj071.htm· ...I expect pictures of yours soon!


    Post Edited (cabojoe) : 10/25/2004 8:40:24 AM GMT
  • Tim M.Tim M. Posts: 26
    edited 2004-10-27 - 22:32:09
    Well, im coming along pretty well with my project.· I found some code for the BS2 that takes ranges from two SRF08 sensors, and displays the info on the debug screen.· That helped out a lot.· I now realize that you can just look at the first ping return, and that way, they will work as collision detectors.· But i'm confused about that code.· For some reason, i cant seem to grasp what's going on.

    Basically, what i'm trying to do is, take a reading from the left sensor ($e0) and store it to a variable.

    Then, take a reading from the right sensor ($e2), and store it to a variable.
    Then, compare the two readings.· If both responses returned are greater than say, 10 inches, not to even worry about it, keep going Forward.· But if the value returned is less than 10, compare the two to see which is greater, and go that direction, either left or right.
    Does that make sense?· It does to me, but i cant seem to get it to work...· I've got subroutines for "Forward:" , "Left:", "Right:", and one called "Stop:", in case something jumps out in front all of the sudden, and the distances are less than say 4 or 5 inches.
    Even though my SRF08's are mounted on servos right now, they are fixed stationary to the front.· I just want to get a grasp on how to use them for simple object avoiding right now.·
    Do i at least have the right idea on how to approach this?
    Thanks for all the help.
    -Tim
  • cabojoecabojoe Posts: 72
    edited 2004-10-28 - 05:49:07
    You absolutely have it right. I have found no reason to move the rangers on a servo...instead finding that proper static placement of them works much better. There is a 2 ranger holder available from acroname I believe that works really good for holding them in the proper angles from each other. I find that having a serial LCD onboard the bot is way more convenient than having to be hooked up to the pc. I usually range, display range on lcd, make a decision, and move bot. The one autonomous program I'm looking at·takes a reading from both rangers, and if either is less than 13, then I backup, stop, turn a bit, range again and then go forward. I'm sure you can do it your way also. Sounds like you are making good progress. Maybe attach a copy of your program so I can look it over. Sounds like you are thinking in the right direction.
  • Kenny LevinsenKenny Levinsen Posts: 19
    edited 2004-10-28 - 10:32:56
    hi im 12 years and ive gona buy a boe bot and ive got 461,6$.
    can you give som help with a start project?
  • Tim M.Tim M. Posts: 26
    edited 2004-10-29 - 05:18:12
    First of all, Thank you Cabojoe, for you've been LOTS of help to me in this project.

    Secondly, i have attatched the code that I was using to check the two SRF08 rangers, and display their values on the debug screen.· I found this code on the net, and its been really the only SRF08 code that i could find.·
    My question is, is all of that code necessary just to fire the 2 rangers and store the first ping (result) in a variable so that i can compare the results to each other?· I'm kinda confused about all of that.· I would understand it more, if it was JUST doing what i am needing it to do.·
    I hate to ask this, but if someone could please simplify that code down to what i am needing it to do, i would REALLY appreciate it.· I've been messing with this for a few days now, and i cant grasp it.· I would be able to learn it easier if it was simpler... lol.
    Anyway, thanks for all the help so far.· I really do appreciate it.
    -Tim
  • cabojoecabojoe Posts: 72
    edited 2004-10-29 - 10:18:15
    That code is almost as minimal as you can get for running·two 08's on a BS2. You could get rid of the light measurement parts of it to make it run faster. I also program a register to shorten the time that the receiver waits for the incoming ping, since at default you are ranging out to 3 to 6 meters I think...I only range out to a meter, so I can range·ALOT faster. I'll attach the file I use for faster ranging and no light metering...all the debug statements are in green since I use a serial lcd, but you should get the idea. I think the only way to make it simpler would be to use a BS2P since it has it's own I2C commands so you don't need all the I2C subroutines(bit bashing I think they are called).·This Attachment is for a BS2E, so declare your stamp before you run it, and make sure you alter the clock and data pins to suit your setup.
    I'm sure Jon Williams could explain the bit bashing part of it to you, and as a matter of fact he's got a good article in this month's Nuts and Volts magazine on this. As far as trying to make sense of what's happening in the program, just try to understand the flow of the main part of the program...try to just ignore in your mind for now what comes after the I2C subroutine headings...that might be what is confusing you.
  • Tim M.Tim M. Posts: 26
    edited 2004-10-29 - 18:28:12
    Thank you sir.· You were right, all the subroutines were throwing me off.· I looked into the BS2p, and it does seem like it would be easier as far as I2C goes.· The little booklets that come with the SRF08s have a small bit of code for the TEA language, and it seems pretty simple to me.· I was expecting the BS2 to be similar, but I didnt think about it not having the I2C capability of other microcontrollers.· That helps me understand, or "ignore", what's under the subroutine headlines.· I do have 1 more question that is still confusing me.· Its about the variable that the ping return is stored in.·

    It says in that code, that· I2cReg = 2·· 'address of first ranging result

    that is in BOTH the left and right ranger code.· And to display your results on your LCD, you put ....... DEC4 I2cData
    So, i take it that the ranges are stored in the variable I2cData, correct?· My question is, how do I compare the Left ranger's I2cData to the Right ranger's I2cData?· I want to use an IF THEN statement to do it, or if there is a better way, i could try that.· This is kinda what i have in mind:

    IF I2cData (Right Side) > I2cData (Left Side)
    THEN GOSUB TurnLeft


    That's a shortened version of what im wanting to do.· I dont think it will work with the data from both stored in the same variable.
    Is that the best way to go about this?
    Thanks a bunch,
    -Tim

  • cabojoecabojoe Posts: 72
    edited 2004-10-30 - 02:19:38
    Here's your original program with some stuff added...look carefully to see what I've added. Make sure left and right are in the right spot in the program to match your setup. Insert your comparison code where I've indicated. This should help.cool.gif
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 02:51:27
    DOH!· <hits self in head repeatedly>
    I can't believe I didnt think of that...· Wow.· Thank you.· That accomplishes everything that I was trying to grasp...· I really don't know what to say.· My guess is that all the Acks and Naks and I2Cs threw me off so far that I couldn't remember the basics.· Either way though, I can now do as I had hoped, and compare those 2 results.

    Once again, thanks so much
    -Tim
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 05:01:12
    Well,· i got it working now.... Kinda.· I've posted my·code so you can look at it.·
    Here's what it does...
    When the Right sensor is less than 15, and the Left sensor is greater than 15, it goes Left.· Just likes its supposed to.
    When JUST the Left sensor is less than 15, it well, does nothing.· It keeps going forward.· On the debug screen, it shows that the Left sensor is reading just fine.· Also, when both sensors are less than 15, it is supposed to go backward.· BUT, JUST the rear 2 wheels(servos) go backward.· The front 2 keep going forward... Weird.·
    Also, MOST of the time the left sensor will just suddenly read 5355 on the debug screen, and when it does that, the right sensor will continue to display its correct reading, but the robot just jumps to ForwardFast and stays there..
    Now, i do not have pull up resistors on the two I2c pins.· could that be the problem of all of this?
    I plan on installing them tomorrow sometime.· However, i would think that if that were the case, they just wouldnt give correct readings, and not mess with the other code.· Like my first problem for example.
    If you have any ideas, please feel free to let me know.·
    Thanks
    -Tim
  • LarryLarry Posts: 212
    edited 2004-10-30 - 05:09:26
    Install the pullups, then try the program again. Until you do, the interface won't work properly. I'm kinda surprised you got any results at all!

    Larry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 05:10:35
    I will try installing the pullups. Can i use a different resistor other than a 1k8? I dont have any at this time
  • LarryLarry Posts: 212
    edited 2004-10-30 - 05:17:31
    resistor size isn't all that important. I've used anything from 4.7K to 12K ohm and they all work equally well. You could probably expand this range in a pinch. Anything is better than no resistors.

    Larry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 05:18:50
    Ok, i will rig up some 1k resistors that i have handy. Hopefully i will get better results. Thanks
    -Tim
  • cabojoecabojoe Posts: 72
    edited 2004-10-30 - 05:28:31
    You know what Tim, I think it's in the code I gave you, the same thing happened to me a few times last night when I ran that program...sometimes it works fine, sometimes it does·exactly what you said. Try using the original code with your updated coding in it. The resistors are essential.
    EDIT: Your code is very well organized and easy to read...great job.

    Post Edited (cabojoe) : 10/30/2004 5:30:23 AM GMT
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 05:30:53
    Ok, i will try that too. Im in the process of installing the resistors right now. I'll let you know if the original code works for me. Thanks
    -Tim
  • cabojoecabojoe Posts: 72
    edited 2004-10-30 - 06:09:25
    In the code I gave you I left out a PAUSE 70 in the left section of the "init" section...compare left and right sections of that section and you will find it. Both sections should have the delay so that the registers can be written properly. This could be the bug.

    Init:···························· 'initialize SRF08 range and gain settings
    'left SRF08 ranger
    I2cAddr = $e2··············· 'left address
    I2cReg = 2···················· 'range register
    I2cData = 24··················'set range to 1 meter max
    GOSUB I2cByteWrite······ · 'write
    PAUSE 70····················· ·'delay
    I2cAddr = $e2··············· ·'left address
    I2cReg = 1···················· 'gain register
    I2cData = 16················ ·'set gain to 177 max
    GOSUB I2cByteWrite········ 'write
    PAUSE 70····················· ·'delay·· ADDED

    'right SRF08 ranger
    I2cAddr = $e0··············· ·'right address
    I2cReg = 2··················· ·'range register
    I2cData = 24················ ·'set range to 1 meter max
    GOSUB I2cByteWrite······· 'write
    PAUSE 70···················· ·'delay
    I2cAddr = $e0··············· 'right address
    I2cReg = 1··················· ·'gain register
    I2cData = 16················ ·'set gain to 177 max
    GOSUB I2cByteWrite······ ·'write
    PAUSE 70···················· ·'delay
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 06:10:00
    Ok, i got the resistors installed and everything works the same as it did. so apparently, they werent the problem. I switched back to the original code, and added my parts to it. It works the same as yours, other than it wont "lock up" like it was before.
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 06:15:27
    Ok, i added that other pause. Still the same. With your code, and mine mixed in, here are my results:
    Left sensor displays correctly on debug screen, but no change in wheel movement.
    Right sensor displays and works correctly. Changes wheel movement
    Both sensors triggered = ONLY 2 servos (servos1 and 3) spinning in reverse, while the others keep going forward....
    If i trigger the right sensor, THEN trigger the left. it locks up and goes into ForwardFast (loops over and over)

    On the original code with mine mixed here i get:
    The same as yours, only it never "locks" up on me"
    I cant figure out what's wrong here...
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 06:32:18
    Here's something i just found out. I changed all of my GOSUB commands to show on the DEBUG screen what SUB it would be going to.
    It works like it should now...
    I dont understand why it has problems sending commands to the servo controller. I will try a different baud rate and see if that changes anything..
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 06:43:50
    Here's what i found with different baud rates.
    When using 84 in the SEROUT commands (9600baud) it will "lock up the program" and cause the left SRF08 to display 5355 on the debug screen.
    When using 396 (2400baud) it never locks up, but it still doesnt work the way it should.
    Any suggestions? Does this point to anything?
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 07:35:12
    Ok, my last post for tonight...
    Here's what i've found out. About the BackUp only making 2 wheels go in reverse, i fixed that. My error, i had the servo numbers wrong in the Subroutine.
    In Cabojoe's code that i am currently using, my Left sensor works and displays the range, but it wont go to the subroutine GoRight.
    However, i can reverse the addresses of the 2 sensors in the code, and it changes which sensor doesnt work properly. When i reverse all the $e0's to $e2's and vice versa, its the Right sensor that is doing it. So, that tells me it may be somewhere in that code. BUT, it does just the same thing on the original code that i had....

    Here's another thing that i noticed while debugging. If i change all MY gosub commands to DEBUG....(whichever sub it WOULD be going to) here's what i get:
    When i put my hand in front of the Right sensor, it reads "GoLeft" and it doesnt flicker or anything. <---normal
    When i put my hand in front of both sensors, it reads "BackUp" and it doesnt flicker. <---normal
    When i put something in front of both sensors that is closer than 20inches but more than 15 inches it reads, "ForwardSlow" with no flicker. <---normal.
    BUT when i just put in hand in front of the Left sensor, it reads "GoRight", but it flickers a LOT. I dont know what that means, but i know that's part of the problem.
    Hopefully i can get this thing workin right.
    Thanks
    -Tim
  • cabojoecabojoe Posts: 72
    edited 2004-10-30 - 09:27:25
    Think I cleaned it up, try this one. The last mistake was in your comparison section.·Was doing the same thing you described...wouldn't go into TurnRight properly...works properly on my bot now.smilewinkgrin.gif

    Post Edited (cabojoe) : 10/30/2004 9:39:48 AM GMT
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 16:50:13
    I tried your fixed code. But it still wont TurnRight for me. I replaced the GOSUB commads to debug what was going on, and everything displays properly, except GoRight. It wont even appear now, as where before, it would flicker. Both sensors correctly display their results on the screen, but the code wont GoRight for nothin.....
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 17:15:03
    OK, i went back to how i was doing the IF THEN statements. I made each one go IF - THEN - ENDIF. That got me back to where i was. They all work, but the GoRight will flicker on the screen. I tried putting small Pause 10's in between the statements and that didnt help. I dont know why the GoRight is now flickering.
  • Tim M.Tim M. Posts: 26
    edited 2004-10-30 - 18:09:17
    Ok, here's how i fixed it now.... I dont understand WHY this fixed it, but it did.. I changed all my 20's to 15's, and all my 15's to 8's. So basically what that did, was lower the distance of the objects in which it reacts to. It goes slow, fast, right, left, and backs up.
    I've hit another wall though. When on a stand at my desk, it works just fine. Never locks up. BUT, when i put it down on the floor, it sometimes just goes in reverse like something is right in front of it, but there's not. I think it is reading off of the floor maybe. I tried using address 4 for reading the ping, which would be the next HIGH byte returned, but that just didnt work at all... Is there a way i can turn the sensitivity down?
    Thanks
    -TIm

    EDIT:· When on the floor, it VERY MUCH likes to lock up and get stuck in ForwardFast and go straight for the wall.
  • cabojoecabojoe Posts: 72
    edited 2004-10-30 - 22:05:02
    Good to see that you are no longer in over your head...maybe just up to your neck now. Try to code I gave you, but take out the first comparison(FastForward) and see if it does everything but fast forward(on your desk). My bot is happily running the code I gave you, with a coffee cup in front of the left sensor and it's going right. Sensor placement is·crucial. Put it on the ground still hooked up to pc and see what the readings are. The sensors don't aim straight ahead...they function much like headlights do. Think of them as cones that head out 30 degrees in all directions. When you drive at night, your headlights will make much the same pattern on the ground in front of you. The ground is read as well as anything else in that cone.
Sign In or Register to comment.