![]() |
problem with autonomous that has stumped all programmers so far
1 Attachment(s)
The autonomous mode i programmed for our robot for dead wreckoning was working fine. It would count the # of 26.2 ms and use them to time the movements of the bot. The first time i setup the code with sample times it worked just fine, but once i put actual times in that we received from out test runs, the cpu seemed to skip the first few steps and and go directly to the area where the robot is todl to move forward for 3 seconds. I asked a group of programmers at the Regional in Trenton, which were mostly coaches or people with enough knowledge of the language to comprehend my code, and they all said my code was written fine and should be working ok. I myself do web programming the usual html (even though it isn't really considered a language), vbscript, javascript, asp, sql, and php, and have had no real trouble in the past with debugging, but now I'm just stuck. Can anyone help me with this? :confused:
Attatched is my working code. Whenever i changed the time values for each state or change SECS_TO_TICKS to MSECS_TO_TICKS, it throws it off for some reason and makes it skip states. Any ideas? |
Re: problem with autonomous that has stumped all programmers so far
we orignaly had an atonomus code that looke strikingly similar to yours and had a very similar problem, we could not resolve it. after 2 days of total frustration, i compleatly re-wrote the code using 6 big if statements and a simple counter. from then on it worked perfectly. i think that there might be an issue with how the compiler disassembles complex switch statements. i hope you can get it working!
|
Re: problem with autonomous that has stumped all programmers so far
I'll have to try that. It actually seems more practical than these huge cases. The reason the code might look so familiar is because it is based on a few lines of code I found here on the Delphi forums.
|
Re: problem with autonomous that has stumped all programmers so far
what i did... if youll hold on ill get you the actual code... is not actualy a timer but a inturupt on a wheel counter. this however can be used exactly like a timer except it is not speed dependent ( i.e. you can change speed without haveing to wory about distance ). stand by
|
Re: problem with autonomous that has stumped all programmers so far
My first guess would be that the variables used in auton mode, ie tick count or the states... are not being cleared when auton mode is not running - it should be done at the end of your driver mode code, so that whenever the bot is switched into (back into?) auton mode, it starts from the beginning.
|
Re: problem with autonomous that has stumped all programmers so far
Quote:
|
Re: problem with autonomous that has stumped all programmers so far
I just checked again
tick_count is cleared to 0 when your auton code is first called, but AUTO_STATE is not set to the first state. |
Re: problem with autonomous that has stumped all programmers so far
Quote:
|
Re: problem with autonomous that has stumped all programmers so far
reset does not clear your variables unless you have then specified with a init value somewhere else in the code, where they are declared or in the initialization section.
but either way, you should be able to switch back and forth between auton and driver mode without someone having to push a reset button - just have a section at the end of your driver mode code that sets up the auton variables to start from the beginning - it will make testing your bot much easier. BTW - when the bot is disabled it is in normal(driver) mode - the pwm outputs are disabled but that code is still running - when they do auton mode they enable it for a cycle or two, then they switch to auton mode. |
Re: problem with autonomous that has stumped all programmers so far
this is the meat of my code... as you can guess the drive motors are on pwms 15,16 and the inturpts incrment count.
Code:
/******************************************************** |
Re: problem with autonomous that has stumped all programmers so far
I noticed the prob with the vars not returning to their original values when i first modified the code, so i couldn't run it again once i had already ran it, but once i pressed the reset button it would run it perfectly as though i had never ran it before, so i just figured it cleared my values to the original state
|
Re: problem with autonomous that has stumped all programmers so far
Quote:
Code:
unsigned count = 0; |
Re: problem with autonomous that has stumped all programmers so far
I'll try it out and let you know how it works out. I just found out my team is totally redesigning the electronics board, so that complicates things a bit for me, but i'll let you know in a few days or so what's goin' on.
|
Re: problem with autonomous that has stumped all programmers so far
if the only thing you changed was adding this stuff:
SECS_TO_TICKS(a) ( ((int)(a)) * 10000 / 262 ) then maybe its not doing what you think it is? int is signed, isnt it? so if a = 4 you end up with 40,000 which is a negative number divide by 262? if this is what you changed and it got weird on you, just work with the tick counts in your code forget the fancy translations. also could try running with a few printf statements and see what is happening at the start and end of each state - there might be something weird going on. |
Re: problem with autonomous that has stumped all programmers so far
Quote:
the problem is that for any time period larger than about 3 seconds, 10000*a is greater than the max limit for a plain "int", and thus it's either wrapping around or just mucking stuff up. you can solve this problem by changing the declarations of SECS_TO_TICKS and MSECS_TO_TICKS to the following, which use a "long" instead of an "int" (you'll notice that tickCount is already defined as a "long"... at least I was thinking clearly there! :)): Code:
//A handy-dandy macro to convert a number of seconds into a number of 26.2ms ticksI remember when I originally typed in the code, i for some reason was thinking that seconds would only need to be multiplied by 1000 - I realized my mistake, but forgot that by changing it to 10000 i needed to increase the type of integer for which that math was done. So for anyone using the example I posted here, that change should fix it quite nicely. :) Nice to see my examples are being used and are helpful for some teams. |
| All times are GMT -5. The time now is 15:45. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi