##

ContactManager.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_PHYSICS_CONTACTMANAGER_HH_
#define GAZEBO_PHYSICS_CONTACTMANAGER_HH_
#include <vector>
#include <string>
#include <map>
#include <ignition/transport/Node.hh>
#include <boost/unordered/unordered_set.hpp>
#include <boost/unordered/unordered_map.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include "gazebo/transport/TransportTypes.hh"
#include "gazebo/physics/PhysicsTypes.hh"
#include "gazebo/physics/Contact.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace physics
{
class GZ_PHYSICS_VISIBLE ContactPublisher
{
public: transport::PublisherPtr publisher;
public: boost::unordered_set<Collision *> collisions;
public: std::vector<std::string> collisionNames;
public: std::vector<Contact *> contacts;
// Place ignition::transport objects at the end of this file to
// guarantee they are destructed first.
public: ignition::transport::Node::Publisher publisherIgn;
};
class GZ_PHYSICS_VISIBLE ContactManager
{
public: ContactManager();
public: virtual ~ContactManager();
public: void Init(WorldPtr _world);
public: Contact *NewContact(Collision *_collision1,
Collision *_collision2,
const common::Time &_time);
public: void SetNeverDropContacts(const bool _neverDrop);
public: bool NeverDropContacts() const;
public: bool SubscribersConnected(Collision *_collision1,
Collision *_collision2) const;
public: unsigned int GetContactCount() const;
public: Contact *GetContact(unsigned int _index) const;
public: const std::vector<Contact *> &GetContacts() const;
public: void Clear();
public: void PublishContacts();
public: void ResetCount();
public: std::string CreateFilter(const std::string &_topic,
const std::vector<std::string> &_collisions);
public: std::string CreateFilter(const std::string &_topic,
const std::string &_collision);
public: std::string CreateFilter(const std::string &_name,
const std::map<std::string, physics::CollisionPtr>
&_collisions);
public: void RemoveFilter(const std::string &_name);
public: unsigned int GetFilterCount();
public: bool HasFilter(const std::string &_name);
private: void GetCustomPublishers(Collision *_collision1,
Collision *_collision2, const bool _getOnlyConnected,
std::vector<ContactPublisher*> &_publishers);
private: std::vector<Contact*> contacts;
private: unsigned int contactIndex;
private: transport::NodePtr node;
private: transport::PublisherPtr contactPub;
private: WorldPtr world;
private: boost::unordered_map<std::string, ContactPublisher *>
customContactPublishers;
private: boost::recursive_mutex *customMutex;
// Place ignition::transport objects at the end of this file to
// guarantee they are destructed first.
private: ignition::transport::Node nodeIgn;
private: ignition::transport::Node::Publisher contactPubIgn;
private: bool neverDropContacts;
};
}
}
#endif
gazebo::physics::Contact
A contact between two collisions. Each contact can consist of a number of contact points.
Definition: Contact.hh:48
gazebo::physics::ContactManager::GetContact
Contact * GetContact(unsigned int _index) const
Get a single contact by index.
gazebo::physics::Collision
Base class for all collision entities.
Definition: Collision.hh:38
gazebo::physics::ContactManager::RemoveFilter
void RemoveFilter(const std::string &_name)
Remove a contacts filter and the associated custom publisher param[in] _name Filter name.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::physics::ContactManager::SetNeverDropContacts
void SetNeverDropContacts(const bool _neverDrop)
If set to true, NewContact() will always add contacts even if there are no subscribers.
gazebo::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
gazebo::physics::ContactManager::NeverDropContacts
bool NeverDropContacts() const
returns the value last set with SetNeverDropContacts().
gazebo::transport::PublisherPtr
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
TransportTypes.hh
Forward declarations for transport.
system.hh
gazebo::physics::ContactManager::ContactManager
ContactManager()
Constructor.
PhysicsTypes.hh
default namespace for gazebo
gazebo::transport::NodePtr
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
gazebo::physics::ContactPublisher::collisionNames
std::vector< std::string > collisionNames
Definition: ContactManager.hh:54
gazebo::physics::ContactManager::SubscribersConnected
bool SubscribersConnected(Collision *_collision1, Collision *_collision2) const
Returns true if any subscribers are connected which would be interested in contact details of either ...
gazebo::physics::ContactManager::HasFilter
bool HasFilter(const std::string &_name)
Check if a filter with the specified name exists.
gazebo::physics::ContactManager::ResetCount
void ResetCount()
Set the contact count to zero.
gazebo::physics::ContactManager::Init
void Init(WorldPtr _world)
Initialize the ContactManager.
gazebo::physics::ContactPublisher::contacts
std::vector< Contact * > contacts
A list of contacts associated to the collisions.
Definition: ContactManager.hh:57
gazebo::physics::ContactPublisher::publisher
transport::PublisherPtr publisher
Contact message publisher.
Definition: ContactManager.hh:45
gazebo::physics::ContactManager::GetContacts
const std::vector< Contact * > & GetContacts() const
Get all the contacts.
gazebo::physics::ContactManager::CreateFilter
std::string CreateFilter(const std::string &_topic, const std::vector< std::string > &_collisions)
Create a filter for contacts.
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::physics::ContactManager
Aggregates all the contact information generated by the collision detection engine.
Definition: ContactManager.hh:72
gazebo::physics::ContactPublisher::collisions
boost::unordered_set< Collision * > collisions
Pointers of collisions monitored by contact manager for contacts.
Definition: ContactManager.hh:49
Contact.hh
gazebo::physics::ContactManager::~ContactManager
virtual ~ContactManager()
Destructor.
gazebo::physics::ContactManager::GetContactCount
unsigned int GetContactCount() const
Return the number of valid contacts.
gazebo::physics::WorldPtr
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
gazebo::physics::ContactPublisher::publisherIgn
ignition::transport::Node::Publisher publisherIgn
Ignition contact message publisher.
Definition: ContactManager.hh:63
gazebo::physics::ContactManager::PublishContacts
void PublishContacts()
Publish all contacts in a msgs::Contacts message.
gazebo::physics::ContactPublisher
A custom contact publisher created for each contact filter in the Contact Manager.
Definition: ContactManager.hh:42
gazebo::physics::ContactManager::NewContact
Contact * NewContact(Collision *_collision1, Collision *_collision2, const common::Time &_time)
Add a new contact.
gazebo::physics::ContactManager::Clear
void Clear()
Clear all stored contacts.
gazebo::physics::ContactManager::GetFilterCount
unsigned int GetFilterCount()
Get the number of filters in the contact manager.