View unanswered posts | View active topics It is currently Sat Aug 30, 2014 5:15 pm






Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
StopPgm and UserMode variables values are "backwards" 
Author Message
Rookie

Joined: Sun Sep 14, 2008 8:06 pm
Posts: 6
Location: Vienna, VA
Post StopPgm and UserMode variables values are "backwards"
Running version 1.44.

See example below

Using your FTC controller simulator or the Labview FTC Controller simulator, the values of the StopPgm and UserMode seem to be the reverse of what is expected.

Disabled is reported when enabled is selected

Teleop is reported when autonomous is selected

#include "JoystickDriver.c"

task main()
{
while(true) //continously loop to check for "mode" switching
{
getJoystickSettings(joystick); //update joystick values from FMS
if( joystick.UserMode == false) //While in "autonomous" mode (UserMode = false)
{
//do autonomous
if( joystick.StopPgm == true )
{
// we are disabled
nxtDisplayClearTextLine( 4 );
nxtDisplayTextLine( 4, "Disabled Autonomous" );
}
else
{
// we are enabled
nxtDisplayClearTextLine( 4 );
nxtDisplayTextLine( 4, "Running Autonomous" );
}
}
else //While in "User Control" mode (UserMode = false)
{
//do usercontrol
if( joystick.StopPgm == true )
{
// we are disabled
nxtDisplayClearTextLine( 4 );
nxtDisplayTextLine( 4, "Disabled Teleop" );
}
else
{
// we are enabled
nxtDisplayClearTextLine( 4 );
nxtDisplayTextLine( 4, "Running Teleop" );
}
}

// wait for next packet
wait1Msec( 50 );
}
}


Attachments:
File comment: Sample program to test transition between Enabled/Disabled and Autonomous/Teleop
robotcteleop.cpp [1.07 KiB]
Downloaded 267 times

_________________
Ramblin Wreck
FRC 623
FTC 226 & 369
Tue Sep 30, 2008 4:24 pm
Profile
Expert
User avatar

Joined: Sat Sep 20, 2008 12:16 pm
Posts: 106
Location: Curently fighting aliens on P3X-828
Post Re: StopPgm and UserMode variables values are "backwards"
It does the right thing when I run my program... :|
I guess that you did not take into account that StopPgm would be True if the robot is disabled because the variable is named StopPgm and not StartPgm...
Just use common sense to write the program, not boolien logic. If you were trying to stop the program, then you would want StopPgm to be true.

_________________
:downloading:
Sorry, your program could not be downloaded. Please reboot your computer.
FTC Team #2959 Team Smash Bros CLICK HERE.(or click www)
Quote:
What the world needs is more geniuses with humility, there are so few of us left.

Agreed


Wed Oct 01, 2008 4:10 pm
Profile WWW
Rookie

Joined: Sun Sep 14, 2008 8:06 pm
Posts: 6
Location: Vienna, VA
Post Re: StopPgm and UserMode variables values are "backwards"
In the example program, when StopPgm is true the message printed to the screen is "Disabled Autonomous" or "Disabled Teleop". ie StopPgm == true means disabled. However, when you use the field controller simulators (LabView or RobotC) and select "Disabled" the display on the NXT changes to enabled. This means that StopPgm is being set to false when disabled is selected on the field controllers. This is the opposite of how it should work.

_________________
Ramblin Wreck
FRC 623
FTC 226 & 369


Wed Oct 01, 2008 8:14 pm
Profile
Expert
User avatar

Joined: Sat Sep 20, 2008 12:16 pm
Posts: 106
Location: Curently fighting aliens on P3X-828
Post Re: StopPgm and UserMode variables values are "backwards"
That is strange, I just tried out my NXT a few days ago, and the same problem happened. Get RobotC version 1.45 out before it's too late!!!

_________________
:downloading:
Sorry, your program could not be downloaded. Please reboot your computer.
FTC Team #2959 Team Smash Bros CLICK HERE.(or click www)
Quote:
What the world needs is more geniuses with humility, there are so few of us left.

Agreed


Thu Oct 02, 2008 5:11 pm
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: StopPgm and UserMode variables values are "backwards"
I'm looking at the root cause now.

An immediate and temporary fix appears to be change "bool" to "short" in the following two lines in "yostickDriver.c" program.

Old Value
Code:
  bool    UserMode;          // Autonomous or Telep-Operated mode
  bool    StopPgm;           // Stop program


New Value:
Code:
  short   UserMode;          // Autonomous or Telep-Operated mode
  short   StopPgm;           // Stop program

If a new version of ROBOTC is required, then it should be release monday (tomorrow).


Sun Oct 05, 2008 6:43 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: StopPgm and UserMode variables values are "backwards"
Another small point. In the C-lanague a boolean value of false has the value zero. Any value that is not zero is usually considered true.

Internally, ROBOTC, along with many other compilers/systems, uses a numeric value of 1 to store the true value.

It is not best programming practices to use the following language construct because of the potential ambiguity.
Code:
if (<boolean value> == true)

because it will be a comparison against the value '1' which is most likely not the intent. The intent is most likely is the value not false.

So the following are good programming practices
Code:
if (<boolean value> == false) // comparison is OK since false has single unique value of zero
if (<boolean value> != false) // comparison is OK since false has single unique value of zero


Sun Oct 05, 2008 6:52 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: StopPgm and UserMode variables values are "backwards"
A small clarification on the intent of the "StopPgm" variable. It is used as a "Pause" command to stop your robot moving. I believe the only case where it will be used is before the start of either autonomous or tele-operation mode.


Sun Oct 05, 2008 6:59 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: StopPgm and UserMode variables values are "backwards"
A new version of ROBOTC with this fix is available. See forum posting http://www.robotc.net/forums/viewtopic.php?f=33&t=797 for location.


Thu Oct 09, 2008 1:02 am
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: StopPgm and UserMode variables values are "backwards"
Dick Swan wrote:
...So the following are good programming practices
Code:
if (<boolean value> == false) // comparison is OK since false has single unique value of zero
if (<boolean value> != false) // comparison is OK since false has single unique value of zero


Even better practice is to never compare anything to "true" or "false" but to use the boolean values directly like so:
Code:
if (<boolean value>)  // != false is implied

or

if (!<boolean value>)  // The ! operator does a boolean invert (not a bitwise invert)

_________________
Jeff McBride
Benson Robotics Club


Thu Oct 09, 2008 2:05 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: StopPgm and UserMode variables values are "backwards"
Dick Swan wrote:
It is not best programming practices to use the following language construct because of the potential ambiguity.
Code:
if (<boolean value> == true)

because it will be a comparison against the value '1' which is most likely not the intent. The intent is most likely is the value not false.

Dick,
this is not correct !

in ANSI C
the "truth value FALSE" means equal to 0 (zero)
the "truth value TRUE" means unequal to 0, so any other value different from 0 is TRUE (e.g., 2 or 6Million or -784623 or "t").

So if you define a system constant / key word "true", this has to be taken into account; maybe the (pre-) compiler should substitute the key word "true" by "not 0" or "not false", so that there won't be any difference between the "truth value TRUE" and the system constant "true":

if (boolean_value == true)
means:
if (boolean_value !=0)
and must not mean
if (boolean_value ==1)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Oct 09, 2008 4:24 am
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: StopPgm and UserMode variables values are "backwards"
Sorry Ford but ANSI C does not include keywords for "true" and "false". Most C compilers include them either as #defines or as keywords but there is nothing in the ANSI spec about it. Furthermore, every C/C++ compiler that I have ever used (or heard of) that does defined "true" uses a single numeric value, typically either 1 or -1.

Example: Microsoft VS 2008's documentation for the C++ "false" keyword says:

Code:
// bool_false.cpp
#include <stdio.h>

int main()
{
    bool bb = true;
    printf_s("%d\n", bb);
    bb = false;
    printf_s("%d\n", bb);
}

1
0


Please point me to where in the ASCI C definition that it says otherwise.

_________________
Jeff McBride
Benson Robotics Club


Thu Oct 09, 2008 10:28 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: StopPgm and UserMode variables values are "backwards"
no, Ididn't say that it should have!

I said: the truth values of TRUE or FALSE (statements) are defined like this in ANSI C, e.g. in
if (bool_var)
or
if (!bool_var)

And what I meant was, when there is a global system constant called "true" (which in fact does exist in RobotC, and what actually is NOT ANSI C), this constant "true" must behave just like the logical truth values, so

if (bool_var) must always be identical to if (bool_var==true) // which is NOT the same in the moment
and
if (!bool_var) must always be identical to if (bool_var==false) // which (mostly) is the same in the moment

There are 2 implications to be made for this

bool_var = true
has to be exchanged by the (pre-)compiler to --> bool_var = 1

and
if (bool_var == true)
has to be exchanged by the (pre-)compiler to --> if (bool_var != 0) or to if (bool_var)

If it's interpreted like this, it will work logically correctly.

sorry for my poor English - if you wish, I will be able to explain it better in German.
One point is (German:) der logische Wahrheitswert einer Aussage ,
the other point is (German:) der Variablenwert einer Booleschen Variablen oder Systemkonstanten,
und alle Wahrheitswerte und Variablenwerte müssen im logischen Sinne immer übereinstimmen.
Die Konstante "true" grundsätzlich immer mit "1" gleichzusetzen ist jedenfalls Bullshit.
(You understand "Bullshit"? It's supposed to be the same word as in English ;) )

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Oct 09, 2008 11:17 am
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: StopPgm and UserMode variables values are "backwards"
Your theory would make more sense if ANSI C specified intrinsic "true" and "false" constants. It doesn't. As you say, in C any non-zero value is logically true. So, the statement "if (5) ...." is functionally equivalent to "if (1) ...." or "if (-742) ....". However, no C complier makes "if (<expression> == true)" mean "if (<expression> != false)".

Find me a single example of any C compiler that would evaulate (5 == true) to be logically true. Every C compiler would evaluate (5 != false) to be logically true.

Jeff

_________________
Jeff McBride
Benson Robotics Club


Thu Oct 09, 2008 12:55 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: StopPgm and UserMode variables values are "backwards"
I never said ANSI C specified intrinsic "true" and "false" constants, I spoke of truth values, an these are values of Boole's Algebra.

Jeff wrote:
I completly understand your argument. I did from your very first post. In pure boolean algebra your arugment is true.

ok, I thought you didn't understand the mathmatical deduction. So I can make it quite easy:

C compilers identify a statement (expression) as false, if the numeric value is equal to 0 (zero),
and a statement (expression) is identified as true, if the the numeric value is unequal to 0 (zero), e.g. 2 or even -3.

Regarding this, you can't go and define a "faked constant" also called "true", which is only equal to 1.
That's a contradiction.

If you implement a Boole's variable called "true" (like in RobotC) you have to consider this.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Oct 10, 2008 5:01 am, edited 7 times in total.



Thu Oct 09, 2008 2:54 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: StopPgm and UserMode variables values are "backwards"
I completly understand your argument. I did from your very first post. In pure boolean algebra your arugment is true. However, you are were talking about a C compiler. No C compiler treats boolean expressions and relational expressions the way you think they should. I believe that it is more important for RobotC to treat boolean expressions and relational operators consistantly with all other C compilers than to meet a theoretical standard of boolean algebra that no other compiler follows.

Jeff

_________________
Jeff McBride
Benson Robotics Club


Thu Oct 09, 2008 3:03 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.