18 #include <std_msgs/Float64.h> 20 #include <gazebo/common/Console.hh> 21 #include <gazebo/common/SphericalCoordinates.hh> 22 #include <gazebo/physics/Model.hh> 23 #include <ignition/math/Quaternion.hh> 24 #include <ignition/math/Vector3.hh> 30 : waypointMarkers(
"station_keeping_marker")
32 gzmsg <<
"Stationkeeping scoring plugin loaded" << std::endl;
43 gzmsg <<
"Task [" << this->
TaskName() <<
"]" << std::endl;
46 ignition::math::Vector3d latlonyaw(0, 0, 0);
47 if (!_sdf->HasElement(
"goal_pose"))
49 ROS_ERROR(
"Unable to find <goal_pose> element in SDF.");
54 latlonyaw = _sdf->Get<ignition::math::Vector3d>(
"goal_pose");
62 ignition::math::Vector3d scVec(this->goalLat, this->
goalLon, 0.0);
64 #if GAZEBO_MAJOR_VERSION >= 8 65 ignition::math::Vector3d cartVec =
66 _world->SphericalCoords()->LocalFromSpherical(scVec);
68 ignition::math::Vector3d cartVec =
69 _world->GetSphericalCoordinates()->LocalFromSpherical(scVec);
73 this->
goalX = cartVec.X();
74 this->
goalY = cartVec.Y();
78 gzmsg <<
"StationKeeping Goal, Spherical: Lat = " << this->goalLat
79 <<
" Lon = " << this->
goalLon << std::endl;
80 gzmsg <<
"StationKeeping Goal, Local: X = " << this->
goalX 81 <<
" Y = " << this->
goalY <<
" Yaw = " << this->
goalYaw << std::endl;
85 this->
goalPub = this->
rosNode->advertise<geographic_msgs::GeoPoseStamped>(
96 if (_sdf->HasElement(
"markers"))
104 gzerr <<
"Error creating visual marker" << std::endl;
109 gzwarn <<
"Cannot display gazebo markers (Gazebo version < 8)" 121 #if GAZEBO_MAJOR_VERSION >= 8 134 std_msgs::Float64 poseErrorMsg;
135 std_msgs::Float64 meanErrorMsg;
137 #if GAZEBO_MAJOR_VERSION >= 8 140 const auto robotPose = this->
vehicleModel->GetWorldPose().Ign();
143 double currentHeading = robotPose.Rot().Euler().Z();
144 double dx = this->
goalX - robotPose.Pos().X();
145 double dy = this->
goalY - robotPose.Pos().Y();
146 double dhdg =
abs(this->
goalYaw - currentHeading);
147 double headError = 1 -
abs(dhdg - M_PI)/M_PI;
159 if (this->
timer.GetElapsed() >= gazebo::common::Time(1.0))
173 gzmsg <<
"Publishing Goal coordinates" << std::endl;
174 geographic_msgs::GeoPoseStamped goal;
177 goal.pose.position.latitude = this->
goalLat;
178 goal.pose.position.longitude = this->
goalLon;
179 goal.pose.position.altitude = 0.0;
181 const ignition::math::Quaternion<double> orientation(0.0, 0.0, this->
goalYaw);
183 goal.pose.orientation.x = orientation.X();
184 goal.pose.orientation.y = orientation.Y();
185 goal.pose.orientation.z = orientation.Z();
186 goal.pose.orientation.w = orientation.W();
196 gzmsg <<
"OnReady" << std::endl;
204 gzmsg <<
"OnRunning" << std::endl;
void OnReady() override
Callback executed when the task state transition into "ready".
std::string poseErrorTopic
Topic where 2D pose error is published.
A plugin for computing the score of the station keeping task. This plugin derives from the generic Sc...
std::string TaskName() const
Get the task name.
WaypointMarkers waypointMarkers
Waypoint visualization markers.
void publish(const boost::shared_ptr< M > &message) const
double meanError
Cumulative 2D RMS error in meters.
double goalY
Goal pose in local (Gazebo) coordinates.
GZ_REGISTER_WORLD_PLUGIN(UsvWindPlugin)
bool IsAvailable()
Returns if markers are available for current system.
std::string TaskState() const
Get the task state.
double poseError
Combined 2D pose error (distance and yaw).
ros::Publisher goalPub
Publisher for the goal.
void Load(gazebo::physics::WorldPtr _world, sdf::ElementPtr _sdf)
void Update()
Callback executed at every world update.
double goalLon
Goal pose in spherical (WGS84) coordinates.
double goalLat
Goal pose in spherical (WGS84) coordinates.
void PublishGoal()
Publish the goal pose.
gazebo::event::ConnectionPtr updateConnection
Pointer to the update event connection.
std::string meanErrorTopic
Topic where mean pose error is published.
std::string goalTopic
Topic where the task stats are published.
double goalYaw
Goal pose in local (Gazebo) coordinates.
double totalPoseError
Sum of all pose error scores calculated so far.
void Load(gazebo::physics::WorldPtr _world, sdf::ElementPtr _sdf)
void Load(sdf::ElementPtr _sdf)
Load marker parameters from SDF.
void OnRunning() override
Callback executed when the task state transition into "running".
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
gazebo::physics::WorldPtr world
A world pointer.
gazebo::physics::ModelPtr vehicleModel
Pointer to the vehicle to score.
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
StationkeepingScoringPlugin()
Constructor.
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
std::unique_ptr< ros::NodeHandle > rosNode
ROS node handle.
bool DrawMarker(int _marker_id, double _x, double _y, double _yaw, std::string _text="")
Draw waypoint marker in Gazebo.
unsigned int sampleCount
Number of instant pose error scores calculated so far .
ros::Publisher meanErrorPub
Publisher for the current mean error.
gazebo::common::Timer timer
Timer used to calculate the elapsed time docked in the bay.
ros::Publisher poseErrorPub
Publisher for the combined 2D pose error.
void SetScore(double _newScore)
Set the score.
double goalX
Goal pose in local (Gazebo) coordinates.
std::string vehicleName
The name of the vehicle to score.