Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _ARIAC_HH_
00018 #define _ARIAC_HH_
00019
00020 #include <ostream>
00021 #include <map>
00022 #include <string>
00023 #include <vector>
00024
00025 #include <gazebo/gazebo.hh>
00026
00027 namespace ariac
00028 {
00029 using namespace gazebo;
00030
00031 typedef std::string KitType_t;
00032 typedef std::string TrayID_t;
00033 typedef std::string GoalID_t;
00034
00036 class TrayScore
00037 {
00042 public: friend std::ostream &operator<<(std::ostream &_out,
00043 const TrayScore &_obj)
00044 {
00045 _out << "<tray_score " << _obj.trayID << ">" << std::endl;
00046 _out << "Total score: [" << _obj.total() << "]" << std::endl;
00047 _out << "Complete: [" << (_obj.isComplete ? "true" : "false") << "]" << std::endl;
00048 _out << "Part presence score: [" << _obj.partPresence << "]" << std::endl;
00049 _out << "All parts bonus: [" << _obj.allPartsBonus << "]" << std::endl;
00050 _out << "Part pose score: [" << _obj.partPose << "]" << std::endl;
00051 _out << "</tray_score>" << std::endl;
00052 return _out;
00053 }
00054 public: TrayID_t trayID;
00055 double partPresence = 0.0;
00056 double allPartsBonus = 0.0;
00057 double partPose = 0.0;
00058 bool isComplete = false;
00059
00061 double total() const
00062 {
00063 return partPresence + allPartsBonus + partPose;
00064 }
00065 };
00066
00068 class GoalScore
00069 {
00074 public: friend std::ostream &operator<<(std::ostream &_out,
00075 const GoalScore &_obj)
00076 {
00077 _out << "<goal_score " << _obj.goalID << ">" << std::endl;
00078 _out << "Total score: [" << _obj.total() << "]" << std::endl;
00079 _out << "Time taken: [" << _obj.timeTaken << "]" << std::endl;
00080 _out << "Complete: [" << (_obj.isComplete() ? "true" : "false") << "]" << std::endl;
00081 for (const auto & item : _obj.trayScores)
00082 {
00083 _out << item.second << std::endl;
00084 }
00085 _out << "</goal_score>" << std::endl;
00086 return _out;
00087 }
00088
00090 public: std::map<TrayID_t, TrayScore> trayScores;
00091
00093 GoalID_t goalID;
00094
00096 double timeTaken = 0.0;
00097
00101 bool isComplete() const
00102 {
00103 bool isGoalComplete = !this->trayScores.empty();
00104 for (const auto & item : this->trayScores)
00105 {
00106 isGoalComplete &= item.second.isComplete;
00107 if (!isGoalComplete)
00108 {
00109 break;
00110 }
00111 }
00112 return isGoalComplete;
00113 };
00114
00116 double total() const
00117 {
00118 double total = 0.0;
00119 for (const auto & item : this->trayScores)
00120 {
00121 total += item.second.total();
00122 }
00123 return total;
00124 };
00125 };
00126
00128 class GameScore
00129 {
00134 public: friend std::ostream &operator<<(std::ostream &_out,
00135 const GameScore &_obj)
00136 {
00137 _out << "<game_score>" << std::endl;
00138 _out << "Total score: [" << _obj.total() << "]" << std::endl;
00139 _out << "Total process time: [" << _obj.totalProcessTime << "]" << std::endl;
00140 _out << "Part travel time: [" << _obj.partTravelTime << "]" << std::endl;
00141 for (const auto & item : _obj.goalScores)
00142 {
00143 _out << item.second << std::endl;
00144 }
00145 _out << "</game_score>" << std::endl;
00146 return _out;
00147 }
00148
00149 public: double totalProcessTime = 0.0;
00150 double partTravelTime = 0.0;
00151 double planningTime = 0.0;
00152 double partTravelDistance = 0.0;
00153 double manipulatorTravelDistance = 0.0;
00154
00155
00156 std::map<GoalID_t, GoalScore> goalScores;
00157
00159 double total() const
00160 {
00161 double total = 0;
00162 total += totalProcessTime;
00163 total += partTravelTime;
00164 total += planningTime;
00165 total += partTravelDistance;
00166 total += manipulatorTravelDistance;
00167
00168 for (const auto & item : this->goalScores)
00169 {
00170 total += item.second.total();
00171 }
00172 return total;
00173 };
00174 };
00175
00177
00178 class ScoringParameters
00179 {
00184 public: friend bool operator==(const ScoringParameters &sp1, const ScoringParameters &sp2)
00185 {
00186 return (
00187 sp1.objectPresence == sp2.objectPresence &&
00188 sp1.objectPosition == sp2.objectPosition &&
00189 sp1.objectOrientation == sp2.objectOrientation &&
00190 sp1.allObjectsBonusFactor == sp2.allObjectsBonusFactor &&
00191 sp1.distanceThresh == sp2.distanceThresh);
00192 }
00193
00198 public: friend bool operator!=(const ScoringParameters &sp1, const ScoringParameters &sp2)
00199 {
00200 return !(sp1 == sp2);
00201 }
00202
00203 public: double objectPresence = 1.0;
00204 public: double objectPosition = 0.0;
00205 public: double objectOrientation = 1.0;
00206
00207
00208 public: double allObjectsBonusFactor = 1.0;
00209
00210
00211
00212
00213 public: double distanceThresh = 0.03;
00214
00215
00216
00217
00218 public: double orientationThresh = 0.1;
00219 };
00220
00222 TrayID_t DetermineModelType(const std::string &modelName)
00223 {
00224 TrayID_t modelType(modelName);
00225
00226
00227 size_t index = modelType.find_last_of('|');
00228 modelType = modelType.substr(index + 1);
00229
00230
00231 index = modelType.find_last_not_of("0123456789");
00232 if (modelType[index] == '_' && index > 1)
00233 {
00234 modelType = modelType.substr(0, index);
00235 }
00236
00237 return modelType;
00238 }
00239
00241 class KitObject
00242 {
00247 public: friend std::ostream &operator<<(std::ostream &_out,
00248 const KitObject &_obj)
00249 {
00250 _out << "<object>" << std::endl;
00251 _out << "Type: [" << _obj.type << "]" << std::endl;
00252 _out << "Pose: [" << _obj.pose << "]" << std::endl;
00253 _out << "</object>" << std::endl;
00254 return _out;
00255 }
00256
00258 public: std::string type;
00259
00261 public: math::Pose pose;
00262
00263 };
00264
00266 class Kit
00267 {
00272 public: friend std::ostream &operator<<(std::ostream &_out,
00273 const Kit &_kit)
00274 {
00275 _out << "<kit type='" << _kit.kitType << "'>";
00276 for (const auto & obj : _kit.objects)
00277 _out << std::endl << obj;
00278 _out << std::endl << "</kit>" << std::endl;
00279
00280 return _out;
00281 }
00282
00284 public: KitType_t kitType;
00285
00287 public: std::vector<KitObject> objects;
00288 };
00289
00291 class Goal
00292 {
00296 public: bool operator<(const Goal &_goal) const
00297 {
00298 return this->startTime < _goal.startTime;
00299 }
00300
00305 public: friend std::ostream &operator<<(std::ostream &_out,
00306 const Goal &_goal)
00307 {
00308 _out << "<Goal>" << std::endl;
00309 _out << "Start time: [" << _goal.startTime << "]" << std::endl;
00310 _out << "Allowed time: [" << _goal.allowedTime << "]" << std::endl;
00311 _out << "Kits:" << std::endl;
00312 for (const auto & item : _goal.kits)
00313 {
00314 _out << item.second << std::endl;
00315 }
00316 _out << "</goal>" << std::endl;
00317
00318 return _out;
00319 }
00320
00322 public: GoalID_t goalID;
00323
00325 public: double startTime;
00326
00329 public: double allowedTime;
00330
00332 public: std::map<KitType_t, Kit> kits;
00333
00335 public: double timeTaken;
00336 };
00337 }
00338 #endif