View unanswered posts | View active topics It is currently Sun Nov 23, 2014 12:46 am






Reply to topic  [ 8 posts ] 
Redefining sensors. 
Author Message
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Redefining sensors.
I have a lego colour sensor and I need to use it as both a light and colour sensor in a program. Is this possible?Is it also possible to switch between the modes of the sensor during the program?
I have tried but I cannot define sensors other than the beginning of the program.


Sat Aug 04, 2012 12:32 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: Redefining sensors.
Sure, that's very possible.
Code:
SetSensorType(S1, sensorCOLORFULL);   // Colour sensor
SetSensorType(S1, sensorCOLORRED);   // Light sensor

SensorValue will adjust accordingly. In FULL mode, it will return the colour number, otherwise it will return a number between 0-100. You can do this in the middle of your code without any problems at all.

- 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]


Sat Aug 04, 2012 1:36 am
Profile WWW
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: Redefining sensors.
Thanks.
I never knew there was that.

That would save a lot of time.


Sat Aug 04, 2012 1:56 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: Redefining sensors.
So much to discover :)

- 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]


Sat Aug 04, 2012 2:17 am
Profile WWW
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: Redefining sensors.
Another question. I really need to make the sensor switch modes extremely fast. I have tried and can only make than switch succesfully in approx. 160 milliseconds. What is the fastest the LEGO colour sensor can do?


Sun Aug 05, 2012 2:04 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: Redefining sensors.
That is pretty much the fastest it'll go. It is very slow to switch modes, I am not sure why that is.

- 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]


Sun Aug 05, 2012 11:33 am
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Redefining sensors.
In full color mode, the FW reads the light level with no light (LED off), red light, green light, and blue light. The value provided as the "sensor value" is a color number based on the 4 values that it read. In NXC you can access these 4 values that the FW is reading, so unless for cosmetic reasons, there is usually no real functional reason to use any mode but full color mode. I don't know if ROBOTC supports something that, but it should, since the FW already knows the values, and it's just a matter of giving access to the user program. That way you can avoid the extremely long mode switching times, and have access to any value the sensor/FW can provide.

_________________
Matt


Sun Aug 05, 2012 11:41 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3289
Location: Rotterdam, The Netherlands
Post Re: Redefining sensors.
You can in ROBOTC, too. I'll see if I have some code to do that.

- 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]


Sun Aug 05, 2012 11:50 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

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.