waypoint_markers.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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 
19 
21 WaypointMarkers::WaypointMarkers(std::string _namespace)
22  : ns(_namespace), material("Gazebo/Red"), scaling{0.2, 0.2, 1.5}, height(4.0)
23 {
24 }
25 
27 void WaypointMarkers::Load(sdf::ElementPtr _sdf)
28 {
29  if (_sdf->HasElement("material"))
30  {
31  this->material = _sdf->Get<std::string>("material");
32  }
33 
34  if (_sdf->HasElement("scaling"))
35  {
36  this->scaling = _sdf->Get<ignition::math::Vector3d>("scaling");
37  }
38 
39  if (_sdf->HasElement("height"))
40  {
41  this->height = _sdf->Get<double>("height");
42  }
43 }
44 
47 {
48 #if GAZEBO_MAJOR_VERSION >= 8
49  return true;
50 #else
51  return false;
52 #endif
53 }
54 
56 bool WaypointMarkers::DrawMarker(int _marker_id, double _x, double _y,
57  double _yaw, std::string _text)
58 {
59 #if GAZEBO_MAJOR_VERSION >= 8
60  ignition::msgs::Marker markerMsg;
61  markerMsg.set_ns(this->ns);
62  markerMsg.set_action(ignition::msgs::Marker::ADD_MODIFY);
63  ignition::msgs::Material *matMsg = markerMsg.mutable_material();
64  matMsg->mutable_script()->set_name(this->material);
65 
66  // draw cylinder
67  markerMsg.set_type(ignition::msgs::Marker::CYLINDER);
68  ignition::msgs::Set(markerMsg.mutable_scale(),
69  this->scaling);
70  ignition::msgs::Set(markerMsg.mutable_pose(),
71  ignition::math::Pose3d(_x, _y,
72  this->height + this->scaling.Z() / 2.0,
73  0, 0, 0));
74  markerMsg.set_id(_marker_id);
75  bool result = node.Request("/marker", markerMsg);
76  if (!result)
77  {
78  return false;
79  }
80  // draw direction cylinder
81  markerMsg.set_type(ignition::msgs::Marker::CYLINDER);
82  ignition::msgs::Set(markerMsg.mutable_scale(),
83  this->scaling);
84  ignition::msgs::Set(markerMsg.mutable_pose(),
85  ignition::math::Pose3d(_x + cos(_yaw), _y + sin(_yaw),
86  this->height + this->scaling.Z() / 2.0,
87  0, M_PI/2, _yaw));
88  markerMsg.set_id((_marker_id+1)*1000);
89  result = node.Request("/marker", markerMsg);
90  if (!result)
91  {
92  return false;
93  }
94  // draw text
95  if (!_text.empty())
96  {
97  markerMsg.set_type(ignition::msgs::Marker::TEXT);
98  markerMsg.set_text(_text);
99  ignition::msgs::Set(markerMsg.mutable_scale(),
100  ignition::math::Vector3d(1.0, 1.0, 1.0));
101  ignition::msgs::Set(markerMsg.mutable_pose(),
102  ignition::math::Pose3d(_x, _y - 0.2,
103  this->height + this->scaling.Z() + 0.8,
104  0, 0, 0));
105  markerMsg.set_id((_marker_id + 1) * 10000);
106  result = node.Request("/marker", markerMsg);
107  }
108  return result;
109 
110 #else
111  return false;
112 #endif
113 }
bool IsAvailable()
Returns if markers are available for current system.
std::string material
Name of Gazebo material for marker.
WaypointMarkers(std::string _namespace)
Constructor.
double height
Height of marker above water.
void Load(sdf::ElementPtr _sdf)
Load marker parameters from SDF.
std::string ns
Namespace for Gazebo markers.
bool DrawMarker(int _marker_id, double _x, double _y, double _yaw, std::string _text="")
Draw waypoint marker in Gazebo.
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
ignition::math::Vector3d scaling
Scaling factor for cylinder marker.


vrx_gazebo
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Thu May 7 2020 03:54:56