Package populus :: Module PerceptionSystem :: Class Sensor
[frames] | no frames]

Class Sensor


Sensor base class. A sensor is the mechanism used by an object to gather information about its surroundings. The field of perception is defined by means of a collection of percetion areas, which are space filters shaped like sphere sectors. A sensor can be attached to the object's geometry setting an attacher NodePath for it. The attacher will assign also a coordinate system to the sensor. Setting a mask for the sensor is a way of filtering perceptible objects by perceiving only perceptibles which have the same mask of the sensor. A sensor which has an owner, has been attached to a NodePath and has at least one perception area is a valid sensor and can be mounted. After mounting, the sensor starts gathering information about the its surroundings which can be retrieved any time.

Instance Methods
 
__init__(self, name='Sensor', owner=None, attachTo=None, mask=0)
 
__str__(self)
 
getName(self)
Return the sensor's name.
 
getOwner(self)
Return the sensor's owner, which is the object using the sensor.
 
getMask(self)
Return the sensor's perception filtering mask.
 
getMaxDistance(self)
Return the max distance reached amongst all the perception areas defined by the sensor.
 
getPerceptAreas(self)
Return a list of the perception areas defined by the sensor.
 
getArea(self, n)
Return the nth perception area.
 
setOwner(self, owner)
Set an owner for the sensor.
 
setMask(self, mask)
Set a perception filtering mask for the sensor.
 
attacherNodePath(self)
Return the NodePath where the sensor has been attached.
 
attachToNodePath(self, np)
Attach the sensor to a given NodePath.
 
on(self)
Switch on the sensor.
 
off(self)
Switch off the sensor.
 
notifyOnEnter(self, event)
Ask the sensor to notify with an event when a new object enters the sensor area.
 
notifyOnExit(self, event)
Ask the sensor to notify with an event when an object exits the sensor area.
 
isOn(self)
Tells if the sensor is switched on.
 
isOff(self)
Tells if the sensor is switched off.
 
isValid(self)
Tells if the sensor is valid and can be mounted and used.
 
isMounted(self)
Tells if the sensor has been succesfully mounted.
 
addPerceptArea(self, name, distance=10.0, angularExtension=360.0, aimingDirection=(0, 1, 0), color=(1, 0, 0, 1))
Add a perception area to the sensor.The area is a sphere sector where distance is the sphere's radius and angularExtension is the angle between then sector's edges.
 
mount(self)
Request to mount the sensor at Perception System.
 
flush(self)
Clean up the Sensors perceptual buffers and cache the old percepts.
 
perceive(self, beacon)
Try to perceive a given beacon.
 
retrievePercepts(self)
Return a dictionary of the percepts, that is the set of the objects perceived by the sensor.
 
retrievePerceptsFromArea(self, n)
Return a dictionary of the percepts gather by the nth percetion area.
 
redefinePerceptArea(self, n, distance=None, angularExtension=None, aimingDirection=None)
Redefine the internal parameters of a given sensor's perception area.
 
toggleVis(self)
Toggle visibility of all the sensor's perception areas.
 
show(self)
Show all the perception areas of this sensor.
 
hide(self)
Hide all the perception areas of this sensor.
Method Details

setOwner(self, owner)

 

Set an owner for the sensor. The owner is the object using the sensor.

addPerceptArea(self, name, distance=10.0, angularExtension=360.0, aimingDirection=(0, 1, 0), color=(1, 0, 0, 1))

 

Add a perception area to the sensor.The area is a sphere sector where distance is the sphere's radius and angularExtension is the angle between then sector's edges. aiming is pointing direction of the area and color is the color of its annotation.

mount(self)

 

Request to mount the sensor at Perception System. Its is forbiden to mount an invalid sensor.

perceive(self, beacon)

 

Try to perceive a given beacon. A beacon reveal the presence of a potential source of stimuli and is attached to a parent object. If the beacon's mask is equal to the sensor mask and there is at least one perception area where the beacon falls into, then the beacon is perceived and a reference to the parent object is saved in the area's buffer.

NOTE: in the current implementation a beacon is a simple PhysX shape belonging to the PERCEPTIBLE group.

retrievePercepts(self)

 

Return a dictionary of the percepts, that is the set of the objects perceived by the sensor. The set is defined as the union between the buffers of each perception areas. Duplicates are not allowed.