gsiBot - out.student(2).lab = 0; case 'move' % set up...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [out] = gsiBot(self, enemy, tank, mine, req) % % test robot for students during E7 robot tournament % % the code contains the main switch case statement of the robot determining % whether or not it will give the student information or a move. the code % determining the movement is a simple algorithm that goes to the nearest % fuel tank if there are any left and moves towards the enemy if there % aren't anymore. % feel free to use this code to get your started. % % note that a robot of this caliber will not be competitive in the final % tournament. the robots in the tournament will be much stronger. % switch req case 'info' = 'GSI Bot'; out.student(1).first = 'Timmy'; out.student(1).last = 'Siauw'; out.student(1).SID = '12345678'; out.student(1).lab = 0; out.student(2).first = 'James'; out.student(2).last = 'Lew'; out.student(2).SID = '87654321';
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: out.student(2).lab = 0; case 'move' % set up parameters for robot params.speed_fuel = 2; params.speed_end = 2.5; if ~isempty(tank) % start d at infinity d = inf; I = 0; % loop through fuel tanks checking if current fuel tank is % closer than previous closest. for i = 1:length(tank) % get distance to this fuel tank D = norm(tank(i).pos - self.pos); if D < d d = D; I = i; end end % make movement towards closest fuel tank dx = (params.speed_fuel/d)*(tank(I).pos(1)-self.pos(1)); dy = (params.speed_fuel/d)*(tank(I).pos(2)-self.pos(2)); % assign output out = [dx, dy]; else % get distance to enemy d = norm(self.pos - enemy.pos); % make movement toward enemy dx = (params.speed_end/d)*(enemy.pos(1)-self.pos(1)); dy = (params.speed_end/d)*(enemy.pos(2)-self.pos(2)); % assign output out = [dx, dy]; end end % end switch...
View Full Document

This note was uploaded on 11/16/2009 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at University of California, Berkeley.

Page1 / 2

gsiBot - out.student(2).lab = 0; case 'move' % set up...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online