This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full 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.
- Spring '08