/*

ARIA header files for use with ARNL 1.7.1

Copyright(C) 2004, 2005 ActivMedia Robotics, LLC. 
Copyright(C) 2006, 2007, 2008, 2009 MobileRobots Inc.
All rights reserved.

This copy of Aria was relicensed for use with Arnl and the Arnl
license by MobileRobots Inc.  If you wish to download a seperate
distribution of Aria licensed under the GPL or a commercial license go to
http://www.mobilerobots.com/SOFTWARE/aria.html or contact MobileRobots
Inc, at robots@mobilerobots.com or MobileRobots Inc,
10 Columbia Drive, Amherst, NH 03031; 800-639-9481

MobileRobots Inc hereby grants to other individuals or
organizations permission to use this software with Arnl and in
compliance with the Arnl license.  This software may not be
distributed to others except by MobileRobots Inc.

MobileRobots Inc does not make any representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.

*/

#ifndef ARIRRFDEVICE_H
#define ARIRRFDEVICE_H

#include "ariaTypedefs.h"
#include "ArRangeDevice.h"
#include "ArFunctor.h"

#include "ArRobot.h"

/// A class for connecting to a PB-9 and managing the resulting data
/**
   This class is for use with a PB9 IR rangefinder.  It has the packethandler
   necessary to process the packets, and will put the data into ArRangeBuffers
   for use with obstacle avoidance, etc.

   The PB9 is still under development, and only works on an H8 controller
   running AROS.
*/

class ArIrrfDevice : public ArRangeDevice
{
public:
  /// Constructor
  AREXPORT ArIrrfDevice(size_t currentBufferSize = 91,
                        size_t cumulativeBufferSize = 273,
                        const char * name = "irrf");
  /// Destructor
  AREXPORT virtual ~ArIrrfDevice();

  /// The packet handler for use when connecting to an H8 micro-controller
  AREXPORT bool packetHandler(ArRobotPacket *packet);

  /// Maximum range for a reading to be added to the cumulative buffer (mm)
  AREXPORT void setCumulativeMaxRange(double r) { myCumulativeMaxRange = r; }
  AREXPORT virtual void setRobot(ArRobot *);

protected:
  ArRetFunctor1C<bool, ArIrrfDevice, ArRobotPacket *> myPacketHandler;
  ArTime myLastReading;
  AREXPORT void processReadings(void);
  double myCumulativeMaxRange;
  double myFilterNearDist;
  double myFilterFarDist;
  std::map<int, ArSensorReading *> myIrrfReadings;
};


#endif // ARIRRFDEVICE_H
