RAW to percentage/temperature

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RAW to percentage/temperature

Post by mattallen37 »

Where is it? I would like to see it, even though I don't know if I will get much from it.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: RAW to percentage/temperature

Post by gloomyandy »

You can download it from the Lego Mindstorms site...
http://mindstorms.lego.com/en-us/suppor ... x#Firmware

If you want to explore it make sure you use a good ide with good search tools to let you follow the code around (something like NetBeans or Eclipse, or if you are a command line sort of guy make sure you have grep etc. available)...

Andy
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: RAW to percentage/temperature

Post by gloomyandy »

Sorry, wrong link. The correct one is here...
http://mindstorms.lego.com/en-us/suppor ... x#Advanced
scroll the horizontal scrolling thing until you can choose "open source firmware" and download that!

Andy
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: RAW to percentage/temperature

Post by afanofosc »

Here's the important bit (from the enhanced NBC/NXC firmware which is slightly different than the standard firmware):

Code: Select all

      else if (sType == TEMPERATURE)
      {
        if (InputVal < 290)
          InputVal = 290;
        else if (InputVal > 928)
          InputVal = 928;
        InputVal = TempConvTable[(InputVal) - /*197*/ 290];
        InputVal = InputVal + 200;
        InputVal = (UWORD)(((SLONG)InputVal * (SLONG)1023)/(SLONG)900);
The TempConvTable is here:

Code: Select all


const     SWORD TempConvTable[] =
{
/* 1500,  1460,  1430,  1400,  1380,  1360,  1330,  1310,  1290,  1270,  1250,  1230,  1220,  1200,  1190,  1170,
   1160,  1150,  1140,  1130,  1110,  1100,  1090,  1080,  1070,  1060,  1050,  1040,  1030,  1020,  1010,  1000,
    994,   988,   982,   974,   968,   960,   954,   946,   940,   932,   926,   918,   912,   906,   900,   894,
    890,   884,   878,   874,   868,   864,   858,   854,   848,   844,   838,   832,   828,   822,   816,   812,
    808,   802,   798,   794,   790,   786,   782,   780,   776,   772,   768,   764,   762,   758,   754,   750,
    748,   744,   740,   736,   732,   730,   726,   722,   718,   716,   712,   708,   704,*/ 700,   696,   694,
    690,   688,   684,   682,   678,   674,   672,   668,   666,   662,   660,   656,   654,   650,   648,   644,
    642,   640,   638,   634,   632,   630,   628,   624,   622,   620,   616,   614,   612,   610,   608,   604,
    602,   600,   598,   596,   592,   590,   588,   586,   584,   582,   580,   578,   576,   574,   572,   570,
    568,   564,   562,   560,   558,   556,   554,   552,   550,   548,   546,   544,   542,   540,   538,   536,
    534,   532,   530,   528,   526,   524,   522,   520,   518,   516,   514,   512,   510,   508,   508,   506,
    504,   502,   500,   498,   496,   494,   494,   492,   490,   488,   486,   486,   484,   482,   480,   478,
    476,   476,   474,   472,   470,   468,   468,   466,   464,   462,   460,   458,   458,   456,   454,   452,
    450,   448,   448,   446,   444,   442,   442,   440,   438,   436,   436,   434,   432,   432,   430,   428,
    426,   426,   424,   422,   420,   420,   418,   416,   416,   414,   412,   410,   408,   408,   406,   404,
    404,   402,   400,   398,   398,   396,   394,   394,   392,   390,   390,   388,   386,   386,   384,   382,
    382,   380,   378,   378,   376,   374,   374,   372,   370,   370,   368,   366,   366,   364,   362,   362,
    360,   358,   358,   356,   354,   354,   352,   350,   350,   348,   348,   346,   344,   344,   342,   340,
    340,   338,   338,   336,   334,   334,   332,   332,   330,   328,   328,   326,   326,   324,   322,   322,
    320,   320,   318,   316,   316,   314,   314,   312,   310,   310,   308,   308,   306,   304,   304,   302,
    300,   300,   298,   298,   296,   296,   294,   292,   292,   290,   290,   288,   286,   286,   284,   284,
    282,   282,   280,   280,   278,   278,   276,   274,   274,   272,   272,   270,   270,   268,   268,   266,
    264,   264,   262,   262,   260,   260,   258,   258,   256,   254,   254,   252,   252,   250,   250,   248,
    248,   246,   244,   244,   242,   240,   240,   240,   238,   238,   236,   236,   234,   234,   232,   230,
    230,   228,   228,   226,   226,   224,   224,   222,   220,   220,   218,   218,   216,   216,   214,   214,
    212,   212,   210,   210,   208,   208,   206,   204,   204,   202,   202,   200,   200,   198,   198,   196,
    196,   194,   194,   192,   190,   190,   188,   188,   186,   186,   184,   184,   182,   182,   180,   180,
    178,   178,   176,   176,   174,   174,   172,   172,   170,   170,   168,   168,   166,   166,   164,   164,
    162,   162,   160,   160,   158,   156,   156,   154,   154,   152,   152,   150,   150,   148,   148,   146,
    146,   144,   144,   142,   142,   140,   140,   138,   136,   136,   136,   134,   134,   132,   130,   130,
    128,   128,   126,   126,   124,   124,   122,   122,   120,   120,   118,   118,   116,   116,   114,   114,
    112,   110,   110,   108,   108,   106,   106,   104,   104,   102,   102,   100,   100,    98,    98,    96,
     94,    94,    92,    92,    90,    90,    88,    88,    86,    86,    84,    82,    82,    80,    80,    78,
     78,    76,    76,    74,    74,    72,    72,    70,    70,    68,    68,    66,    66,    64,    62,    62,
     60,    60,    58,    56,    56,    54,    54,    52,    52,    50,    50,    48,    48,    46,    46,    44,
     44,    42,    40,    40,    38,    38,    36,    34,    34,    32,    32,    30,    30,    28,    28,    26,
     24,    24,    22,    22,    20,    20,    18,    16,    16,    14,    14,    12,    12,    10,    10,     8,
      6,     6,     4,     2,     2,     0,     0,    -2,    -4,    -4,    -6,    -6,    -8,   -10,   -10,   -12,
    -12,   -14,   -16,  - 16,   -18,   -20,   -20,   -22,   -22,   -24,   -26,   -26,   -28,   -30,   -30,   -32,
    -34,   -34,   -36,   -36,   -38,   -40,   -40,   -42,   -42,   -44,   -46,   -46,   -48,   -50,   -50,   -52,
    -54,   -54,   -56,   -58,   -58,   -60,   -60,   -62,   -64,   -66,   -66,   -68,   -70,   -70,   -72,   -74,
    -76,   -76,   -78,   -80,   -80,   -82,   -84,   -86,   -86,   -88,   -90,   -90,   -92,   -94,   -94,   -96,
    -98,   -98,  -100,  -102,  -104,  -106,  -106,  -108,  -110,  -112,  -114,  -114,  -116,  -118,  -120,  -120,
   -122,  -124,  -126,  -128,  -130,  -130,  -132,  -134,  -136,  -138,  -140,  -142,  -144,  -146,  -146,  -148,
   -150,  -152,  -154,  -156,  -158,  -160,  -162,  -164,  -166,  -166,  -168,  -170,  -172,  -174,  -176,  -178,
   -180,  -182,  -184,  -186,  -188,  -190,  -192,  -194,  -196,  -196,  -198,  -200/*,-202,  -204,  -206,  -208,
   -210,  -212,  -214,  -216,  -218,  -220,  -224,  -226,  -228,  -230,  -232,  -234,  -236,  -238,  -242,  -246,
   -248,  -250,  -254,  -256,  -260,  -262,  -264,  -268,  -270,  -274,  -276,  -278,  -282,  -284,  -286,  -290,
   -292,  -296,  -298,  -300,  -306,  -308,  -312,  -316,  -320,  -324,  -326,  -330,  -334,  -338,  -342,  -344,
   -348,  -354,  -358,  -362,  -366,  -370,  -376,  -380,  -384,  -388,  -394,  -398,  -404,  -410,  -416,  -420,
   -428,  -432,  -440,  -446,  -450,  -460,  -468,  -476,  -484,  -492,  -500,  -510,  -524,  -534,  -546,  -560,
   -572,  -588,  -600,  -630,  -656,  -684,  -720,  -770 */
};
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RAW to percentage/temperature

Post by mattallen37 »

Ok, thank you. Hopefully I will be able to learn from it.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: RAW to percentage/temperature

Post by nxtreme »

I hate to bump up old posts but I found something rather interesting that I thought you might want to know. While reading the Spanish Wikipedia entry for Lego Mindstorms (which, IMHO is way better than the numerous English entries) I came across a simple equation that supposedly calculates the temperature from the raw value. Keep in mind that I haven't tested this, the main reason being that I don't have a Legacy Temp sensor. I also remember finding an equation for raw-to-temp in the Extreme NXT book (second edition) but for some reason didn't bookmark it...

-Edit- Post 100! :lol:
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: RAW to percentage/temperature

Post by h-g-t »

The formula is on page 80 of the book.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: RAW to percentage/temperature

Post by nxtreme »

Or, page 82 in the second edition. Ok, I thought that equation was to calculate which thermistor would be best as far as similarity to the Legacy sensor. I thought I'd found a different, simpler, equation elsewhere in the book, I must be mistaken :shock:.
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RAW to percentage/temperature

Post by mattallen37 »

Thanks, I'll be sure to try it out. Just so you don't have to go looking, here are the formulas according to that page.

Code: Select all

Light = 146 − RAW / 7

Temp = (785 − RAW) / 8

if (RAW>450)              //touch = 1
Edited for accuracy.
Last edited by mattallen37 on 25 Jan 2011, 01:47, edited 1 time in total.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: RAW to percentage/temperature

Post by nxtreme »

I think that when you copied the Light equation over you might have missed some of it :oops:. Complete version below.

Code: Select all

Light = 146 − RAW / 7
-EDIT- Now I messed up! Copied over the Temperature equation instead of the Light equation :oops:.
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest