HT Color sensor: -> calibrating?
| Author |
Message |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 HT Color sensor: -> calibrating?
hi, I tried a little with the HT Color Sensor, using a sample prog which I changed I little. Testing the colors I found out that the returned green and red values always are too small, compared to blue, so the colors appear "bluish". e.g. The color "names " may be a little faulty, but at the white color you may see clearly, that the 3 color values are not identical as they should be. how can this be corrected by calibrating?  |  |  |  | Code: ////////////////////////////////////////////////////////////////////////////////////////// // // Hitechnic Color Sensor Example // ============================== // // This file is a small application program that tests the NXT Color Sensor from HiTechnic. // // The program: // 1. Configures sensor port 'S2' as a HiTechnic color sensor. // 2. Displays the current color components (red, green, blue) on the NXT LCD. // 3. Checks to see whether the current color matches one of two predefined colors. If so // a unique tone is played on the NXT speaker to indicate which of the two colors were // matched. // // This sample provides a good framework for easy cut and paste and // ////////////////////////////////////////////////////////////////////////////////////////// #pragma platform (NXT, FTC) const tSensors kColorSensorPort = S2; // We want the color sensor to be on port "S2" #include "AdvancedSensors.c" // // Get the colors from the sensor and display on the NXT LCD // int nRed; int nGreen; int nBlue; short nColor; string strColor;
void Color2String(short color, string &sbuf) { if (color==0) sbuf="black"; else if (color==1) sbuf="violet"; else if (color==2) sbuf="blue"; else if (color==3) sbuf="cyan"; else if (color==4) sbuf="green"; else if (color==5) sbuf="YeGreen"; else if (color==6) sbuf="yellow"; else if (color==7) sbuf="orange"; else if (color==8) sbuf="red"; else if (color==9) sbuf="magenta"; else if (color==10) sbuf="pink"; else if (color==11) sbuf="lViolet"; else if (color==12) sbuf="lCyan"; else if (color==13) sbuf="lYellow"; else if (color==14) sbuf="lOrange"; else if (color==15) sbuf="lRed"; else if (color==16) sbuf="lPink"; else if (color==17) sbuf="white"; }
task main() { long nCycles = 0; SensorType[kColorSensorPort] = sensorI2CHiTechnicColor; // Configure the sensor nxtDisplayTextLine(1, "Port: S%d", kColorSensorPort + 1); while (true) { getRGB(kColorSensorPort, nRed, nGreen, nBlue); nColor=SensorValue[kColorSensorPort]; Color2String(nColor,strColor); nxtDisplayTextLine(2, "Color:%3d %s", nColor, strColor); nxtDisplayTextLine(3, "Red: %3d", nRed); nxtDisplayTextLine(4, "Green:%3d", nGreen); nxtDisplayTextLine(5, "Blue: %3d", nBlue); // // Use utility routine to see if current color detected is close enough // to a specific target color. // // // To determine the color constants to match on, manually "watch" the output from the // color sensor and record the components of a target color. Edit the data below // // Adjust the "kRange" constant as appropriate to determine how close the target colors have to // be to detect a specific color. // const int kRedTarget1 = 20; const int kGreenTarget1 = 0; const int kBlueTarget1 = 0; const int kRedTarget2 = 52; const int kGreenTarget2 = 0; const int kBlueTarget2 = 0; const int kColorRange = 10; if (bColorMatched(kColorSensorPort, kRedTarget1, kGreenTarget1, kBlueTarget1, kColorRange)) PlayTone(400, 20); else if (bColorMatched(kColorSensorPort, kRedTarget2, kGreenTarget2, kBlueTarget2, kColorRange)) PlayTone(800, 20); else ClearSounds(); // Display the number of cycles on the LCD. It runs pretty fast. ++nCycles; nxtDisplayTextLine(7, "Cycles: %d", nCycles); } return; }
|  |  |  |  |
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Nov 14, 2008 2:37 pm |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
I tried to get support from Hitechnic, but unfortunately they don't support RobotC. Here is what they wrote: So this - again - is a support request specifically to the RobotC developers!
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Nov 28, 2008 1:05 pm |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
what a ****ing support!
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Wed Dec 10, 2008 1:45 pm |
|
 |
|
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 537
|
 Re: HT Color sensor: -> calibrating?
ROBOTC supports all of the features of the color sensor through I2C messaging. I would test out and see what I could do about the color sensor, except the three we have in our office no longer work for some reason.
NXT-G doesn't have some magical "calibration" tool. I would anticipate that it just sets the Normalized color values available here: 4DH byte Normalized red reading 4EH byte Normalized green reading 4FH byte Normalized blue reading
From our communication with HiTechnic in the past regarding the color sensor, they apparently have to be shipped back to HiTechnic to be "recalibrate". DickSwan might have more information regarding that.
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
| Fri Dec 12, 2008 10:11 am |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
I got additional information on this subject, but I don't understand how to write an I²C program because for me this is far too complicated and cumbersome to do in RobotC:
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Dec 12, 2008 10:33 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: HT Color sensor: -> calibrating?
Ford, I2C isn't all that cumbersome  I am sure I could cobble something together in a couple of minutes. I can't test it as I don't have one of these sensors. Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Dec 12, 2008 10:55 am |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
OT: Why isn't it possible to install just 2 easy-to-use macros like which don't need any of those two pages full of unintelligible code (except in a library or header file)?
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Dec 12, 2008 11:17 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: HT Color sensor: -> calibrating?
I have such a header file  Right now it only has two functions, but I think that having two functions like yours would be a pretty simple addition. I would change the order of the parameters somewhat to make it match the rest of my functions. After all, it's *my* header file  Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Dec 12, 2008 12:40 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: HT Color sensor: -> calibrating?
Here it is. It has only been compiled, not actually tested as I don't own a colour sensor. #include <std_warnings_and_disclaimers.h> Regards, Xander  |  |  |  | Code: #ifndef __I2C_H__ #define __I2C_H__
#define MAX_ARR_SIZE 16 typedef byte byte_array[MAX_ARR_SIZE];
void clearI2CBus(tSensors _link); void waitForI2CBus(tSensors _link); void writeI2Cvalue(tSensors _link, byte_array &_data, int _replylen); void readI2Cvalue(tSensors _link, byte_array &_data, int _replylen);
/* ============================================================================= Clear the I2C bus before we send new data.
*/ void clearI2CBus(tSensors _link) { ubyte _tmp = 0; while (nI2CBytesReady[_link] > 0) readI2CReply(_link, _tmp, 1); }
/* ============================================================================= We wait for the I2C bus to be ready for the next message or emit a loud annoying buzz sound if there's an error. Taken from RobotC example code and modified.
*/ void waitForI2CBus(tSensors _link) { byte _tmp = 0; TI2CStatus nStatus;
while (true) { nStatus = nI2CStatus[_link]; switch (nStatus) { case NO_ERR: return;
case STAT_COMM_PENDING: break;
case ERR_COMM_BUS_ERR: PlaySound(soundLowBuzz); while (bSoundActive) {} // clear out any old buffers. clearI2CBus(_link); return; } } }
void writeI2Cvalue(tSensors _link, byte_array &_data, int _replylen) { clearI2CBus(_link); waitForI2CBus(_link); sendI2CMsg(_link, _data[0], _replylen); waitForI2CBus(_link); }
void readI2Cvalue(tSensors _link, byte_array &_data, int _replylen) { readI2CReply(_link, _data[0], _replylen); waitForI2CBus(_link); }
#endif // __I2C_H__
|  |  |  |  |
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Dec 12, 2008 1:10 pm |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
Hi Xander, you're a genius! The good news: the program runs  Before Calibrating, pointing to a real white sheet of paper, the screen showed before: after running your calibration program, it currently showes: So unfortunately there is actually not a big improvement... It's not supposed to be your fault, I guess, I think it's the calibration routine itself - or the sensor is faulty! Or maybe Hitechnic is right and the faulty colors come from a wrong I²C speed. How can the I²C speed be set to the Lego standard?
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Dec 12, 2008 2:54 pm |
|
 |
|
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 537
|
 Re: HT Color sensor: -> calibrating?
You make the Macro definitions you want, and we'll include them in the next build.
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
| Fri Dec 12, 2008 3:04 pm |
|
 |
|
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 537
|
 Re: HT Color sensor: -> calibrating?
The "Low Speed" which is the NXT-G standard won't make a difference... but if you feel like trying it... I don't believe it's a 9V sensor, but if it is, you can use "sensorI2CCustom9V" as the type.
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
| Fri Dec 12, 2008 3:18 pm |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
I changed Xander's program to Surprisingly there's now a low tone (200 Hz?) for about 1 second, but the result stays the same:
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Dec 12, 2008 3:29 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: HT Color sensor: -> calibrating?
The low tone means there's an I2C error. Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Dec 12, 2008 4:03 pm |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 Re: HT Color sensor: -> calibrating?
ok, thx Xander, with your original code there was no tone though even the calibration didnt work  . @tfriez: This I unfortunately don't understand quite right, what shall I do, and what exactly will you do in the next build?
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Fri Dec 12, 2008 4:11 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|