DRInterface.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 
24 #ifndef _DOMAIN_RANDOMIZATION_INTERFACE_HH_
25 #define _DOMAIN_RANDOMIZATION_INTERFACE_HH_
26 
27 // Gazebo
28 #include <gazebo/gazebo_client.hh>
29 #include <gazebo/gazebo_config.h>
30 #include <gazebo/transport/transport.hh>
31 #include <gazebo/msgs/msgs.hh>
32 
33 #include <gazebo/physics/bullet/BulletSurfaceParams.hh>
34 #include <gazebo/physics/ode/ODESurfaceParams.hh>
35 #include <gazebo/physics/dart/DARTSurfaceParams.hh>
36 
37 // Custom messages
38 #include "dr_request.pb.h"
39 #include "model_cmd.pb.h"
40 
41 // Debug streams
42 #include "debug.hh"
43 
44 // Required fields workaround
45 #include <limits>
46 
50 typedef gap::msgs::ModelCmd ModelCmdMsg;
51 
52 /*
53 typedef boost::shared_ptr <gazebo::physics::BulletSurfaceParams>
54  BulletSurfaceParamsPtr;
55 typedef boost::shared_ptr <gazebo::physics::DARTSurfaceParams>
56  DARTSurfaceParamsPtr;
57 typedef boost::shared_ptr <gazebo::physics::ODESurfaceParams>
58  ODESurfaceParamsPtr;
59 */
60 
63 {
64 
66  public: static const char REQUEST_TOPIC[];
68  public: static const char RESPONSE_TOPIC[];
70  public: static const char VISUAL_TOPIC[];
72  public: static const int POSITION;
74  public: static const int VELOCITY;
75 
77  private: gazebo::transport::NodePtr node;
79  private: gazebo::transport::PublisherPtr pub;
81  private: gazebo::transport::PublisherPtr pub_visual;
82 
84  public: DRInterface();
85 
88  public: DRRequest createRequest();
89 
92  public: void publish(const DRRequest & msg);
93 
96  public: void publish(const gazebo::msgs::Visual & msg);
97 
98  // Features
99 
103  public: void addGravity(DRRequest & msg,
104  const ignition::math::Vector3d & gravity);
105 
110  public: void addModelScale(DRRequest & msg,
111  const std::string & model,
112  const ignition::math::Vector3d & scale);
113 
119  public: void addLinkMass(DRRequest & msg,
120  const std::string & model,
121  const std::string & link,
122  double mass);
123 
134  public: void addInertiaMatrix(DRRequest & msg,
135  const std::string & model,
136  const std::string & link,
137  double ixx, double iyy, double izz,
138  double ixy, double ixz, double iyz);
139 
146  public: void addSurface(DRRequest & msg,
147  const std::string & model,
148  const std::string & link,
149  const std::string & collision,
150  const gazebo::msgs::Surface & surface);
151 
165  public: void addJoint(DRRequest & msg,
166  const std::string & model,
167  const std::string & joint,
168  double limit_lower = INFINITY,
169  double limit_upper = INFINITY,
170  double limit_effort = INFINITY,
171  double limit_velocity = INFINITY,
172  double damping = INFINITY,
173  double friction = INFINITY);
174 
186  public: void addModelCmd(DRRequest & msg,
187  const std::string & model,
188  const std::string & joint,
189  int type,
190  double p_gain = INFINITY,
191  double i_gain = INFINITY,
192  double d_gain = INFINITY);
193 
205  public: void addColors(gazebo::msgs::Visual & msg,
206  const std::string & visual,
207  const std::string & parent,
208  const ignition::math::Color & ambient,
209  const ignition::math::Color & diffuse,
210  const ignition::math::Color & emissive,
211  const ignition::math::Color & specular);
212 };
213 
214 #endif
static const char REQUEST_TOPIC[]
Topic for DRPlugin requests.
Definition: DRInterface.hh:66
void addGravity(DRRequest &msg, const ignition::math::Vector3d &gravity)
Updates physics engine gravity.
Definition: DRInterface.cc:64
void addJoint(DRRequest &msg, const std::string &model, const std::string &joint, double limit_lower=INFINITY, double limit_upper=INFINITY, double limit_effort=INFINITY, double limit_velocity=INFINITY, double damping=INFINITY, double friction=INFINITY)
Updates joint.
Definition: DRInterface.cc:154
Domain Randomization Plugin Interface.
Definition: DRInterface.hh:62
gazebo::transport::PublisherPtr pub_visual
Publisher to the visual topic.
Definition: DRInterface.hh:81
DRRequest createRequest()
Creates a domain randomization request.
Definition: DRInterface.cc:45
Debug utilities.
void addModelCmd(DRRequest &msg, const std::string &model, const std::string &joint, int type, double p_gain=INFINITY, double i_gain=INFINITY, double d_gain=INFINITY)
Updates model controllers.
Definition: DRInterface.cc:189
void addColors(gazebo::msgs::Visual &msg, const std::string &visual, const std::string &parent, const ignition::math::Color &ambient, const ignition::math::Color &diffuse, const ignition::math::Color &emissive, const ignition::math::Color &specular)
Updates visual color.
Definition: DRInterface.cc:217
void publish(const DRRequest &msg)
Publishes request.
Definition: DRInterface.cc:52
gap::msgs::DRRequest DRRequest
Declaration for request message type.
Definition: DRInterface.hh:48
static const char VISUAL_TOPIC[]
Topic for outgoing visual requests.
Definition: DRInterface.hh:70
static const char RESPONSE_TOPIC[]
Topic for DRPlugin responses.
Definition: DRInterface.hh:68
void addSurface(DRRequest &msg, const std::string &model, const std::string &link, const std::string &collision, const gazebo::msgs::Surface &surface)
Updates collision surface.
Definition: DRInterface.cc:132
void addModelScale(DRRequest &msg, const std::string &model, const ignition::math::Vector3d &scale)
Updates model scale.
Definition: DRInterface.cc:76
static const int VELOCITY
Velocity controller type.
Definition: DRInterface.hh:74
void addInertiaMatrix(DRRequest &msg, const std::string &model, const std::string &link, double ixx, double iyy, double izz, double ixy, double ixz, double iyz)
Updates link inertia matrix.
Definition: DRInterface.cc:108
gazebo::transport::NodePtr node
Node used for transport.
Definition: DRInterface.hh:77
DRInterface()
Constructor.
Definition: DRInterface.cc:34
static const int POSITION
Position controller type.
Definition: DRInterface.hh:72
void addLinkMass(DRRequest &msg, const std::string &model, const std::string &link, double mass)
Updates link mass.
Definition: DRInterface.cc:90
gap::msgs::ModelCmd ModelCmdMsg
Declaration for model command message type.
Definition: DRInterface.hh:50
gazebo::transport::PublisherPtr pub
Publisher to the request topic.
Definition: DRInterface.hh:79