View unanswered posts | View active topics It is currently Thu Oct 23, 2014 8:54 am






Reply to topic  [ 13 posts ] 
thermal sensors / dexter industries 
Author Message
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post thermal sensors / dexter industries
I am currently having sporadic issue in invalid data from the port. Just by unplug and replug the sensor port revives the valid feedback.

We suspected that we should try to ensure all buffer used for the I2C calls are clear and do error checking before each send and read. That did not correct the issue.

Wonder if anyone has that experience. I wonder if there is a way to program it to simulate the unplug and replug. (not an elegant solution, but have yet found out how else)


Wed Apr 18, 2012 7:23 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: thermal sensors / dexter industries
Are you talking about the Thermal IR Sensor? What do you mean by "invalid data"? Be specific. More detailed information generally means better help.

The buffers on the NXT side are cleared before each I2C call, that is, if you are using my driver suite.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 20, 2012 1:50 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: thermal sensors / dexter industries
Sorry, yes, i should be clearer.. Posted that in a rush!
I wrote a test code which has logged the raw data.
e.g.
Valid Hi : 0x39 Lo: a0

Invalid Hi: 0x1b or 0x1c Lo: something (I am not too worried about as it will be factored out after the conversion.

To replicate the problem, you may need to try running this multiple times. Once you got the invalid number, just unplug and replug the port will resurrect the bits.

I wonder if there is a way to programmatically simulate the effect of unplug and replug the port, like cut off power to the port or somekind of reset!?

Code:
#define rdAmbient(s)  read_value(0x00,s)
#define rdEmiss(s)    read_value(0x03,s)
#define rdObject(s)   read_value(0x01,s)
#define isValid(c1, c2)  (((c1>= 10 && c1<=45) && (c2>=10 && c2<=45))? true : false)

#define LOGGING_ON
#define TS1  S1
#define TS2  S2


typedef struct
{
  int hi;
  int lo;
  int final;
} RAWTEMP;

RAWTEMP Temp[2];

bool seeVictim=false;

int Celcius1 = 0, Celcius2 = 0;
int Emissivity=8700;  // plastic dark green object

#ifdef LOGGING_ON
//============Log to temp.txt ==============================
task Logging()
{
  TFileHandle fp;
  TFileIOResult ret;
  string str;
  int size=9000, pts=0;
  const string fname = "temp.txt";

  PlaySound(soundFastUpwardTones);

  Delete(fname, ret);

  fp = 0;
  OpenWrite(fp, ret, fname, size);

  while (pts++ <900)
  {
    //    sprintf(str, "%d %d\n", Celcius1, Celcius2);
    //    WriteString(fp, ret, str);
    sprintf(str, "1:%x %x %d\n", Temp[0].hi, Temp[0].lo, Temp[0].final);
    sprintf(str, "2:%x %x %d\n", Temp[1].hi, Temp[1].lo, Temp[1].final);
    WriteString(fp, ret, str);
    wait1Msec(100);  // data collect interval
  }
  Close(fp, ret);
  PlaySound(soundBeepBeep);
  return;
}

#endif

//===========Thermal sensor functions==============================
// change the default emissivity level according to the surface that
//   you are trying to detect
void write_emissivity(long emis, tSensors sensor){
  ubyte I2Cmessage2[5];

  I2Cmessage2[0] = 4;         
  I2Cmessage2[1] = 0x0E;     
  I2Cmessage2[2] = 0x02;     
 
  I2Cmessage2[3] = (ubyte)(emis>>8);
  I2Cmessage2[4] = (ubyte)(emis&0xff);   


  sendI2CMsg(sensor, I2Cmessage2[0], 0); 
  wait1Msec(500);
}


int read_value(ubyte address, tSensors sensor){
  ubyte I2Cmessage[3];
  ubyte I2Creply[4];
  float ftempFactor = 0.02, ftempData=0.0;
  int itempData = 0;

  I2Cmessage[0] = 2;         
  I2Cmessage[1] = 0x0E;     
  I2Cmessage[2] = address;     

  wait1Msec(50);
  sendI2CMsg(sensor, I2Cmessage[0], 3);
  wait1Msec(50);
  memset(I2Creply, 0, 4);
  readI2CReply(sensor, I2Creply[0], 2); 

  // Convert to celsius value.

  if (sensor == TS1)
  {
    Temp[0].hi = I2Creply[1];
    Temp[0].lo = I2Creply[0];
    Temp[0].final = ((Temp[0].hi<<8)) | Temp[0].lo;
    itempData = Temp[0].final;
  }
  else
  {
    Temp[1].hi = I2Creply[1];
    Temp[1].lo = I2Creply[0];
    Temp[1].final = ((Temp[1].hi<<8)) | Temp[1].lo;
    itempData = Temp[1].final;
  }
 
  ftempData = ((float)itempData * ftempFactor) - 0.01;
  itempData = (int)(ftempData - 273.15);            // Convert from Kelvin to Celsius

  return itempData;
}


//==========test task =======================================
task  SimpleTemp()
{
  SensorType[TS1] = sensorI2CCustom9V;
  SensorType[TS2] = sensorI2CCustom9V;

  write_emissivity(Emissivity,TS1);    // reset the EEPROM value of the emissivity.
  wait1Msec(100);
  write_emissivity(Emissivity,TS2);                         

  while (true){
    Celcius1 =  rdObject(TS1);
    Celcius2 =  rdObject(TS2);
    if (!isValid(Celcius1, Celcius2))
    {
      nxtDisplayCenteredTextLine(0, "Invalid");
      nxtDisplayCenteredTextLine(1, "1: %x %x", Temp[0].hi, Temp[0].lo);
      nxtDisplayCenteredTextLine(2, "2: %x %x", Temp[1].hi, Temp[1].lo);
    }
    else
    {
      if (Celcius1 >= 30 || Celcius2 >= 30)  //target temperature: 30s & 40s
      {
        seeVictim = true;
      }
      else
        seeVictim = false;
    }
    nxtDisplayCenteredTextLine(4, "Temp: %d", Celcius1);
    nxtDisplayCenteredTextLine(5, "Temp: %d", Celcius2);
    wait1Msec(50);
  }
}

task main()
{
  StartTask(SimpleTemp);
  StartTask(Logging);
  wait1Msec(500);
  while (true)
  {
    if (seeVictim)
    {
      PlaySound(soundBeepBeep);
      while (bSoundActive)
        wait10Msec(10);
    }
  }
}


Fri Apr 20, 2012 6:00 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: thermal sensors / dexter industries
Have you tried your sensor with TIR-test1.c from the driver suite? Does it lock up with that program?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Apr 20, 2012 8:33 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: thermal sensors / dexter industries
Are you referring to the sample file from Dexter or one from your driver suites? I could not locate TIR-test1.c from your suite. Dexter's sample file named RobotC_TIR.c...

Yes, I used its test file first with 2 sensors. Same issue. Then, I rewrite it to add in the logging to see the hi an lo bits. Again, there is no issue with one single sensor, just when you have two of those.

So, if you use the code I provided, it does the same thing as the test file coming from Dexter, except I added in the structure to allow better data logging.


Sat Apr 21, 2012 8:23 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: thermal sensors / dexter industries
sorry, I found it... i came with robotc...

I noticed the only difference is that checks the link first. And Yes, I did that initially, and did not resolve the issue either. I did pretty the same thing as you did, wait for the link status no error... nI2CStatus[link] == NO_ERR. But then, it hosts on the wait for the valid link - simply does not return NO_ERR. (well, I put it in a while loop until it returns NO_ERR). That's why I removed it from my new sample code in order for me to at least log the bits to verify what it looks like.

Anyhow, I believe port 4 is on a different bus, isn't it? I'll try to put one on port 1 and another one port 4 if that's the case.


Sat Apr 21, 2012 8:26 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: thermal sensors / dexter industries
Elizabeth,

You should always download the latest driver suite from my site. The one shipped with ROBOTC is sometimes older. Check my signature for the link.

As for port 4 being on a different bus, that's true to a degree, since all ports are on a different bus. However, port 4 also has the ability to act as a high speed serial port using RS485. However, if you don't configure it for this purpose, it shouldn't affect you.

Which test file have you used? Mine or the one you downloaded from Dexter Industries?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Apr 22, 2012 2:00 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: thermal sensors / dexter industries
Hi Xander,

I have tried both the one Dexter and yours (the one comes with 3.04). Is there a way to get the latest driver without downloading the new 3.08. We have over 45 kids participating RobocupJunior. They all have been using 3.04. Therefore, we are yet at the stage to upgrade yet. Perhaps in the next week. However, I can get the driver without downloading the new 3.08, I can test that out in the next few days.

Meanwhile, my husband is playing with it thru an analyzer to see any anormaly when using 2 of them.
--Elizabeth Mabrey
--Storming Robots


Sun Apr 22, 2012 6:03 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: thermal sensors / dexter industries
Elizabeth,

ROBOTC is made by Robotics Academy, the driver suite is made by me. They are developed independently and the suite version shipped with ROBOTC is often not the most recent one. You don't need to download a new version of ROBOTC, other than the one you're using now, to use my latest version of the suite. Just download it from the link below.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Apr 22, 2012 6:32 am
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: thermal sensors / dexter industries
cool... I'll definitely try and keep you posted... probably after sometime coming week.


Sun Apr 22, 2012 9:42 pm
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: thermal sensors / dexter industries
Terminating a transaction with an I2C slave before it's complete can lock up the I2C communication on the slave. The necessity to unplug and plug back in (restarting the slave) is a definite symptom of this. Unfortunately, ROBOTC doesn't support the ability to run user-code at program exit. The best workaround I know of, is to do something like this:
Code:
task main(){
  while(true){
    if button pressed{
      exit program
    }
    read sensor
  }
}
Where the program will only exit when it's not talking with the slave. However, this will only work if you use the button interface to end the program. If you remote terminate the program, it obviously won't use the safeguard.

_________________
Matt


Mon Apr 23, 2012 4:50 pm
Profile WWW
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 138
Location: New Jersey
Post Re: thermal sensors / dexter industries
Xander,

Can the Thermal Infrared sensor's I2C slave address can be changed from 0x0E to another address?


Thu May 10, 2012 4:13 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: thermal sensors / dexter industries
Elizabeth,

Not that I am aware of, no. Is there a specific reason you want to change its address?

Edit: I have just re-read the datasheet and it seems you can set it to something else by writing to register 0x0E. See page 11 of http://www.melexis.com/Assets/IR-sensor ... -5152.aspx

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri May 11, 2012 3:30 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.