Go to Post If we're engineers, I feel we shouldn't be content with the what without the why... - Chris is me [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-02-2013, 07:40
tlewis tlewis is offline
Registered User
None #0138
 
Join Date: Feb 2012
Location: NH
Posts: 3
tlewis is an unknown quantity at this point
Re: Wierd Robot Problems

And at the end of your driving() routine, the line:
if (gyroe=true){

likely doesn't do what you want.....it does not test to see if the value of "gyroe" is "true", but assigns the value "true" to the variable "gyroe", then evaluates the result -- which will ALWAYS be true. What you want is:
if (gyroe==true){

You can catch these errors at compile time if you write it this way:
if (true == gyroe){

because then if you forget one of the equal signs, then you are attempting to assign a value to the constant "true", which the compiler will flag as an error. I learned that the hard way. More than once.
Reply With Quote
  #2   Spotlight this post!  
Unread 21-02-2013, 12:34
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,055
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Wierd Robot Problems

Quote:
Originally Posted by tlewis View Post
And at the end of your driving() routine, the line:
if (gyroe=true){

likely doesn't do what you want.....it does not test to see if the value of "gyroe" is "true", but assigns the value "true" to the variable "gyroe", then evaluates the result -- which will ALWAYS be true. What you want is:
if (gyroe==true){

You can catch these errors at compile time if you write it this way:
if (true == gyroe){

because then if you forget one of the equal signs, then you are attempting to assign a value to the constant "true", which the compiler will flag as an error. I learned that the hard way. More than once.
Most modern compilers (though I don't recall whether the gcc used by Wind River is one of them) will give you a warning when you do "if (x = 1)" instead of "if (x == 1)". It is generally considered good practice to have code that doesn't generate any compiler warnings, and you will avoid errors such as these. I generally turn the warning level all the up as well, to avoid even more errors.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #3   Spotlight this post!  
Unread 21-02-2013, 17:41
codes02 codes02 is offline
Randolph aka Roxbury aka R_______
AKA: Cody Schafer
no team (Formerly: Team 11, MORT)
 
Join Date: Oct 2007
Rookie Year: 2008
Location: MA, USA
Posts: 57
codes02 is on a distinguished road
Re: Wierd Robot Problems

WindRiver ships a (probably modified by them) 3.4.4 release of gcc. That bugfix version was released on May 18, 2005. The minor version, 3.4.0 (the last one to have new features, like warnings), was released April 20, 2004.

Hilariously, 3.4.4 isn't even the newest bugfix release (3.4.6 exists)

I wouldn't count it as modern. That said, I haven't actually tested it to see if it emits a warning related to = in if statements.

Last edited by codes02 : 21-02-2013 at 17:44.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 18:18.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi