AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
agxSensor::Environment Class Reference

Sensor environment implementation where different sensors collects data given a set of added objects, such as rigid bodies, geometries, shapes, wires, cables, terrains, etc. More...

#include <Environment.h>

+ Inheritance diagram for agxSensor::Environment:

Public Member Functions

 Environment ()
 Default constructor - the default sensor systems will be added.
 
virtual ~Environment ()
 Destructor.
 
bool add (agx::RigidBody *rb)
 Add rigid body to be visible to sensors in this sensor environment.
 
bool add (agxCollide::Geometry *geometry)
 Add geometry to be visible to sensors in this sensor environment.
 
bool add (agxCollide::Shape *shape)
 Add shape to be visible to sensors in this sensor environment.
 
bool add (agxModel::DeformableObject *deformable)
 Add deformable object to be visible to sensors in this sensor environment.
 
bool add (agxSDK::LinkedStructure *linkedStructure)
 Add agxCable::Cable, agxVehicle::Track, agxModel::Beam, ..., to be visible to sensors in this sensor environment.
 
bool add (agxTerrain::Terrain *terrain)
 Add terrain to be visible to sensors in this sensor environment.
 
bool add (agxTerrain::TerrainPager *pager)
 Add terrain pager to be visible to sensors in this sensor environment.
 
bool add (agxWire::Wire *wire)
 Add wire to be visible to sensors in this sensor environment.
 
bool add (SystemNode *system)
 Add system root node (normally an implementation of a sensor) to this sensor environment.
 
MagneticFieldgetMagneticField ()
 
const MagneticFieldgetMagneticField () const
 
RtSceneRef getScene () const
 
bool remove (agx::RigidBody *rb)
 Remove the rigid body, and all its geometries, from this sensor environment.
 
bool remove (agxCollide::Geometry *geometry)
 Remove geometry, and all its shapes, from this sensor environment.
 
bool remove (agxCollide::Shape *shape)
 Remove shape from this sensor environment.
 
bool remove (agxModel::DeformableObject *deformable)
 Remove deformable object from this sensor environment.
 
bool remove (agxSDK::LinkedStructure *linkedStructure)
 Remove linked structure (agxCable::Cable, agxVehicle::Track, agxModel::Beam, ...) from this sensor environment.
 
bool remove (agxTerrain::Terrain *terrain)
 Remove terrain from this sensor environment.
 
bool remove (agxTerrain::TerrainPager *pager)
 Remove terrain pager from this sensor environment.
 
bool remove (agxWire::Wire *wire)
 Remove wire from this sensor environment.
 
bool remove (SystemNode *system)
 Remove system root node (sensor) from this sensor environment.
 
void setMagneticField (MagneticField *magneticField)
 Set environment magnetic field.
 
- Public Member Functions inherited from agxSDK::ISensorEnvironment
 ISensorEnvironment ()=default
 Default constructor.
 
virtual ~ISensorEnvironment ()=default
 Destructor.
 
virtual void addNotification ()=0
 Called when added to a simulation or explicitly called when the sensor simulation should start.
 
virtual void fetchStepResults ()=0
 Block main thread until the sensor simulation is done and the data/results/outputs are accessible.
 
const SimulationgetSimulation () const
 
virtual void removeNotification ()=0
 Called when removed from a simulation or explicitly called when the sensor simulation should stop/join the main thread.
 
virtual void step (agx::Real dt)=0
 Start the sensor simulation and step for delta time dt.
 
virtual void updateGraphics (const agxRender::RenderManager &renderManager)=0
 Update the graphical components of the sensor environment.
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor.
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting.
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match.
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test.
 
Referencedoperator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object.
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 
- Public Member Functions inherited from agxStream::Serializable
virtual ~Serializable ()
 Destructor for normal C++ use but hidden from SWIG bindings.
 
virtual const char * getClassName () const
 
bool getEnableSerialization () const
 
bool getEnableUuidGeneration ()
 
agx::UInt32 getIndex () const
 This index is given at creation of this object.
 
virtual StorageAgent * getStorageAgent () const =0
 
agx::Uuid getUuid () const
 
bool isFinished () const
 
void setEnableSerialization (bool flag)
 Set to false to disable serialization of this object.
 
void setFinished ()
 Tells this class that it is restored correctly and should not be deleted during destruction of an Archive.
 
void setUuid (const agx::Uuid &uuid)
 Explicitly set a Uuid on a serializable object.
 

Static Public Member Functions

static Environmentget (agxSDK::Simulation *simulation)
 
static const Environmentget (const agxSDK::Simulation *simulation)
 
static EnvironmentgetOrCreate (agxSDK::Simulation *simulation)
 Returns an existing or creates and initializes a new instance of a sensor environment given a simulation.
 
- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- Static Public Member Functions inherited from agxStream::Serializable
static void setEnableUuidGeneration (bool flag)
 Specify if there should be UUID:s generated for each new Serializable object. By default it is enabled.
 

Additional Inherited Members

- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor.
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
- Protected Member Functions inherited from agxStream::Serializable
 Serializable ()
 Default constructor.
 
 Serializable (const Serializable &other)
 Copy constructor.
 
void generateUuid ()
 
- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandlergetDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

Sensor environment implementation where different sensors collects data given a set of added objects, such as rigid bodies, geometries, shapes, wires, cables, terrains, etc.

This sensor environment can be run in cooperative mode with an agxSDK::Simulation instance (normal use case) or standalone and is always integrated in its own thread.

In cooperative mode, the stepping/integration of the sensor environment starts after the simulation step event 'preCollide'. New/updated sensor data is available from the simulation step event 'post'. This means that any changes, such as updated transforms or configuration changes, has to be made before calling simulation 'stepForward' or in a 'preCollide' step event.

Important: When the sensor environment is integrated in its own thread it's undefined to interact with sensors and/or adding removing objects during the collision detection, contact event callbacks, pre step events and dynamics solvers integrations. Data access and object/sensor modifications are safe to do in post step events, post contact events, last step events and outside of 'stepForward'.

To create or access a sensor simulation using agxSDK::Simulation, do:

Cooperative: agxSensor::Environment* sensorEnv = agxSensor::Environment::getOrCreate( simulation ); simulation->stepForward(); // Will step the sensor environment.

OR (also cooperative) agxSensor::EnvironmentRef sensorEnv = new agxSensor::Environment(); simulation->setSensorEnvironment( sensorEnv ); simulation->stepForward(); // Will step the sensor environment.

Standalone: agxSensor::EnvironmentRef sensorEnv = new agxSensor::Environment(); sensorEnv->addNotification(); // Important, will create a separate thread that the sensor environment is integrated in. while ( !done ) { sensorEnv->step( 0.0166667 ); // Read data from added objects and start the sensor environment simulation step - in the thread created in addNotification. ... // Do other things. sensorEnv->fetchStepResults(); // Blocking until the sensor environment has been integrated and new sensor output data is available. }

Definition at line 112 of file agxSensor/Environment.h.

Constructor & Destructor Documentation

◆ Environment()

agxSensor::Environment::Environment ( )

Default constructor - the default sensor systems will be added.

◆ ~Environment()

virtual agxSensor::Environment::~Environment ( )
virtual

Destructor.

Member Function Documentation

◆ add() [1/9]

bool agxSensor::Environment::add ( agx::RigidBody rb)

Add rigid body to be visible to sensors in this sensor environment.

All geometries (and shapes) of the given rigid body will also be added and visible to sensors. If added successfully, a reference to the rigid body will be held until the rigid body is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
rb- rigid body instance (and its geometries) to add
Returns
true if the rigid body is successfully added, otherwise false

◆ add() [2/9]

bool agxSensor::Environment::add ( agxCollide::Geometry geometry)

Add geometry to be visible to sensors in this sensor environment.

All shapes of the given geometry will also be added and visible to sensors. If added successfully, a reference to the geometry will be held until the geometry is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
geometry- geometry instance (and its shapes) to add
Returns
true if the geometry is successfully added, otherwise false

◆ add() [3/9]

bool agxSensor::Environment::add ( agxCollide::Shape shape)

Add shape to be visible to sensors in this sensor environment.

If added successfully, a reference to the shape will be held until the shape is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
shape- shape instance to add
Returns
true if the shape is successfully added, otherwise false

◆ add() [4/9]

bool agxSensor::Environment::add ( agxModel::DeformableObject deformable)

Add deformable object to be visible to sensors in this sensor environment.

If added successfully, a reference to the deformable will be held until the deformable is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
deformable- deformable instance to add
Returns
true if the deformable is successfully added, otherwise false

◆ add() [5/9]

bool agxSensor::Environment::add ( agxSDK::LinkedStructure linkedStructure)

Add agxCable::Cable, agxVehicle::Track, agxModel::Beam, ..., to be visible to sensors in this sensor environment.

The wheels (agxVehicle::TrackWheel) of agxVehicle::Track instances are added as separate rigid bodies during this call, but can be removed separately if they shouldn't be visible to sensors, e.g., sensorEnv->remove( wheel4->getRigidBody() ). If added successfully, a reference to the linked structure will be held until the linked structure is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
linkedStructure- agxCable::Cable, agxVehicle::Track, agxModel::Beam, ..., instance to add
Returns
true if the linked structure is successfully added, otherwise false

◆ add() [6/9]

bool agxSensor::Environment::add ( agxTerrain::Terrain terrain)

Add terrain to be visible to sensors in this sensor environment.

The granular bodies and topology changes will be reflected and visible to the sensors and the active granular bodies will inherit the surface material (or other) properties of this given terrain instance. If added successfully, a reference to the terrain will be held until the terrain is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
terrain- terrain instance to add
Returns
true if the terrain is successfully added, otherwise false

◆ add() [7/9]

bool agxSensor::Environment::add ( agxTerrain::TerrainPager pager)

Add terrain pager to be visible to sensors in this sensor environment.

The granular bodies and topology changes will be reflected and visible to the sensors and the active granular bodies will inherit the surface material (or other) properties of this given terrain pager instance. If added successfully, a reference to the terrain pager will be held until the terrain pager is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
pager- terrain pager instance to add
Returns
true if the terrain pager is successfully added, otherwise false

◆ add() [8/9]

bool agxSensor::Environment::add ( agxWire::Wire wire)

Add wire to be visible to sensors in this sensor environment.

If added successfully, a reference to the wire will be held until the wire is removed or when this sensor environment is removed from its cooperative simulation (or explicit call to removeNotification for standalone).

Parameters
wire- wire instance to add
Returns
true if the wire is successfully added, otherwise false

◆ add() [9/9]

bool agxSensor::Environment::add ( SystemNode system)

Add system root node (normally an implementation of a sensor) to this sensor environment.

If added successfully, the system will receive calls to 'synchronize', from the main thread, and 'execute', from the sensor environment thread, each step.

Parameters
system- system to add
Returns
true if successfully added, otherwise false (nullptr or initialization failed)

◆ get() [1/2]

static Environment * agxSensor::Environment::get ( agxSDK::Simulation simulation)
static
Parameters
simulation- simulation instance for the sensor environment
Returns
the sensor environment for the given simulation instance, nullptr if simulation hasn't been assigned one
See also
getOrCreate

◆ get() [2/2]

static const Environment * agxSensor::Environment::get ( const agxSDK::Simulation simulation)
static
Parameters
simulation- simulation instance for the sensor environment
Returns
the sensor environment for the given simulation instance, nullptr if simulation hasn't been assigned one
See also
getOrCreate

◆ getMagneticField() [1/2]

MagneticField * agxSensor::Environment::getMagneticField ( )
Returns
the magnetic field in the sensor environment

◆ getMagneticField() [2/2]

const MagneticField * agxSensor::Environment::getMagneticField ( ) const
Returns
the magnetic field in the sensor environment

◆ getOrCreate()

static Environment * agxSensor::Environment::getOrCreate ( agxSDK::Simulation simulation)
static

Returns an existing or creates and initializes a new instance of a sensor environment given a simulation.

This method will only return nullptr if the given simulation is nullptr.

Parameters
simulation- simulation instance for the sensor environment
Returns
sensor environment for the given simulation instance, nullptr if simulation is nullptr

◆ getScene()

RtSceneRef agxSensor::Environment::getScene ( ) const
Returns
the raytrace scene, possible to assign ambient/atmosphere material

◆ remove() [1/9]

bool agxSensor::Environment::remove ( agx::RigidBody rb)

Remove the rigid body, and all its geometries, from this sensor environment.

The rigid body will no longer be visible to sensors.

Parameters
rb- rigid body instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [2/9]

bool agxSensor::Environment::remove ( agxCollide::Geometry geometry)

Remove geometry, and all its shapes, from this sensor environment.

The geometry will no longer be visible to sensors.

Parameters
geometry- geometry instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [3/9]

bool agxSensor::Environment::remove ( agxCollide::Shape shape)

Remove shape from this sensor environment.

The shape will no longer be visible to sensors.

Parameters
shape- shape instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [4/9]

bool agxSensor::Environment::remove ( agxModel::DeformableObject deformable)

Remove deformable object from this sensor environment.

The deformable will no longer be visible to sensors.

Parameters
deformable- deformable instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [5/9]

bool agxSensor::Environment::remove ( agxSDK::LinkedStructure linkedStructure)

Remove linked structure (agxCable::Cable, agxVehicle::Track, agxModel::Beam, ...) from this sensor environment.

The linked structure will no longer be visible to sensors. The wheels of agxVehicle::Track instances will also be removed.

Parameters
linkedStructure- linked structure instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [6/9]

bool agxSensor::Environment::remove ( agxTerrain::Terrain terrain)

Remove terrain from this sensor environment.

The terrain will no longer be visible to sensors.

Parameters
terrain- terrain instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [7/9]

bool agxSensor::Environment::remove ( agxTerrain::TerrainPager pager)

Remove terrain pager from this sensor environment.

The terrain pager will no longer be visible to sensors.

Parameters
pager- terrain pager instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [8/9]

bool agxSensor::Environment::remove ( agxWire::Wire wire)

Remove wire from this sensor environment.

The wire will no longer be visible to sensors.

Parameters
wire- wire instance to remove
Returns
true if previously successfully added, otherwise false (nullptr or not previously added)

◆ remove() [9/9]

bool agxSensor::Environment::remove ( SystemNode system)

Remove system root node (sensor) from this sensor environment.

Parameters
system- system to remove
Returns
true if removed, otherwise false (nullptr or not present in this sensor environment)

◆ setMagneticField()

void agxSensor::Environment::setMagneticField ( MagneticField magneticField)

Set environment magnetic field.

Parameters
magneticField- magnetic field to span the environment, nullptr removes the current magnetic field

The documentation for this class was generated from the following file: