|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Autonomous Program
Hi, we are currently working on a new autonomous program which uses infared sensors for more accurate readings I know several teams have done this. Anyways this is what we have come up w/ so far... can anyone spot a mistake? It tokenizes but there is a Basic run error when putting it on the robot.
if auton_mode=1 then auto1: goto end_auto_loop: auto1: first: if dist>7 then end_first: drive_R=0 'ur going backwards remember drive_L=0 if rc_sw3=0 then end_auto_loop: dist=dist + whlc goto end_auto_loop: end_first: turn: if dist>9 then end_turn: drive_R=difrdir drive_L=difldir if rc_sw3=0 then end_auto_loop: dist=dist + whlc goto end_auto_loop: end_turn: open_pnuematics: if dist>10 then end_open_pnuematics: p1_sw_trig=1 'open lower pneumatic p2_sw_top=1 'close shoulder pneumatic end_open_pnuematics: straight: if dist>16 then end_straight: drive_R=255 'straight now drive_L=255 if rc_sw3=0 then end_auto_loop: dist=dist + whlc goto end_auto_loop: end_straight: straight2: if dist>21 then end_straight2: drive_R=255 'straight now drive_L=255 end_straight2: finish: drive_R=127 drive_L=127 p1_sw_top=1 'close lower pneumatic p2_sw_top=1 'open shoulder pneumatic end_auto_loop: |
|
#2
|
||||
|
||||
|
Well, one guess is that you're feeding 255 as a value. That particular value is used to store something partaining to the code (I forget what) but basically, avoid it. Try using 254 instead.
Man I need to open up pBasic again! It been so...long.... Anyaway, the new language sould be revealed 10/01/03 |
|
#3
|
||||
|
||||
|
Sachiel7 has it pretty well correct, but I don't think (s)he (trying not to be presumptuous, here) explained the concept well enough.
To my knowledge, when you send the value 255 to a speed controller, by defining either drive_L, drive_R, or PWMn as 255, the speed controller interprets this as 0V (or 0% duty cycle), rather than +12V (100% duty cycle), which is full forward. 254 is the maximum value which you're supposed to send to a speed controller. I just looked at the RC Reference Guide, on IFI's website, and there isn't a very descriptive explanation as to what specifically is wrong. Id est... Quote:
Hope this helps, some. Good luck! |
|
#4
|
||||
|
||||
|
A value of 255 in the wrong place will not cause a Basic Run error, unless you're very lucky. Instead, it'll make your robot do a "not-so-happy" dance, with random LEDs blinking and whatnot, due to the problem Jim mentioned, that the SEROUT command gets screwed up. We had this problem in 2002, and it took a bit of time to figure it out
.Instead, one thing that I've noticed, unless you have any debug statements, leaving the serial cable in the Programming Port will trigger an error, I believe a Basic Run error, but I can't remember what exactly. Another possible problem is that someone touched the uP init section, and I'm pretty sure that can't be touched or it'll break. Also, make sure you use the Constants section correctly, because I believe any value used in SERIN and/or SEROUT must be "signed" by a Constant. It's been a while, so I can't remember exactly, but definitely check the default code on www.innovationfirst.com/firstrobotics to make sure nothing crucial changed. |
|
#5
|
||||
|
||||
|
Well, after a short collaboration with my team's lead programmer, we agree that for the robot, 255 exceeds the max value of what the robot controller can understand. 254 is the max value, I believe. Try changing it to that and then running the program. That should help
EDIT: Another idea is to check your var declarations, and make sure you have everything declared, as well as checking constants and SERIN and SEROUT. Also, try unplugging the serial cable from the program port and resetting the bot. When we had basic run errors and did that, they usually went away. Otherwise, we turned to the lead programmer and made him go fix the code ![]() Last edited by Jeremy J : 20-09-2003 at 21:47. |
|
#6
|
|||||
|
|||||
|
As far as I can remember, sending two values of 255 in a row in the serout will cause a reset, and everything will be messed up. This is why there are two 255's at the beginning of the serout. It tells the processor that the outputs begin there. If it resets later, the variables wil not match up with what is being outputed, hense undesired motor output. If this makes no sense, I can try to explain it better, but for right now I am too tired.
I think the consensus is that 255 should be avoided, due to many reasons. --Damian Manda |
|
#7
|
|||
|
|||
|
Quote:
![]() |
|
#8
|
||||||
|
||||||
|
A few things:
a) NEVER EVER EVER EVER EVER set a PWM to 255. EVER! As Damian Manda said, sending two 255's in a row will cause the RC to think that all bytes following it are the start of a new Serout command. Thus, what should have been output to PWM5, for example, may end up being interpreted as relayA, causing stuff to go massively haywire. b) The "wrapping" of numbers isn't really an issue here. PWMs are stored as bytes (8 bits), so they can have 256 values (0-255). It's just that 255 means something else... c) For you power freaks out there that are concerned about not getting that extra 1/256 of an output to your speed controllers, don't be! The Victors interpret anything above about 240 to be full ahead and anything below about 17 (IIRC) to be full reverse. The only even semi-real disadvantage to not being able to use 255 is that you'll loose 1/256th of a rotation on your servo. -Rob |
|
#9
|
|||
|
|||
|
thank you
Thank you, thank you, thank you, Rob for saying everything I'd wanted to scream since starting of reading the post. Probably better you said it though, since I tend to get a little excited. Oh well, it's all been said. But anyway, that code looks like a perfectly good SELECTION of code - there may be an error somewhere else that you didn't include; though your 255 error is an almost certain culprit of your problem. Tell us if it's still not working out for you.
|
|
#10
|
||||||
|
||||||
|
I think it is unlikley that setting the pwm values to 255 is causing the problem. But, it depends on what PWM values the variables correspond to. If this was the problem, you'd have a problem sometime into running the program, not on download.
how big is dist and whlc and do you overrun anything when adding them together? Same thing, this shouldn't cause the error, but is something to look into. I think the most likely cause was already mentioned by Ian. If you tried to read in a new sensor, but didn't define the constant saying that you want to read it, your serin will be mismatched with the initialization. Look at the section of the code labled "DEFINE CONSTANTS FOR INITIALIZATION" It would also be helpful to see more of your code if one of the suggestions doesn't help. |
|
#11
|
|||||
|
|||||
|
Fotoplasma has it right, and I like how Rob described the problem. I remember researching this, and if you look into the code, every time it sends out to the RC the new packet it sends "255,255" at the beginning to tell it that this is new information if I'm not mistaken. The purpose of this, is code has errors, it skips (delta_t counts how many times it's skipped for those that don't know) and when it skips, without that "255,255" it'll interpret the inputs as part of the line before, and we all know we don't want that. So when you have 255 run in another part of the robot, as someone put it, it does a dance, because it keeps translating the inputs into different areas and each time it errors (I believe) the outputs will swap again, so things go nuts. I'm not 100% sure about all of this, but this is the conclusion I came to awhile ago and I think that's what happens. But yea, swapping your 255 will almost ALWAYS fix that. Another trick if that doesn't work, stick a debug statement somewhere before the lines to output "hello" or something, just so you can tell if the code gets to that without having an error, then move the debug around to find the problem area, then you work with that area and sometimes it connects to something else and then you have to look at that as well. I hope this helps. Good luck!
|
|
#12
|
|||
|
|||
|
Quote:
) it specifically says that a PWM can have 255 values, not 256. So the wrapping error is very important for people to understand, since it is 0-254, not 1-255 ![]() |
|
#13
|
||||
|
||||
|
A wrapping error that I think he was refferring to would be a variable overflow... that isn't the case here.
|
|
#14
|
|||||
|
|||||
|
Quote:
From the Innovation First Full-Size Robot Controller Reference Guide: Quote:
BTW, the two relay bytes are deliberately interspersed in the serout command between PWMs 1, 2 and 3 to prevent 255s output to PWMs from causing problems in the most common cases where someone is using the default code (or has made minimal modifications to it.) So, Salik, if you're using two consecutive PWMs (not including 1 and 2) for drive_r and drive_l, there's your problem. (Actually, it is still possible to provoke this problem when you're using PWMs 1 through 3 if you happen to turn on all the relays in one of the relay bytes.) Last edited by Greg Ross : 24-09-2003 at 18:17. |
|
#15
|
|||
|
|||
|
Are you using the newer version of PBASIC or the older version? Innovation First came out with a newer version for the 2003 season, and it doesn't use that format for the IF statements. I don't know if that would tokenize properly, but might be your problem.
However, if those 255s aren't causing a problem now, they will later. Outputting 2 values of 255 in a row will mess up your program. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A better autonomous method.. | randomperson | Programming | 4 | 24-02-2004 18:02 |
| autonomous mode problem on field | Chris_C | Programming | 17 | 26-03-2003 19:11 |
| Fried program slots? | Jeff Waegelin | Programming | 18 | 19-03-2003 18:08 |
| Autonomous Kill Switch | UCGL_Guy | Programming | 8 | 15-01-2003 17:39 |
| Ahh! Program trick confusing! | archiver | 2001 | 9 | 24-06-2002 02:26 |