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 <stdint.h>
26 #include <vector>
27 #include <map>
28 #include <string>
29 
30 #include "math/Angle.hh"
31 #include "sensors/Sensor.hh"
32 #include "physics/Contact.hh"
33 
34 namespace gazebo
35 {
38  namespace sensors
39  {
40  class Contact;
41 
47  class ContactSensor: public Sensor
48  {
52  public: ContactSensor();
53 
55  public: virtual ~ContactSensor();
56 
60  public: virtual void Load(const std::string &_worldName,
61  sdf::ElementPtr _sdf);
62 
65  public: virtual void Load(const std::string &_worldName);
66 
68  public: virtual void Init();
69 
72  protected: virtual void UpdateImpl(bool _force);
73 
75  protected: virtual void Fini();
76 
79  public: unsigned int GetCollisionCount() const;
80 
84  public: std::string GetCollisionName(unsigned int _index) const;
85 
89  public: unsigned int GetCollisionContactCount(
90  const std::string &_collisionName) const;
91 
98  const std::string &_collisionName, unsigned int _index) const;
99 
104  public: std::map<std::string, physics::Contact> GetContacts(
105  const std::string &_collisionName);
106 
111  private: void OnContact(const std::string &_collisionName,
112  const physics::Contact &_contact);
113 
114  private: std::vector<physics::CollisionPtr> collisions;
115 
116  private: typedef std::map<std::string,
117  std::map<std::string, physics::Contact> > Contact_M;
118 
119  private: Contact_M contacts;
120 
121  private: transport::PublisherPtr contactsPub;
122 
123  private: boost::mutex *mutex;
124 
128  public: boost::mutex* GetUpdateMutex() const
129  {return this->mutex;}
130  };
132  }
133 }
134 
135 #endif
136 
137