From 9eb889d30d07345de9f7d8f41240c94cb24c4638 Mon Sep 17 00:00:00 2001 From: "rmackay9@yahoo.com" Date: Thu, 23 Dec 2010 01:23:10 +0000 Subject: [PATCH] AP_RangeFinder - added support for MaxsonarLV and corrected some descriptions and links for the other rangefinders git-svn-id: https://arducopter.googlecode.com/svn/trunk@1234 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/AP_RangeFinder/AP_RangeFinder.h | 1 + .../AP_RangeFinder_MaxsonarLV.cpp | 67 +++++++++++++++++++ .../AP_RangeFinder_MaxsonarLV.h | 15 +++++ .../AP_RangeFinder_MaxsonarXL.cpp | 6 +- .../AP_RangeFinder_SharpGP2Y.cpp | 2 +- .../AP_RangeFinder_test.pde | 3 +- libraries/AP_RangeFinder/keywords.txt | 1 + 7 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 libraries/AP_RangeFinder/AP_RangeFinder_MaxsonarLV.cpp create mode 100644 libraries/AP_RangeFinder/AP_RangeFinder_MaxsonarLV.h diff --git a/libraries/AP_RangeFinder/AP_RangeFinder.h b/libraries/AP_RangeFinder/AP_RangeFinder.h index 0f1da2fc08..e578b8ccb2 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder.h @@ -5,3 +5,4 @@ #include "AP_RangeFinder_SharpGP2Y.h" #include "AP_RangeFinder_MaxsonarXL.h" +#include "AP_RangeFinder_MaxsonarLV.h" diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_MaxsonarLV.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_MaxsonarLV.cpp new file mode 100644 index 0000000000..d873d20442 --- /dev/null +++ b/libraries/AP_RangeFinder/AP_RangeFinder_MaxsonarLV.cpp @@ -0,0 +1,67 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 3; indent-tabs-mode: t -*- +/* + AP_RangeFinder_MaxsonarLV.cpp - Arduino Library for Maxbotix's LV-MaxSonar + Sonic proximity sensor + Code by Jose Julio and Randy Mackay. DIYDrones.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Sparkfun URL: http://www.sparkfun.com/products/8502 + datasheet: http://www.maxbotix.com/uploads/LV-MaxSonar-EZ0-Datasheet.pdf + + Sensor should be connected to one of the analog ports + + Variables: + int raw_value : raw value from the sensor + int distance : distance in cm + int max_distance : maximum measurable distance (in cm) + int min_distance : minimum measurable distance (in cm) + + Methods: + init(int analogPort) : Initialization of sensor + read() : read value from analog port and returns the distance (in cm) + +*/ + +// AVR LibC Includes +#include "WConstants.h" +#include "AP_RangeFinder_MaxsonarLV.h" + +// Public Methods ////////////////////////////////////////////////////////////// +void AP_RangeFinder_MaxsonarLV::init(int analogPort) +{ + // local variables + int i; + + // set the given analog port to an input + pinMode(analogPort, INPUT); + + // initialise everything + _analogPort = analogPort; + max_distance = AP_RANGEFINDER_MAXSONARLV_MAX_DISTANCE; + min_distance = AP_RANGEFINDER_MAXSONARLV_MIN_DISTANCE; + + // make first call to read to get initial distance + read(); + + // initialise history + for( i=0; i