View unanswered posts | View active topics It is currently Sat Aug 23, 2014 9:45 am






Reply to topic  [ 6 posts ] 
Help with Light Sensors. 
Author Message
Rookie

Joined: Tue Oct 15, 2013 10:21 am
Posts: 2
Post Help with Light Sensors.
In my PLTW class we are working on Marble sorters. What we need to have it do is sense the type of marble (Wood, plastic, and Aluminum) I need the light sensor to detect what marble is infont of it and move the catching tray to the correct position.

I need to have a range of variables for each of the SensorValue constructs

When using the debugging menu I found that the lightsensor returns these values,
Plastic 325 - 340
Wood 415-420
Aluminum 380-390

How would I set up the construct so the tray goes to the correct spot for each.
Move to position one if the value is between 325-340
Move to position two if the value is between 415-420
Move to position three if the value is between 380-390


Tue Oct 15, 2013 10:29 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Help with Light Sensors.
Use an "if... else if... else"-chain. http://www.learncpp.com/cpp-tutorial/52-if-statements/

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Tue Oct 15, 2013 8:29 pm
Profile
Rookie

Joined: Tue Oct 15, 2013 10:21 am
Posts: 2
Post Re: Help with Light Sensors.
I understand how to use if else if statements, I need to know how to use ranges for the variables


Mon Oct 21, 2013 10:07 am
Profile
Rookie

Joined: Thu Dec 01, 2011 12:07 am
Posts: 33
Post Re: Help with Light Sensors.
You could do this in a while loop...

IF((sensor>324)&&(sensor<341))
{move to plastic position}

IF((sensor>379)&&(sensor<391))
{move to aluminum position}

IF((sensor>414)&&(sensor<421))
{move to wood position}

Good luck, reply back with what you actually used.


Mon Oct 21, 2013 12:41 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Help with Light Sensors.
It would be better to use an if-else if-else chain instead of a bunch of if's, just as good practice. It is also more optimal, since the loop will only have to do an average of 2 checks each time, instead of 3 checks. That's a 33% improvement.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Oct 21, 2013 5:40 pm
Profile
Rookie

Joined: Thu Dec 01, 2011 12:07 am
Posts: 33
Post Re: Help with Light Sensors.
Would Ernest3.14 be so kind as to post pseudocode on how 3 non adjacent regions could be decided with two IF/ELSE statements.


Fri Oct 25, 2013 12:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

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.