ROBOTC.net forums
http://www.robotc.net/forums/

HT Color sensor: -> calibrating?
http://www.robotc.net/forums/viewtopic.php?f=41&t=926
Page 4 of 4

Author:  Ford Prefect [ Wed Jan 21, 2009 9:54 am ]
Post subject:  Re: HT Color sensor: -> calibrating?

today I received my new calibrated sensor back from Hitechnic's, they recalibrated it with a Lego program.
now pointing to a white sheet of paper it shows quite correctly
red=54
green=58
blue=62
color=17=white

It's really a mess that it's not been possible to have such a claibration tool from the RobotC Co.!!

Author:  tmr [ Wed Jan 21, 2009 11:04 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

Ford Prefect wrote:
today I received my new calibrated sensor back from Hitechnic's, they recalibrated it with a Lego program.
now pointing to a white sheet of paper it shows quite correctly
red=54
green=58
blue=62
color=17=white

It's really a mess that it's not been possible to have such a claibration tool from the RobotC Co.!!


Given the HiTechnic site doesn't provide the documentation for calibration I don't see why RobotC would provide a calibratin routine. It seems details had been provided at one point because folks have developed calibration programs for the sensor, but I wouldn't expect any official support for this until Hitechnic provides official documentation. Currently the Command byte used to switch to calibration mode is listed by HiTechnic as reserved for future use. One of these days I'll add this functionality for my sensor. It looks pretty straight forward. Here is a link with some sample code (not RobotC but shouldn't be difficult to translate): http://www.mindstorms.rwth-aachen.de/su ... ateColor.m

Author:  spaceballs [ Thu Jan 22, 2009 12:41 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

as Ford wrote above, Hitechnic actually provided the data for calibration, but nevertheless all attempts with RobotC calibration programs didn't work! E.g., you can read a program written by Mightor above, but unfortunately it didn't work (I was able to watch this as I visited Ford).

Hitechnic doesn't support RobotC, so I agree that it's wishful that the RobotC Company supports third party sensors like Hitechnic.

Author:  Ford Prefect [ Thu Jan 22, 2009 3:55 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

yes, correct.
the reason why RobotC calibration programs don't work, are incompatibilities of the RobotC I²C driver libraries and intrinsics with the Hitechnic and Lego standards - and it's not due to the calibration algorithm itself.

Author:  tmr [ Fri Jan 23, 2009 2:13 am ]
Post subject:  Re: HT Color sensor: -> calibrating?

Ford Prefect wrote:
yes, correct.
the reason why RobotC calibration programs don't work, are incompatibilities of the RobotC I²C driver libraries and intrinsics with the Hitechnic and Lego standards - and it's not due to the calibration algorithm itself.


Well for sure I don't know much about RobotC but couldn't the problem be with the sample code you're trying? Shouldn't the line

_data[1] = _link;

be

_data[1] = 0x02;

Here is my simple calibration routine

Code:
typedef struct
{
  byte nMsgSize;
  byte nDeviceAddress;
  byte nRegisterIndex;
  byte nData;
} TI2C_Output;

void CalibrateColorSensor(tSensors ColorSensor, int Mode)
{
  TI2C_Output sOutput;

  switch(Mode)
  {
    // white point calibration
    // sensor should be positioned about a half inch above a white surface
     case 1:
      sOutput.nData = 0x43; // white calibration
      break;

    // black point calibration
    // sensor should be pointed in a direction with no near objects
    case 2:
      sOutput.nData = 0x42; // black point calibration
      break;

    default:
      return;
  }
  sOutput.nMsgSize = 3;
  sOutput.nDeviceAddress = 0x02;
  sOutput.nRegisterIndex = 0x41;
  sendI2CMsg(ColorSensor, sOutput.nMsgSize, 0);
  return;
}


I haven't tested this yet as under my current lighting conditions my sensor reads a white as 17. I'm guessing you won't want to test it on yours either given its newly calibrated condition.

Author:  mightor [ Fri Jan 23, 2009 4:14 am ]
Post subject:  Re: HT Color sensor: -> calibrating?

You are right, setting the address to _link will definitely cause a failure :)

Xander

Author:  tmr [ Fri Jan 23, 2009 10:11 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

mightor wrote:
You are right, setting the address to _link will definitely cause a failure :)

Xander


Well someday I'll get up the gumption to test it out. I really didn't trust chalking this up to differences in standards and driver libraries.

Author:  starwarslegokid [ Sun Feb 08, 2009 3:37 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

Sorry guys, I still feel like your doing something wrong.....

Have you guys tried using other I2C buss settings other than HiTechnic Color? If you can find another buss setting that works, maybe the HiTechnic Color setting should have the same specs and you can let Dick know.

Id try I2C custom just to see, stay away from the fast ones. Cant hurt anything to try.

Scott B-)

Author:  Ford Prefect [ Sun Mar 08, 2009 9:49 am ]
Post subject:  Re: HT Color sensor: -> calibrating?

hi.
is there now a (tested) calibrating routine for RobotC or not?
(I woudn't like to uncalibrate my new enjusted sensor just for a test...)

Author:  mightor [ Sun Mar 08, 2009 10:02 am ]
Post subject:  Re: HT Color sensor: -> calibrating?

I have a program for it now :)

Usual charge applies, of course. I'll keep checking my bank statements. KKTHX

Regards,
Xander "I'm gonna be rich!!" Soldaat

Just kidding. This should do the trick for you :)

Just so you know I am working very hard on a driver suite that will include the following:
* ALL of the HiTechnic sensors, including their less frequently used functionality (like calibration)
* NXT Cam
* MAX127 ADC
* MCP23008

All of them will be heavily documented with examples. They all share common code to reduce size. Stay tuned!

For some reason I can't attach files to my posts, so I'll have to paste it in:
Code:
#pragma config(Sensor, S1,     HTCS_PORT,           sensorI2CCustomStd)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*
    Name: HTCS-calibrate.c
    Author: Xander Soldaat
    Date: 05/02/2009
    Version: 0.2
    Contact: mightor_at_gmail.com

    Address      Type      Contents
      00 - 07H   chars      Sensor version number
      08 - 0FH   chars      Manufacturer
      10 - 17H   chars      Sensor type
      18 - 3DH   bytes      Not used
      3E, 3FH      chars      Reserved
      40H            byte      Not used
      41H            byte      Reserved
      42H            byte      Color number
      43H            byte      Red reading
      44H            byte      Green reading
      45H            byte      Blue reading

    More information is available at www.hitechnic.com or by email at support@hitechnic.com
*/

byte cmdbuff[4];
byte reply[8];
byte _tmp;

task main() {

  while (nI2CBytesReady[HTCS_PORT] > 0)
    readI2CReply(HTCS_PORT, _tmp, 1);

  while(nI2CStatus[HTCS_PORT]== STAT_COMM_PENDING)
  wait1Msec(2);

  cmdbuff[0] = 2;                           // Number of bytes in I2C command
  cmdbuff[1] = 0x02;                        // I2C address of colour sensor
  cmdbuff[2] = 0x10;                        // Set write address to calibration register

  sendI2CMsg(HTCS_PORT, cmdbuff[0], 8);
  while(nI2CStatus[HTCS_PORT]== STAT_COMM_PENDING)
    wait1Msec(2);

  eraseDisplay();
  if (nI2CStatus[HTCS_PORT] != NO_ERR) {
    nxtDisplayTextLine(1, "ERROR: Couldn't");
    nxtDisplayTextLine(2, "talk to sensor.");
    nxtDisplayTextLine(4, "Check connection");
    nxtDisplayTextLine(5, "and try again.");
    PlaySound(soundException);
    while(bSoundActive);
    wait1Msec(5000);
    StopAllTasks();
  }

  readI2CReply(HTCS_PORT, reply[0], 8);

  cmdbuff[0] = 3;                           // Number of bytes in I2C command
  cmdbuff[1] = 0x02;                        // I2C address of colour sensor
  cmdbuff[2] = 0x41;                        // Set write address to calibration register
  cmdbuff[3] = 0x43;                        // The data to be written

  eraseDisplay();
  nxtDisplayTextLine(2, "Calibr. %s", reply);
  PlaySound(soundFastUpwardTones);
  while(bSoundActive);
  sendI2CMsg(HTCS_PORT, cmdbuff[0], 0);    // Send command to protoboard
  wait1Msec(1000);
  if (nI2CStatus[S1] == ERR_COMM_BUS_ERR) {
    nxtDisplayTextLine(1, "ERROR: Couldn't");
    nxtDisplayTextLine(2, "calibrate sensor.");
    nxtDisplayTextLine(4, "Check connection");
    nxtDisplayTextLine(5, "and try again.");
    PlaySound(soundException);
    while(bSoundActive);
    wait1Msec(5000);
    StopAllTasks();
  } else {
    nxtDisplayTextLine(4, "Done");
    PlaySound(soundBeepBeep);
    while(bSoundActive);
  }
  wait1Msec(1000);
}

Author:  mightor [ Tue Mar 10, 2009 1:05 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

I've tested this program with my own sensor and it works like a charm. Before calibration the readings tended towards the green. After I ran the program, the readings were perfect.

Regards,
Xander

Author:  Ford Prefect [ Tue Mar 10, 2009 3:29 pm ]
Post subject:  Re: HT Color sensor: -> calibrating?

fine, thank you! (since when have you got a color sensor? ;)
so I won't have to ship my sensor each time for calibrating to the U.S. any more. :P

what about Royalties from the R.C.C. and the H.T.C. for your program?

Page 4 of 4 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/