How to calibrate light sensor using nxc?
How to calibrate light sensor using nxc?
Hi, guys,
I want to calibrate my light sensor before using it, like the calibrate block in the NXT.
But I can't found similar method in the NXC.
Thanks for your help!
I want to calibrate my light sensor before using it, like the calibrate block in the NXT.
But I can't found similar method in the NXC.
Thanks for your help!
-
- Posts: 100
- Joined: 27 Dec 2010, 19:10
Re: How to calibrate light sensor using nxc?
Here's some ideas that may help. I build various race car and dancing robots that follow a black line on a
light surface. To account for various robot designs, and parts, and especially room lighting, I do a short
"calibration" routine at the start of each program. The attached file, Ty_Dncr_31_Line_Contrast_Discover.nxc,
has code for 2 tasks that run concurrently to measure the lightness and darkness of the dark line and the
light background. The first task, task line_wiper(), rotates the robot about 60 degrees, in either direction,
over the light and dark areas. The second task, task line_contrast_discover(), measures the light intensity,
the minimum and maximum, as the robot moves back and forth. (I got some of the ideas for this code from
the site <http://www.nxtprograms.com/>. This site shows NXT-G code, but the ideas are great.) I then calculate
the mid or average, and the range, and can use this in the main program as needed. I display the min, max,
mid, and range with the following code.
It takes some experimentation to determine how much to run the motor as the robots moves over the light and
dark, depending on whether your robot has wheels or treads, or whatever. Hope this helps.
light surface. To account for various robot designs, and parts, and especially room lighting, I do a short
"calibration" routine at the start of each program. The attached file, Ty_Dncr_31_Line_Contrast_Discover.nxc,
has code for 2 tasks that run concurrently to measure the lightness and darkness of the dark line and the
light background. The first task, task line_wiper(), rotates the robot about 60 degrees, in either direction,
over the light and dark areas. The second task, task line_contrast_discover(), measures the light intensity,
the minimum and maximum, as the robot moves back and forth. (I got some of the ideas for this code from
the site <http://www.nxtprograms.com/>. This site shows NXT-G code, but the ideas are great.) I then calculate
the mid or average, and the range, and can use this in the main program as needed. I display the min, max,
mid, and range with the following code.
Code: Select all
void display_light_min_max()
{
unsigned short Bat_Lev;
TextOut(0, LCD_LINE1, "Volts = ", DRAW_OPT_CLEAR_WHOLE_SCREEN);
Bat_Lev = BatteryLevel();
NumOut((6 * StrLen("Volts = ")), LCD_LINE1, Bat_Lev);
TextOut(0, LCD_LINE4, "Current = ");
NumOut((6 * StrLen("Current = ")), LCD_LINE4, current_reflected_light_intensity);
TextOut(0, LCD_LINE5, "lite_min = ");
NumOut((6 * StrLen("lite_min = ")), LCD_LINE5, reflected_light_min);
TextOut(0, LCD_LINE6, "lite_max = ");
NumOut((6 * StrLen("lite_max = ")), LCD_LINE6, reflected_light_max);
TextOut(0, LCD_LINE7, "lite_mid = ");
NumOut((6 * StrLen("lite_mid = ")), LCD_LINE7, reflected_light_mid);
TextOut(0, LCD_LINE8, "lite_range = ");
NumOut((6 * StrLen("lite_range = ")), LCD_LINE8, reflected_light_range);
} // End - function - display_light_min_max
dark, depending on whether your robot has wheels or treads, or whatever. Hope this helps.
- Attachments
-
- Ty_Dncr_31_Line_Contrast_Discover.nxc
- (4.99 KiB) Downloaded 288 times
Re: How to calibrate light sensor using nxc?
Thanks for your reply.
I should explain my question more clearly.
I can calibrate or recaculate the value of light senor by some method defined by myself.
But i want some nxc API to do it.
Like calibrate("SensorType", minRaw, maxRaw), and read the calibrated value by call normal Sensor(PORT).
In that way,don't need to known the calibating thing when you using Sensor(PORT). If you want calibration , just add a API to the top of code.
Any way, like NXT-G, just add a block to do it, nothing else need to change.
btw:
In your code, maybe uing SensorRaw insdead of SensorScale more efficacious.
Sometimes(depend on the lightness of environment mostly), the range of SensorScale will shrink, need calibrate to expand the range to 0~100 (or a bit less), to obtain more precision.
I should explain my question more clearly.
I can calibrate or recaculate the value of light senor by some method defined by myself.
But i want some nxc API to do it.
Like calibrate("SensorType", minRaw, maxRaw), and read the calibrated value by call normal Sensor(PORT).
In that way,don't need to known the calibating thing when you using Sensor(PORT). If you want calibration , just add a API to the top of code.
Any way, like NXT-G, just add a block to do it, nothing else need to change.
btw:
In your code, maybe uing SensorRaw insdead of SensorScale more efficacious.
Sometimes(depend on the lightness of environment mostly), the range of SensorScale will shrink, need calibrate to expand the range to 0~100 (or a bit less), to obtain more precision.
Re: How to calibrate light sensor using nxc?
hey,
as far as I know there is not such a calibration function.
I think you'd consider that NXC and NXT-G (or, e.g., Labview as well) are completely different in their functionality, the only common element is the sharable firmware base.
NXC does not claim to mimic NXT-G functions or procedures or blocks by it's API at all.
If any compatibility is largely aimed by NXC then it's the syntax rules of plain C.
So the bad news is: you must do lot of things by yourself.
But the good news is: you can do lot of things by yourself.
(John, CMIIW)
as far as I know there is not such a calibration function.
I think you'd consider that NXC and NXT-G (or, e.g., Labview as well) are completely different in their functionality, the only common element is the sharable firmware base.
NXC does not claim to mimic NXT-G functions or procedures or blocks by it's API at all.
If any compatibility is largely aimed by NXC then it's the syntax rules of plain C.
So the bad news is: you must do lot of things by yourself.
But the good news is: you can do lot of things by yourself.
(John, CMIIW)
-
- Posts: 100
- Joined: 27 Dec 2010, 19:10
Re: How to calibrate light sensor using nxc?
Thanks for the ideas about SensorRaw vs. SensorScale. I'll try it.
Re: How to calibrate light sensor using nxc?
If you post a zip containing an RXE file built using NXT-G that does nothing more than calibrate the light sensor, read the calibrated value, and show it on the screen before ending then I can convert it into an NXC function that does the same thing.
Whether that function will be made an official standard NXC API function or not is not certain but it might.
At the moment I am primarily focused on quietly adding support for the new LEGO MINDSTORMS EV3 in BricxCC. My plan is to have a firmware-targeting compiler integrated into BricxCC as well as to have support for launching GNU C/C++ and Free Pascal cross compilers from within BricxCC to build native executables.
John Hansen
Whether that function will be made an official standard NXC API function or not is not certain but it might.
At the moment I am primarily focused on quietly adding support for the new LEGO MINDSTORMS EV3 in BricxCC. My plan is to have a firmware-targeting compiler integrated into BricxCC as well as to have support for launching GNU C/C++ and Free Pascal cross compilers from within BricxCC to build native executables.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: How to calibrate light sensor using nxc?
Thanks everyone!
Here is the rxe and screen shot for the nxt-g.
I'm expecting EV3, especially NXC for EV3.
Did you known EV3 run with byte code for virtual machine or native binary on linux?
Here is the rxe and screen shot for the nxt-g.
I'm expecting EV3, especially NXC for EV3.
Did you known EV3 run with byte code for virtual machine or native binary on linux?
- Attachments
-
- Archive.zip
- rxe and screen shot
- (51.36 KiB) Downloaded 303 times
Re: How to calibrate light sensor using nxc?
The VM runs as a native application on Linux, but the code you compile with the EV3 Programming Environment is byte code. It's a lot faster than NXT-G, though.
= 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)
Re: How to calibrate light sensor using nxc?
Is that mean EV3 will be compatible with NXT at byte code level?
-
- Posts: 100
- Joined: 27 Dec 2010, 19:10
Re: How to calibrate light sensor using nxc?
John, Do you have any idea on a timetable, or a date you can publish, for 'EV3-NXC'? (I'm sure it willafanofosc wrote:At the moment I am primarily focused on quietly adding support for the new LEGO MINDSTORMS EV3
in BricxCC.
have a new name.) I'm debating whether to get an Education EV3 sooner or a retail unit when they ship. Don't worry, I
won't hold you to the date. (My manager used to double the times I gave him before publishing them.) Thanks.
Howard
Who is online
Users browsing this forum: No registered users and 4 guests