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

ArRangeDevice Class Reference

#include <ArRangeDevice.h>

Inheritance diagram for ArRangeDevice:

ArBumpers ArForbiddenRangeDevice ArIrrfDevice ArIRs ArLaserReflectorDevice ArRangeDeviceThreaded ArSonarDevice ArLaser ArLaserFilter ArLMS1XX ArLMS2xx ArSimulatedLaser ArUrg List of all members.

Detailed Description

The base class for all sensing devices which return range information from the device (mounted on a robot) to an object in the environment.

This class maintains two ArRangeBuffer objects: a current buffer for storing very recent readings, and a cumulative buffer for a longer history of readings. The maximum sizes of each buffer can be set in the constructor or resized later. Range device readings are most often represented as a point in space (X,Y) where the sensor detected an object. (Therefore an ArPose object may only have X and Y components set). Some devices provide extra information in a "raw" buffer, or in lists of more detailed ArSensoReading objects.

Subclasses are used for specific sensor implementations like ArSick for SICK lasers and ArSonarDevice for the Pioneer sonar array. It can also be useful to treat "virtual" objects like forbidden areas specified by the user in a map like range devices. Some of these subsclasses may use a separate thread to update the range reading buffers, and so this base class provides "lock" and "unlock" methods which you should use when accessing device data.

A range device may have an ArRobot object associated with it. A range device may also be associated with an ArRobot by calling ArRobot::addRangeDevice(). ArRobot provides functions which operate on all such associated ArRangeDevice objects. This is a convenient (and thread-safe) way to access all range device data without depending on a specific set of individual range devices. For example, you can find the closest reading in a box or a polar section, no matter if that reading originated from the sonar, a laser, or other device.

Examples:

actionExample.cpp.


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, bool locationDependent=false)
 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 const std::list< ArSensorReading * > * getAdjustedRawReadings (void) const
 Gets the raw unfiltered readings from the device (but pose takens are corrected).
virtual std::vector< ArSensorReading > * getAdjustedRawReadingsAsVector (void)
 Gets the raw adjusted readings from the device into a vector.
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.
virtual ArDrawingDatagetCumulativeDrawingData (void)
 Gets data used for visualizing the cumulative buffer (see ArNetworking).
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.
virtual ArDrawingDatagetCurrentDrawingData (void)
 Gets data used for visualizing the current buffer (see ArNetworking).
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
double getMaxInsertDistCumulative (void)
 Gets the maximum distance a cumulative reading can be from the robot and still be inserted.
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
double getMinDistBetweenCumulative (void)
 Gets the minimum distance between cumulative readings.
double getMinDistBetweenCurrent (void)
 Gets the minimum distance between current readings.
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.
virtual ArRobotgetRobot (void)
 Gets the robot this device is attached to.
bool isLocationDependent (void)
 Gets if this device is location dependent or not.
virtual int lockDevice ()
 Lock this device.
virtual void setCumulativeBufferSize (size_t size)
 Sets the maximum size of the buffer for cumulative readings.
virtual void setCumulativeDrawingData (ArDrawingData *data, bool takeOwnershipOfData)
 Sets data for visualizing the cumulative buffer (and if we own it).
virtual void setCurrentBufferSize (size_t size)
 Sets the maximum size of the buffer for current readings.
virtual void setCurrentDrawingData (ArDrawingData *data, bool takeOwnershipOfData)
 Sets data for visualizing the current buffer (and if we own it).
void setMaxDistToKeepCumulative (double maxDistToKeepCumulative)
 sets the maximum distance cumulative readings can be from current pose
void setMaxInsertDistCumulative (double maxInsertDistCumulative)
 Sets the maximum distance a cumulative reading can be from the robot and still be inserted.
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)
 Sets the maximum seconds to keep current readings around.
void setMinDistBetweenCumulative (double minDistBetweenCumulative)
 Sets the minimum distance between cumulative readings.
void setMinDistBetweenCurrent (double minDistBetweenCurrent)
 Sets the minimum distance between current readings.
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 adjustRawReadings (bool interlaced)
void filterCallback (void)

Protected Attributes

std::list< ArSensorReading * > * myAdjustedRawReadings
std::vector< ArSensorReadingmyAdjustedRawReadingsVector
ArRangeBuffer myCumulativeBuffer
ArDrawingDatamyCumulativeDrawingData
ArRangeBuffer myCurrentBuffer
ArDrawingDatamyCurrentDrawingData
ArMutex myDeviceMutex
ArFunctorC< ArRangeDevicemyFilterCB
bool myIsLocationDependent
double myMaxDistToKeepCumulative
double myMaxDistToKeepCumulativeSquared
double myMaxInsertDistCumulative
ArPose myMaxInsertDistCumulativePose
double myMaxInsertDistCumulativeSquared
unsigned int myMaxRange
int myMaxSecondsToKeepCumulative
int myMaxSecondsToKeepCurrent
double myMinDistBetweenCumulative
double myMinDistBetweenCumulativeSquared
double myMinDistBetweenCurrent
double myMinDistBetweenCurrentSquared
std::string myName
bool myOwnCumulativeDrawingData
bool myOwnCurrentDrawingData
std::list< ArSensorReading * > * myRawReadings
std::vector< ArSensorReadingmyRawReadingsVector
ArRobotmyRobot


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,
bool  locationDependent = false
 

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 maximum 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 in the current buffer. If less than 0, then readings are not automatically removed based on time (but can be replaced or removed for other reasons).
maxSecondsToKeepCumulative this is the number of seconds to keep cumulative readings in the cumulative buffer. If less than 0 then readings are not automatically based on time (but can be replaced or removed for other reasons).
maxDistToKeepCumulative if cumulative readings are further than this distance from the current robot pose, then they are removed. If this is less than 0 they are not removed because of this
locationDependent if the data in this range device is dependent on the robot's location or not... For instance, a laser would not be dependent on location, because it'll be correct in a relative manner, whereas forbidden lines are dependent on location, because if the robot isn't where it thinks it is then the forbidden lines will be avoided in the wrong spots... this is mainly just a flag for other things to use when deciding what range devices to avoid
planar if the range device is planar or not... planar range devices are ones like the Sick LMS200 that are only in one plane and and are all measured from a single point... Where you can use the beams of the current reading to filter out any cumulative readings that are close to the beam... these range devices need to simply build a set of raw readings and then call 'planarProcessReadings' for this filtering to work


Member Function Documentation

void ArRangeDevice::adjustRawReadings bool  interlaced  )  [protected]
 

This call should be called by the range device every robot cycle before the range device makes new readings (and even if it isn't adding any that cycle)... it will adjust the raw readings by the robot odometry offset. The robot should be locked when this happens (which should be the case if you're doing it in the robot callback). The code currently assumes that all readings were taken at the same point, so if that isn't true with your device then you can't use this mechanism.

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

Applies a transform to the buffers.

Applies a coordinate transformation to some or all buffers. This is mostly useful for translating to/from local/global coordinate systems, 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 ArLaser.

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.

Get the closest reading in the cumulative buffer within a rectangular region around the range device, defined by two points (opposeite points of a rectangle).

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
pose a pointer to an ArPose object in which to store the location of the closest position
Returns:
The range to the reading from the device, or a value >= maxRange if no reading was found in the box.

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

Gets the closest cumulative reading in the given polar region.

The closest reading in this range device's cumulative buffer within a polar region or "slice" defined by the given angle range is returned. Optionally return the specific angle of the found reading as well. The region searched is the region between a starting angle, sweeping counter-clockwise to the ending angle (0 is straight ahead of the device, -90 to the right, 90 to the left). Note that there is a difference between the region (0, 10) and (10, 0). (0, 10) is a 10-degree span near the front of the device, while (10, 0) is a 350 degree span covering the sides and rear. Similarly, (-60, -30) covers 30 degrees on the right hand side, while (-30, -60) covers 330 degrees. In other words, if you want the smallest section between the two angles, ensure than startAngle < endAngle.

Parameters:
startAngle where to start the slice
endAngle where to end the slice, going counterclockwise from startAngle
angle if given, a pointer to a value in which to put the specific angle to the found reading
Returns:
the range to the obstacle (a value >= the maximum range indicates that no reading was detected in the specified region)
Example:
ArRangeDevice_currentReadingPolar.png

This figure illustrates an example range device and the meanings of arguments and return value.

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.

Get the closest reading in the current buffer within a rectangular region defined by two points (opposite corners of the rectangle).

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
pose a pointer to an ArPose object in which to store the location of the closest position
Returns:
The range to the reading from the device, or a value >= maxRange if no reading was found in the box.

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

Gets the closest current reading in the given polar region.

The closest reading within a polar region or "slice" defined by the given angle range is returned. Optionally, the specific angle of the found may be placed in angle, if not NULL. The region searched is the region between startAngle, sweeping counter-clockwise to endAngle (0 is straight ahead of the device, -90 to the right, 90 to the left). Note that therefore there is a difference between e.g. the regions (0, 10) and (10, 0). (0, 10) is a 10-degree span near the front of the device, while (10, 0) is a 350 degree span covering the sides and rear. Similarly, (-60, -30) covers 30 degrees on the right hand side, while (-30, -60) covers 330 degrees. (-90, 90) is 180 degrees in front. (-180, 180) covers all sides of the robot. In other words, if you want the smallest section between the two angles, ensure that startAngle < endAngle.

Parameters:
startAngle where to start the slice
endAngle where to end the slice, going counterclockwise from startAngle
angle if given, a pointer to a value in which to put the specific angle to the found reading
Returns:
the range to the obstacle (a value >= the maximum range indicates that no reading was detected in the specified region)
Example:
ArRangeDevice_currentReadingPolar.png

This figure illustrates an example range device and the meanings of arguments and return value.

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

Gets the raw unfiltered readings from the device (but pose takens are corrected).

The raw readings are the full set of unfiltered readings from the device. They are the latest readings. You should not 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.)

This is like the raw readings but they were corrected for the robot odometry offset (just the pose taken, and encoder psoe taken).

Note:
Only ArSick provides this data currently. Sonar, bumpers, etc. do not provide raw readings. This method was added to this base class for future lasers or other similar devices. Other kinds of range devices are sufficiently different from lasers that any "raw" information provided would usually require very different interpretation.

std::vector< ArSensorReading > * ArRangeDevice::getAdjustedRawReadingsAsVector void   )  [virtual]
 

Gets the raw adjusted readings from the device into a vector.

Copies the list into a vector.

Java and Python Wrappers: The return type will be named ArSensorReadingVector instead of the std::vector template type.

virtual const std::list<ArPoseWithTime *>* ArRangeDevice::getCumulativeBuffer void   )  const [inline, virtual]
 

Gets the current buffer of readings.

Java and Python Wrappers: Not available in Java or Python wrapper libraries. See getCumulativeBufferAsVector()

virtual std::vector<ArPoseWithTime>* ArRangeDevice::getCumulativeBufferAsVector void   )  [inline, virtual]
 

Gets the cumulative buffer of readings as a vector.

Java and Python Wrappers: The return type will be named ArPoseWithTimeVector instead of the std::vector template.

virtual const ArRangeBuffer* ArRangeDevice::getCumulativeRangeBuffer void   )  const [inline, virtual]
 

Gets the cumulative range buffer.

Java and Python Wrappers: Not available in Java or Python wrapper libraries. See getCumulativeBufferAsVector()

virtual const std::list<ArPoseWithTime *>* ArRangeDevice::getCurrentBuffer void   )  const [inline, virtual]
 

Gets the current buffer of readings.

Java and Python Wrappers: Not available in Java or Python wrapper libraries. See getCurrentBufferAsVector()

virtual std::vector<ArPoseWithTime>* ArRangeDevice::getCurrentBufferAsVector void   )  [inline, virtual]
 

Gets the current buffer of readings as a vector.

Java and Python Wrappers: The return type will be named ArPoseWithTimeVector instead of the std::vector template.

virtual const ArRangeBuffer* ArRangeDevice::getCurrentRangeBuffer void   )  const [inline, virtual]
 

Gets the current range buffer.

Java and Python Wrappers: Not available in Java or Python wrapper libraries. See getCurrentBufferAsVector()

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

double ArRangeDevice::getMaxInsertDistCumulative void   )  [inline]
 

Gets the maximum distance a cumulative reading can be from the robot and still be inserted.

Returns:
The maximum distance a cumulative reading can have from the robot's current position and still be inserted into the cumulative readings, this is applied in the addReading call so range devices need to call that for this to take effect.

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

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

double ArRangeDevice::getMinDistBetweenCumulative void   )  [inline]
 

Gets the minimum distance between cumulative readings.

Returns:
The minimum distance between cumulative readings, this is applied in the addReading call so range devices need to call that for this to take effect.

double ArRangeDevice::getMinDistBetweenCurrent void   )  [inline]
 

Gets the minimum distance between current readings.

Returns:
The minimum distance between current readings, this is applied in the addReading call so range devices need to call that for this to take effect.

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 readings. You should not 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:
Only ArSick provides this data currently. Sonar, bumpers, etc. do not provide raw readings. This method was added to this base class for future lasers or other similar devices. Other kinds of range devices are sufficiently different from lasers that any "raw" information provided would usually require very different interpretation.

std::vector< ArSensorReading > * ArRangeDevice::getRawReadingsAsVector void   )  [virtual]
 

Gets the raw unfiltered readings from the device into a vector.

Copies the list into a vector.

Java and Python Wrappers: The return type will be named ArSensorReadingVector instead of the std::vector template type.

void ArRangeDevice::setCumulativeBufferSize size_t  size  )  [virtual]
 

Sets the maximum size of the buffer for cumulative readings.

If the size is smaller than the cumulative buffer size, then the oldest readings are discarded, leaving only size newest readings. If size is larger than the cumulative buffer size, then the buffer size will be allowed to grow to that size as new readings are added.

Parameters:
size number of readings to set the buffer to

Reimplemented in ArLaser.

void ArRangeDevice::setCurrentBufferSize size_t  size  )  [virtual]
 

Sets the maximum size of the buffer for current readings.

If the size is smaller than the current buffer size, then the oldest readings are discarded, leaving only size newest readings. If size is larger than the current size, then the buffer size will be allowed to grow to that size as new readings are added.

Parameters:
size number of readings to set the buffer's maximum size to

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

void ArRangeDevice::setMaxInsertDistCumulative double  maxInsertDistCumulative  )  [inline]
 

Sets the maximum distance a cumulative reading can be from the robot and still be inserted.

Parameters:
maxInsertDistCumulative The maximum distance a cumulative reading can have from the robot's current position and still be inserted into the cumulative readings, this is applied in the addReading call so range devices need to call that for this to take effect.

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

void ArRangeDevice::setMaxSecondsToKeepCurrent int  maxSecondsToKeepCurrent  )  [inline]
 

Sets 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

void ArRangeDevice::setMinDistBetweenCumulative double  minDistBetweenCumulative  )  [inline]
 

Sets the minimum distance between cumulative readings.

Parameters:
minDistBetweenCumulative The minimum distance between cumulative readings, this is applied in the addReading call so range devices need to call that for this to take effect.

void ArRangeDevice::setMinDistBetweenCurrent double  minDistBetweenCurrent  )  [inline]
 

Sets the minimum distance between current readings.

Parameters:
minDistBetweenCurrent The minimum distance between current readings, this is applied in the addReading call so range devices need to call that for this to take effect.


The documentation for this class was generated from the following files:
Generated on Thu Jan 7 10:34:43 2010 for Aria by  doxygen 1.4.2