You are on page 1of 4

Robot Soccer Programming 2

Robot Soccer Programming

Robot Soccer Programming Lab 2 : Robot Dance


1. Objectives i. To create strategy in Robot Soccer using Visual C++. ii. To create strategy and simulate in Robot Soccer Simulator. iii. To create Robot Dance in Robot Soccer. 2. System Requirements i. Personal Computer. ii. Visual Studio. iii. Robot Soccer Simulator. 3. Ball Chasser For made the robot follow the ball you can added this code extern "C" STRATEGY_API void Strategy ( Environment *env ) { int desired_angle = 30; switch (env->gameState) { case 0: { MerlinPosition(&env->home [0], env>currentBall.pos.x, env->currentBall.pos.y, 0.1); } break; } } 4. Display Robot Coordinate i. Open RobotSoccer Simutaor ii. Click Strategy Then click open Viewer

Faculty of Information Science & Technology, UKM | Robot Soccer Programming

Robot Soccer Programming 2

Robot Soccer Programming

iii. Click i for showing frame counter, B1, B2,B3,B4,B5, for showing coordinate of Blue Robot [number] Coordinates, Y1,Y2,Y3,Y4,Y5, for Yellow Robots(Opponent) Coordinates n Ball for Showing ball Coordinates (but in this simulator system is not working / the ball coordinates is no correct ), Code for showing robot coordinates in screen added this program into your latest strategy. extern "C" STRATEGY_API void Strategy ( Environment *env ) { int desired_angle = 30; switch (env->gameState) { case 0: { MerlinPosition(&env->home [0], env>currentBall.pos.x, env->currentBall.pos.y, 1.5); OutputToWindow(env->home [0].pos.x,env->home [0].pos.y,env->currentBall.pos.x,env->currentBall.pos.y); PrintToFile(env->home [0].pos.x,env->home [0].pos.y); } break; } void OutputToWindow(double xr, double yr, double xb, double yb) { HWND hWnd = GetActiveWindow(); HDC hDC = GetDC(hWnd); RECT pos = {0,550,600,580}; char buffer[500]={0}; sprintf(buffer,"Robot x: %.02f, Y:%.02f\0", xr,yr);
Faculty of Information Science & Technology, UKM | Robot Soccer Programming

Robot Soccer Programming 2

Robot Soccer Programming

DrawText(hDC, buffer, strlen(buffer),&pos,0); sprintf(buffer,"\n ball x: %.02f, Y:%.02f\0", xb,yb); DrawText(hDC, buffer, strlen(buffer),&pos,0); ReleaseDC(hWnd,hDC); } void PrintToFile(double x, double y) { FILE * fp = fopen("logx.csv","a"); fprintf(fp,"%.02f, %.02f\n",x,y); fclose(fp); } Void OutputToWindow Uses for showing the Robot and Ball Coordnate in Screen. Void PrintTo File for save the ball coordinate in your files. For oppening the file Open yor windows Explorer C:\Documents and Settings\Computer user\ 5. Move Around The Field Robot Soccer code for Moving around of the Field. For Made robot moving around the field ypu can added the code below : extern "C" STRATEGY_API void Strategy ( Environment *env ) { int desired_angle = 30; switch (env->gameState) { case 0: { static int state = 0; bool r0 = false; if (state==0) { // see if we are close enough to the target position r0 = MerlinPosition (&env->home[0],88,71,1); if (r0 == true) { state = 1; } } if (state==1) { // see if we are close enough to the target position r0 = MerlinPosition (&env->home[0],11,72,1); if (r0 == true) state = 2; } if (state==2)
Faculty of Information Science & Technology, UKM | Robot Soccer Programming

Robot Soccer Programming 2

Robot Soccer Programming

{ // see if we are close enough to the target position r0 = MerlinPosition (&env->home[0],11,10,1); if (r0 == true) state = 3; } if (state==3) { // see if we are close enough to the target position r0 = MerlinPosition (&env->home[0],88,10,1); if (r0 == true) state = 0; } } break; } } 6. Task a. Modify your robot soccer strategy for running all code above. b. Discuss your scenario, song and RobotDance Storyboards. c. Create RobotDance Strategy. 7. Group Exercise (2 student each group) a. Create Robot Dance follow your Music with your creativity and innovation. b. Create Storyboard that illustrates the movement of the robot dance

Faculty of Information Science & Technology, UKM | Robot Soccer Programming

You might also like