![]() |
Autonomous Code trouble
can anyone find whats wrong with this code ?
static unsigned int t; while (autonomous_mode) /* DO NOT CHANGE! */ { if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */ { Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */ /* Add your own autonomous code here. */ t++; if (t <114) { pwm01=160; pwm02=160; } i know this should run indefinitely....and that is the goal right now......but everytime i compile everything and load the code.....it doesnt work (this is the autonomous code i wrote for the user_routines_fast.c area where it says autonomous code here..) any help would be much appeciated please reply or email me at Johnbk14@gmail.com |
Re: Autonomous Code trouble
one possible problem is that you never set variable t, and you never have it do anything after the 114 loops, like neutralizing them.
Try this: Code:
static unsigned int t=0; |
Re: Autonomous Code trouble
It would be helpful if you'd include your entire user_routines_fast.c file. Looking at your code sample, for example, you're missing a closing '}', but I know it must be there, because you code compiles. So... the entire file would be helpful.
|
Re: Autonomous Code trouble
Quote:
|
Re: Autonomous Code trouble
you know how to enable autonomous mode, don't you? you have to put a jumper somewhwere- don't remember where.
you could try enabling it manualy: ////////////////////////////////////////////////////////// autonomous_mode=1; while (autonomous_mode) /* DO NOT CHANGE! */ { if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */ I didn't check that, so it might do something else instead. |
Re: Autonomous Code trouble
That looks like the answer. Be sure to trace variables used in loops and if's etc if you find that things aren't working the way you want them to.
Also, for autonomous mode testing and such, having a mock competition port is very useful. Firstly so you can activate autonomous mode with the flick of a switch, and also if that goes crazy, you can disable it by pressing the disable button. |
Re: Autonomous Code trouble
as people said, make sure that your actually going into autonomous mode. Look at this link:http://www.ifirobotics.com/docs/comp...guide-reva.pdf. if you want to make something to be able to kill your bot or put it in autonomous mode
|
Re: Autonomous Code trouble
i figured it all out.....i should have posted a long time ago..... i misplaced the line of code that declared my variable..... int t=0;
t++; that should have been in a different location.......thanks for all the advice/help/links and such Thanks again everyone, John |
Re: Autonomous Code trouble
Guys thanks for all the help and advice during the season.
I have become more familiar with C and C++ now. And advice i have for other rookies like myself is to stay away from Global Variables. :yikes: |
Re: Autonomous Code trouble
I ask my students to add a 2 letter prefix to variable names in order to keep the different scopes and types of variables sorted out. We don't touch the IFI variables, just the custom code we create...but that helps to identify IFIs code, as well:
First character: t - type m -data member of class, struct or union (non-static) s - static class scope g - global scope a - argument, non-reference r - reference argument l - auto local (temporary storage) Second character: n - number/scalar, non-enumeration e - enumeration scalar s - struct u - union a - array p - pointer So if we wanted to add a static int "t", it'd be snt and snT. If global, gnt or gnT or if used solely in a function lnt or lnT. It looks a bit awkward, but it really helps me when I'm code reading and debugging. Eric |
Re: Autonomous Code trouble
I wish that MPLAB was more like Visual Studio 2005, there'd be much less complaining. If you forget to initialize a variable, it tells you with those nice underline spellcheck uses in MS-office. You forget a semicolon? VS2005 tells you right away at the end of that line, in a way that doesn't make you have to click a button in an alert box. It helps you get into good habits.
|
Re: Autonomous Code trouble
Quote:
|
Re: Autonomous Code trouble
Even though the comment says that it is a 26.2ms Loop area (I think it was 26.2?) it is in fact 40ms. The autonomous loop runs in 26.2ms space, but your code actually runs in 40ms space.
What I do to keep from getting confused is this: Quote:
Hope this helps. |
Re: Autonomous Code trouble
Quote:
Your code is correct but your statement about 40 milliseconds is wrong: 40ms * 40 = 1.6 seconds 40ms * 4 = 0.16 seconds However, if we assume that the loop cycle is 26 ms we get: 26.2 ms * 40 = 1.048 seconds 26.2 ms * 4 = 0.1048 seconds Trust the math... Mike |
Re: Autonomous Code trouble
Thanks for the clarification on that, no wonder my autonmous values seemed incorrect :P
|
| All times are GMT -5. The time now is 01:12. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi