From bcd63a980796f04a82ed102b6c6b149e7914eaaf Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Sat, 14 Jan 2012 12:34:29 +0900 Subject: [PATCH] OpticalFlow - bug fix - highest resolution was incorrectly set as 1200 instead of 1600 --- .../AP_OpticalFlow/AP_OpticalFlow_ADNS3080.cpp | 13 +++++++++---- libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.h | 6 +++--- .../AP_OpticalFlow_test/AP_OpticalFlow_test.pde | 5 ++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.cpp b/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.cpp index 3ea0e60590..dfd6ae870e 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.cpp +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.cpp @@ -237,17 +237,17 @@ AP_OpticalFlow_ADNS3080::set_led_always_on( bool alwaysOn ) write_register(ADNS3080_CONFIGURATION_BITS, regVal); } -// returns resolution (either 400 or 1200 counts per inch) +// returns resolution (either 400 or 1600 counts per inch) int AP_OpticalFlow_ADNS3080::get_resolution() { if( (read_register(ADNS3080_CONFIGURATION_BITS) & 0x10) == 0 ) return 400; else - return 1200; + return 1600; } -// set parameter to 400 or 1200 counts per inch +// set parameter to 400 or 1600 counts per inch void AP_OpticalFlow_ADNS3080::set_resolution(int resolution) { @@ -255,12 +255,17 @@ AP_OpticalFlow_ADNS3080::set_resolution(int resolution) if( resolution == ADNS3080_RESOLUTION_400 ) { regVal &= ~0x10; - }else if( resolution == ADNS3080_RESOLUTION_1200) { + scaler = AP_OPTICALFLOW_ADNS3080_SCALER; + }else if( resolution == ADNS3080_RESOLUTION_1600) { regVal |= 0x10; + scaler = AP_OPTICALFLOW_ADNS3080_SCALER * 4; } delayMicroseconds(50); // small delay write_register(ADNS3080_CONFIGURATION_BITS, regVal); + + // this will affect conversion factors so update them + update_conversion_factors(); } // get_frame_rate_auto - return whether frame rate is set to "auto" or manual diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.h b/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.h index 79be9492ee..bd257c986f 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.h +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_ADNS3080.h @@ -77,7 +77,7 @@ #define ADNS3080_LED_MODE_WHEN_REQUIRED 0x01 #define ADNS3080_RESOLUTION_400 400 -#define ADNS3080_RESOLUTION_1200 1200 +#define ADNS3080_RESOLUTION_1600 1600 // Extended Configuration bits #define ADNS3080_SERIALNPU_OFF 0x02 @@ -118,8 +118,8 @@ class AP_OpticalFlow_ADNS3080 : public AP_OpticalFlow bool get_led_always_on(); // returns true if LED is always on, false if only on when required void set_led_always_on( bool alwaysOn ); // set parameter to true if you want LED always on, otherwise false for only when required - int get_resolution(); // returns resolution (either 400 or 1200 counts per inch) - void set_resolution(int resolution); // set parameter to 400 or 1200 counts per inch + int get_resolution(); // returns resolution (either 400 or 1600 counts per inch) + void set_resolution(int resolution); // set parameter to 400 or 1600 counts per inch bool get_frame_rate_auto(); // get_frame_rate_auto - return true if frame rate is set to "auto", false if manual void set_frame_rate_auto(bool auto_frame_rate); // set_frame_rate_auto(bool) - set frame rate to auto (true), or manual (false) diff --git a/libraries/AP_OpticalFlow/examples/AP_OpticalFlow_test/AP_OpticalFlow_test.pde b/libraries/AP_OpticalFlow/examples/AP_OpticalFlow_test/AP_OpticalFlow_test.pde index 197845c31f..fa369532ce 100644 --- a/libraries/AP_OpticalFlow/examples/AP_OpticalFlow_test/AP_OpticalFlow_test.pde +++ b/libraries/AP_OpticalFlow/examples/AP_OpticalFlow_test/AP_OpticalFlow_test.pde @@ -201,7 +201,7 @@ void set_resolution() Serial.print("resolution: "); Serial.println(resolution); Serial.println("Choose new value:"); - Serial.println(" 1) 1200"); + Serial.println(" 1) 1600"); Serial.println(" 4) 400"); Serial.println(" x) exit"); Serial.println(); @@ -215,10 +215,9 @@ void set_resolution() // update resolution if( value == '1' ) { - flowSensor.set_resolution(ADNS3080_RESOLUTION_1200); + flowSensor.set_resolution(ADNS3080_RESOLUTION_1600); } if( value == '4' ) { - Serial.println("you want 1200!"); flowSensor.set_resolution(ADNS3080_RESOLUTION_400); }