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 
106  public: Contact *NewContact(Collision *_collision1,
107  Collision *_collision2,
108  const common::Time &_time);
109 
113  public: void SetNeverDropContacts(const bool _neverDrop);
114 
118  public: bool NeverDropContacts() const;
119 
140  public: bool SubscribersConnected(Collision *_collision1,
141  Collision *_collision2) const;
142 
144  public: unsigned int GetContactCount() const;
145 
150  public: Contact *GetContact(unsigned int _index) const;
151 
157  public: const std::vector<Contact *> &GetContacts() const;
158 
160  public: void Clear();
161 
163  public: void PublishContacts();
164 
166  public: void ResetCount();
167 
173  public: std::string CreateFilter(const std::string &_topic,
174  const std::vector<std::string> &_collisions);
175 
181  public: std::string CreateFilter(const std::string &_topic,
182  const std::string &_collision);
183 
190  public: std::string CreateFilter(const std::string &_name,
191  const std::map<std::string, physics::CollisionPtr>
192  &_collisions);
193 
196  public: void RemoveFilter(const std::string &_name);
197 
200  public: unsigned int GetFilterCount();
201 
205  public: bool HasFilter(const std::string &_name);
206 
214  private: void GetCustomPublishers(Collision *_collision1,
215  Collision *_collision2, const bool _getOnlyConnected,
216  std::vector<ContactPublisher*> &_publishers);
217 
218  private: std::vector<Contact*> contacts;
219 
220  private: unsigned int contactIndex;
221 
223  private: transport::NodePtr node;
224 
226  private: transport::PublisherPtr contactPub;
227 
229  private: WorldPtr world;
230 
233  private: boost::unordered_map<std::string, ContactPublisher *>
234  customContactPublishers;
235 
237  private: boost::recursive_mutex *customMutex;
238 
239  // Place ignition::transport objects at the end of this file to
240  // guarantee they are destructed first.
241 
243  private: ignition::transport::Node nodeIgn;
244 
246  private: ignition::transport::Node::Publisher contactPubIgn;
247 
251  private: bool neverDropContacts;
252  };
254  }
255 }
256 #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