DRPlugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 João Borrego
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 
26 #ifndef _DOMAIN_RANDOMIZATION_PLUGIN_HH_
27 #define _DOMAIN_RANDOMIZATION_PLUGIN_HH_
28 
29 // Gazebo
30 #include "gazebo/common/Plugin.hh"
31 #include <gazebo/msgs/msgs.hh>
32 #include <gazebo/transport/transport.hh>
33 #include <gazebo/sensors/sensors.hh>
34 
35 // Custom messages
36 #include "dr_request.pb.h"
37 #include "model_cmd.pb.h"
38 // Custom gazebo debug utilities
39 #include "gz_debug.hh"
40 
41 // Required fields workaround
42 #include <limits>
43 
44 namespace gazebo {
45 
46  // Message types
47 
51  typedef const boost::shared_ptr<const gap::msgs::DRRequest>
54  typedef gap::msgs::ModelCmd ModelCmdMsg;
56  typedef const boost::shared_ptr<const gap::msgs::ModelCmd>
58 
59  // Forward declaration of private data class
60  class DRPluginPrivate;
61 
71  class DRPlugin : public WorldPlugin
72  {
74  public: static const char REQUEST_TOPIC[];
76  public: static const char RESPONSE_TOPIC[];
78  public: static const int POSITION;
80  public: static const int VELOCITY;
81 
82  // Private attributes
83 
85  private: std::unique_ptr<DRPluginPrivate> data_ptr;
87  private: event::ConnectionPtr update_connection;
88 
90  private: physics::WorldPtr world;
92  private: physics::PhysicsEnginePtr physics_engine;
93 
95  private: boost::shared_ptr<DRRequest const> msg;
96 
97  // Public methods
98 
100  public: DRPlugin();
101 
103  public: virtual ~DRPlugin();
104 
108  public: virtual void Load(
109  physics::WorldPtr _world, sdf::ElementPtr _sdf);
110 
112  public: void onUpdate();
113 
116  public: void onRequest(DRRequestPtr & _msg);
117 
118  // Physics
119 
122  private: void processPhysics(const msgs::Physics & msg);
123 
126  private: void processModel(const msgs::Model & msg);
127 
131  private: void processJoint(
132  physics::ModelPtr model,
133  const msgs::Joint & msg);
134 
138  private: void processLink(
139  physics::ModelPtr model,
140  const msgs::Link & msg);
141 
145  private: void processInertial(
146  physics::LinkPtr link,
147  const msgs::Inertial & msg);
148 
152  private: void processSurface(
153  physics::CollisionPtr collision,
154  const msgs::Surface & msg);
155 
158  private: void processModelCmd(
159  const ModelCmdMsg & msg);
160 
164  private: void processJointCmd(
165  physics::ModelPtr model,
166  const msgs::JointCmd & msg);
167 
173  private: void processPID(
174  int type,
175  physics::JointControllerPtr controller,
176  const std::string & joint,
177  const msgs::PID & msg);
178 
179  };
180 }
181 
182 #endif
const boost::shared_ptr< const gap::msgs::DRRequest > DRRequestPtr
Shared pointer declaration for request message type.
Definition: DRPlugin.hh:52
Multi-purpose domain randomization plugin.
Definition: DRPlugin.hh:71
static const char RESPONSE_TOPIC[]
Topic for DRPlugin responses.
Definition: DRPlugin.hh:76
virtual ~DRPlugin()
Destroys the object.
Definition: DRPlugin.cc:61
void processInertial(physics::LinkPtr link, const msgs::Inertial &msg)
Updates inertial.
Definition: DRPlugin.cc:240
static const int POSITION
Position controller type.
Definition: DRPlugin.hh:78
Definition: CameraUtils.cc:30
static const int VELOCITY
Velocity controller type.
Definition: DRPlugin.hh:80
void onRequest(DRRequestPtr &_msg)
Callback function for handling incoming requests.
Definition: DRPlugin.cc:111
Gazebo debug utilities.
void processJointCmd(physics::ModelPtr model, const msgs::JointCmd &msg)
Processes joint command message.
Definition: DRPlugin.cc:296
void processPhysics(const msgs::Physics &msg)
Processes physics message.
Definition: DRPlugin.cc:124
void processSurface(physics::CollisionPtr collision, const msgs::Surface &msg)
Updates surface.
Definition: DRPlugin.cc:268
std::unique_ptr< DRPluginPrivate > data_ptr
Class with private attributes.
Definition: DRPlugin.hh:85
boost::shared_ptr< DRRequest const > msg
Pending request.
Definition: DRPlugin.hh:95
physics::PhysicsEnginePtr physics_engine
Physics engine pointer.
Definition: DRPlugin.hh:92
physics::WorldPtr world
World to which the plugin is attached.
Definition: DRPlugin.hh:90
void processModelCmd(const ModelCmdMsg &msg)
Processes model command message.
Definition: DRPlugin.cc:279
gap::msgs::ModelCmd ModelCmdMsg
Declaration for model command message type.
Definition: DRPlugin.hh:54
void processJoint(physics::ModelPtr model, const msgs::Joint &msg)
Updates joint.
Definition: DRPlugin.cc:166
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
Loads the plugin.
Definition: DRPlugin.cc:67
const boost::shared_ptr< const gap::msgs::ModelCmd > ModelCmdPtr
Shared pointer declaration for model command message type.
Definition: DRPlugin.hh:57
event::ConnectionPtr update_connection
Connection to world update event.
Definition: DRPlugin.hh:87
void onUpdate()
Called on World Update event.
Definition: DRPlugin.cc:87
Class for private Domain Randomization plugin data.
Definition: DRPlugin.cc:37
gap::msgs::DRRequest DRRequest
Declaration for request message type.
Definition: DRPlugin.hh:49
void processLink(physics::ModelPtr model, const msgs::Link &msg)
Updates link.
Definition: DRPlugin.cc:211
DRPlugin()
Constructs the object.
Definition: DRPlugin.cc:54
static const char REQUEST_TOPIC[]
Topic for DRPlugin requests.
Definition: DRPlugin.hh:74
void processModel(const msgs::Model &msg)
Processes model message.
Definition: DRPlugin.cc:136
void processPID(int type, physics::JointControllerPtr controller, const std::string &joint, const msgs::PID &msg)
Updates PID controller.
Definition: DRPlugin.cc:320