Page 2 of 4
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 19:34
by mightor
Matt,
I will run some tests with ROBOTC now, will let you know how it goes.
- Xander
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 19:44
by mattallen37
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
Hmm, ok. Sometime I might run a test with the Lego FW (enhanced).
mightor wrote:Matt,
I will run some tests with ROBOTC now, will let you know how it goes.
- Xander
Ok, thanks.
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 20:09
by afanofosc
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
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 20:11
by mightor
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.
- IMAG0153.jpg (281.99 KiB) Viewed 7685 times
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
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:
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);
}
Edit: The sensor is set to BLUE here, I just tweaked for each run.
- Xander
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 20:48
by mattallen37
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.
Code: Select all
until(SENSOR_1>500){
i++;
Wait(1);
}
//then I read the variable "i" to see how long it took.
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?
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 20:52
by mightor
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
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 03 Jan 2011, 21:08
by mattallen37
Ok. Is there anything like that in NXC?
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 04 Jan 2011, 04:30
by mightor
mattallen37 wrote:Ok. Is there anything like that in NXC?
Is there no way to get the current tick count?
- Xander
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 04 Jan 2011, 12:59
by gloomyandy
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
Re: NXC: NXT 2.0 color sensor in lamp mode
Posted: 04 Jan 2011, 16:15
by mightor
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