scoring_plugin.hh
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 
18 #ifndef VMRC_GAZEBO_SCORING_PLUGIN_HH_
19 #define VMRC_GAZEBO_SCORING_PLUGIN_HH_
20 
21 #include <ros/ros.h>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 #include <gazebo/common/Events.hh>
26 #include <gazebo/common/Plugin.hh>
27 #include <gazebo/common/Time.hh>
28 #include <gazebo/physics/World.hh>
29 #include <sdf/sdf.hh>
30 #include "vmrc_gazebo/Task.h"
31 
99 class ScoringPlugin : public gazebo::WorldPlugin
100 {
102  public: ScoringPlugin() = default;
103 
104  // Documentation inherited.
105  protected: void Load(gazebo::physics::WorldPtr _world,
106  sdf::ElementPtr _sdf);
107 
110  protected: double Score() const;
111 
114  protected: void SetScore(double _newScore);
115 
118  protected: std::string TaskName() const;
119 
122  protected: std::string TaskState() const;
123 
126  protected: gazebo::common::Time ElapsedTime() const;
127 
130  protected: gazebo::common::Time RemainingTime() const;
131 
134  protected: void Finish();
135 
137  private: void Update();
138 
140  private: void UpdateTime();
141 
143  private: void UpdateTaskState();
144 
146  private: void UpdateTaskMessage();
147 
149  private: void PublishStats();
150 
152  private: void ReleaseVehicle();
153 
155  private: virtual void OnReady();
156 
158  private: virtual void OnRunning();
159 
161  private: virtual void OnFinished();
162 
166  private: bool ParseSDFParameters();
167 
171  private: bool ParseJoints();
172 
174  protected: gazebo::physics::WorldPtr world;
175 
177  protected: std::string taskName = "undefined";
178 
180  protected: gazebo::event::ConnectionPtr updateConnection;
181 
183  protected: std::string topic = "/vmrc/task/info";
184 
186  protected: double score = 0.0;
187 
189  protected: std::string vehicleName;
190 
192  protected: gazebo::physics::ModelPtr vehicleModel;
193 
195  private: sdf::ElementPtr sdf;
196 
198  private: double initialStateDuration = 30.0;
199 
201  private: double readyStateDuration = 60.0;
202 
204  private: double runningStateDuration = 300.0;
205 
207  private: gazebo::common::Time readyTime;
208 
210  private: gazebo::common::Time runningTime;
211 
213  private: gazebo::common::Time finishTime;
214 
216  private: gazebo::common::Time currentTime;
217 
218  // \brief Elapsed time since the start of the task (running state).
219  private: gazebo::common::Time elapsedTime;
220 
222  private: gazebo::common::Time remainingTime;
223 
225  private: bool timedOut = false;
226 
228  private: gazebo::common::Time lastStatsSent = gazebo::common::Time::Zero;
229 
231  private: std::string taskState = "initial";
232 
234  private: vmrc_gazebo::Task taskMsg;
235 
237  private: std::vector<std::string> lockJointNames;
238 
240  private: std::unique_ptr<ros::NodeHandle> rosNode;
241 
244 };
245 
246 #endif
void UpdateTime()
Update all time-related variables.
std::string TaskName() const
Get the task name.
double Score() const
Get the current score.
void ReleaseVehicle()
Tries to release the vehicle in case is locked.
std::vector< std::string > lockJointNames
The name of the joints to be dettached during ReleaseVehicle().
ScoringPlugin()=default
Class constructor.
gazebo::common::Time currentTime
Current time (simulation).
void UpdateTaskMessage()
Update the task stats message.
std::string TaskState() const
Get the task state.
gazebo::common::Time remainingTime
Remaining time since the start of the task (running state).
vmrc_gazebo::Task taskMsg
The next task message to be published.
void Load(gazebo::physics::WorldPtr _world, sdf::ElementPtr _sdf)
double runningStateDuration
Duration (seconds) of the running state (max task time).
void Finish()
Finish the current task. This will set the "finished" flag in the task message to true...
ros::Publisher taskPub
Publisher for the task state.
virtual void OnRunning()
Callback executed when the task state transition into "running".
void UpdateTaskState()
Update the state of the current task.
gazebo::common::Time ElapsedTime() const
Elapsed time in the running state.
bool ParseSDFParameters()
Parse all SDF parameters.
std::string taskState
The task state.
gazebo::common::Time elapsedTime
void PublishStats()
Publish the task stats over a ROS topic.
std::unique_ptr< ros::NodeHandle > rosNode
ROS node handle.
void Update()
Callback executed at every world update.
gazebo::common::Time runningTime
Absolute time specifying the start of the running state.
gazebo::common::Time readyTime
Absolute time specifying the start of the ready state.
A plugin that provides common functionality to any scoring plugin. This plugin defines four different...
gazebo::physics::WorldPtr world
A world pointer.
gazebo::common::Time finishTime
Absolute time specifying the start of the finish state.
gazebo::physics::ModelPtr vehicleModel
Pointer to the vehicle to score.
sdf::ElementPtr sdf
Pointer to the SDF plugin element.
double initialStateDuration
Duration (seconds) of the initial state.
gazebo::common::Time lastStatsSent
Time at which the last message was sent.
gazebo::event::ConnectionPtr updateConnection
Pointer to the update event connection.
gazebo::common::Time RemainingTime() const
Remaining time in the running state.
std::string topic
Topic where the task stats are published.
double readyStateDuration
Duration (seconds) of the ready state.
std::string taskName
The name of the task.
virtual void OnFinished()
Callback executed when the task state transition into "finished".
bool timedOut
Whether the current task has timed out or not.
bool ParseJoints()
Parse the joints section of the SDF block.
void SetScore(double _newScore)
Set the score.
virtual void OnReady()
Callback executed when the task state transition into "ready".
std::string vehicleName
The name of the vehicle to score.
double score
The score.


vmrc_gazebo
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Sun Feb 17 2019 03:14:16