RobWorkProject  23.9.11-
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
ContactDetector Class Reference

The ContactDetector allows detailed control of the strategies used for contact detection between specific frames and geometry types. More...

#include <ContactDetector.hpp>

Inherits BaseContactDetector.

Classes

struct  StrategyTableRow
 One row in the strategy table, with a priority, match-rules, a strategy and associated ContactModels. More...
 

Public Types

typedef rw::core::Ptr< ContactDetectorPtr
 smart pointer type to this class
 
typedef std::list< StrategyTableRowStrategyTable
 Type for the strategy table.
 
- Public Types inherited from BaseContactDetector
typedef rw::core::Ptr< BaseContactDetectorPtr
 smart pointer type to this class
 

Public Member Functions

 ContactDetector (rw::core::Ptr< rw::models::WorkCell > workcell, rw::proximity::ProximityFilterStrategy::Ptr filter=NULL)
 Contact detector for a workcell. More...
 
virtual ~ContactDetector ()
 Destruct contact detector. More...
 
virtual std::vector< ContactfindContacts (const rw::kinematics::State &state)
 Find contacts in workcell. More...
 
virtual std::vector< ContactfindContacts (const rw::kinematics::State &state, ContactDetectorData &data)
 Find contacts in workcell. More...
 
virtual std::vector< ContactfindContacts (const rw::kinematics::State &state, ContactDetectorData &data, ContactDetectorTracking &tracking, rwsim::log::SimulatorLogScope *log=NULL)
 Find contacts in workcell while tracking known contacts. More...
 
virtual std::vector< ContactupdateContacts (const rw::kinematics::State &state, ContactDetectorData &data, ContactDetectorTracking &tracking, rwsim::log::SimulatorLogScope *log=NULL)
 Updates previously found contacts. More...
 
Strategy table functions.

Functions used to construct and edit the strategy table.

virtual StrategyTable getContactStategies () const
 Get the complete contact strategy table. More...
 
virtual StrategyTable getContactStrategies (const std::string &frameA, const std::string &frameB) const
 Get the contact strategies that match the given frame names. More...
 
virtual StrategyTable getContactStrategies (const std::string &frameA, rw::core::Ptr< const rw::geometry::GeometryData > geometryA, const std::string &frameB, rw::core::Ptr< const rw::geometry::GeometryData > geometryB) const
 Get the contact strategies that match the given frame names and geometries. More...
 
virtual void addContactStrategy (rw::core::Ptr< ContactStrategy > strategy, std::size_t priority=0)
 Add a strategy to the strategy table that matches all frames. More...
 
virtual void addContactStrategy (rw::proximity::ProximitySetupRule rule, rw::core::Ptr< ContactStrategy > strategy, std::size_t priority=0)
 Add a strategy that is only used for frames matching one rule. More...
 
virtual void addContactStrategy (rw::proximity::ProximitySetup rules, rw::core::Ptr< ContactStrategy > strategy, std::size_t priority=0)
 Add a strategy that is used for frames that match a set of rules. More...
 
virtual void addContactStrategy (StrategyTableRow &strategy, std::size_t priority=0)
 Add a strategy from an existing strategy table rule. More...
 
virtual void removeContactStrategy (std::size_t priority=0)
 Remove the strategy with a certain priority in the table. More...
 
virtual void clearStrategies ()
 Remove all strategies and contact models in the table.
 
virtual void setContactStrategies (StrategyTable strategies)
 Set a complete strategy table. More...
 
virtual void setDefaultStrategies ()
 Auto-generate a suitable general-purpose strategy table. More...
 
virtual void setDefaultStrategies (const rw::core::PropertyMap &map)
 Auto-generate a suitable general-purpose strategy table with strategies using the given properties. More...
 
virtual void printStrategyTable () const
 Print the current strategy table to standard output.
 
virtual void printStrategyTable (std::ostream &out) const
 Print the current strategy table to given output stream.
 
- Public Member Functions inherited from BaseContactDetector
 BaseContactDetector (rw::core::Ptr< rw::models::WorkCell > workcell, rw::proximity::ProximityFilterStrategy::Ptr filter=NULL)
 Contact detector for a workcell. More...
 
virtual ~BaseContactDetector ()
 Destruct contact detector. More...
 
void setProximityFilterStrategy (rw::proximity::ProximityFilterStrategy::Ptr filter)
 Set a new broad-phase filter. More...
 
virtual rw::proximity::ProximityFilterStrategy::Ptr getProximityFilterStrategy () const
 The broad-phase filter strategy used by the contact detector.
 
virtual double getTimer () const
 The number of seconds measured used in contact detection. More...
 
virtual void setTimer (double value=0)
 Set the value of a timer that will measure time used during contact detection. More...
 

Static Public Member Functions

static ContactDetector::Ptr makeDefault (rw::core::Ptr< rw::models::WorkCell > workcell)
 Create a default workcell from a workcell, where the default strategies has been set. More...
 
static ContactDetector::Ptr makeDefault (rw::core::Ptr< rw::models::WorkCell > workcell, const rw::core::PropertyMap &map)
 Create a default workcell from a workcell, where the default strategies has been set. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const ContactDetector &detector)
 Stream operator. More...
 
std::ostream & operator<< (std::ostream &out, ContactDetector::Ptr detector)
 Stream operator. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseContactDetector
rw::core::Ptr< rw::proximity::ProximityFilterStrategy_bpFilter
 
rw::core::Ptr< rw::models::WorkCell_wc
 
double _timer
 

Detailed Description

The ContactDetector allows detailed control of the strategies used for contact detection between specific frames and geometry types.

A concrete strategy for contact detection is chosen by a rule-based lookup in a strategy table. For general purpose usage the contact detector can auto-generate the most suitable set of rules for a given workcell. The user can alter this table to specific needs, or create its own strategy table from scratch.

Each rule has a priority from 0 and upwards, where 0 is the highest priority. When finding contacts, the rule with priority 0 will be tested first. If no match is found, the next rule in the table will be tested.

The first condition for a match, will be that the frame names match a specific pattern. If the frame names match, each combination of geometries for the two frames is tested by calling the boolean match function on the ContactStrategy. If the geometries can not be handled by the strategy, the next strategy in the table will be tested. If the geometries can be handled by the strategy, this strategy is used for contact detection between this specific combination of geometries.

This way the user can easily extend the default contact detections strategy with own strategies. These strategies can be applied for specific frame names, specific geometry types or both.

Constructor & Destructor Documentation

◆ ContactDetector()

Contact detector for a workcell.

If no broad-phase filter is given, a default will be created for the workcell.

Note
The strategy rule table will be empty and no contacts will be found before strategies are added.
Parameters
workcell[in] the workcell.
filter[in] broad-phase filter to remove frames that are obviously not colliding.

◆ ~ContactDetector()

virtual ~ContactDetector ( )
virtual

Destruct contact detector.

The strategy table and stored contact models is cleared.

Member Function Documentation

◆ addContactStrategy() [1/4]

virtual void addContactStrategy ( rw::core::Ptr< ContactStrategy strategy,
std::size_t  priority = 0 
)
virtual

Add a strategy to the strategy table that matches all frames.

Parameters
strategy[in/out] The strategy to add. Relevant ContactModels are automatically created.
priority[in] the priority of the new strategy (default is maximum priority - 0).

◆ addContactStrategy() [2/4]

virtual void addContactStrategy ( rw::proximity::ProximitySetup  rules,
rw::core::Ptr< ContactStrategy strategy,
std::size_t  priority = 0 
)
virtual

Add a strategy that is used for frames that match a set of rules.

Parameters
rules[in] The rules for the frame names that this strategy applies to.
strategy[in/out] The strategy to add. Relevant ContactModels are automatically created.
priority[in] the priority of the new strategy (default is maximum priority - 0).

◆ addContactStrategy() [3/4]

virtual void addContactStrategy ( rw::proximity::ProximitySetupRule  rule,
rw::core::Ptr< ContactStrategy strategy,
std::size_t  priority = 0 
)
virtual

Add a strategy that is only used for frames matching one rule.

Parameters
rule[in] The rule for the frame names that this strategy applies to.
strategy[in/out] The strategy to add. Relevant ContactModels are automatically created.
priority[in] the priority of the new strategy (default is maximum priority - 0).

◆ addContactStrategy() [4/4]

virtual void addContactStrategy ( StrategyTableRow strategy,
std::size_t  priority = 0 
)
virtual

Add a strategy from an existing strategy table rule.

Parameters
strategy[in/out] The strategy to add. The priority will be changed automatically, and relevant ContactModels are created automatically if not already present.
priority[in] the priority of the new strategy (default is maximum priority - 0).

◆ findContacts() [1/3]

virtual std::vector<Contact> findContacts ( const rw::kinematics::State state)
virtual

Find contacts in workcell.

Parameters
state[in] The state for which to check for contacts.
Returns
a vector of contacts, some might be subclasses of the Contact class.

Implements BaseContactDetector.

◆ findContacts() [2/3]

virtual std::vector<Contact> findContacts ( const rw::kinematics::State state,
ContactDetectorData data 
)
virtual

Find contacts in workcell.

Use of this function is encouraged if changes between consecutive calls are expected to be small. This will allow the detection algorithms to do certain speed-ups.

Parameters
state[in] The state for which to check for contacts.
data[in/out] Allows caching between contact detection calls, and makes it possible for detection algorithms to exploit spatial and temporal coherence.
Returns
a vector of contacts, some might be subclasses of the Contact class.

Implements BaseContactDetector.

◆ findContacts() [3/3]

virtual std::vector<Contact> findContacts ( const rw::kinematics::State state,
ContactDetectorData data,
ContactDetectorTracking tracking,
rwsim::log::SimulatorLogScope log = NULL 
)
virtual

Find contacts in workcell while tracking known contacts.

Parameters
state[in] the state to find contacts for.
data[in/out] allows caching between contact detection calls, and makes it possible for detection algorithms to exploit spatial and temporal coherence.
tracking[in/out] the tracking data with information about known contacts.
log[in/out] (optional) store detailed logging information.
Returns
a vector of new contacts.

Implements BaseContactDetector.

◆ getContactStategies()

virtual StrategyTable getContactStategies ( ) const
virtual

Get the complete contact strategy table.

Returns
The strategy table used.

◆ getContactStrategies() [1/2]

virtual StrategyTable getContactStrategies ( const std::string &  frameA,
const std::string &  frameB 
) const
virtual

Get the contact strategies that match the given frame names.

Parameters
frameA[in] the name of the first frame.
frameB[in] the name of the second frame.
Returns
a new strategy table that includes only strategies matching the given frame pair.

◆ getContactStrategies() [2/2]

virtual StrategyTable getContactStrategies ( const std::string &  frameA,
rw::core::Ptr< const rw::geometry::GeometryData geometryA,
const std::string &  frameB,
rw::core::Ptr< const rw::geometry::GeometryData geometryB 
) const
virtual

Get the contact strategies that match the given frame names and geometries.

Parameters
frameA[in] the name of the first frame.
geometryA[in] the first geometry.
frameB[in] the name of the second frame.
geometryB[in] the second geometry.
Returns
a new strategy table that includes only strategies matching the given frame pair, and uses the given geometries.

◆ makeDefault() [1/2]

static ContactDetector::Ptr makeDefault ( rw::core::Ptr< rw::models::WorkCell workcell)
static

Create a default workcell from a workcell, where the default strategies has been set.

Parameters
workcell[in] the workcell to create detector for.
Returns
a new contact detector.

◆ makeDefault() [2/2]

static ContactDetector::Ptr makeDefault ( rw::core::Ptr< rw::models::WorkCell workcell,
const rw::core::PropertyMap map 
)
static

Create a default workcell from a workcell, where the default strategies has been set.

Parameters
workcell[in] the workcell to create detector for.
map[in] the map to take properties from.
Returns
a new contact detector.

◆ removeContactStrategy()

virtual void removeContactStrategy ( std::size_t  priority = 0)
virtual

Remove the strategy with a certain priority in the table.

Contact models will removed for the relevant strategy, and updated for the other strategies in the table.

Parameters
prioritythe priority to remove.

◆ setContactStrategies()

virtual void setContactStrategies ( StrategyTable  strategies)
virtual

Set a complete strategy table.

Parameters
strategies[in] the strategy table.

◆ setDefaultStrategies() [1/2]

virtual void setDefaultStrategies ( )
virtual

Auto-generate a suitable general-purpose strategy table.

This function will generate the most suitable default contact strategy for the workcell.

◆ setDefaultStrategies() [2/2]

virtual void setDefaultStrategies ( const rw::core::PropertyMap map)
virtual

Auto-generate a suitable general-purpose strategy table with strategies using the given properties.

This function will generate the most suitable default contact strategy for the workcell.

Parameters
map[in] the PropertyMap to use by all the strategies.

◆ updateContacts()

virtual std::vector<Contact> updateContacts ( const rw::kinematics::State state,
ContactDetectorData data,
ContactDetectorTracking tracking,
rwsim::log::SimulatorLogScope log = NULL 
)
virtual

Updates previously found contacts.

Parameters
state[in] the new state to find the updated contacts for.
data[in/out] allows caching between contact detection calls, and makes it possible for detection algorithms to exploit spatial and temporal coherence.
tracking[in/out] the tracking data with information about known contacts.
log[in/out] (optional) store detailed logging information.
Returns
a vector of contacts.

Implements BaseContactDetector.

Friends And Related Function Documentation

◆ operator<< [1/2]

std::ostream& operator<< ( std::ostream &  out,
const ContactDetector detector 
)
friend

Stream operator.

Parameters
out[in/out] the stream to write to.
detector[in] the detector to print strategy table for.
Returns
the same ostream as out parameter.

◆ operator<< [2/2]

std::ostream& operator<< ( std::ostream &  out,
ContactDetector::Ptr  detector 
)
friend

Stream operator.

Parameters
out[in/out] the stream to write to.
detector[in] the detector to print strategy table for.
Returns
the same ostream as out parameter.

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