20 #include <gazebo/math/Pose.hh>    21 #include <gazebo/math/Vector3.hh>    22 #include <gazebo/math/Quaternion.hh>    64   auto v = std::getenv(
"ARIAC_COMPETITION");
    87   for (
const auto & item : this->
kitTrays)
    89     auto trayID = item.first;
    90     auto tray = item.second;
    91     if (tray.currentKit.kitType != 
"")
    95         "' with kit type '" << tray.currentKit.kitType << 
"': " << trayScore.total());
   101         auto kit = item.second;
   102         auto goalKitType = kit.kitType;
   103         tray.currentKit.kitType = goalKitType;
   106           << 
"' if it were to have kit type '" << goalKitType << 
"': "   107           << trayScore.total());
   116   auto it = this->
kitTrays.find(trayID);
   122   kitTray = it->second;
   147   auto numAssignedObjects = assignedKit.
objects.size();
   149     " assigned objects with the current " <<
   150     kit.
objects.size() << 
" objects");
   153   std::map<std::string, unsigned int> assignedObjectTypeCount, currentObjectTypeCount;
   154   for (
const auto & obj : assignedKit.
objects)
   156     if (assignedObjectTypeCount.find(obj.type) == assignedObjectTypeCount.end())
   158       assignedObjectTypeCount[obj.type] = 0;
   160     assignedObjectTypeCount[obj.type] += 1;
   165   bool assignedObjectsMissing = 
false;
   166   for (
auto & value : assignedObjectTypeCount)
   168     auto assignedObjectType = value.first;
   169     auto assignedObjectCount = value.second;
   170     auto currentObjectCount =
   172         [assignedObjectType](
ariac::KitObject k) {
return k.type == assignedObjectType;});
   174       " objects of type '" << assignedObjectType << 
"'");
   177     if (currentObjectCount < assignedObjectCount)
   179       assignedObjectsMissing = 
true;
   182   if (!assignedObjectsMissing)
   191   std::vector<ariac::KitObject> remainingAssignedObjects(assignedKit.
objects);
   193   for (
const auto & currentObject : kit.
objects)
   195     for (
auto it = remainingAssignedObjects.begin(); it != remainingAssignedObjects.end(); ++it)
   198       auto assignedObject = *it;
   199       if (assignedObject.type != currentObject.type)
   204         "' with the assigned pose '" << assignedObject.pose << 
"'");
   205       gazebo::math::Vector3 posnDiff = assignedObject.pose.CoordPositionSub(currentObject.pose);
   210         "' in the correct position");
   214       gazebo::math::Quaternion objOrientation = currentObject.pose.rot;
   215       gazebo::math::Quaternion goalOrientation = assignedObject.pose.rot;
   219       double orientationDiff = objOrientation.Dot(goalOrientation);
   222       double quaternionDiffThresh = 0.05;
   223       if (std::abs(orientationDiff) < (1.0 - quaternionDiffThresh))
   227       double yawDiff = objOrientation.GetYaw() - goalOrientation.GetYaw();
   232         "' in the correct orientation");
   236       remainingAssignedObjects.erase(it);
   242   if (remainingAssignedObjects.empty())
   256   std::string trayID = trayMsg->tray.data;
   271   this->
kitTrays[trayID].UpdateKitState(kitState);
   281   goal.
goalID = goalMsg->goal_id.data;
   282   for (
const auto & kitMsg : goalMsg->kits)
   287     goal.
kits[kitType] = assignedKit;
   320   for (
const auto & objMsg : kitMsg.objects)
   324     geometry_msgs::Point p = objMsg.pose.position;
   325     geometry_msgs::Quaternion o = objMsg.pose.orientation;
   326     gazebo::math::Vector3 objPosition(p.x, p.y, p.z);
   327     gazebo::math::Quaternion objOrientation(o.w, o.x, o.y, o.z);
   328     obj.
pose = gazebo::math::Pose(objPosition, objOrientation);
 std::vector< KitObject > objects
A kit is composed of multiple objects. 
Class to store information about a goal. 
void AssignGoal(const ariac::Goal &goal)
Assign a goal to process. 
bool isPartTravelling
Whether or not there is a travelling part in the gripper. 
void ScoreCurrentState()
Calculate the score for the trays given the objects in them. 
bool newGoalReceived
Flag for signalling new goal to process. 
std::map< TrayID_t, TrayScore > trayScores
Mapping between tray IDs and scores. 
std::map< ariac::TrayID_t, ariac::KitTray > kitTrays
The trays to monitor the score of. 
void Update(double timeStep=0.0)
Update the scorer. 
std::string type
Object type. 
void OnGripperStateReceived(const osrf_gear::VacuumGripperState &stateMsg)
Callback for receiving gripper state message. 
static void FillKitFromMsg(const osrf_gear::Kit &kitMsg, ariac::Kit &kit)
Helper function for filling a Kit from a kit ROS message. 
ariac::GoalScore UnassignCurrentGoal(double timeTaken=0.0)
Stop processing the current goal. 
Kit currentKit
The current state of the kit on the tray. 
ariac::Goal newGoal
Goal receivd from goal messages. 
bool newTrayInfoReceived
Flag for signalling new tray info to process. 
ariac::GoalScore * goalScore
Pointer to the score of the current goal. 
math::Pose pose
Pose in which the object should be placed. 
void OnTrayInfoReceived(const osrf_gear::KitTray::ConstPtr &trayMsg)
Callback for receiving tray state message. 
std::string trayID
The ID of the tray. 
Class to store information about each object contained in a kit. 
ariac::ScoringParameters scoringParameters
Parameters to use for calculating scores. 
bool IsCurrentGoalComplete()
Get the score of the current goal. 
std::map< KitType_t, Kit > kits
A goal is composed of multiple kits of different types. 
bool isComplete() const 
Calculate if the goal is complete. 
The score of a competition run. 
ariac::GameScore gameScore
The score of the run. 
double timeTaken
Time in seconds spend on the goal. 
void OnGoalReceived(const osrf_gear::Goal::ConstPtr &goalMsg)
Callback for receiving goal message. 
ariac::TrayScore SubmitTray(const ariac::KitTray &tray)
Submit tray for scoring and store the result in the goal score. 
std::map< GoalID_t, GoalScore > goalScores
virtual ~AriacScorer()
Destructor. 
#define ROS_DEBUG_STREAM(args)
GoalID_t goalID
The ID of this goal. 
ariac::GoalScore GetCurrentGoalScore()
Get the score of the current goal. 
double allObjectsBonusFactor
#define ROS_INFO_STREAM(args)
bool GetTrayById(const ariac::TrayID_t &trayID, ariac::KitTray &kitTray)
Get the kit tray with the specified ID. 
TrayID_t DetermineModelType(const std::string &modelName)
Determine the type of a gazebo model from its name. 
Class to store information about a kit. 
ariac::TrayScore ScoreTray(const ariac::KitTray &tray)
Calculate the score for a tray given the type of kit being built. 
boost::mutex kitTraysMutex
Mutex for protecting the kit trays being monitored. 
AriacScorer()
Constructor. 
KitType_t kitType
The type of the kit. 
ariac::Goal currentGoal
Current goal being monitored. 
ariac::GameScore GetGameScore()
Get the current score. 
Class to store information about a kit tray.