ARIAC.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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 #ifndef _ARIAC_HH_
18 #define _ARIAC_HH_
19 
20 #include <ostream>
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 #include <gazebo/gazebo.hh>
26 
27 namespace ariac
28 {
29  using namespace gazebo;
30 
31  typedef std::string KitType_t;
32  typedef std::string TrayID_t;
33  typedef std::string GoalID_t;
34 
36  class TrayScore
37  {
42  public: friend std::ostream &operator<<(std::ostream &_out,
43  const TrayScore &_obj)
44  {
45  _out << "<tray_score " << _obj.trayID << ">" << std::endl;
46  _out << "Total score: [" << _obj.total() << "]" << std::endl;
47  _out << "Complete: [" << (_obj.isComplete ? "true" : "false") << "]" << std::endl;
48  _out << "Part presence score: [" << _obj.partPresence << "]" << std::endl;
49  _out << "All parts bonus: [" << _obj.allPartsBonus << "]" << std::endl;
50  _out << "Part pose score: [" << _obj.partPose << "]" << std::endl;
51  _out << "</tray_score>" << std::endl;
52  return _out;
53  }
54  public: TrayID_t trayID;
55  double partPresence = 0.0;
56  double allPartsBonus = 0.0;
57  double partPose = 0.0;
58  bool isComplete = false;
59 
61  double total() const
62  {
63  return partPresence + allPartsBonus + partPose;
64  }
65  };
66 
68  class GoalScore
69  {
74  public: friend std::ostream &operator<<(std::ostream &_out,
75  const GoalScore &_obj)
76  {
77  _out << "<goal_score " << _obj.goalID << ">" << std::endl;
78  _out << "Total score: [" << _obj.total() << "]" << std::endl;
79  _out << "Time taken: [" << _obj.timeTaken << "]" << std::endl;
80  _out << "Complete: [" << (_obj.isComplete() ? "true" : "false") << "]" << std::endl;
81  for (const auto & item : _obj.trayScores)
82  {
83  _out << item.second << std::endl;
84  }
85  _out << "</goal_score>" << std::endl;
86  return _out;
87  }
88 
90  public: std::map<TrayID_t, TrayScore> trayScores;
91 
93  GoalID_t goalID;
94 
96  double timeTaken = 0.0;
97 
101  bool isComplete() const
102  {
103  bool isGoalComplete = !this->trayScores.empty();
104  for (const auto & item : this->trayScores)
105  {
106  isGoalComplete &= item.second.isComplete;
107  if (!isGoalComplete)
108  {
109  break;
110  }
111  }
112  return isGoalComplete;
113  };
114 
116  double total() const
117  {
118  double total = 0.0;
119  for (const auto & item : this->trayScores)
120  {
121  total += item.second.total();
122  }
123  return total;
124  };
125  };
126 
128  class GameScore
129  {
134  public: friend std::ostream &operator<<(std::ostream &_out,
135  const GameScore &_obj)
136  {
137  _out << "<game_score>" << std::endl;
138  _out << "Total score: [" << _obj.total() << "]" << std::endl;
139  _out << "Total process time: [" << _obj.totalProcessTime << "]" << std::endl;
140  _out << "Part travel time: [" << _obj.partTravelTime << "]" << std::endl;
141  for (const auto & item : _obj.goalScores)
142  {
143  _out << item.second << std::endl;
144  }
145  _out << "</game_score>" << std::endl;
146  return _out;
147  }
148 
149  public: double totalProcessTime = 0.0;
150  double partTravelTime = 0.0;
151  double planningTime = 0.0;
152  double partTravelDistance = 0.0;
153  double manipulatorTravelDistance = 0.0;
154 
155  // The score of each of the goals during the game.
156  std::map<GoalID_t, GoalScore> goalScores;
157 
159  double total() const
160  {
161  double total = 0;
162  total += totalProcessTime;
163  total += partTravelTime;
164  total += planningTime;
165  total += partTravelDistance;
166  total += manipulatorTravelDistance;
167 
168  for (const auto & item : this->goalScores)
169  {
170  total += item.second.total();
171  }
172  return total;
173  };
174  };
175 
177  // TODO: this should have a different data type
179  {
184  public: friend bool operator==(const ScoringParameters &sp1, const ScoringParameters &sp2)
185  {
186  return (
187  sp1.objectPresence == sp2.objectPresence &&
188  sp1.objectPosition == sp2.objectPosition &&
191  sp1.distanceThresh == sp2.distanceThresh);
192  }
193 
198  public: friend bool operator!=(const ScoringParameters &sp1, const ScoringParameters &sp2)
199  {
200  return !(sp1 == sp2);
201  }
202 
203  public: double objectPresence = 1.0;
204  public: double objectPosition = 0.0;
205  public: double objectOrientation = 1.0;
206 
207  // Bonus when all objects in the tray: factor * (number of objects)
208  public: double allObjectsBonusFactor = 1.0;
209 
210  // Acceptable distance in meters to object's target position.
211  // The measured distance is between the center of the model and its target,
212  // projected onto the tray.
213  public: double distanceThresh = 0.03;
214 
215  // Acceptable difference in radians to object's target orientation.
216  // The measured difference is from a top-down view of the tray, but only if
217  // the quaternions are aligned.
218  public: double orientationThresh = 0.1;
219  };
220 
222  TrayID_t DetermineModelType(const std::string &modelName)
223  {
224  TrayID_t modelType(modelName);
225 
226  // Trim namespaces
227  size_t index = modelType.find_last_of('|');
228  modelType = modelType.substr(index + 1);
229 
230  // Trim trailing underscore and number caused by inserting multiple of the same model
231  index = modelType.find_last_not_of("0123456789");
232  if (modelType[index] == '_' && index > 1)
233  {
234  modelType = modelType.substr(0, index);
235  }
236 
237  return modelType;
238  }
239 
241  class KitObject
242  {
247  public: friend std::ostream &operator<<(std::ostream &_out,
248  const KitObject &_obj)
249  {
250  _out << "<object>" << std::endl;
251  _out << "Type: [" << _obj.type << "]" << std::endl;
252  _out << "Pose: [" << _obj.pose << "]" << std::endl;
253  _out << "</object>" << std::endl;
254  return _out;
255  }
256 
258  public: std::string type;
259 
261  public: math::Pose pose;
262 
263  };
264 
266  class Kit
267  {
272  public: friend std::ostream &operator<<(std::ostream &_out,
273  const Kit &_kit)
274  {
275  _out << "<kit type='" << _kit.kitType << "'>";
276  for (const auto & obj : _kit.objects)
277  _out << std::endl << obj;
278  _out << std::endl << "</kit>" << std::endl;
279 
280  return _out;
281  }
282 
284  public: KitType_t kitType;
285 
287  public: std::vector<KitObject> objects;
288  };
289 
291  class Goal
292  {
296  public: bool operator<(const Goal &_goal) const
297  {
298  return this->startTime < _goal.startTime;
299  }
300 
305  public: friend std::ostream &operator<<(std::ostream &_out,
306  const Goal &_goal)
307  {
308  _out << "<Goal>" << std::endl;
309  _out << "Start time: [" << _goal.startTime << "]" << std::endl;
310  _out << "Allowed time: [" << _goal.allowedTime << "]" << std::endl;
311  _out << "Kits:" << std::endl;
312  for (const auto & item : _goal.kits)
313  {
314  _out << item.second << std::endl;
315  }
316  _out << "</goal>" << std::endl;
317 
318  return _out;
319  }
320 
322  public: GoalID_t goalID;
323 
325  public: double startTime;
326 
329  public: double allowedTime;
330 
332  public: std::map<KitType_t, Kit> kits;
333 
335  public: double timeTaken;
336  };
337 }
338 #endif
std::vector< KitObject > objects
A kit is composed of multiple objects.
Definition: ARIAC.hh:287
Class to store information about a goal.
Definition: ARIAC.hh:291
double total() const
Calculate the total score.
Definition: ARIAC.hh:159
double allPartsBonus
Definition: ARIAC.hh:56
std::string TrayID_t
Definition: ARIAC.hh:32
TrayID_t trayID
Definition: ARIAC.hh:54
friend std::ostream & operator<<(std::ostream &_out, const GameScore &_obj)
Stream insertion operator.
Definition: ARIAC.hh:134
std::map< TrayID_t, TrayScore > trayScores
Mapping between tray IDs and scores.
Definition: ARIAC.hh:90
double timeTaken
Simulation time in seconds spent on this goal.
Definition: ARIAC.hh:335
double totalProcessTime
Definition: ARIAC.hh:149
std::string type
Object type.
Definition: ARIAC.hh:258
double total() const
Calculate the total score.
Definition: ARIAC.hh:61
double partTravelTime
Definition: ARIAC.hh:150
The score of a tray.
Definition: ARIAC.hh:36
std::string GoalID_t
Definition: ARIAC.hh:33
math::Pose pose
Pose in which the object should be placed.
Definition: ARIAC.hh:261
friend std::ostream & operator<<(std::ostream &_out, const GoalScore &_obj)
Stream insertion operator.
Definition: ARIAC.hh:74
Class to store information about each object contained in a kit.
Definition: ARIAC.hh:241
The parameters used for scoring the competition.
Definition: ARIAC.hh:178
double allowedTime
Simulation time in seconds permitted for the goal to be completed before cancelling it...
Definition: ARIAC.hh:329
std::map< KitType_t, Kit > kits
A goal is composed of multiple kits of different types.
Definition: ARIAC.hh:332
bool isComplete() const
Calculate if the goal is complete.
Definition: ARIAC.hh:101
The score of a competition run.
Definition: ARIAC.hh:128
double timeTaken
Time in seconds spend on the goal.
Definition: ARIAC.hh:96
friend std::ostream & operator<<(std::ostream &_out, const KitObject &_obj)
Stream insertion operator.
Definition: ARIAC.hh:247
bool operator<(const Goal &_goal) const
Less than operator.
Definition: ARIAC.hh:296
std::map< GoalID_t, GoalScore > goalScores
Definition: ARIAC.hh:156
friend std::ostream & operator<<(std::ostream &_out, const Kit &_kit)
Stream insertion operator.
Definition: ARIAC.hh:272
bool isComplete
Definition: ARIAC.hh:58
double total() const
Calculate the total score.
Definition: ARIAC.hh:116
GoalID_t goalID
The ID of this goal.
Definition: ARIAC.hh:322
friend std::ostream & operator<<(std::ostream &_out, const Goal &_goal)
Stream insertion operator.
Definition: ARIAC.hh:305
std::string KitType_t
Definition: ARIAC.hh:31
friend bool operator==(const ScoringParameters &sp1, const ScoringParameters &sp2)
Equality comparison operator.
Definition: ARIAC.hh:184
double allObjectsBonusFactor
Definition: ARIAC.hh:208
double startTime
Simulation time in which the goal should be triggered.
Definition: ARIAC.hh:325
GoalID_t goalID
ID of the goal being scored.
Definition: ARIAC.hh:93
TrayID_t DetermineModelType(const std::string &modelName)
Determine the type of a gazebo model from its name.
Definition: ARIAC.hh:222
The score of a goal.
Definition: ARIAC.hh:68
double partPresence
Definition: ARIAC.hh:55
friend bool operator!=(const ScoringParameters &sp1, const ScoringParameters &sp2)
Inequality comparison operator.
Definition: ARIAC.hh:198
Class to store information about a kit.
Definition: ARIAC.hh:266
double partPose
Definition: ARIAC.hh:57
Definition: ARIAC.hh:27
KitType_t kitType
The type of the kit.
Definition: ARIAC.hh:284
friend std::ostream & operator<<(std::ostream &_out, const TrayScore &_obj)
Stream insertion operator.
Definition: ARIAC.hh:42


osrf_gear
Author(s):
autogenerated on Wed Sep 7 2016 03:48:12