PING))) with Mesmic code?
Can anyone please show me how to run my Boe-Bot with both a PING))) for object avoidance, and a Mesmic accelerometer acting as an anti-tip over sensor? I have them both hooked up, and can run programs for either one, but when I try to combine them, I get way confused.
I have these connections:
Ping))) servo on P14
Ping P15
Mesmic X on P4
mesmic Y on P5
It would help if the code was documented a bit, so I could learn what was going on, but if not, I will eventually muddle my way through it...
I really appreciate any help anyone can give!
Scott
I have these connections:
Ping))) servo on P14
Ping P15
Mesmic X on P4
mesmic Y on P5
It would help if the code was documented a bit, so I could learn what was going on, but if not, I will eventually muddle my way through it...
I really appreciate any help anyone can give!
Scott
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I also had found the code 'Advanced_Tank_Bot.BS2' which is also attached. I just can't keep it straight in my head as to how to combine the two.
Thanks again for your help!
That said, though, if you want some simple results, I would start with the Get_Sonar routine from Roaming with Ping. In a way, this routine is the main "decide what to do code":
I would take the second half of this sub and move it to your main loop. Leave just the "reading" of the sonar in the sub. Then add in the sub for reading the memsic and add the extra decision making to the main loop. For example:
Obviously, I'm leaving work here for ya -- I would start by getting the memsic code into the Roaming program and make sure you have pins and vars assigned properly and that the subroutines run correctly and give you good values THEN start doing stuff with the read info. Build it up in pieces. I.E., the first round of your program might just be:
This way if you have problems as the program gets more complex you will be able to rule out problems with each "module" (like reading the sensors) as you'll already have debugged them in their "simple" version.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Scott
Oh yeah, I have a subroutine to check for Bumper whiskers, but I don't actually have any whiskers installed on the Boe-Bot... I set the values to '1' instead of '0', because if I have them set to '0', the Boe-Bot continually runs backwards... I have not built the bumper as of yet, but I'll get around to it one of these days....
In any case, some of it is pretty straight forward and at quick glance looks OK, but some of it is a bit involuted for me to parse out in a quick read. Have you made sure it's not possible to call more than 4 GOSUBs in some of your escape routine near the bottom? You can not call more than 4 "nested" GOSUBS in a row without a return or the Stamp interpreter will "lose it's way" back. (i.e., the main program calls a sub, which itself has another gosub within it, which itself has another gosub...you can only do that 4 times then one of them *must* return or you will overflow)
Second, make sure your two main sensor routines are giving you correct values based on dist. measured, tilt. Ensure that those are rock solid THEN start using those values (as you have) to make your decisions.
Third, don't run bumper check until you have whiskers installed and running properly. That routine will give you strange results and may be a big source of strange behaviors.
Fourth, as a matter of style and need you might nuke all the debug "text..." statements at the start of your subroutines. Debug strings take up a lot of code space, but more importantly, they are SLOW and take time to send even if you are not hooked up to a PC via serial cable. Note that in my "conditionally compiled" version the long, slow debug statements only appear in the version where it is presumed the 'bot is hooked up to a PC for debugging.
To wit, the edited version here should just give you debug values for your sensors w/o running the 'bot. If that's good, then you can at least rule out inaccurate readings. Note that I used conditional compilation -- it's like having two versions of the same program in one -- one version doesn't move the bot and shows sensor values in the debug window; the other doesn't have the debugs and essentially runs your program as it was.
Lastly, indenting code and even the most rudimentary comments in the code can make it *way* easier for others (and yourself in twelve months) to read. Not that I added any comments either ...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Pin 1 = open
Pin 2 = tp P5 (Yout) - Through a 220 ohm resistor
Pin 3 = to Vss
Pin 4 = open (or Vss)
Pin 5 = to P4 (Xout) - Through a 220 ohm resistor
Pin 6 = to Vdd
Beeper = + to P8
- to Vss
Running your program that shows just the sensor data, for the X/Yraw: and X/Ycal:, I get numbers that look like this:
YRaw: 2540
YCal: 25
XRaw: 2675
Xcal: 26
and they don't change when I tilt the bot....
I know I should have the DEBUG statements in my code, but I put them in there to see if the actual subroutines were being called.
I borrowed most (ok, all) of the code I used, and one of them was the 'Advanced_Tank_Bot.bs2' program, and I wasn't sure what to do about the part of the code in it, which reads (in part):
Main:
Do
Gosub Check_level
Gosub Read_IR_Sensors
ON irBits Gosub Forward, Go_Left, Go_Right, U_Turn <
this bit...
so I modified to to check my imaginary bumpers. This was the only thing that I saw that was telling my bot to go forward.
Well, now it's late, and I am getting more confused, so I'll stop here, and see how clearly I can think tomorrow.
Thanks again for your help!!
Scott
P.S. I'll clean up the code a bit... take out the DEBUGS, and indent it to make it easier to read...
BUT -- unless I'm missing something, the last version of your code has different pin assignments compared to what you mentioned in your post from last night!!??
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Thanks once again for your help!
This is giving me a headache.
If that's the case, then I would sent the conditional compilation flag to showonlysensors. Run it hooked up to the PC and check what X/Y vals you get when you tilt the 'bot different ways. Then (re)set your thresholds accordingly. You also might need > AND < to cover different tilt directions i.e.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
XRaw YRaw
level: 5000 5000
nose down: 5000 6300
nose up: 5000 3800
rolled to right 90 degrees: 6300 5000
rolled to left 90 degrees: 3800 5000
So I'd say you're right... but I don't know what is amiss, or how to go about fixing it. Yet. I'm not giving up!
I've attached the modified Mesmic Test, just in case I've done something wrong, and I'm not getting correct Raw returns...
So... when you run the "test" program, you get the values described, but when you run your own program, with "showonlysensors" set to 1, you don't?
Use my revised and attached version of your program. This has been changed to "scale" the memsic readings to microseconds, like the test program. In looking both programs over, I can't imagine why you would NOT see the same "raw" values in the test program and this new version of your program. Pins look the same, the rest looks OK.
For now, disregard the cal values, etc., until you know you've got good readings from the memsic into your program.
Also, see my other comments regarding these lines:
If "level" is between tiltup and tiltdown, then you would want something more like:
The above would have the backup happen if you are tilted more than "deadzone" units below LevelValue OR more than "deadzone" units above LevelValue
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I am getting good readings now with the showonlysensors set to 1 now!!! When I comment 'showonlysensors' out, the bot won't back up when it's tilted, so now I need to work out the other parts of the code, and see if I can figure out how to work in your other ideas for the 'deadzone'. I need to get some ink for my printer now, so I can look at it on paper. It's easier for me to follow when I can see it all at once.
Thanks again for all your help!
forward too far -- 1250
about level -- 1100
backward too far -- 900
In the interest of simplicity, call the +/- threshold 175
If you are more than 175 units higher than level (~1275) then you are tilted too far forward
If you are more than 175 units lower than level (~925) then you are tilted too far backward
In between, you're OK to roam.
So your logic would be:
But for testing do this, as a conditional compilation when only showing sensors:
And the same for the X axis, of course. This way you can just see if your constants are good and if the 'bot is triggering the "I am not level" response when it should.
If that's all working how you'd like, then plug the logic back into the actual behaviors. The idea here is that if your 'bot is still not behaving at that point, you know that you have logic or code or movement problems, without wondering if you're getting a good "level/not-level" flags from your sensor routines.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
What I got for values though are something like this:
LEVEL Max Tilt Fwd Max Tilt Back Max Tilt Right Max Tilt Left
YRaw 4980 5680 4280
YCal 49 56 42
XRaw 5025 4400 5650
XCal 50 44 56
Maybe I'm just confusing myself further and (trying) to think too much?
If I have your X and Y switched here, sorry.
You can get fancier too -- for example, you could adjust your speed depending on how close to Xlevel you are, or take different actions if tipping one way or the other (depending on your other sensors). But if something like the above is at least giving you good readings, then you can hitch the readings to your behaviors (backup, turn, etc).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Maybe I should stick to the simple stuff... *sigh*
I mean, I can follow programs pretty well, but troubleshooting and combining them? I suck.
I'll keep at it though... I can't stop now after all your help......... You give me something to shoot for!
This will likely just take me forever to complete... maybe even longer.
When I get to my other machine later today I'll take a crack and incorporating this into your current code. Actually, can you post your most *current* version of the code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I have attached your code again to this, so you could get it easier, I did rename it though...
And yes, I do need to thank you. I do appreciate your help, and eventually, I hope I can learn this stuff. But at the very least, you've practically written my entire program, and for that I'm grateful!
I've been looking at and mulling over this code. I think it will be quite tricky to integrate both the memsic and the Ping scan code. Both are fine perhaps standalone, but I think that a different kind of setup would make it much easier to integrate both.
That said, I still think you should get just the Memsic parts working OK, then work on program logic, then insert Ping code. The latter is easier because it's just distance and is already calibrated (i.e., it's easy enough to say "if distance is less than 20 cm, then turn" as opposed to figuring your constants for tilt -- plus the fact with your tilts you've got FOUR possibilities to contend with -- tilt forward, tilt back, tilt left, tilt right).
So... the question now is -- (and here, I feel like you owe you one because I haven't been particularly helpful) -- do you want to take a crack at the code yourself with some guidance, or should I hack the code into something worth testing?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
No problem at all! I know that you get very busy with more important things. I've been way busy at work myself these past couple of weeks, and have been battling an illness as well. Not much fun. Anyway, I haven't had time to do a thing with the bot since my last post. I don't think you 'owe' me a thing... you've been great help, even if I haven't been able to get it working yet. You've given me great ideas and have taught me quite a bit too. If you want to take a stab at making something that I can test, then I'd be happy to accept it! I think that I'd get a LOT farther on it than if I tried to get it working. Of course, I'll still be looking into it as well, but I'm nowhere near as good at it as you are...
Thanks heaps!!!
Scott
Note that I took out all the material for "scanning" the ping and such -- I think if you get the following working to your satisfaction then we can start adding more features back in. I also made one to change to "foward" and "backup" so that you can pass the "number" of pulses to these routines from the main program (this makes the routines a little more flexible).
Run it with just sensors and double check that I plugged in correct "set points" -- where the 'bot is tilted too far in a given direction -- for your tilt measurements. Ditto the ping measurements. Note that the setpoints are constants at the top of the program.
Then, if you run the bot with the showonlysensors = 0, I would *expect* the 'bot to behave something like as follows:
- if tilted too far forward: stop, makes sound, backs up longer than your "normal" backup, turns around
- if tilted too far backward: stop, makes sound, go forward longer than your "normal" forward, turns around
- if tilted too far left/right: turn other way
- if object is 8" or less in front, stop, make sound, backup briefly, turn around
- otherwise, drive forward
- I would expect some "stutter" at times in the motors -- this is because depending on actual Ping and Memsic measurements, it is likely that you won't a servo pulse every 20ms -- however, when turning, backing up I would expect smoother motion
- you will want to adjust the times in the pulsout routines (the number of pulses sent for a turn, backup, etc) AND the setpoints so that the 'bot responds to the memsic and ping when you want AND turns/moves the approx. amount you want.
Then, we can return to getting your scanning and bumpers code back in and perhaps reworking so you have a real subsumption engine and can refresh your pulses. See, the one issue with a setup like this is that it's purely "ballistic" -- say a tilt is detected, the program then drops into backing up and turning around. What if the sonar is too close *while* it's turning around? What about if it's tilted 2 ways at once? What about getting servo pulses every 20ms no matter what? There are some pretty clever ways to do all that (and they are much more variable and code efficient), but we can get there (hopefully) in time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php