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 (C) 2012-2014 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 
129  public: msgs::Contacts GetContacts() const;
130 
134  public: std::map<std::string, physics::Contact> GetContacts(
135  const std::string &_collisionName);
136 
137  // Documentation inherited.
138  public: virtual bool IsActive();
139 
141  private: void OnContacts(ConstContactsPtr &_msg);
142 
144  private: std::vector<std::string> collisions;
145 
147  private: transport::PublisherPtr contactsPub;
148 
150  private: transport::SubscriberPtr contactSub;
151 
153  private: mutable boost::mutex mutex;
154 
156  private: msgs::Contacts contactsMsg;
157 
158  typedef std::list<boost::shared_ptr<msgs::Contacts const> > ContactMsgs_L;
159  private: ContactMsgs_L incomingContacts;
160  };
162  }
163 }
164 #endif