Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Autonomous Code trouble (http://www.chiefdelphi.com/forums/showthread.php?t=34569)

The yellowdart 13-02-2005 17:09

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

AIBob 13-02-2005 17:33

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;
 
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

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.

Alan Anderson 13-02-2005 20:54

Re: Autonomous Code trouble
 
Quote:

Originally Posted by The yellowdart
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

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.

Ssbfalcon 14-02-2005 16:17

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.

whakojacko 16-02-2005 21:51

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

The yellowdart 21-04-2005 21:55

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

The yellowdart 08-08-2005 21:08

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:

EricS-Team180 09-08-2005 19:47

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

Kyle T 11-08-2005 01:09

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.

miketwalker 11-08-2005 13:57

Re: Autonomous Code trouble
 
Quote:

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

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

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:

#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

Re: Autonomous Code trouble
 
Quote:

Originally Posted by RIgnazio
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

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