All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ContactSensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
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 /* Desc: Contact sensor
18  * Author: Nate Koenig
19  * Date: 09 Sept. 2008
20 */
21 
22 #ifndef _CONTACTSENSOR_HH_
23 #define _CONTACTSENSOR_HH_
24 
25 #include <vector>
26 #include <map>
27 #include <string>
28 
29 #include "gazebo/math/Angle.hh"
30 #include "gazebo/sensors/Sensor.hh"
32 
33 namespace gazebo
34 {
37  namespace sensors
38  {
39  class Contact;
40 
46  class ContactSensor: public Sensor
47  {
51  public: ContactSensor();
52 
54  public: virtual ~ContactSensor();
55 
59  public: virtual void Load(const std::string &_worldName,
60  sdf::ElementPtr _sdf);
61 
64  public: virtual void Load(const std::string &_worldName);
65 
67  public: virtual void Init();
68 
71  protected: virtual void UpdateImpl(bool _force);
72 
74  protected: virtual void Fini();
75 
78  public: unsigned int GetCollisionCount() const;
79 
83  public: std::string GetCollisionName(unsigned int _index) const;
84 
88  public: unsigned int GetCollisionContactCount(
89  const std::string &_collisionName) const;
90 
96  const std::string &_collisionName, unsigned int _index) const;
97 
101  public: std::map<std::string, physics::Contact> GetContacts(
102  const std::string &_collisionName);
103 
107  private: void OnContact(const std::string &_collisionName,
108  const physics::Contact &_contact);
109 
110  private: std::vector<physics::CollisionPtr> collisions;
111 
112  private: typedef std::map<std::string,
113  std::map<std::string, physics::Contact> > Contact_M;
114 
115  private: Contact_M contacts;
116 
117  private: transport::PublisherPtr contactsPub;
118 
119  private: boost::mutex *mutex;
120 
124  public: boost::mutex* GetUpdateMutex() const
125  {return this->mutex;}
126  };
128  }
129 }
130 
131 #endif
132 
133