Author Topic: WebBot Lib and SRF08  (Read 2269 times)

0 Members and 1 Guest are viewing this topic.

Offline Max WebTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 1
WebBot Lib and SRF08
« on: May 19, 2012, 11:34:04 PM »
Hi,

I'm encountering yet another strange problem while using a Devantech SRF08 (firmware version 8 ) with WebBot Lib 2.09 (C version).
The upper code outputs the correct distance while the original version always outputs 0 (zero):

This is the code I am using:
Code: [Select]
//This part of the code works!
i2cMasterWriteRegister(&sonar.i2cInfo, 0, 0x51); // Send command to register 0

DISTANCE_TYPE val=4;
uint8_t response[4];
// Read registers 0,1,2,3
delay_ms(80);

if(!i2cMasterReadRegisters(&(sonar.i2cInfo), 0, 4, response)){
rprintf("Error reading SRF!\r\n");
}
while(i2cMasterReadRegisters(&(sonar.i2cInfo), 0, 4, response)){
if(response[0]!=255){
// Ranging has finished
val = response[2]; // get high byte
val = (val << 8) + response[3]; // put in low byte
break;
}
}

rprintf("sonar(CUSTOM): %u, %d, %d\r\n", val, val, sonar.i2cInfo.addr);
//But this part (library code) fails...
// -------- Start Devantech SRF08 sonar-------
// Read the Devantech SRF08 sonar and store the result in sonar.distance.cm
distanceRead(sonar);

// The value can be printed using %u eg rprintf("Distance=%u",sonar.distance.cm);
// or dumped using:
rprintf("sonar(LIB): ");
distanceDump(sonar);
rprintfCRLF();
// -------- End   Devantech SRF08 sonar-------

I believe that I found out which part of the library's code causes this problem (excerpt from 'SRF08.c'):

Code: [Select]
static void getReading(Devantech_SRF08* device){
if(device){
uint8_t response[4];
const I2C_DEVICE* i2c = &(device->i2cInfo);

// Read registers 0,1,2,3
while(i2cMasterReadRegisters(i2c, 0, sizeof(response), response)){ //I think it fails over here!
if(response[0]!=255){
// Ranging has finished
DISTANCE_TYPE val = response[2]; // get high byte
val = (val << 8) | response[3]; // put in low byte
device->distance.cm = val;
device->ldr = response[1]; // Store the light level
break;
}
}
}
}

Because the sensor works perfectly while using the upper code (with the delay included), I think it does not react to any I2C requests while it's measuring...
My SRF's firmware version is 8. Am I right with my suspicion or am I using the library in a wrong way? Is my sensor broken?
How could this issue be fixed in a better way than duplicating the SRF's code?

Regards,

Max Web
« Last Edit: May 19, 2012, 11:39:18 PM by Max Web »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: WebBot Lib and SRF08
« Reply #1 on: May 20, 2012, 12:25:19 PM »
Try replacing the SRF-08.c in WebbotLib with the attached.
Then re-compile WebbotLib, ie from a command prompt, change to the install directory and type 'make'.

Then rebuild your project and let me know if it fixes the problem.

As you can prbably tell - I don't own e3very sensor on earth so some drivers are just written based on what the spec sheet says. Sometimes they are a bit 'grey'.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Max WebTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 1
Re: WebBot Lib and SRF08
« Reply #2 on: May 20, 2012, 12:48:15 PM »
Hi,

the new file fixes the problem, the SRF08 works fine now - thanks!

This fix might also apply to the SRF02 - I don't possess one any more but their I2C interface is quite similar.

Regards,

Max Web

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: WebBot Lib and SRF08
« Reply #3 on: May 20, 2012, 01:06:22 PM »
+1 Help for being an educated guinea pig !
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list