Log in

View Full Version : Autonomous Code trouble


The yellowdart
13-02-2005, 17:09
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

AIBob
13-02-2005, 17:33
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:

static unsigned int t=0;

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) //edit(added): runs Forward for 113*26.2ms = 2.9606s
{
pwm01=160;
pwm02=160;
}
else
{
pwm01 = 127;
pwm02 = 127;
}
...etc...

Ryan M.
13-02-2005, 18:19
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.

Alan Anderson
13-02-2005, 20:54
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
Be more specific. What do you want it to do? What does it do instead?

Anton
14-02-2005, 08:09
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.

Ssbfalcon
14-02-2005, 16:17
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.

whakojacko
16-02-2005, 21:51
as people said, make sure that your actually going into autonomous mode. Look at this link:http://www.ifirobotics.com/docs/competition-port-pinout-guide-reva.pdf. if you want to make something to be able to kill your bot or put it in autonomous mode

The yellowdart
21-04-2005, 21:55
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

The yellowdart
08-08-2005, 21:08
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:

EricS-Team180
09-08-2005, 19:47
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

Kyle T
11-08-2005, 01:09
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.

miketwalker
11-08-2005, 13:57
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

You should've told me that 3 years ago Eric, I would've understood your code much more then, I always wondered why you labeled your variables like you did. :-p

RIgnazio
22-09-2005, 18:44
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:

#define second 40
#define tenth_second 4

//IFI code goes here
unsigned int autonomous_clock;

if (autonomous_clock < ((2*second) + (4*tenth_second))
{
pwm01 = 254;
pwm02 = 254;
}
else
{
pwm01 = 127;
pwm02 = 127;
}

++autonomous_clock; //adds 1 to the autonomous_clock count


I forget if the default code uses pwm_max, pwm_min, or pwm_neutral, but my code did. I merely use pwm_max as 254, pwm_neutral as 127, and pwm_min as 0

Hope this helps.

Mike Betts
22-09-2005, 20:14
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...

Roger,

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

RIgnazio
22-09-2005, 20:17
Thanks for the clarification on that, no wonder my autonmous values seemed incorrect :P

jazzsaxman1988
23-09-2005, 09:21
Originally Posted by EricS-Team180
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

So yeah, good example of using the basic idea behind Hungarian notation. It's good that you make your students do it, it makes for much easier code reading, and it keeps you from ripping your hair out trying to fix things. The code for FRC isn't so bad, but when you get into Windows programming it really makes a difference.

The yellowdart
21-01-2006, 10:36
There is a way to make MPLAB recognize that......I'll look it up and let ya know how to do it.