function fhandle = hw03_hard % Approach food and avoid toxin % Make a hard-switch between food approach and % toxin avoidance, based on toxin levels % % MCB 419, Brain, Behavior & Info Processing % M. Nelson, 2007 %----------------------------------------------------------- % parameters L = 1; R = 2; OPEN = 1; CLOSED = 0; %#ok % default inputs/outputs sensor = []; motor.wheel = [0 0]; motor.mouth = CLOSED; motor.flash = 0.0; % state variables % -- none -- % function handle fhandle = @controller; function output = controller(cmd, input) switch cmd case 'update' % INPUT sensor = input; %----------------------------------------------------- % USER UPDATE CODE GOES HERE % Make a hard-switch between food approach and % toxin avoidance, based on toxin levels % check toxin level if(sum(sensor.toxin) > 0.8) % avoid toxin (crossed inhib - Brait explorer) gain = 1; motor.wheel(L) = 0.38 - gain * sensor.toxin(R); motor.wheel(R) = 0.40 - gain * sensor.toxin(L); motor.mouth = CLOSED; else % approach food (crossed excit - Brait aggressive) gain = 3; motor.wheel(L) = 0.38 + gain * sensor.food(R); motor.wheel(R) = 0.40 + gain * sensor.food(L); motor.mouth = OPEN; end %----------------------------------------------------- % OUTPUT output = motor; case 'disp' try disp('sensor:'); disp(sensor); disp('motor:'); disp(motor); if(exist('state','var')) disp('state:'); disp(state); end catch end end end end