View Single Post
  #15   Spotlight this post!  
Unread 01-12-2006, 14:02
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Auto Mode!!! WHOA...what tha?

Quote:
Originally Posted by teh_pwnerer795
When running in the user_routines_fast.c in auto-mode, all of the pwms, relays, digital/analog inputs are set to unsigned automaticaly.

example.

unsigned int pwm01;
unsigned int relay1_fwd;

Again, if u dont not redeclare all of ur varibles like in the user_routines.c the values that you state in user_routines_fast.c will stay at that value because their value has not been declared.
That's not quite how it works. In C, when you "declare" a variable, you merely define what kind of values it can hold. The unsigned keyword means it never has negative values, and int means it is 16 bits in size (using the C18 compiler, anyway). An unsigned int can range in value from 0-65535.

(You may also set an initial value for the variable at the same time as declaring it, but you don't have to.)

What's confusing me most, though, is why you'd want to "redeclare" things like pwm01 or relay1_fwd. They are already defined in the ifi_aliases.h file, and they are shortcuts to pieces of the internal data structure used for communication between the master and user processors in the Robot Controller. The pwm outputs are actually declared for you as unsigned char, meaning they can have values from 0-255, and the relay outputs are single bits holding either 0 or 1. You should never try to redefine them.

Quote:
The main reason how i found this out was this guy online told me
"Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface"
I believe you are misunderstanding the difference between "declare" and "initialize". To initialize a variable merely means to set it to a known value before using it. The pwm and relay variables are already declared for you; all you need to do is set them to safe values. His warning is for you not to assume anything about their value, and to make them explicitly what you want them to be.