Log in

View Full Version : bool Variables, Autonomous Mode


lasindi
22-01-2004, 03:09
First off, can you declare bool variables? I tried to compile a boolean variable, just because 1 bit is more efficient than wasting a whole byte on a char or 2 on a short.
Second, I looked at ifi_aliases.h in the default code. At the bottom it uses a #define compiler directive to define the macro autonomous_mode. Could anyone show me how to use this? Would you use code like
if(autonomous_mode)
{
/* Do whatever I want the robot to do during autonomous mode. */
}
in the Process_Data_From_Local_IO() function user_routines_fast.c?
Thanks for the help.

lasindi

Astronouth7303
22-01-2004, 07:35
First off, you can't just use 1 bit. it has to be in a structure with 7 others. If you want just 1 bool, I would use char and set it to 0 or 255

Travis Hoffman
22-01-2004, 07:49
IFI set up a type structure called "bitid" for defining 1-bit variables:

Declare your variable:

bitid statusbyte

Define your macros:

#define gearstatus statusbyte.bit0
#define wingstatus statusbyte.bit1
.
.
.
#define wheeliestatus statusbyte.bit7

Seems to work fine.

Hope this helps.

Guest
22-01-2004, 10:00
By default, if you use a char to store "boolean" values, 0 is false and everything else is true. However if you have:

char boolVal=0;
boolVal=!boolVal;
// boolVal is now 255

Hence, you probably want to #define the following:

// Put this in a header file that every .c file accesses
typedef char bool;
#define true (char)(255)
#define false (char)(0)

Be sure to watch out for automatic cast of anything below above -1 and below 256 to an unsigned char.

Guest
22-01-2004, 10:02
And, there's no such thing as a real boolean variable in C, only in C++.

lasindi
22-01-2004, 20:36
Thanks a lot for the help with the boolean variables. Could someone answer my question about using the autonomous_mode macro?

Guest
22-01-2004, 22:26
Thanks a lot for the help with the boolean variables. Could someone answer my question about using the autonomous_mode macro?
Where to put your auto code:

/************************************************** *****************************
*
* FUNCTION: User_Autonomous_Code()
*
* PURPOSE: Executes user's code during autonomous robot operation.
* You should modify this routine by adding code which you
* wish to run in autonomous mode. This executes every 26.2ms.
*
* CALLED FROM: main.c/main()
*
* PARAMETERS: None
*
* RETURNS: Nothing
*
************************************************** *****************************/
void User_Autonomous_Code(void)
{
while(autonomous_mode)
{
if(statusflag.NEW_SPI_DATA)
{
Getdata(&rxdata); // bad things will happen if you move or delete this
// autonomous code goes here
Putdata(&txdata); //even more bad things will happen if you mess with this
}
}
}