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 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 /* 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 <list>
28 #include <string>
29 
30 #include "gazebo/msgs/msgs.hh"
31 
32 #include "gazebo/math/Angle.hh"
33 #include "gazebo/sensors/Sensor.hh"
35 
36 namespace gazebo
37 {
40  namespace sensors
41  {
44 
48  class ContactSensor: public Sensor
49  {
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 
93  public: msgs::Contacts GetContacts() const;
94 
98  public: std::map<std::string, physics::Contact> GetContacts(
99  const std::string &_collisionName);
100 
101  // Documentation inherited.
102  public: virtual bool IsActive();
103 
105  private: void OnContacts(ConstContactsPtr &_msg);
106 
108  private: std::vector<std::string> collisions;
109 
111  private: transport::PublisherPtr contactsPub;
112 
114  private: transport::SubscriberPtr contactSub;
115 
117  private: mutable boost::mutex mutex;
118 
120  private: msgs::Contacts contactsMsg;
121 
122  typedef std::list<boost::shared_ptr<msgs::Contacts const> > ContactMsgs_L;
123  private: ContactMsgs_L incomingContacts;
124  };
126  }
127 }
128 #endif