In this assignment, you will implement some simple soccer-playing agents. All parts of this assignment can be done with purely reactive behaviors. Please describe in your email to us the extent to which your behaviors are reactive. (It's OK if they're not, just make sure that if you create an agent that is non-reactive in some way, you describe clearly why not in your email).
This assignment (and all for this course) is about creating agents. It's not about programming. If you have programming questions/problems, etc. (e.g. "How do I generate a random number in C?") ask the class list early and often.
A good debugging tool is to print stuff out, in C you can do it with printf or in C++ you can do it with cout. Here is a simple example which should help (for more info check the printf reference):
#include <stdio.h> // This should be at the top of the file ... char str[10] = "agents"; int num = 1; double dbl = 2.0; // It prints out the value of variables str,num and dbl. // Notice the difference between %s, %d and %f. printf("string: %s, int:%d, double:%f\n", str, num, dbl);The output would be: "string: agents, int:1, double:2.000000"
The codebase also has a LOG_STR
macro which takes in a string and prints out both the string as well as the line
of code the string is being printed from. The
code LOG_STR("hello");
placed in
selectSkill()
at line 82 of strategy.cc would produce
the following output: strategy.cc:selectSkill():82:: hello.
In RoboViz you can draw things on the field to help with debugging. The following is an example of how to draw a red dot on the field 1 meter away from the agent and 15 degrees from the agent's current orientation.
char buf[512]; sprintf(buf, "DrawPoint.%d", worldModel->getUNum()); string str = string(buf); float pointDistance = 1.0; float pointAngle = 15.0; // Convert from polar to cartesian VecPosition drawPoint = VecPosition::getVecPositionFromPolar(pointDistance, pointAngle, 0); // Converts point from local to global coordinate system that // RoboViz uses when drawing. This conversion is possible as the // agent localizes itself using a particle filter (or in the case of // this assignment ground truth localization data provided by the server). drawPoint = worldModel->l2g(drawPoint); // Need to rotate point 180 degrees around origin to line up with global // coordinate system if agent is starting on the right side if (worldModel->getSide() == SIDE_RIGHT) { drawPoint = drawPoint.rotateAboutZ(180); } // Set color of dot float red = 1.0; float green = 0.0; float blue = 0.0; // Set size of dot float size = 5.0; // Set position of dot float x = drawPoint.getX(); float y = drawPoint.getY(); float z = 0.0; // Write drawing code to str worldModel->getRVSender()->drawPoint ( x, y, z, size, red, green, blue, &str ); // Pass str containing draw instruction to RoboViz worldModel->getRVSender()->swapBuffers(&str);There are methods for drawing things in RoboViz other than points, such as lines and annotations, contained in rvdraw.h. These are the
draw*()
methods. Additional information about drawing
objects in RoboViz can be found on the RoboViz
drawing protocol page.
A good method for parsing strings, is sscanf. Here is an example:
#include <stdio.h> // This should be at the top of the file ... char str[20] = "((b) 23 1.5)"; int i = 0; double dbl = 0; // The integer value appeared at the place of the %d would go to the i variable, // and the the double value would go to the dbl variable. sscanf(str, "((b) %d %lf)", &i, &dbl); printf("i:%d dbl:%f\n", i, dbl);The output would be: "i:23 dbl:1.50000"
The strstr() function may also be useful. (Here is code that parses a sample server message and find the distance and angle to the ball.)
Also, the sprintf() function is useful for creating strings with variable content. For example, you can use sprintf() to create a
(dash N)string for any number N.
Instructions:
% cp -r /projects/cs344M.pstone/3d/nao-agent .IMPORTANT: You will need to do this step again even if you already did this for the first assignment (you should delete all files copied from the first assignment) as the codebase has been updated for the second assignment.
% rcroboviz
% ./agentspark --host=localhost --team myteam --unum 2 --paramsfile paramfiles/defaultParams.txt&
You will see the same behavior as last week. This time instead of starting play with a kickoff do a drop ball by pressing 'b' or press 'o' and choose PlayOn from the play mode selection menu. This is necessary as your agent will want to touch the ball multiple times during this assignment and kickoff rules limit the agent to only touching the ball once until another agent touches the ball after a kickoff.
Your task is to alter the code in strategy.cc that the player does the following :
beam()
method) where -15 < x < 0, -10 < y < 10.worldModel->getSide()
method which returns an enumerated value of either SIDE_LEFT
or SIDE_RIGHT
.worldModel->getLastVisionInput()
method to find the distance
and angle to the ball and/or the relevant goal posts (if they're in the player's view).(ObjName (pol <radius> <theta> <phi>))These values are in a spherical coordinate system but you don't really need to understand this as the VecPosition class makes it easy to convert from spherical to cartesian coordinate values. Also it is a good idea to transform these measurements from the robot's camera to be relative to its body origin for better accuracy. Look at the code again in tst.cc to see an example of how to do this. The
ObjName
variable can be many things, including: Note that objects can only be seen in a 120 degree view cone.
getWalk(direction /*in degrees*/, rotation
/*in degrees*/, speed /*0-1*/)
method.
getWalk(0, 0, 1); // Walk forwards getWalk(180, 0, 1); // Walk backwards getWalk(-90, 0, 1); // Walk to the right getWalk(90, 0, 1); // Walk to the left getWalk(0, -90, 0); // Turn clockwise getWalk(0, 90, 0); // Turn counter-clockwise
canKick()
method and see if it returns true
.kickBall(kickTypeToUse, direction, distance)
method. This will put the agent in an auto pilot mode to kick the ball in the specified direction. Parameters for kickBall
are the following:
kickTypeToUse: enumerated int value of KICK_LONG, KICK_MED, KICK_QUICK, KICK_IK, or KICK_DRIBBLE (any of these are fine) direction: angle in degrees relative to agent's current orientation to kick the ball toward distance: distance away from the agent that its desired target to kick the ball toward is
stopKickBall()
method.What to turn in:
--team
command line option.
Turn in a logfile that runs at least until one player scores or 120 seconds (whichever comes first).What to turn in:
A logfile called [yourlogin]-1on13d.log compressed with gzip.
Hints:
What to turn in:
This assignment will be graded as follows:
Part 1:
Part 2: 1 point if it works.
Part 3:
Description:
Page maintained by
Patrick MacAlpine
Questions? Send me
mail