NXT - light sensor blinking - to get rid of ambient light
Posted: 17 Oct 2017, 14:43
Hi,
I have a question related to NXT hardware and Bricx software.. With a line following robot there is a problem with changing ambient light which shifts the required setpoint. An obvious choice how to get rid of this is to blink with the LED in the light sensor and subtract the two readings (LED on and off) which should cancel out the ambient... Of course one can use some shield around the sensor, but it is not so nice...
I can blink with the LED at frequency of 500 Hz (measured by oscilloscope and probe with photodiode..) using following code:
while(TRUE){
SetSensorType(IN_1, IN_TYPE_LIGHT_INACTIVE);
Wait(1);
SetSensorType(IN_1, IN_TYPE_LIGHT_ACTIVE);
Wait(1);
}; //500Hz
With a different function the blinking is very slow:
while(TRUE){
SetSensorLight(IN_1, true);
Wait(1);
SetSensorLight(IN_1, false);
Wait(1);
}; //22.7Hz
But the problem appears when one needs to read the values from the sensor:
while(TRUE){
SetSensorType(IN_1, IN_TYPE_LIGHT_INACTIVE);
Wait(1);
A = SensorRaw(IN_1);
SetSensorType(IN_1, IN_TYPE_LIGHT_ACTIVE);
Wait(1);
B = SensorRaw(IN_1);
C = B-A;
}; //23.8Hz it can blink faster, but I get readings only for Wait >21ms, otherwise I get probably zeros (writing to LCD, or using motor functions as indicator)
This gives some meaningful results only for long Waits, which than vastly degrades the control loop speed...
Please is there another way how to use "modulated" light sensor at higher speed - like 100-200Hz?
I have not found anything on this topic "using google" for some reasonable time... which seems quite strange concerning the usefulness of the principle..
Thank you for any suggestion
Regards,
vp
I have a question related to NXT hardware and Bricx software.. With a line following robot there is a problem with changing ambient light which shifts the required setpoint. An obvious choice how to get rid of this is to blink with the LED in the light sensor and subtract the two readings (LED on and off) which should cancel out the ambient... Of course one can use some shield around the sensor, but it is not so nice...
I can blink with the LED at frequency of 500 Hz (measured by oscilloscope and probe with photodiode..) using following code:
while(TRUE){
SetSensorType(IN_1, IN_TYPE_LIGHT_INACTIVE);
Wait(1);
SetSensorType(IN_1, IN_TYPE_LIGHT_ACTIVE);
Wait(1);
}; //500Hz
With a different function the blinking is very slow:
while(TRUE){
SetSensorLight(IN_1, true);
Wait(1);
SetSensorLight(IN_1, false);
Wait(1);
}; //22.7Hz
But the problem appears when one needs to read the values from the sensor:
while(TRUE){
SetSensorType(IN_1, IN_TYPE_LIGHT_INACTIVE);
Wait(1);
A = SensorRaw(IN_1);
SetSensorType(IN_1, IN_TYPE_LIGHT_ACTIVE);
Wait(1);
B = SensorRaw(IN_1);
C = B-A;
}; //23.8Hz it can blink faster, but I get readings only for Wait >21ms, otherwise I get probably zeros (writing to LCD, or using motor functions as indicator)
This gives some meaningful results only for long Waits, which than vastly degrades the control loop speed...
Please is there another way how to use "modulated" light sensor at higher speed - like 100-200Hz?
I have not found anything on this topic "using google" for some reasonable time... which seems quite strange concerning the usefulness of the principle..
Thank you for any suggestion
Regards,
vp