18 #include <geographic_msgs/GeoPoseStamped.h> 19 #include <geographic_msgs/GeoPath.h> 20 #include <std_msgs/Float64.h> 21 #include <std_msgs/Float64MultiArray.h> 22 #include <std_msgs/String.h> 24 #include <gazebo/common/Console.hh> 25 #include <gazebo/common/SphericalCoordinates.hh> 26 #include <ignition/math/Quaternion.hh> 27 #include <ignition/math/Vector3.hh> 28 #include <gazebo/physics/Model.hh> 35 : waypointMarkers(
"waypoint_marker")
37 gzmsg <<
"Wayfinding scoring plugin loaded" << std::endl;
48 gzmsg <<
"Task [" << this->
TaskName() <<
"]" << std::endl;
51 if (!this->
sdf->HasElement(
"waypoints"))
53 gzerr <<
"Unable to find <waypoints> element in SDF." << std::endl;
56 auto waypointsElem = this->
sdf->GetElement(
"waypoints");
59 if (!waypointsElem->HasElement(
"waypoint"))
61 gzerr <<
"Unable to find <waypoint> element in SDF." << std::endl;
64 auto waypointElem = waypointsElem->GetElement(
"waypoint");
68 ignition::math::Vector3d latlonyaw =
69 waypointElem->Get<ignition::math::Vector3d>(
"pose");
73 ignition::math::Vector3d scVec(latlonyaw.X(), latlonyaw.Y(), 0.0);
75 #if GAZEBO_MAJOR_VERSION >= 8 76 ignition::math::Vector3d cartVec =
77 _world->SphericalCoords()->LocalFromSpherical(scVec);
79 ignition::math::Vector3d cartVec =
80 _world->GetSphericalCoordinates()->LocalFromSpherical(scVec);
83 cartVec.Z() = latlonyaw.Z();
90 gzmsg <<
"Waypoint, Spherical: Lat = " << latlonyaw.X()
91 <<
" Lon = " << latlonyaw.Y() << std::endl;
92 gzmsg <<
"Waypoint, Local: X = " << cartVec.X()
93 <<
" Y = " << cartVec.Y() <<
" Yaw = " << cartVec.Z() << std::endl;
95 waypointElem = waypointElem->GetNextElement(
"waypoint");
101 this->
rosNode->advertise<geographic_msgs::GeoPath>(
105 this->
rosNode->advertise<std_msgs::Float64MultiArray>(
109 this->
rosNode->advertise<std_msgs::Float64>(
116 if (_sdf->HasElement(
"markers"))
125 waypoint.Y(), waypoint.Z(), std::to_string(markerId)))
127 gzerr <<
"Error creating visual marker" << std::endl;
134 gzwarn <<
"Cannot display gazebo markers (Gazebo version < 8)" 146 #if GAZEBO_MAJOR_VERSION >= 8 159 std_msgs::Float64MultiArray minErrorsMsg;
160 std_msgs::Float64 meanErrorMsg;
162 #if GAZEBO_MAJOR_VERSION >= 8 165 const auto robotPose = this->
vehicleModel->GetWorldPose().Ign();
167 double currentHeading = robotPose.Rot().Euler().Z();
169 double currentTotalError = 0;
174 double dx = wp.X() - robotPose.Pos().X();
175 double dy = wp.Y() - robotPose.Pos().Y();
176 double dhdg =
abs(wp.Z() - currentHeading);
177 double headError = 1 -
abs(dhdg - M_PI)/M_PI;
179 double poseError =
sqrt(
pow(dx, 2) +
pow(dy, 2)) + headError;
194 currentTotalError += this->
minErrors.at(i);
200 minErrorsMsg.layout.dim.push_back(std_msgs::MultiArrayDimension());
201 minErrorsMsg.layout.dim[0].label =
"minimum errors";
209 if (this->
timer.GetElapsed() >= gazebo::common::Time(1.0))
223 gzmsg <<
"Publishing Waypoints" << std::endl;
224 geographic_msgs::GeoPoseStamped wp_msg;
225 geographic_msgs::GeoPath path_msg;
231 wp_msg.pose.position.latitude = wp.X();
232 wp_msg.pose.position.longitude = wp.Y();
233 wp_msg.pose.position.altitude = 0.0;
235 const ignition::math::Quaternion<double> orientation(0.0, 0.0, wp.Z());
237 wp_msg.pose.orientation.x = orientation.X();
238 wp_msg.pose.orientation.y = orientation.Y();
239 wp_msg.pose.orientation.z = orientation.Z();
240 wp_msg.pose.orientation.w = orientation.W();
243 path_msg.poses.push_back(wp_msg);
251 gzmsg <<
"OnReady" << std::endl;
259 gzmsg <<
"OnRunning" << std::endl;
gazebo::event::ConnectionPtr updateConnection
Pointer to the update event connection.
double meanError
Current average minimum error for all waypoints.
std::string TaskName() const
Get the task name.
void PublishWaypoints()
Publish the waypoints through which the vehicle must navigate.
void publish(const boost::shared_ptr< M > &message) const
GZ_REGISTER_WORLD_PLUGIN(UsvWindPlugin)
bool IsAvailable()
Returns if markers are available for current system.
std::vector< double > minErrors
Vector containing current minimum 2D pose error achieved for each waypoint so far.
void OnReady() override
Callback executed when the task state transition into "ready".
std::string TaskState() const
Get the task state.
ros::Publisher meanErrorPub
Publisher for the current rms error.
std::unique_ptr< ros::NodeHandle > rosNode
ROS node handle.
void Load(gazebo::physics::WorldPtr _world, sdf::ElementPtr _sdf)
std::string minErrorsTopic
Topic where the current minimum pose error distance for each waypoint is published.
void Load(gazebo::physics::WorldPtr _world, sdf::ElementPtr _sdf)
ros::Publisher waypointsPub
Publisher for the goal.
std::string waypointsTopic
Topic where the list of waypoints is published.
void Update()
Callback executed at every world update.
ros::Publisher minErrorsPub
Publisher for the combined 2D pose error.
std::vector< ignition::math::Vector3d > localWaypoints
Vector containing waypoints as 3D vectors of doubles representing X Y yaw, where X and Y are local (G...
void Load(sdf::ElementPtr _sdf)
Load marker parameters from SDF.
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
gazebo::physics::WorldPtr world
A world pointer.
std::vector< ignition::math::Vector3d > sphericalWaypoints
Vector containing waypoints as 3D vectors of doubles representing Lattitude Longitude yaw...
gazebo::physics::ModelPtr vehicleModel
Pointer to the vehicle to score.
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
WayfindingScoringPlugin()
Constructor.
WaypointMarkers waypointMarkers
Waypoint visualization markers.
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
bool DrawMarker(int _marker_id, double _x, double _y, double _yaw, std::string _text="")
Draw waypoint marker in Gazebo.
std::string meanErrorTopic
Topic where the current average minimum error is published.
gazebo::common::Timer timer
Timer used to calculate the elapsed time docked in the bay.
A plugin for computing the score of the wayfinding navigation task. This plugin derives from the gene...
void SetScore(double _newScore)
Set the score.
void OnRunning() override
Callback executed when the task state transition into "running".
std::string vehicleName
The name of the vehicle to score.