-- file light_control.vhd ------------------------------------------------------- -- This file is used to determine the direction and speed -- of the car for different light directions -- -- Novemeber 13, 1999 library ieee; use ieee.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity light_control is port(reset, enable : in std_logic; light_dir: in std_logic_vector(2 downto 0); obj_ahead: in std_logic; fwd_back, left_right: out std_logic_vector(3 downto 0) ); end light_control; architecture behavioural of light_control is -- define constants for direction constant left : std_logic_vector(3 downto 0) := "0000"; constant slight_left: std_logic_vector(3 downto 0) := "0011"; constant right : std_logic_vector(3 downto 0) := "1111"; constant slight_right:std_logic_vector(3 downto 0) := "1100"; --define constants for speed constant forward : std_logic_vector(3 downto 0) := "0011"; constant back : std_logic_vector(3 downto 0) := "1010"; -- define zero constant for both direction and speed constant zero : std_logic_vector(3 downto 0) := "0111"; begin process (reset, enable) begin if reset = '0' then fwd_back <= zero; left_right <= zero; elsif enable = '1' then -- if the sonar detects an object -- hirra should slow down and turn hard -- in the appropriate direction if obj_ahead = '1' then case light_dir is --light in front when "000" => left_right <= right; fwd_back <= forward; --light in front right when "001" => left_right <= right; fwd_back <= forward; -- light on right when "010" => left_right <= right; fwd_back <= forward; -- light in back right when "011" => left_right <= right; fwd_back <= back; -- light in back when "100" => left_right <= back; fwd_back <= back; -- light in back left when "101" => left_right <= left; fwd_back <= back; -- light on left when "110" => left_right <= left; fwd_back <= forward; -- light in front left when "111" => left_right <= left; fwd_back <= forward; when others => left_right <= zero; fwd_back <= forward; end case; -- otherwise it should respond to the light -- if light is equal stop = 1 and hirra should stop else -- drive forward case light_dir is -- light in front when "000" => left_right <= zero; fwd_back <= forward; -- light in front right when "001" => left_right <= slight_right; fwd_back <= forward; -- light on right when "010" => left_right <= right; fwd_back <= forward; -- light in back right when "011" => left_right <= left; fwd_back <= back; -- light in back when "100" => fwd_back <= back; left_right <= zero; -- light in back left when "101" => left_right <= right; fwd_back <= back; -- light on left when "110" => left_right <= left; fwd_back <= forward; -- light in front left when "111" => left_right <= slight_left; fwd_back <= forward; when others => left_right <= zero; end case; end if; end if; end process; end behavioural;