ContactSensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 #include "gazebo/util/system.hh"
36 
37 namespace gazebo
38 {
41  namespace sensors
42  {
45 
50  {
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 
70  // Documentation inherited
71  protected: virtual bool 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
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Contact sensor.
Definition: ContactSensor.hh:49
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
Base class for sensors.
Definition: Sensor.hh:67
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48