RegionEventBoxPlugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2016 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 
18 #ifndef _GAZEBO_REGION_EVENT_BOX_PLUGIN_HH_
19 #define _GAZEBO_REGION_EVENT_BOX_PLUGIN_HH_
20 
21 #ifdef _WIN32
22  // Ensure that Winsock2.h is included before Windows.h, which can get
23  // pulled in by anybody (e.g., Boost).
24 #include <Winsock2.h>
25 #endif
26 
27 #include <map>
28 #include <string>
29 
30 #include <gazebo/physics/physics.hh>
31 #include <gazebo/common/Plugin.hh>
32 
33 #include "EventSource.hh"
34 
35 namespace gazebo
36 {
50  {
52  public: RegionEventBoxPlugin();
53 
54  // Documentation Inherited.
55  public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf);
56 
59  public: void OnModelMsg(ConstModelPtr &_msg);
60 
63  public: void OnUpdate(const common::UpdateInfo &_info);
64 
70  private: bool PointInRegion(const ignition::math::Vector3d &_point,
71  const ignition::math::Box &_box, const ignition::math::Pose3d &_pose)
72  const;
73 
77  private: void UpdateRegion(const ignition::math::Vector3d &_size,
78  const ignition::math::Pose3d &_pose);
79 
82  private: void SendEnteringRegionEvent(physics::ModelPtr _model) const;
83 
86  private: void SendExitingRegionEvent(physics::ModelPtr _model) const;
87 
89  private: physics::WorldPtr world;
90 
92  private: physics::ModelPtr model;
93 
95  private: event::ConnectionPtr updateConnection;
96 
98  private: std::string modelName;
99 
102 
104  public: std::mutex receiveMutex;
105 
107  private: ignition::math::Vector3d boxSize;
108 
110  private: ignition::math::Vector3d boxScale;
111 
113  private: ignition::math::Pose3d boxPose;
114 
116  private: ignition::math::Box box;
117 
119  private: transport::SubscriberPtr modelSub;
120 
122  private: bool hasStaleSizeAndPose;
123 
126  private: std::map<std::string, common::Time> insiders;
127 
129  private: transport::PublisherPtr eventPub;
130 
132  private: gazebo::EventSourcePtr eventSource;
133  };
134 }
135 
136 #endif
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:153
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:88
std::mutex receiveMutex
Mutex to protect incoming messages.
Definition: RegionEventBoxPlugin.hh:104
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
void OnUpdate(const common::UpdateInfo &_info)
Updates the box event plugin at every physics iteration.
boost::shared_ptr< EventSource > EventSourcePtr
Definition: EventSource.hh:86
Information for use in an update event.
Definition: UpdateInfo.hh:30
void OnModelMsg(ConstModelPtr &_msg)
Callback when a model message is received.
transport::NodePtr node
Transport node pointer.
Definition: RegionEventBoxPlugin.hh:101
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:84
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
Load function.
A plugin that fires an event when another model enters the region defined by the size of this model's...
Definition: RegionEventBoxPlugin.hh:49
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
RegionEventBoxPlugin()
Constructor.
A plugin with access to physics::Model.
Definition: Plugin.hh:245