Moderator

Thermopile code

Hi, I was just reading through the code, and cant seem to understand the following part in the sensor tab/section


long x_axis(void)// roll
{
return ((analog1 - 511l) * 9000l) / ir_max;
}

long y_axis(void)// pitch
{
return ((analog0 - 511l) * 9000l) / ir_max;

I basically get all of the other stuff about reading the thermopile's

I get that the analoge port reads a value between 1 and 1022 or something, and that 511 would imply horizontal.

But I don't understand where the multiplication of the number 90001 comes from.

I think i understand that the ir_max is for calibration or to make the readings more accurate, but is this by finding the maximum difference between ground and sky? Idealy using the z sensor when angle <10 deg


Thanks

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Moderator
    ahh, its an L and not a 1 :P Thanks for your replies. So if i am understanding correctly, you use the L at the end of a number to scale it to a long? instead of putting in all the place holders? or am I completely wrong? But to be honest I am not realy an expert in this so I think i may be wrong.

    I have been doing some more studing of the code, and once again don't quite understand this line.
    analog2 = ((float)analogRead(2) * 0.01) + ((float)analog2 * .99);
    why breaking it down into two float values, and not taking the reading from just one analogRead(2) ? I am guessing this is for some accuracy and rounding errors?

    I think if some-one could recommend a good book/ website that I can consult about programming micro controllers it would probably help as I can try work it out on my own instead of asking 100's of questions :P I have been working through all of the arduino.cc help on the site, but it doesnt always go into much detail about these technical things
  • Developer
    Hi Alex,

    That bit had me confused for a while because on my text editor the default font has like 1 pixel difference between l and 1. It can be very easy to confuse 90000l and 90001
  • Developer
    That's actually 9000 Long. 90 for degrees and *100 for accuracy. It's a way of doing integers instead of floats and it's how the output from the 406 GPS comes out.

    The ir_max is the maximum difference, say 200. If we are at 100 then we divide and multiply that times 90 to get 45°. I do it in this order to preserve accuracy in the calculation.

    Floats are great but for Lat and Long they aren't accurate enough on AVRs.
    for example the location -1223811835 is actually -122.3811835, but in AVR world the last two numbers 35 will get rounded off to who knows what. That's almost a 10 meter difference I believe.
This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…