ContactManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GAZEBO_PHYSICS_CONTACTMANAGER_HH_
19 #define GAZEBO_PHYSICS_CONTACTMANAGER_HH_
20 
21 #include <vector>
22 #include <string>
23 #include <map>
24 #include <ignition/transport/Node.hh>
25 
26 #include <boost/unordered/unordered_set.hpp>
27 #include <boost/unordered/unordered_map.hpp>
28 #include <boost/thread/recursive_mutex.hpp>
29 
31 
34 #include "gazebo/util/system.hh"
35 
36 namespace gazebo
37 {
38  namespace physics
39  {
42  class GZ_PHYSICS_VISIBLE ContactPublisher
43  {
46 
49  public: boost::unordered_set<Collision *> collisions;
50 
54  public: std::vector<std::string> collisionNames;
55 
57  public: std::vector<Contact *> contacts;
58 
59  // Place ignition::transport objects at the end of this file to
60  // guarantee they are destructed first.
61 
63  public: ignition::transport::Node::Publisher publisherIgn;
64  };
65 
68 
72  class GZ_PHYSICS_VISIBLE ContactManager
73  {
75  public: ContactManager();
76 
78  public: virtual ~ContactManager();
79 
85  public: void Init(WorldPtr _world);
86 
99  public: Contact *NewContact(Collision *_collision1,
100  Collision *_collision2,
101  const common::Time &_time);
102 
104  public: unsigned int GetContactCount() const;
105 
110  public: Contact *GetContact(unsigned int _index) const;
111 
117  public: const std::vector<Contact *> &GetContacts() const;
118 
120  public: void Clear();
121 
123  public: void PublishContacts();
124 
126  public: void ResetCount();
127 
133  public: std::string CreateFilter(const std::string &_topic,
134  const std::vector<std::string> &_collisions);
135 
141  public: std::string CreateFilter(const std::string &_topic,
142  const std::string &_collision);
143 
150  public: std::string CreateFilter(const std::string &_name,
151  const std::map<std::string, physics::CollisionPtr>
152  &_collisions);
153 
156  public: void RemoveFilter(const std::string &_name);
157 
160  public: unsigned int GetFilterCount();
161 
165  public: bool HasFilter(const std::string &_name);
166 
167  private: std::vector<Contact*> contacts;
168 
169  private: unsigned int contactIndex;
170 
172  private: transport::NodePtr node;
173 
175  private: transport::PublisherPtr contactPub;
176 
178  private: WorldPtr world;
179 
182  private: boost::unordered_map<std::string, ContactPublisher *>
183  customContactPublishers;
184 
186  private: boost::recursive_mutex *customMutex;
187 
188  // Place ignition::transport objects at the end of this file to
189  // guarantee they are destructed first.
190 
192  private: ignition::transport::Node nodeIgn;
193 
195  private: ignition::transport::Node::Publisher contactPubIgn;
196  };
198  }
199 }
200 #endif
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
Base class for all collision entities.
Definition: Collision.hh:38
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
A contact between two collisions.
Definition: Contact.hh:48
transport::PublisherPtr publisher
Contact message publisher.
Definition: ContactManager.hh:45
ignition::transport::Node::Publisher publisherIgn
Ignition contact message publisher.
Definition: ContactManager.hh:63
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
default namespace for gazebo
A custom contact publisher created for each contact filter in the Contact Manager.
Definition: ContactManager.hh:42
std::vector< std::string > collisionNames
Definition: ContactManager.hh:54
boost::unordered_set< Collision * > collisions
Pointers of collisions monitored by contact manager for contacts.
Definition: ContactManager.hh:49
std::vector< Contact * > contacts
A list of contacts associated to the collisions.
Definition: ContactManager.hh:57
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Aggregates all the contact information generated by the collision detection engine.
Definition: ContactManager.hh:72
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44