Calibration

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
cyragia
Posts: 8
Joined: 11 Jan 2012, 12:57

Calibration

Post by cyragia »

Hello,
I have a robot which uses 2 light sensors (from lego).
I use NXT-G to program the robot.

The problem is that the 2 sensors don't give the same values (raw) at the same colors.
In NXT-G you can only calibrate 1 sensor and the other one is calibrated with the same scheme.
As my sensors are different the second sensor is wrongly calibrated, so i can't use it properly.

Does someone know a way to calibrate the 2 sensors independent ? Or another solution ?
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Calibration

Post by mattallen37 »

One way would be to use offsets from the values. Find the offset to the color with the highest RAW reading, and add that offset to the RAW reading. Do this for both sensors. If they still don't match up (if they aren't linear), you can scale the readings instead, but that would take a lot more math (which isn't all that easy in NXT-G).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
cyragia
Posts: 8
Joined: 11 Jan 2012, 12:57

Re: Calibration

Post by cyragia »

that's the problem; they're not linear and like you say math is pretty hard to do in NXT-G. :cry:
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Calibration

Post by mattallen37 »

Okay then, just for the sake of argument, lets say the ranges are 1000-500 for sensor 1, and 900 - 550 for sensor 2 (highest to lowest readings). You want them to both be on the same scale (eg 100-0).

Here is my NXC function for scaling numbers:

Code: Select all

//Scales a range of numbers to a new range.
//Input value, lowest possible, highest possible, scale from this, to this. It returns the result.
float ScaleRange(float Value, float ValueMin, float ValueMax, float DesiredMin, float DesiredMax)
{
  return (DesiredMax - DesiredMin) * (Value - ValueMin) / (ValueMax - ValueMin) + DesiredMin;
}
So to put actual numbers in for your case, it would be something like this:

Code: Select all

(100-0)*(sensor - 500)/(1000-500)+0 //for sensor 1
(100-0)*(sensor - 550)/(900-550)+0  //for sensor 2
Or to simplify it:

Code: Select all

100 * (sensor - 500) / (1000 - 500) //for sensor 1
100 * (sensor - 550) / (900 - 550)  //for sensor 2
This is probably the closest you will get to making the values the same. Due to part tolerance and such, it could take an extreme amount of work to match the values perfectly.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
cyragia
Posts: 8
Joined: 11 Jan 2012, 12:57

Re: Calibration

Post by cyragia »

Thanks ! :D
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests