NXC: NXT 2.0 color sensor in lamp mode
Re: NXC: NXT 2.0 color sensor in lamp mode
Matt,
I will run some tests with ROBOTC now, will let you know how it goes.
- Xander
I will run some tests with ROBOTC now, will let you know how it goes.
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: NXT 2.0 color sensor in lamp mode
Hmm, ok. Sometime I might run a test with the Lego FW (enhanced).mightor wrote:I have no idea tbh. One way you could find out is to compare the time it takes with various firmwares Use an NXT 1.0 light sensor to measure, it's got a 3ms update time.
- Xander
Ok, thanks.mightor wrote:Matt,
I will run some tests with ROBOTC now, will let you know how it goes.
- Xander
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: NXT 2.0 color sensor in lamp mode
The time that it takes to switch from one type of device to another for the color sensor is part of the design of the device itself. The standard NXT firmware specifically includes wait states any time you change the color sensor type (i.e., red, green, blue, full, or none) in order to make sure that the device works correctly as you switch it from one type to another. It might be possible to handle the device as a custom sensor and manually "program" it via the digital pins but that is not something I have ever tried. If all you cared about was using it as a light output device it may not matter if you strictly adhere to the way it is used internally by the firmware.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: NXC: NXT 2.0 color sensor in lamp mode
My results are quite surprising. I used the setup in the image below. An NXT 1.0 light sensor in ambient mode and the colour sensor facing it. I made sure the space between the two sensors was quite well insulated from outside light. I had an average measured raw value on my light sensor of about 23, which is really quite low, so I was pretty sure not a lot of light was coming in.
I have no idea why it takes longer to switch on and off in non-RGB mode. Let me know if you get similar results.
This is the code I used:
Edit: The sensor is set to BLUE here, I just tweaked for each run.
- Xander
I measured the time it took for the light to turn on and for the light to turn off using RGB, Red, Green and Blue mode. All times are measured in ms.
Code: Select all
Mode ON OFF
------------------
RGB 139 17
Red 320 122
Green 319 122
Blue 319 122
This is the code I used:
Code: Select all
#pragma config(Sensor, S1, COLOUR, sensorCOLORNONE)
#pragma config(Sensor, S2, LIGHT, sensorLightInactive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#define THRESHOLD 30
#define SAMPLES 100
task main () {
long timer1 = 0;
long timer2 = 0;
for (int i = 0; i < SAMPLES; i++) {
time1[T1] = 0;
SensorType[COLOUR] = sensorCOLORBLUE;
while(SensorRaw[LIGHT] < THRESHOLD); EndTimeSlice();
timer1 += time1[T1];
time1[T1] = 0;
SensorType[COLOUR] = sensorNone;
while(SensorRaw[LIGHT] > THRESHOLD); EndTimeSlice();
timer2 += time1[T1];
}
nxtDisplayCenteredBigTextLine(0, "%d", timer1 / SAMPLES);
nxtDisplayCenteredBigTextLine(3, "%d", timer2 / SAMPLES);
while (true);
}
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: NXT 2.0 color sensor in lamp mode
Thanks for the tests. It appears to similar to the Lego FW speed, based on "about 1/3 of a second". I'll try to do a test sometime, and report back.
BTW, how do you get time measurements in exact milliseconds? I always do something like the following, which I know is not true milliseconds.
I know it is not an accurate way of doing it, but how do you use the internal timers so that it IS true milliseconds?
BTW, how do you get time measurements in exact milliseconds? I always do something like the following, which I know is not true milliseconds.
Code: Select all
until(SENSOR_1>500){
i++;
Wait(1);
}
//then I read the variable "i" to see how long it took.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: NXT 2.0 color sensor in lamp mode
In ROBOTC I have four ms timers, T1...T4 that I can access with time1[T1] to get 1ms, time10 to get 10ms and time100 to get 100ms accuracy, respectively. You reset them with a time1[T1] = 0 and then read them when you're done timing.
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC: NXT 2.0 color sensor in lamp mode
Ok. Is there anything like that in NXC?
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC: NXT 2.0 color sensor in lamp mode
Is there no way to get the current tick count?mattallen37 wrote:Ok. Is there anything like that in NXC?
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 323
- Joined: 29 Sep 2010, 05:03
Re: NXC: NXT 2.0 color sensor in lamp mode
Hi,
From looking at your test code it would seem that with RobotC the setting of the sensor mode is asynchronous )or at least might be). That is that after setting SensorType[COLOUR] then it may take some time before the light is turned on or off. Is this correct? If this is the case how in RobotC do you know when the sensor has finished setting things up? Could this be the cause of your timings for off being different? In leJOS the process is synchronous and after the method call has returned the sensor is in that mode (light on or off). So anyway running your test (or at least a Java version of it), on leJOS gives 180mS to either turn on or off in all modes...
Andy
From looking at your test code it would seem that with RobotC the setting of the sensor mode is asynchronous )or at least might be). That is that after setting SensorType[COLOUR] then it may take some time before the light is turned on or off. Is this correct? If this is the case how in RobotC do you know when the sensor has finished setting things up? Could this be the cause of your timings for off being different? In leJOS the process is synchronous and after the method call has returned the sensor is in that mode (light on or off). So anyway running your test (or at least a Java version of it), on leJOS gives 180mS to either turn on or off in all modes...
Andy
Re: NXC: NXT 2.0 color sensor in lamp mode
I don't know if it is asynchronous or not, that is why I didn't rely on the sensor itself to give me the info. I use the normal light sensor to check when the light turns on or off. I have no explanation for the weird time difference.
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Who is online
Users browsing this forum: Semrush [Bot] and 10 guests