Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArRangeDevice Class Reference

The class for all devices which return range info (laser, sonar). More...

#include <ArRangeDevice.h>

Inheritance diagram for ArRangeDevice:

ArBumpers ArForbiddenRangeDevice ArIrrfDevice ArIRs ArRangeDeviceThreaded ArSonarDevice ArSick List of all members.

Public Member Functions

virtual void addReading (double x, double y)
 Adds a reading to the buffer.
virtual void applyTransform (ArTransform trans, bool doCumulative=true)
 Applies a transform to the buffers.
 ArRangeDevice (size_t currentBufferSize, size_t cumulativeBufferSize, const char *name, unsigned int maxRange, int maxSecondsToKeepCurrent=0, int maxSecondsToKeepCumulative=0, double maxDistToKeepCumulative=0)
 Constructor.
virtual void clearCumulativeOlderThan (int milliSeconds)
 Clears all the cumulative readings older than this number of milliseconds.
virtual void clearCumulativeOlderThanSeconds (int seconds)
 Clears all the cumulative readings older than this number of seconds.
virtual void clearCumulativeReadings (void)
 Clears all the cumulative readings.
virtual void clearCurrentReadings (void)
 Clears all the current readings.
virtual double cumulativeReadingBox (double x1, double y1, double x2, double y2, ArPose *readingPos=NULL) const
 Gets the closest current reading from the given box region.
virtual double cumulativeReadingPolar (double startAngle, double endAngle, double *angle=NULL) const
 Gets the closest cumulative reading in the given polar region.
virtual double currentReadingBox (double x1, double y1, double x2, double y2, ArPose *readingPos=NULL) const
 Gets the closest current reading from the given box region.
virtual double currentReadingPolar (double startAngle, double endAngle, double *angle=NULL) const
 Gets the closest current reading in the given polar region.
virtual std::list< ArPoseWithTime * > * getCumulativeBuffer (void)
 Gets the current buffer of readings.
virtual const std::list< ArPoseWithTime * > * getCumulativeBuffer (void) const
 Gets the current buffer of readings.
virtual std::vector< ArPoseWithTime > * getCumulativeBufferAsVector (void)
 Gets the cumulative buffer of readings as a vector (for SWIG (python/java)).
virtual ArDrawingDatagetCumulativeDrawingData (void)
 Gets the data for drawing the cumulative buffer.
virtual ArRangeBuffergetCumulativeRangeBuffer (void)
 Gets the cumulative range buffer.
virtual const ArRangeBuffergetCumulativeRangeBuffer (void) const
 Gets the cumulative range buffer.
virtual std::list< ArPoseWithTime * > * getCurrentBuffer (void)
 Gets the current buffer of readings.
virtual const std::list< ArPoseWithTime * > * getCurrentBuffer (void) const
 Gets the current buffer of readings.
virtual std::vector< ArPoseWithTime > * getCurrentBufferAsVector (void)
 Gets the current buffer of readings as a vector (for SWIG (python/java)).
virtual ArDrawingDatagetCurrentDrawingData (void)
 Gets the data for drawing the current buffer.
virtual ArRangeBuffergetCurrentRangeBuffer (void)
 Gets the current range buffer.
virtual const ArRangeBuffergetCurrentRangeBuffer (void) const
 Gets the current range buffer.
double getMaxDistToKeepCumulative (void)
 sets the maximum distance cumulative readings can be from current pose
virtual unsigned int getMaxRange (void)
 Gets the maximum range for this device.
int getMaxSecondsToKeepCumulative (void)
 gets the maximum seconds to keep current readings around
int getMaxSecondsToKeepCurrent (void)
 gets the maximum seconds to keep current readings around
virtual const char * getName (void) const
 Gets the name of the device.
virtual const std::list< ArSensorReading * > * getRawReadings (void) const
 Gets the raw unfiltered readings from the device.
virtual std::vector< ArSensorReading > * getRawReadingsAsVector (void)
 Gets the raw unfiltered readings from the device into a vector for SWIG (python and java).
virtual ArRobotgetRobot (void)
 Gets the robot this device is attached to.
virtual int lockDevice ()
 Lock this device.
virtual void setCumulativeBufferSize (size_t size)
 Sets the size of the buffer for cumulative readings.
virtual void setCumulativeDrawingData (ArDrawingData *data, bool takeOwnershipOfData)
 Sets the data for drawing the cumulative buffer (and if we own it).
virtual void setCurrentBufferSize (size_t size)
 Sets the size of the buffer for current readings.
virtual void setCurrentDrawingData (ArDrawingData *data, bool takeOwnershipOfData)
 Sets the data for drawing the current buffer (and if we own it).
void setMaxDistToKeepCumulative (double maxDistToKeepCumulative)
 sets the maximum distance cumulative readings can be from current pose
virtual void setMaxRange (unsigned int maxRange)
 Sets the maximum range for this device.
void setMaxSecondsToKeepCumulative (int maxSecondsToKeepCumulative)
 gets the maximum seconds to keep cumulative readings around
void setMaxSecondsToKeepCurrent (int maxSecondsToKeepCurrent)
 gets the maximum seconds to keep current readings around
virtual void setRobot (ArRobot *robot)
 Sets the robot this device is attached to.
virtual int tryLockDevice ()
 Try to lock this device.
virtual int unlockDevice ()
 Unlock this device.
virtual ~ArRangeDevice ()
 Destructor.

Protected Member Functions

void filterCallback (void)

Protected Attributes

ArRangeBuffer myCumulativeBuffer
ArDrawingDatamyCumulativeDrawingData
ArRangeBuffer myCurrentBuffer
ArDrawingDatamyCurrentDrawingData
ArMutex myDeviceMutex
ArFunctorC< ArRangeDevicemyFilterCB
double myMaxDistToKeepCumulative
unsigned int myMaxRange
int myMaxSecondsToKeepCumulative
int myMaxSecondsToKeepCurrent
std::string myName
bool myOwnCumulativeDrawingData
bool myOwnCurrentDrawingData
std::list< ArSensorReading * > * myRawReadings
std::vector< ArSensorReadingmyRawReadingsVector
ArRobotmyRobot

Detailed Description

The class for all devices which return range info (laser, sonar).

This class has two buffers, a current buffer for storing just recent (relevant) readings, and a cumulative buffer for a longer history... the sizes of both can be set in the constructor.

This class should be used for all sensors like lasers and sonar, also note that it has the locking functions for such a time when there is a device like a laser that runs in its own thread, so that every device can be locked and unlocked and the users don't have to worry about the detail, because of functions on the ArRobot structure which check all of the ArRangeDevice s attached to a robot.

Definition at line 52 of file ArRangeDevice.h.


Constructor & Destructor Documentation

ArRangeDevice::ArRangeDevice size_t  currentBufferSize,
size_t  cumulativeBufferSize,
const char *  name,
unsigned int  maxRange,
int  maxSecondsToKeepCurrent = 0,
int  maxSecondsToKeepCumulative = 0,
double  maxDistToKeepCumulative = 0
 

Constructor.

Parameters:
currentBufferSize number of readings to store in the current buffer
cumulativeBufferSize number of readings to store in the cumulative buffer
name the name of this device
maxRange the max range of this device, if the device can't find a reading in a specified section, it returns this maxRange
maxSecondsToKeepCurrent this is the number of seconds to keep current readings around, if less than 0 then they are not automatically removed because of this
maxSecondsToKeepCumulative this is the number of seconds to keep cumulative readings around, if less than 0 then they are not automatically removed because of this
maxDistToKeepCumulative if cumulative readings are further than this from where the current pose they are removed, if this is less than 0 they are not removed because of this

Definition at line 55 of file ArRangeDevice.cpp.

References setMaxDistToKeepCumulative(), setMaxSecondsToKeepCumulative(), and setMaxSecondsToKeepCurrent().


Member Function Documentation

void ArRangeDevice::applyTransform ArTransform  trans,
bool  doCumulative = true
[virtual]
 

Applies a transform to the buffers.

Applies a transform to the buffers.. this is mostly useful for translating to/from local/global coords, but may have other uses

Parameters:
trans the transform to apply to the data
doCumulative whether to transform the cumulative buffer or not

Reimplemented in ArSick.

Definition at line 348 of file ArRangeDevice.cpp.

References ArRangeBuffer::applyTransform().

double ArRangeDevice::cumulativeReadingBox double  x1,
double  y1,
double  x2,
double  y2,
ArPose pose = NULL
const [virtual]
 

Gets the closest current reading from the given box region.

Gets the closest reading in a region defined by two points (opposeite points of a rectangle) out of the cumulative buffer.

Parameters:
x1 the x coordinate of one of the rectangle points
y1 the y coordinate of one of the rectangle points
x2 the x coordinate of the other rectangle point
y2 the y coordinate of the other rectangle point
readingPos a pointer to a position in which to store the location of the closest position
Returns:
if the return is >= 0 and <= maxRange then this is the distance to the closest reading, if it is >= maxRange, then there was no reading in the given section

Definition at line 325 of file ArRangeDevice.cpp.

References ArRangeBuffer::getClosestBox(), getName(), ArRobot::getPose(), ArLog::log(), and ArPose::setPose().

Referenced by ArRobot::checkRangeDevicesCumulativeBox().

double ArRangeDevice::cumulativeReadingPolar double  startAngle,
double  endAngle,
double *  angle = NULL
const [virtual]
 

Gets the closest cumulative reading in the given polar region.

Gets the closest reading in a region defined by startAngle going to endAngle... going counterclockwise (neg degrees to poseitive... with how the robot is set up, thats counterclockwise)... from -180 to 180... this means if you want the slice between 0 and 10 degrees, you must enter it as 0, 10, if you do 10, 0 you'll get the 350 degrees between 10 and 0... be especially careful with negative... for example -30 to -60 is everything from -30, around through 0, 90, and 180 back to -60... since -60 is actually to clockwise of -30

Parameters:
startAngle where to start the slice
endAngle where to end the slice, going clockwise from startAngle
position the position to find the closest reading to
angle a pointer return of the angle to the found reading
Returns:
if the return is >= 0 and <= maxRange then this is the distance to the closest reading, if it is >= maxRange, then there was no reading in the given section

Definition at line 265 of file ArRangeDevice.cpp.

References ArRangeBuffer::getClosestPolar(), getName(), ArRobot::getPose(), ArLog::log(), and ArPose::setPose().

Referenced by ArRobot::checkRangeDevicesCumulativePolar().

double ArRangeDevice::currentReadingBox double  x1,
double  y1,
double  x2,
double  y2,
ArPose pose = NULL
const [virtual]
 

Gets the closest current reading from the given box region.

Gets the closest reading in a region defined by two points (opposeite points of a rectangle) out of the current buffer.

Parameters:
x1 the x coordinate of one of the rectangle points
y1 the y coordinate of one of the rectangle points
x2 the x coordinate of the other rectangle point
y2 the y coordinate of the other rectangle point
readingPos a pointer to a position in which to store the location of the closest position
Returns:
if the return is >= 0 and <= maxRange then this is the distance to the closest reading, if it is >= maxRange, then there was no reading in the given section

Definition at line 296 of file ArRangeDevice.cpp.

References ArRangeBuffer::getClosestBox(), getName(), ArRobot::getPose(), ArLog::log(), and ArPose::setPose().

Referenced by ArRobot::checkRangeDevicesCurrentBox(), and ArActionTriangleDriveTo::findTriangle().

double ArRangeDevice::currentReadingPolar double  startAngle,
double  endAngle,
double *  angle = NULL
const [virtual]
 

Gets the closest current reading in the given polar region.

Gets the closest reading in a region defined by startAngle going to endAngle... going counterclockwise (neg degrees to poseitive... with how the robot is set up, thats counterclockwise)... from -180 to 180... this means if you want the slice between 0 and 10 degrees, you must enter it as 0, 10, if you do 10, 0 you'll get the 350 degrees between 10 and 0... be especially careful with negative... for example -30 to -60 is everything from -30, around through 0, 90, and 180 back to -60... since -60 is actually to clockwise of -30

Parameters:
startAngle where to start the slice
endAngle where to end the slice, going clockwise from startAngle
position the position to find the closest reading to
angle a pointer return of the angle to the found reading
Returns:
if the return is >= 0 and <= maxRange then this is the distance to the closest reading, if it is >= maxRange, then there was no reading in the given section

Definition at line 230 of file ArRangeDevice.cpp.

References ArRangeBuffer::getClosestPolar(), getName(), ArRobot::getPose(), ArLog::log(), and ArPose::setPose().

Referenced by ArRobot::checkRangeDevicesCurrentPolar().

double ArRangeDevice::getMaxDistToKeepCumulative void   )  [inline]
 

sets the maximum distance cumulative readings can be from current pose

Returns:
if cumulative readings are further than this from where the current pose they are removed, if this is less than 0 they are not removed because of this

Definition at line 198 of file ArRangeDevice.h.

Referenced by ArSick::getFilterCumulativeMaxDist().

int ArRangeDevice::getMaxSecondsToKeepCumulative void   )  [inline]
 

gets the maximum seconds to keep current readings around

Returns:
this is the number of seconds cumulative readings are kept around for, if less than 0 then they are not automatically removed because of this

Definition at line 180 of file ArRangeDevice.h.

Referenced by ArSick::getFilterCumulativeMaxAge().

int ArRangeDevice::getMaxSecondsToKeepCurrent void   )  [inline]
 

gets the maximum seconds to keep current readings around

Returns:
this is the number of seconds current readings are kept around for, if less than 0 then they are not automatically removed because of this

Definition at line 163 of file ArRangeDevice.h.

virtual const std::list<ArSensorReading *>* ArRangeDevice::getRawReadings void   )  const [inline, virtual]
 

Gets the raw unfiltered readings from the device.

The raw readings are the full set of unfiltered readings from the device, they are the latest reading, you should manipulate the list you get from this function, the only manipulation of this list should be done by the range device itself. Its only pointers for speed.

NOTE that only the lasers have this implemented at the moment (ie ArSick) this was added to the base class for future lasers and that things like the sonar and bumpers don't have this implemented. At some later date this may be implemented for the sonar but is really meant for lasers (since a laser is more straight forward should be interchangeable between lasers and all the readings come in at once as opposed to a sonar where they come in a few at a time and code that works with a laser (for line finding and what not) won't work at all with the sonar)

Definition at line 142 of file ArRangeDevice.h.

virtual int ArRangeDevice::lockDevice void   )  [inline, virtual]
 

Lock this device.

If you are also inheriting an ASyncTask you MUST override this to use the lock from the ArASyncTask

Reimplemented in ArRangeDeviceThreaded.

Definition at line 242 of file ArRangeDevice.h.

References ArMutex::lock().

Referenced by ArRobot::checkRangeDevicesCumulativeBox(), ArRobot::checkRangeDevicesCumulativePolar(), ArRobot::checkRangeDevicesCurrentBox(), ArRobot::checkRangeDevicesCurrentPolar(), ArSonarDevice::processReadings(), and ArForbiddenRangeDevice::processReadings().

void ArRangeDevice::setCumulativeBufferSize size_t  size  )  [virtual]
 

Sets the size of the buffer for cumulative readings.

If the new size is smaller than the current buffer it chops off the readings that are excess from the oldest readings... if the new size is larger then it just leaves room for the buffer to grow

Parameters:
size number of readings to set the buffer to

Definition at line 202 of file ArRangeDevice.cpp.

References ArRangeBuffer::setSize().

void ArRangeDevice::setCurrentBufferSize size_t  size  )  [virtual]
 

Sets the size of the buffer for current readings.

If the new size is smaller than the current buffer it chops off the readings that are excess from the oldest readings... if the new size is larger then it just leaves room for the buffer to grow

Parameters:
size number of readings to set the buffer to

Definition at line 191 of file ArRangeDevice.cpp.

References ArRangeBuffer::setSize().

void ArRangeDevice::setMaxDistToKeepCumulative double  maxDistToKeepCumulative  )  [inline]
 

sets the maximum distance cumulative readings can be from current pose

Parameters:
maxDistToKeepCumulative if cumulative readings are further than this from where the current pose they are removed, if this is less than 0 they are not removed because of this

Definition at line 189 of file ArRangeDevice.h.

Referenced by ArRangeDevice(), ArSonarDevice::ArSonarDevice(), ArSonarDevice::setCumulativeMaxRange(), and ArSick::setFilterCumulativeMaxDist().

void ArRangeDevice::setMaxSecondsToKeepCumulative int  maxSecondsToKeepCumulative  )  [inline]
 

gets the maximum seconds to keep cumulative readings around

Parameters:
maxSecondsToKeepCumulative this is the number of seconds to keep cumulative readings around, if less than 0 then they are not automatically removed because of this

Definition at line 172 of file ArRangeDevice.h.

Referenced by ArRangeDevice(), ArSonarDevice::ArSonarDevice(), and ArSick::setFilterCumulativeMaxAge().

void ArRangeDevice::setMaxSecondsToKeepCurrent int  maxSecondsToKeepCurrent  )  [inline]
 

gets the maximum seconds to keep current readings around

Parameters:
maxSecondsToKeepCurrent this is the number of seconds to keep current readings around, if less than 0 then they are not automatically removed because of this

Definition at line 154 of file ArRangeDevice.h.

Referenced by ArRangeDevice(), and ArSonarDevice::ArSonarDevice().

virtual int ArRangeDevice::tryLockDevice void   )  [inline, virtual]
 

Try to lock this device.

If you are also inheriting an ASyncTask you MUST override this to use the lock from the ArASyncTask

Reimplemented in ArRangeDeviceThreaded.

Definition at line 248 of file ArRangeDevice.h.

References ArMutex::tryLock().

virtual int ArRangeDevice::unlockDevice void   )  [inline, virtual]
 

Unlock this device.

If you are also inheriting an ASyncTask you MUST override this to use the lock from the ArASyncTask

Reimplemented in ArRangeDeviceThreaded.

Definition at line 254 of file ArRangeDevice.h.

References ArMutex::unlock().

Referenced by ArRobot::checkRangeDevicesCumulativeBox(), ArRobot::checkRangeDevicesCumulativePolar(), ArRobot::checkRangeDevicesCurrentBox(), ArRobot::checkRangeDevicesCurrentPolar(), ArSonarDevice::processReadings(), and ArForbiddenRangeDevice::processReadings().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:51 2005 for Aria by  doxygen 1.4.0