• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

RangeFinder.cpp

Go to the documentation of this file.
00001 // -*- tab-width: 4; Mode: C++; c-basic-offset: 3; indent-tabs-mode: t -*-
00002 /*
00003         AP_RangeFinder.cpp - Arduino Library for Sharpe GP2Y0A02YK0F 
00004         infrared proximity sensor
00005         Code by Jose Julio and Randy Mackay. DIYDrones.com
00006 
00007         This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012         This has the basic functions that all RangeFinders need implemented
00013 */
00014 
00015 // AVR LibC Includes
00016 #include "WConstants.h"
00017 #include "RangeFinder.h"
00018 
00019 // Public Methods //////////////////////////////////////////////////////////////
00020 void RangeFinder::set_orientation(int x, int y, int z)
00021 {
00022     orientation_x = x; 
00023         orientation_y = y; 
00024         orientation_z = z;
00025 }
00026 
00027 // Protected Methods //////////////////////////////////////////////////////////
00028 int RangeFinder::filter(int latestValue)
00029 {
00030     int i;
00031     int total = 0;
00032     _history_ptr = (_history_ptr + 1) % AP_RANGEFINDER_NUM_AVERAGES;
00033     _history[_history_ptr] = latestValue;
00034         for(i=0; i<AP_RANGEFINDER_NUM_AVERAGES; i++ )
00035             total += _history[i];
00036     return total / AP_RANGEFINDER_NUM_AVERAGES;
00037 }

Generated for ArduPilot Libraries by doxygen