Skip to content

Commit 826d6cb

Browse files
authored
Station keeping practice worlds (#582)
* Station keeping practice worlds Signed-off-by: Carlos Agüero <[email protected]>
1 parent 2b829a3 commit 826d6cb

11 files changed

+1835
-81
lines changed

vrx_gz/CMakeLists.txt

+15-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ install(
8181
TARGETS ScoringPlugin
8282
DESTINATION lib)
8383

84+
# Stationkeeping scoring plugin
85+
add_library(StationkeepingScoringPlugin SHARED
86+
src/StationkeepingScoringPlugin.cc
87+
src/WaypointMarkers
88+
)
89+
target_link_libraries(StationkeepingScoringPlugin PUBLIC
90+
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
91+
gz-sim${GZ_SIM_VER}::core
92+
gz-math${GZ_MATH_VER}
93+
ScoringPlugin
94+
)
95+
install(
96+
TARGETS StationkeepingScoringPlugin
97+
DESTINATION lib)
98+
8499
# Wayfinding scoring plugin
85100
add_library(WayfindingScoringPlugin SHARED
86101
src/WayfindingScoringPlugin.cc
@@ -108,7 +123,6 @@ list(APPEND VRX_GZ_PLUGINS
108123
PublisherPlugin
109124
ScanDockScoringPlugin
110125
SimpleHydrodynamics
111-
StationkeepingScoringPlugin
112126
Surface
113127
WaveVisual
114128
WildlifeScoringPlugin

vrx_gz/src/StationkeepingScoringPlugin.cc

+13-32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <gz/plugin/Register.hh>
2525

2626
#include "StationkeepingScoringPlugin.hh"
27+
#include "WaypointMarkers.hh"
2728

2829
using namespace gz;
2930
using namespace vrx;
@@ -91,31 +92,12 @@ class StationkeepingScoringPlugin::Implementation
9192
/// \brief Vehicle to score.
9293
public: sim::Entity vehicleEntity{sim::kNullEntity};
9394

94-
/// \brief Waypoint visualization markers
95-
public: bool markers = false;
96-
97-
/// \brief Display goal marker (currently disabled)
98-
public: void AddMarker();
99-
10095
/// \brief Display or suppress state changes
10196
public: bool silent = false;
102-
};
10397

104-
/////////////////////////////////////////////////
105-
void StationkeepingScoringPlugin::Implementation::AddMarker()
106-
{
107-
msgs::Marker markerMsg;
108-
markerMsg.set_id(0);
109-
markerMsg.set_action(msgs::Marker::ADD_MODIFY);
110-
markerMsg.set_type(msgs::Marker::TRIANGLE_FAN);
111-
112-
msgs::Material *matMsg = markerMsg.mutable_material();
113-
matMsg->mutable_script()->set_name("Gazebo/Red");
114-
msgs::Set(markerMsg.mutable_pose(),
115-
math::Pose3d(this->goalX, this->goalY, 1, 0, 0, this->goalYaw));
116-
bool markerRequest = this->node.Request("/marker", markerMsg);
117-
this->markers = markerRequest;
118-
}
98+
/// \brief Waypoint visualization markers
99+
public: WaypointMarkers waypointMarkers{"station_keeping_marker"};
100+
};
119101

120102
/////////////////////////////////////////////////
121103
StationkeepingScoringPlugin::StationkeepingScoringPlugin()
@@ -235,10 +217,15 @@ void StationkeepingScoringPlugin::Configure(const sim::Entity &_entity,
235217
if (_sdf->HasElement("head_error_on"))
236218
this->dataPtr->headErrorOn = _sdf->Get<bool>("head_error_on");
237219

238-
// if (_sdf->HasElement("markers"))
239-
// {
240-
// this->dataPtr->markers = true;
241-
// }
220+
if (_sdf->HasElement("markers"))
221+
{
222+
this->dataPtr->waypointMarkers.Load(_sdf->Clone()->GetElement("markers"));
223+
if (!this->dataPtr->waypointMarkers.DrawMarker(0,
224+
this->dataPtr->goalX, this->dataPtr->goalY, this->dataPtr->goalYaw))
225+
{
226+
gzerr << "Error creating visual marker" << std::endl;
227+
}
228+
}
242229
}
243230

244231
//////////////////////////////////////////////////
@@ -251,12 +238,6 @@ void StationkeepingScoringPlugin::PreUpdate( const sim::UpdateInfo &_info,
251238

252239
ScoringPlugin::PreUpdate(_info, _ecm);
253240

254-
// Check to see if we need to publish the marker(s)
255-
// if (this->dataPtr->markers)
256-
// {
257-
// this->dataPtr->AddMarker();
258-
// }
259-
260241
if (this->TaskState() == "finished")
261242
return;
262243

vrx_gz/src/WayfindingScoringPlugin.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void WayfindingScoringPlugin::Configure(const sim::Entity &_entity,
200200
for (const auto waypoint : this->dataPtr->localWaypoints)
201201
{
202202
if (!this->dataPtr->waypointMarkers.DrawMarker(markerId, waypoint.X(),
203-
waypoint.Y(), waypoint.Z(), std::to_string(markerId)))
203+
waypoint.Y(), waypoint.Z()))
204204
{
205205
gzerr << "Error creating visual marker" << std::endl;
206206
}

vrx_gz/src/WaypointMarkers.cc

+14-28
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ using namespace vrx;
2626

2727
/////////////////////////////////////////////////
2828
WaypointMarkers::WaypointMarkers(const std::string &_namespace)
29-
: ns(_namespace), material("Gazebo/Red"), scaling{0.2, 0.2, 1.5}, height(4.0)
29+
: ns(_namespace), scaling{0.2, 0.2, 1.5}, height(4.0)
3030
{
3131
}
3232

3333
/////////////////////////////////////////////////
3434
void WaypointMarkers::Load(const std::shared_ptr<const sdf::Element> &_sdf)
3535
{
36-
if (_sdf->HasElement("material"))
37-
this->material = _sdf->Get<std::string>("material");
38-
3936
if (_sdf->HasElement("scaling"))
4037
this->scaling = _sdf->Get<math::Vector3d>("scaling");
4138

@@ -47,22 +44,27 @@ void WaypointMarkers::Load(const std::shared_ptr<const sdf::Element> &_sdf)
4744
}
4845

4946
/////////////////////////////////////////////////
50-
bool WaypointMarkers::DrawMarker(double _x, double _y, double _yaw,
51-
const std::string &_text)
47+
bool WaypointMarkers::DrawMarker(double _x, double _y, double _yaw)
5248
{
53-
return this->DrawMarker(this->id++, _x, _y, _yaw, _text);
49+
return this->DrawMarker(this->id++, _x, _y, _yaw);
5450
}
5551

5652
/////////////////////////////////////////////////
5753
bool WaypointMarkers::DrawMarker(int _markerId, double _x, double _y,
58-
double _yaw, const std::string &_text)
54+
double _yaw)
5955
{
60-
//TODO: Fix below. The markers are not showing up.
6156
msgs::Marker markerMsg;
6257
markerMsg.set_ns(this->ns);
6358
markerMsg.set_action(msgs::Marker_Action_ADD_MODIFY);
64-
msgs::Material *matMsg = markerMsg.mutable_material();
65-
matMsg->mutable_script()->set_name(this->material);
59+
markerMsg.set_visibility(gz::msgs::Marker::GUI);
60+
markerMsg.mutable_material()->mutable_ambient()->set_r(1);
61+
markerMsg.mutable_material()->mutable_ambient()->set_g(1);
62+
markerMsg.mutable_material()->mutable_ambient()->set_b(1);
63+
markerMsg.mutable_material()->mutable_ambient()->set_a(1);
64+
markerMsg.mutable_material()->mutable_diffuse()->set_r(1);
65+
markerMsg.mutable_material()->mutable_diffuse()->set_g(1);
66+
markerMsg.mutable_material()->mutable_diffuse()->set_b(1);
67+
markerMsg.mutable_material()->mutable_diffuse()->set_a(1);
6668

6769
// draw cylinder
6870
markerMsg.set_type(msgs::Marker_Type_CYLINDER);
@@ -79,25 +81,9 @@ bool WaypointMarkers::DrawMarker(int _markerId, double _x, double _y,
7981
msgs::Set(markerMsg.mutable_scale(), this->scaling);
8082
msgs::Set(markerMsg.mutable_pose(), math::Pose3d(
8183
_x + cos(_yaw), _y + sin(_yaw), this->height + this->scaling.Z() / 2.0,
82-
0, M_PI/2, _yaw));
84+
0, M_PI / 2, _yaw));
8385
markerMsg.set_id((_markerId + 1) * 1000);
8486
result = node.Request("/marker", markerMsg);
85-
if (!result)
86-
return false;
8787

88-
// draw text
89-
// if (!_text.empty())
90-
// {
91-
// markerMsg.set_type(msgs::Marker_Type_TEXT);
92-
// markerMsg.set_text(_text);
93-
// msgs::Set(markerMsg.mutable_scale(),
94-
// math::Vector3d(1.0, 1.0, 1.0));
95-
// msgs::Set(markerMsg.mutable_pose(),
96-
// math::Pose3d(_x, _y - 0.2,
97-
// this->height + this->scaling.Z() + 0.8,
98-
// 0, 0, 0));
99-
// markerMsg.set_id((_markerId + 1) * 10000);
100-
// result = node.Request("/marker", markerMsg);
101-
// }
10288
return result;
10389
}

vrx_gz/src/WaypointMarkers.hh

+3-14
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@
2727
namespace vrx
2828
{
2929
/// \brief This class is used to display waypoint markers.
30-
/// Cylindrical Gazebo markers are drawn with text on top
3130
///
3231
/// The marker properties can be set using sdf:
33-
/// material: Optional parameter (string type) to specify the material
34-
/// for marker. Default: Gazebo/Green
3532
/// scaling: Optional parameter (vector type) to specify marker scaling.
3633
/// Default: 0.2 0.2 1.5
3734
/// height: Optional parameter (double type) height of marker above water.
3835
/// initial_id: Optional parameter (int type) to be used as initial ID when
3936
/// drawing markers without explicitly specifying ID.
4037
/// E.g.
4138
/// <markers>
42-
/// <material>Gazebo/Green</material>
4339
/// <scaling>0.2 0.2 2.0</scaling>
4440
/// <height>0.5</height>
4541
/// </markers>
@@ -59,31 +55,24 @@ namespace vrx
5955
/// \param[in] _x X coordinate of waypoint marker
6056
/// \param[in] _y Y coordinate of waypoint marker
6157
/// \param[in] _yaw orientation of waypoint marker in radians
62-
/// \param[in] _text (optional) Text above waypoint marker
6358
/// \return Returns true if marker is successfully sent to Gazebo
6459
public: bool DrawMarker(int _markerId,
6560
double _x,
6661
double _y,
67-
double _yaw,
68-
const std::string &_text = "");
62+
double _yaw);
6963

7064
/// \brief Draw a new waypoint marker in Gazebo
7165
/// \param[in] _x X coordinate of waypoint marker
7266
/// \param[in] _y Y coordinate of waypoint marker
7367
/// \param[in] _yaw orientation of waypoint marker in radians
74-
/// \param[in] _text (optional) Text above waypoint marker
7568
/// \return Returns true if marker is successfully sent to Gazebo
7669
public: bool DrawMarker(double _x,
7770
double _y,
78-
double _yaw,
79-
const std::string &_text = "");
71+
double _yaw);
8072

8173
/// \brief Namespace for Gazebo markers
8274
private: std::string ns;
8375

84-
/// \brief Name of Gazebo material for marker
85-
private: std::string material;
86-
8776
/// \brief Scaling factor for cylinder marker
8877
private: gz::math::Vector3d scaling;
8978

@@ -93,7 +82,7 @@ namespace vrx
9382
/// \brief If an ID is not specified, the markers will start using this one.
9483
private: int id = 0;
9584

96-
/// \brief gazebo transport node
85+
/// \brief Gazebo transport node
9786
private: gz::transport::Node node;
9887
};
9988
}

vrx_gz/src/vrx_gz/launch.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
]
4343

4444
STATIONKEEPING_WORLDS = [
45-
'stationkeeping_task'
45+
'stationkeeping_task',
46+
'practice_2022_stationkeeping0_task',
47+
'practice_2022_stationkeeping1_task',
48+
'practice_2022_stationkeeping2_task',
4649
]
4750

4851
WAYFINDING_WORLDS = [

0 commit comments

Comments
 (0)