View Single Post
  #3   Spotlight this post!  
Unread 20-02-2011, 01:15
garyk garyk is offline
Programming Mentor: 668, 972, 2643
FRC #0668 (Apes of Wrath)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Santa Clara (Silicon Valley) Calif.
Posts: 91
garyk is a jewel in the roughgaryk is a jewel in the roughgaryk is a jewel in the roughgaryk is a jewel in the rough
Re: Programming Light Sensor

Quote:
Originally Posted by dratewka2 View Post
We are declaring the LightWhite as a DigitalInput;
then LightWhite = new DigitalInput(5);
we do... if (LightWhite->Get()==1)
{...do something...}

but we do not get the if to be entered....
any ideas???
Are the indicators on the body of the Light Sensor (assuming it's the KOP sensor) showing it's detecting light or dark? The interpretation of the indicators is among the information on the data sheet that came in each sensor bag. If the indicators aren't showing that an object is seen, the cRIO isn't going to see it either.

And the sensor's brown wire is wired to +12v, the blue wire to - ?. And according to your code, the white wire is connected to a DI and the black wire is cut and taped so it won't short to anything?

It's puzzling, but DigitalInput->Get() does not return a boolean, but an UINT32. Please see "WPILib C++ Reference" in c:\windriver\docs\extensions\FRC\.

An UINT32 is an unsigned 32 bit int, but all we care about is that it returns 1 or 0. In c++, as in c, an int can be interpreted as a boolean in an if().

Your
Code:
 if (LightWhite->Get()==1) {}
should work, the old-school C way of doing it is
Code:
 if (LightWhite->Get()) {}
.

Strictly speaking,
Code:
 if (LightWhite->Get())
is identical to
Code:
 if (LightWhite->Get() != 0)
but the effect is the same since the DI returns 0 0r 1.
__________________

Silicon Valley Regional 2005, 2006 972
Silicon Valley Regional 2007 668 Xerox Creativity Award
Championship Event 2007 668
Portland Regional 2008 668
Silicon Valley Regional 2008 668, 972
Beta Test Team 2008 668 (with 100 & 254)
Silicon Valley Regional 2009 668 Regional Chairman's Award; 2643
Sacramento Regional 2009 668 Winning Alliance (thanks, 1717 & 2473!), 2010 Winning Alliance 3256
CalGames 2006, 2007, 2008, 2009, 2010, 2011 Field Tech
NorCal FTC Regional 2008, 2009 Inspector
Championship Event 2009
San Diego, Silicon Valley Regionals; Champ. Event 2010 668, 2643, 3256
Silicon Valley, Madera Regional 2012 2643
WRRF Programming Instructor 2006-2016
Regional Woodie Flowers Award 2014 2643 Utah Regional

Reply With Quote