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 #ifndef _GAZEBO_CONTACTSENSOR_HH_
18 #define _GAZEBO_CONTACTSENSOR_HH_
19 
20 #include <vector>
21 #include <map>
22 #include <list>
23 #include <string>
24 
25 #include "gazebo/msgs/msgs.hh"
26 
27 #include "gazebo/sensors/Sensor.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
35  namespace sensors
36  {
39 
44  {
46  public: ContactSensor();
47 
49  public: virtual ~ContactSensor();
50 
54  public: virtual void Load(const std::string &_worldName,
55  sdf::ElementPtr _sdf);
56 
59  public: virtual void Load(const std::string &_worldName);
60 
62  public: virtual void Init();
63 
64  // Documentation inherited
65  protected: virtual bool UpdateImpl(bool _force);
66 
68  protected: virtual void Fini();
69 
72  public: unsigned int GetCollisionCount() const;
73 
77  public: std::string GetCollisionName(unsigned int _index) const;
78 
82  public: unsigned int GetCollisionContactCount(
83  const std::string &_collisionName) const;
84 
123  public: msgs::Contacts GetContacts() const;
124 
128  public: std::map<std::string, physics::Contact> GetContacts(
129  const std::string &_collisionName);
130 
131  // Documentation inherited.
132  public: virtual bool IsActive();
133 
135  private: void OnContacts(ConstContactsPtr &_msg);
136 
138  private: std::vector<std::string> collisions;
139 
141  private: transport::PublisherPtr contactsPub;
142 
144  private: transport::SubscriberPtr contactSub;
145 
147  private: mutable boost::mutex mutex;
148 
150  private: msgs::Contacts contactsMsg;
151 
152  typedef std::list<boost::shared_ptr<msgs::Contacts const> > ContactMsgs_L;
153  private: ContactMsgs_L incomingContacts;
154  };
156  }
157 }
158 #endif
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Contact sensor.
Definition: ContactSensor.hh:43
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:69
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66