View unanswered posts | View active topics It is currently Fri Oct 24, 2014 8:13 am






Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Light Sensor 
Author Message
Rookie

Joined: Thu Jan 27, 2011 2:23 pm
Posts: 8
Post Light Sensor
Hi, I am new to RobotC but i am trying to program a robot, and my question is, can a light sensor identify a simbol? for example my robot follows a straight line but if i put a "X" or another simbol, can he identify that and stop or do another action? if so how?

Thanks, and I hope you help me.


Thu Jun 28, 2012 12:43 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Light Sensor
Yes, it's possible. Easy? Definitely not. Would I know how to do it? Maybe. Given a couple weeks to work on it. Do you really need it to be a symbol? It would be much easier to put a colored marker off to the side, with another light sensor looking for that.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Thu Jun 28, 2012 12:56 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Light Sensor
Yes it looks like it's possible: viewtopic.php?f=1&t=4454&p=18607
However, as NeXT-Generation said, it won't be easy. What are your design constraints? When I've had to do visual processing with symbols (not with the NXT) I've gotten good results without complicated code by using squares with different parts shaded in to differentiate between the symbols.

_________________
sudo rm -rf /


Thu Jun 28, 2012 1:32 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Light Sensor
It also depends on your goal on "identifying" them. If you just need to differentiate between a few "known symbols", then depends on how big and complex the symbol is and if you can use multiple light sensors. If it is big and simple (e.g. a T versus a cross versus an X) you may be able to use multiple light sensors to quickly tell which one it is. For example, to detect a T from the bottom with 3 light sensors you may see 010, 010, 111 and then 000. For an X, you may see 101, 010, 101. For a cross, you may see 010, 111, 010 etc.


Thu Jun 28, 2012 5:25 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Light Sensor
Or, you could do as MHTS said but with the MindSensors LineLeader. It's eight individually readable light sensors in a single package, connected to one sensor port.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Thu Jun 28, 2012 5:29 pm
Profile WWW
Rookie

Joined: Thu Jan 27, 2011 2:23 pm
Posts: 8
Post Re: Light Sensor
My idea was to do a robot that follows a line and identifies objects with touch and sonar sensor, a simple robot, but my teacher at school said that i could do more, that the robot could identifies simbols, and i know that using a colored marker is much easier, and i dont have that thingy MindSensors LineLeader, i use a NXT light sensor, and i dont have space for 3light sensors maybe 2, and yes I just need to differentiate between a few symbols like squares, or cross, i didnt do the map yet, so i dont know what exact simbols i am going to make, but i dont understand how i am going to do the code, and i dont know what are design constraints xD


Thu Jun 28, 2012 6:05 pm
Profile
Rookie

Joined: Thu Jan 27, 2011 2:23 pm
Posts: 8
Post Re: Light Sensor
i was thinking and i could take the sonar sensor, if its easier that way, and then i can put the 3light sensors, but still i dont know how am i going to write the code, but i will try to find something out.


Thu Jun 28, 2012 6:14 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Light Sensor
icecoldvskenshei wrote:
i was thinking and i could take the sonar sensor, if its easier that way, and then i can put the 3light sensors, but still i dont know how am i going to write the code, but i will try to find something out.

"I don't know how to write the code" is a very broad question. If you can break down the problem and ask specific questions, it is much easier for the people in this forum to help. Breaking down the problem will also help you think of a solution yourself. Then if you have specific questions on how to do a certain things (e.g. how to convert a light sensor value into a 0 or 1 bit?), then it is easier for us to answer.


Thu Jun 28, 2012 6:18 pm
Profile
Rookie

Joined: Thu Jan 27, 2011 2:23 pm
Posts: 8
Post Re: Light Sensor
yup i didnt know how to explain myself, but you give the example that i need it how to convert a light sensor value into a 0 or 1 bit? that is my problem


Thu Jun 28, 2012 6:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Light Sensor
The light sensor is an analog sensor, it will give you a value between 0 and 255. To convert it to a bit value, please refer to the following training video:
http://www.education.rec.ri.cmu.edu/pre ... dark1.html
Basically, you need to calibrate for a threshold value. The 1 or 0 will corresponding to whether the value read is higher or lower than the threshold value.


Thu Jun 28, 2012 6:54 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Light Sensor
I am pretty sure the value returned by the light sensor is between 0 and 100 or 0 and 1023, depending on whether you are using the standard or raw value.

The threshold thing still stands, of course :)

Code:
int threshold = 50;
bool lineDetected(tSensors _sensor)
{
  // Return true if the value detected by the sensor is greater than "threshold"
  // which you need to define somewhere else in your program.
  return (SensorValue[_sensor] > threshold);
}


- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jun 29, 2012 1:12 am
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Light Sensor
mightor wrote:
I am pretty sure the value returned by the light sensor is between 0 and 100 or 0 and 1023, depending on whether you are using the standard or raw value.

The threshold thing still stands, of course :)

Sorry, you are right. That's what happen when you are playing with multiple robot platforms :)


Fri Jun 29, 2012 1:17 am
Profile
Rookie

Joined: Thu Jan 27, 2011 2:23 pm
Posts: 8
Post Re: Light Sensor
//If sensor finds a cross

//lightsensorL = light sensor Left
//lightsensorM = light sensor Middle
//lightsensorR = light sensor Right

//value 30 = black
//value 75 = white

if (sensorValue(lightsensorL) <30)
(sensorValue(lightsensorM) >75)
(sensorValue(lightsensorR) <30)
{
motor[motorA] = 10;
motor[motorB] = 10;
}
if (sensorValue(lightsensorL) <75)
(sensorValue(lightsensorM) <30)
(sensorValue(lightsensorR) <75)
{
motor[motorA] = 10;
motor[motorB] = 10;
}
if (sensorValue(lightsensorL) <30)
(sensorValue(lightsensorM) <75)
(sensorValue(lightsensorR) <30)
{
motor[motorA] = 0;
motor[motorB] = 0;
wait10Msec;

motor[motorA] = 40;
motor[motorB] = 40;
}



My idea is something like this, but i still didnt change the sensors so i dont know if this will work. But if you have any idea that i can use i will apreciate the help.

And the value of black/white arent correct, I just saw those value on the net, so I write the code with this.


Mon Jul 02, 2012 1:13 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 593
Post Re: Light Sensor
Have you decided which symbols you will be looking for? If you have a known list, you might be able to do this fairly simply, actually, with only two 'checks'. For instance:

101.......010.......111.........111
010.......111.......101.........010
101.......010.......111.........010
"X"....."Cross".."Square"...."T"

If that's the case, you can safely distinguish between the four of them by looking at the first two rows only. As an example, the "X" starts with 101 no matter which way you approach it, (and no other symbols do), so you know if you see a symbol that starts with 101 it's an X. For the other ones, you have to look 2 rows deep to determine which one it is. For example, 111 could mean "Square" OR it could be the "T" from the top side, just like 010 could be "Cross" from any side OR "T" from the bottom. To figure out which one it is from there, you have to check the second row; 111 followed by 101 means "Square" while 111 followed by 010 means "T" from the top.

Obviously the more symbols you have, the trickier it's going to get. My suggestion (without getting into functions) is to have the first reading determine if it's an X (which is determined right off the bat) or if it's one of the other symbols. You can then nest if statements within one another to check to see if which one it is exactly.

Code:
string symbol;

If (reading == 101) //Definitely an X
{symbol="X";}

if (reading == 010) //means it is either a Cross or a T
{
   'move forward to next reading
    if (reading == 111) //Second reading shows it's a Cross
      {symbol="Cross";}
    else                    //Otherwise it's a T
      {symbol="T"}
}


Code is very, very rough and not drag & droppable, but it gives you the general idea. If you have to go three deep, you would just have to nest another If statement within the second one. There are other ways to do this, too, such as using a series of switch statements or even using just one side sensor and always starting from the bottom (same idea, 10 would be X, 01 would be Cross, 11 would be Square, and 00 would be T; conveniently using all 4 possible combinations with no overlap).

Hope this helps get you started!

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Jul 02, 2012 2:43 pm
Profile
Rookie

Joined: Thu Jan 27, 2011 2:23 pm
Posts: 8
Post Re: Light Sensor
wow! thanks, that will help a lot, and it will save lots of time.

I will try that tomorrow, when i finish putting my robot all together with the right sensors.


Mon Jul 02, 2012 9:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 19 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


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.