OpticalFlow - add check to see if sensor has initialised correctly.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@2974 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
rmackay9@yahoo.com 2011-07-31 04:31:36 +00:00
parent bcc7bed491
commit f096d8cb23
2 changed files with 14 additions and 4 deletions

View File

@ -51,6 +51,8 @@ AP_OpticalFlow_ADNS3080::AP_OpticalFlow_ADNS3080()
bool bool
AP_OpticalFlow_ADNS3080::init(bool initCommAPI) AP_OpticalFlow_ADNS3080::init(bool initCommAPI)
{ {
int retry = 0;
pinMode(AP_SPI_DATAOUT,OUTPUT); pinMode(AP_SPI_DATAOUT,OUTPUT);
pinMode(AP_SPI_DATAIN,INPUT); pinMode(AP_SPI_DATAIN,INPUT);
pinMode(AP_SPI_CLOCK,OUTPUT); pinMode(AP_SPI_CLOCK,OUTPUT);
@ -65,10 +67,16 @@ AP_OpticalFlow_ADNS3080::init(bool initCommAPI)
// start the SPI library: // start the SPI library:
if( initCommAPI ) { if( initCommAPI ) {
SPI.begin(); SPI.begin();
//SPI.setBitOrder(MSBFIRST);
//SPI.setDataMode(SPI_MODE3);
//SPI.setClockDivider(SPI_CLOCK_DIV8); // sensor running at 2Mhz. this is it's maximum speed
} }
// check the sensor is functioning
if( retry < 3 ) {
if( read_register(ADNS3080_PRODUCT_ID) == 0x17 )
return true;
else
retry++;
}else
return false;
} }
// //

View File

@ -16,7 +16,9 @@ void setup()
delay(1000); delay(1000);
flowSensor.init(); // flowSensor initialization // flowSensor initialization
if( flowSensor.init() == false )
Serial.println("Failed to initialise ADNS3080");
flowSensor.set_orientation(AP_OPTICALFLOW_ADNS3080_PINS_FORWARD); flowSensor.set_orientation(AP_OPTICALFLOW_ADNS3080_PINS_FORWARD);
flowSensor.set_field_of_view(AP_OPTICALFLOW_ADNS3080_12_FOV); flowSensor.set_field_of_view(AP_OPTICALFLOW_ADNS3080_12_FOV);