4.12 Visualising Behaviours
So ofcourse you can use cout
to write to the terminal, however, since each agent is doing this in parrallel it might not be as easy to debug what is happening this way. One way around this is to use the UNUM
inside the print statement so that you know which agent wrote this message:
cout << "Player:" << worldModel->getUNum() << " the message or variable you want to print"
However a better way to do this is to draw information directly onto the RoboViz window using RVSender()
which can be used to draw text or shapes onto the field.
As you might have seen in the Field section we can use RVSender()
to draw lines and Text to the screen
worldModel->getRVSender()->drawLine("line2", 5,-HALF_FIELD_Y, 5,HALF_FIELD_Y, 0,0,0);
The line function takes in the following parameters ("name", "startX", "StartY", "EndX", "EndY", "Red", "Blue", "Green")
worldModel->getRVSender()->drawText("Bottom-5",std::to_string(-5)+","+std::to_string(int(-HALF_FIELD_Y)),-5,-HALF_FIELD_Y,0,0,0);
The text function takes in the following parameters ("name", "the text to be displayed", "startX", "StartY", "EndX", "EndY", "Red", "Blue", "Green")
However a more useful approach is to draw circles at the position of your players to indicate which behaviour they are performing in your decision tree. That can be accomplished as follows:
VecPosition _myPos = worldModel->getMyPosition();
worldModel->getRVSender()->drawCircle("Im at Pos",_myPos.getX(), _myPos.getY(),0.2,1,0.5,0); //ORANGE
The circle function takes in the following parameters ("name", "X Pos", "Y Pos", "Circle Radius", "Blue", "Green")
Below is an example demonstrating the drawing capabilities using our simply task of assigning different tasks based on playernumber
worldModel->getRVSender()->clear(); // erases drawings from previous cycle
int _playerNumber = worldModel->getUNum();
VecPosition _myPos = worldModel->getMyPosition();
if(_playerNumber ==1){
worldModel->getRVSender()->drawCircle("Im at Pos",_myPos.getX(), _myPos.getY(),0.2,1,0,0); //RED
return kickBall(KICK_FORWARD, VecPosition(HALF_FIELD_X, 0, 0)); // Basic kick
}
else{
worldModel->getRVSender()->drawCircle("Im at Pos",_myPos.getX(), _myPos.getY(),0.2,0,1,0); //GREEN
return(SKILL_STAND);
}
return SKILL_STAND;