COMPUTER ENGINEERING 4OI4 LANDMINE DETECTING ROBOT Group Names: Jeyathas Vijayaratnarasa ................................................................. 0141042 Kumar Subramaniam ........................................................................ 0154599 Suthananthan Yoganatham .............................................................. 0261806 Table of Contents 1.0 INTRODUCTION..........................................................................................................1 2.0 OBJECTIVE...................................................................................................................2 3.0 DESIGN METHODOLOGY ........................................................................................2 3.1 Hardware Components.................................................................................................2 3.2 UP2 Education Board...................................................................................................3 3.3 Introduction to Stepper Motors ....................................................................................4 3.4 Stepper Motor Controller ICs.......................................................................................4 4.0 DESIGN ..........................................................................................................................4 4.1 Mechanical Design.......................................................................................................5 4.2 Circuit Design ..............................................................................................................6 4.2.1 Problems Encountered ..........................................................................................6 4.3 Program Design............................................................................................................6 4.3.1 Flow Control .........................................................................................................6 4.3.2 Implementation .....................................................................................................7 4.3.3 Pin Assignments....................................................................................................7 4.4 Simulation & Test Results...........................................................................................8 5.0 CONCLUSION...............................................................................................................8 6.0 REFERENCES...............................................................................................................9 APPENDIX A: Simulation test results.............................................................................10 APPENDIX B: Schematic diagrams of Robot control ...................................................12 APPENDIX C: Source Codes (VHDL) ............................................................................13 1 mines at a faster pace is to use the current technology to assist in any possible way. ABSTRACT It is hard to prevent violators of human rights from planting landmines at “a rate 25 times faster than they are being cleared.”[1] It is better to create robots using the current technology to clear the mines to prevent life threatening disasters. This project is aimed at designing and implementing a robot with the consideration of cost and weight of the materials used. Current technology can be used to help remove land mines by many ways, one way is to build robots that can move through a certain area and detect mines. Even though the technological aspect is fascinating to think, they too have tradeoffs to be considered. One of them is the cost and the effectiveness of building a robot and actually making it function as required. This report mainly focuses on designing the overall robot structure and the design and implementation of the mobility of the robot. This excludes the design and implementation of the landmine detection sensor to be installed on the landminesensing arm. Design and implementation of the robot is done using the Altera University Program Development Kit on which FPGA (Field Programmable Gate Array) devices are integrated. Also stepper motors and infrared sensors are used to maneuver the robot in hopes of avoiding obstacles as well as landmines. The main objective of this project is to build a portable Landmine Detection Robot, with certain budget constraints. This project was considered to be very important and the main task was to design and manufacture the robot. Writing the VHDL code that enables the movement and control aspects of the robot and assembled the components together to make the robot’s framework started it. Following the manufacturing, it was tested and verified with various scenarios. Programming is a way in which a set of instructions are systematically created to achieve the goal. In this case the programming was done to create instructions, which can be understood by the robot and to function as a whole. Programming was written using the Hardware Description Language (HDL), which is used for designing and building programs intended for integrated chips, such as Field Programmable Logic Array (FPGA). The project also used FPGA to program and to execute the robot. The main reason behind using FPGA in this project is to allow reusability in the device, since it is a user programmable component. 1.0 INTRODUCTION War torn countries around the world have day-to-day losses of lives from the detonation of landmines, which are still. Not only are “new landmines are laid at a rate 25 times faster than they are being cleared. New technologies will make it easier to find and locate mines, but can't prevent their placement. As long as nations continue to use landmines, these devices will be a danger for civilians as well as soldiers.” [1] Clearing these mines is one of the complex and expensive tasks to be performed. The landmine is proven to hold a lifespan of fifty years, which means once it has been activated it can be active for fifty years. A possible solution in removing these 1 Further, this report includes an Objective, which explains the reasons behind the undertaking of this project and a detailed Background, which briefly talks about the components being used. Also a Discussion section is included to discuss about my role in the overall design phase of Landmine Detection Robot. A brief conclusion dealing with the outcome of the project and a recommendation section that discusses on how this project can be improved in the future are also included. This was simply accomplished by opening the motor casing and removing a rotation limiter located on the main gear. The servomotor has some control circuits and a potentiometer (a variable resistor, pot) that is connected to the output shaft. In the figure 3.1 below, the pot can be seen on the right side of the circuit board. This pot allows the control circuitry to monitor the current angle of the servomotor. If the shaft is at the correct angle, then the motor shuts off. If the circuit finds that the angle is not correct, it will turn the motor the correct direction until the angle is correct. The output shaft of the servo is capable of traveling somewhere around 180 degrees. 2.0 OBJECTIVE The objective of the project is to build a Landmine Detection Robot, with the consideration of cost. Low cost was taken into consideration because of the fact that not all countries will have sufficient funds to afford robots to find and destroy active landmines. Specifically our objective in this project was to design and build an efficient lightweight structure of the robot. Also, our tasks included implementation of an efficient Hardware Description Language (HDL) based program to run the robot. The program will enable the robot to respond to landmines and allow it to maneuver. The programming component of the robot is achieved through FPGA integrated board designed by Altera Corporation. Figure 3.1: Typical Servo Motor Electrical Specifications: The servomotors operated using a 5 Volt dc power supply and the signal that was provided directly from the UP2 board. The control to the servo was acquired via pulse width modulation. This required the board to pulse 5 volt (HI) at specific intervals to the control board of the servo. The duration and frequency of the pulses determine the angle and the speed for movement. 3.0 DESIGN METHODOLOGY 3.1 Hardware Components The following project required a vast array of hardware components. The following section will provide explicit details of the components used. • Modified HiTEC Brand Servomotors: In order to use the servomotors for continuous rotation slight modifications were required. 2 an object in a small area. Typically the IRPD can detect the objects with in the range from 4” to 20”. Electrical Specifications: The infrared proximity detector operated using battery through a voltage regulator which gives 5 V DC steady outputs from the input voltage grater or equal to 5 V Figure 3.2: Angles with various pulse The angle is determined by the duration of a pulse that is applied to the control wire. This is called Pulse Coded Modulation. The servo expects to see a pulse every 20 milliseconds (.02 seconds). The length of the pulse will determine how far the motor turns. A 1.5 millisecond pulse, for example in the figure 3.2, will make the motor turn to the 90 degree position (often called the neutral position). If the pulse is shorter than 1.5 ms, then the motor will turn the shaft to closer to 0 degrees. If the pulse is longer than 1.5ms, the shaft turns closer to 180 degrees. • Table 3.1: IRPD’s Truth Table 3.2 UP2 Education Board The board consists of two programmable logic devices; they are FLEX10K device and a MAX7000 device, in the same board. The FLEX10K device is based on SRAM technology with 70,000 typical gates. The MAX7000 family is based on Infrared Proximity Detector Figure 3.4: Top view of the UP2 Board with MAX7000 and FLEX10K devices electrically erasable programmable read only memory (EEPROM). This device contains about 2,500 gates and a simple architecture, the MAX7000 (Model: EPM7128S) device is ideal for basic designs [2]. Even though the MAX7000 can hold the data after it loses power, FLEX10K device was used as the primary FPGA chip in this project since Figure 3.3: IRPD’s detecting areas This sensor can be used whenever it is necessary to detect the presence of 3 it contains more gates than MAX7000 device. This project used minimum 10000 gates and the MAX7000 device can not be used for that amount of gates. The figure 3.4 above illustrates the components in the board. 3.4 Stepper Motor Controller ICs There are many stepper motor controllers in the market, in the form of Integrated Circuit (IC) or a Complete Circuit. The Complete circuits are very expensive, but the stepper motor controllers are cheap and easy to get and are easy to connect to the circuit. The one that is used in this project is a kind of integrated circuit, 3.3 Introduction to Stepper Motors There are several kinds of motors, and one of them is a stepper motor, which moves in individual steps of various sizes, in this case it happens to be 1.8 degrees. Motion of each step is controlled by applying electrical current to one or more of the coils, which interact with the magnets along the wall of the motor. Turning these coils on and off in sequence will cause the motor to rotate forward or reverse, and the speed of the motor is determined by the delay between each step. The shaft of the motor can be rotated to a specific location by applying the required number of stepping pulses. This type of motor is chosen to utilize the robot design, because Landmine Detection Robots have to move accurately in order to avoid stepping on the landmine, and for ease of control. The figure 3.5 illustrates how a stepping motor looks like EDE1200 Unipolar Stepper Motor IC. The figure 3.6 illustrates the EDE1200 Unipolar stepper motor IC. Figure 3.6: Stepper Motor control IC From the above IC, the input and output pins of the stepper motor control being used in this project can be seen. When the pin number 10 is low, Run Mode is activated, and active high makes it a Step mode. In this project Step Mode is being used, and in order to use the step mode, proper application of clock pulses is required on pin 9. 4.0 DESIGN This section focuses on the designing aspects of the robot in this project. This part is categorized into three sub sections, which are Mechanical Design, Circuit Design, and Controller Design of the Robot. The design specification of the robot is as follows. Figure 3.5: Unipolar Stepper Motor 4 1. 2. 3. 4. 5. 6. Robot must avoid when there is an obstacle in the left side, it should move to the right side, and vice versa for obstacle in right side. Robot must sound the alarm upon the detection of a landmine. Upon detection of a landmine it should turn accordingly to avoid stepping on it. The forearm must always move left and right sensing for landmines. The angle of the arm motion is configurable, and default value is set at 120 degrees. Robot must move 10cm in forward direction, and stop, while moving the arm left and right. If no landmines are detected the robot must proceed forward repeating the same process again. the robot is done by application of step pulses to both motors to make the robot move in forward or reverse. Figure 4.1a: Schematic diagram of the robot 4.1 Mechanical Design The mechanical design is done, by taking efficiency and weight into consideration. The robot is a triangular shaped body, which is built in fiber disk, with the dimensions of 15cm length in each side. There is a moving arm leaning in front of the body, which is fixed at the center of the body, connected to a gear and a stepper motor. This arm will move to right and left up to 120 degrees in either direction and can be configurable. A four-inch in diameter swivel caster wheel is fixed in front of the robot. There are two plastic wheels; eight inches in diameter for the rear, and each of them are directly connected to a stepper motor, which will allow the maneuvering of the robot simple and easy. Maneuvering of Figure 4.1b: Snapshots of the robot The turning of the robot is done by turning off the opposite side motor to the direction and applying stepping pulses to the motor on the side of the direction in reverse. This robot also consists of an infrared proximity sensor, which can be programmed to sense to a distance between four inches to twenty inches by rotating the turning knob. This sensor is fixed in front of the arm, at a height that is appropriate to climb or avoid an obstacle in the vicinity of the robot. The sensor is fixed using two separate lightweight metal rods from the body. 5 The figure 4.1 illustrates the structure of the landmine detection robot. 4.2.1 Problems Encountered 4.2 Circuit Design The hardware problems encountered were relatively high, where servomotors would not work as expected and the delays in the arrival of the stepper motor control IC kits. Servomotors that received from the manufactures weren’t ideal and fully functional. IC for the unipolar stepper motors weren’t compatible with the stepper motors and it was overcome by ordered the compatible one with the delivery delays. Further more, the metal detector which was ideally proposed to detect the land mines especially landmines covered by metal shield, is expensive and it can not be afforded with in the project budget limit. IR Proximity Detector is used for the land mine detection and to save the project cost. The circuit design of this project is done using the breadboard as the initial step. Each stepping motors are connected to a Unipolar Stepper Motor Controller ICs using a Seven Darlington Array, a Zener Diode, and a 4 MHz Ceramic Resonator, which has internal capacitors. The stepper controller is the main part, which controls the speed and the direction of the motor. The Darlington array connects the controller and the motor together, which converts the CMOS inputs from the controller to 4.3 Program Design In this part of the project is where the coding and configuring of the FPGA integrated Altera prototyping board. This section includes Implementation, Pin Assignment, and Simulations as sub sections 4.3.1 Flow Control Figure 4.2: Stepper Motor control IC kit Flow chart was mainly used to develop the VHDL code to control the robot. According to the flow chart in figure 4.3, the robot will start moving forward when it is initiated. After a certain distance it will stop and start to move the mine sensing arm from right to left and vice versa. If it finds any obstacle or mine on either side it will trigger the alarm and turn the corresponding LED on. If it does not find any obstacle or mine it will continue moving forward and stop. If it finds the obstacle or mine on the left side 500 mA per coil (max of 600mA) peak and apply to the stepper motors. The Zener diodes are used to connect power supply to the Darlington array, which is used to convert the currents into 500mA for the motors. The above part is done for each motor, and the figure 4.2 shows the schematic of single motor controller circuit. The figure 6 shows the over all structure of the motor controller circuit. 6 it will turn right by turning the right OBSTACLES state will be called, whenever there is a detection of mines or an obstacle opposing it, and this state will trigger TURN_LEFT or TURN_RIGHT according to the sensor input, and the mine input from the arm, which are done by the other members of the team. There are six outputs, which are sent to the stepping controller chip, they are LEFT MOTOR DISABLE, RIGHT MOTOR DISABLE, CENTER MOTOR DISABLE, LEFT MOTOR DIRECTION, RIGHT MOTOR DIRECTION, and CENTER MOTOR DIRECTION. The full implementation details including the code for the infrared sensor and clock divider are attached in the Appendix C at the back of this report. Also the implemented codes are generated into a symbol using the MAX+PLUS II software, which came with the development kit. Symbol is how the code is transformed into block diagrams, providing a visual input and output signals pins. The figure 4.4 illustrates a sample symbol block for the robot controller. Figure 4.3: Flow control chart of the robot stepper motor off to avoid stepping on the mine and vice versa. After it turning left or right then it will start moving forward and stop to move the sensing arm. 4.3.2 Implementation The code design is done using VHDL, where the code contains seven states. The states are FORWARD_1, FORWARD_2, TURN_RIGHT, TURN_LEFT, ARM_MOVE_RIGHT, ARM_MOVE_LEFT, and OBSTACLES. The FORWARD_1 state initializes the timer to zero and transition into FORWARD_2. The FORWARD_2 state makes the robot move forward for five seconds, stop, and transition to ARM_MOVE_LEFT. The ARM_MOVE_LEFT state in turn will transition into ARM_MOVE_RIGHT having done its job, the job is to move the arm to left by sixty degrees. ARM_MOVE_RIGHT will move the arm back to right side by sixty degrees. Figure 4.4: The symbol block diagram of a controller code 4.3.3 Pin Assignments The symbols created in the implementation phase are put together using a graphical based circuit editor, which came along with the MAX+PLUS II software. Putting together means connection of each component by using wires to appropriate pins. The schematic 7 without the pin assignment is illustrated below in figure B.1, followed by the illustration with the pin assignments in figure B.2 in the Appendix B. Table 4.1 contains the pin assignment details, with name of the pin and the number. The complete schematic of the robot circuits is on the following figure. This schematic also includes the circuit connections to sound the alarm once a landmine is detected. The Altera user manual is also being attached to this report in the appendix section, in order to provide the instruction on connecting the pins to the Altera board appropriately. Pin Name Type CLOCK_25Mhz SENSOR_OUT MINE MOTOR_STEP LMOTOR_DIS RMOTOR_DIS CMOTOR_DIS LMOTOR_DIR RMOTOR_DIR CMOTOR_DIR LEFT_LED RIGHT_LED Input Input Input Output Output Output Output Output Output Output Output Output 4.4 Simulation & Test Results This section consists of the simulation outcomes of the robot controller, which include waveforms produced by the simulation. Simulation is carried out in a systematic manner, starting with the Design phase, where the graphical entry is made, followed by synthesis in the compilation phase. Then the timing diagram is generated in the simulation phase. This phase is the critical part of the project, since this is where the success or failure of the robot is observed. Several sequences of tests were made with different scenarios, the following timing diagrams illustrates those particular cases. Table 4.2 is provided to help to understand the timing diagrams. Pin Number 211 45 46 65 48 55 53 51 56 54 61 62 5.0 CONCLUSION Working on this project has been a great learning opportunity. It has presented many difficult challenges and decisions, but with the help of a solid engineering background we have successfully created a robot that can detect the mines. The robot’s design and implementation components were a great success. The VHDL design for the robot and the frame structure design turned up very well. As expected, the robot’s physical structure was light weighted, which enabled it to move on top of a Landmine without detonating it. Also the simulation results confirmed that the design and implementation of the robot is a major success and showed successful operations and maneuvering abilities. In addition to the simulation results, the testing confirmed what was proposed in the design section. Table 4.1: Pin assignments for FLEX10K STATE FORWARD_1 FORWARD_2 ARM_MOVE_RIGHT ARM_MOVE_LEFT TURN_LEFT TURN_RIGHT OBSTACLES Number 0 1 2 3 4 5 6 Table 4.2: States number of the robot movements 8 6.0 REFERENCES [1] “How Landmines Work,” [Online document], [cited 2004 Feb. 21], Available: http://people.howstuffworks.com/landmine4.htm [2] James O. Hamblen and Michael D. Furman, “Rapid prototyping of Digital Systems”, Kluwer Academic Publishers, 2000. [3] http://www.mrt.ac.lk/iarc/Research/Research.htm [4] http://www.esit.com/mobile-robots/mr2.html [5] http://www.jhu.edu/~gazette/2004/19jul04/19rugged.html 9 APPENDIX A: Simulation test results Figure A.1: Timing Diagram, with no obstacles and no mines for robot controller Figure A.2: Timing Diagram, with no obstacles and no mines for robot controller 10 Figure A.3: Timing Diagram, with obstacles and mines for robot controller 11 APPENDIX B: Schematic diagrams of Robot control Figure B.1: The overall schematic of the robot without pin assignment Figure B.2: The overall schematic of the robot with pin assignments 12 APPENDIX C: Source Codes (VHDL) • • • Clock Divider IR Sensor Robot Control 13 Clock Divider LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.all; USE IEEE.STD_LOGIC_ARITH.all; USE IEEE.STD_LOGIC_UNSIGNED.all; ENTITY clk_div IS PORT ( clock_25Mhz clock_1MHz clock_100KHz clock_10KHz clock_1KHz clock_100Hz clock_10Hz clock_1Hz : IN : OUT : OUT : OUT : OUT : OUT : OUT : OUT STD_LOGIC; STD_LOGIC; STD_LOGIC; STD_LOGIC; STD_LOGIC; STD_LOGIC; STD_LOGIC; STD_LOGIC); END clk_div; ARCHITECTURE a OF clk_div IS SIGNAL count_1Mhz: STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL count_100Khz, count_10Khz, count_1Khz : STD_LOGIC_VECTOR(2 DOWNTO 0); SIGNAL count_100hz, count_10hz, count_1hz : STD_LOGIC_VECTOR(2 DOWNTO 0); SIGNAL clock_1Mhz_int, clock_100Khz_int, clock_10Khz_int, clock_1Khz_int: STD_LOGIC; SIGNAL clock_100hz_int, clock_10Hz_int, clock_1Hz_int : STD_LOGIC; BEGIN PROCESS BEGIN -- Divide by 25 WAIT UNTIL clock_25Mhz'EVENT and clock_25Mhz = '1'; IF count_1Mhz < 24 THEN count_1Mhz <= count_1Mhz + 1; ELSE count_1Mhz <= "00000"; END IF; IF count_1Mhz < 12 THEN clock_1Mhz_int <= '0'; ELSE 14 clock_1Mhz_int <= '1'; END IF; -- Ripple clocks are used in this code to save prescalar hardware -- Sync all clock prescalar outputs back to master clock signal clock_1Mhz <= clock_1Mhz_int; clock_100Khz <= clock_100Khz_int; clock_10Khz <= clock_10Khz_int; clock_1Khz <= clock_1Khz_int; clock_100hz <= clock_100hz_int; clock_10hz <= clock_10hz_int; clock_1hz <= clock_1hz_int; END PROCESS; -- Divide by 10 PROCESS BEGIN WAIT UNTIL clock_1Mhz_int'EVENT and clock_1Mhz_int = '1'; IF count_100Khz /= 4 THEN count_100Khz <= count_100Khz + 1; ELSE count_100khz <= "000"; clock_100Khz_int <= NOT clock_100Khz_int; END IF; END PROCESS; -- Divide by 10 PROCESS BEGIN WAIT UNTIL clock_100Khz_int'EVENT and clock_100Khz_int = '1'; IF count_10Khz /= 4 THEN count_10Khz <= count_10Khz + 1; ELSE count_10khz <= "000"; clock_10Khz_int <= NOT clock_10Khz_int; END IF; END PROCESS; -- Divide by 10 PROCESS BEGIN WAIT UNTIL clock_10Khz_int'EVENT and clock_10Khz_int = '1'; IF count_1Khz /= 4 THEN count_1Khz <= count_1Khz + 1; ELSE count_1khz <= "000"; clock_1Khz_int <= NOT clock_1Khz_int; 15 END IF; END PROCESS; -- Divide by 10 PROCESS BEGIN WAIT UNTIL clock_1Khz_int'EVENT and clock_1Khz_int = '1'; IF count_100hz /= 4 THEN count_100hz <= count_100hz + 1; ELSE count_100hz <= "000"; clock_100hz_int <= NOT clock_100hz_int; END IF; END PROCESS; -- Divide by 10 PROCESS BEGIN WAIT UNTIL clock_100hz_int'EVENT and clock_100hz_int = '1'; IF count_10hz /= 4 THEN count_10hz <= count_10hz + 1; ELSE count_10hz <= "000"; clock_10hz_int <= NOT clock_10hz_int; END IF; END PROCESS; -- Divide by 10 PROCESS BEGIN WAIT UNTIL clock_10hz_int'EVENT and clock_10hz_int = '1'; IF count_1hz /= 4 THEN count_1hz <= count_1hz + 1; ELSE count_1hz <= "000"; clock_1hz_int <= NOT clock_1hz_int; END IF; END PROCESS; END a; 16 IR_SENSOR library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_ARITH.all; use IEEE.STD_LOGIC_UNSIGNED.all; ENTITY ir_sensor IS PORT ( clock_100Hz, clock_10Khz, clock_1hz, sout : IN STD_LOGIC; left_led, right_led, left, right : OUT STD_LOGIC); END ir_sensor; ARCHITECTURE a OF ir_sensor IS SIGNAL left_rscount, right_rscount, other_rscount : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL set_left, set_right, set_other : STD_LOGIC; SIGNAL state_count : STD_LOGIC_VECTOR(1 DOWNTO 0); BEGIN right_led <= '1' WHEN state_count = "00" ELSE '0'; left_led <= '1' WHEN state_count = "01" ELSE '0'; PROCESS BEGIN WAIT UNTIL clock_100hz'EVENT and clock_100hz = '1'; IF state_count = "10" THEN state_count <= "00"; ELSE state_count <= state_count + 1; END IF; END PROCESS; PROCESS BEGIN WAIT UNTIL clock_10Khz'EVENT and clock_10Khz = '0'; CASE state_count IS WHEN "00" => IF right_rscount < 25 THEN right_rscount <= right_rscount + NOT sout; END IF; IF other_rscount >= 15 THEN set_other <= '1'; 17 ELSIF other_rscount <= 5 THEN set_other <= '0'; END IF; left_rscount <= "00000"; WHEN "01" => IF left_rscount < 25 THEN left_rscount <= left_rscount + NOT sout; END IF; IF right_rscount >= 25 THEN set_right <= '1'; ELSIF right_rscount <= 12 THEN set_right <= '0'; END IF; other_rscount <= "00000"; WHEN "10" => IF left_rscount >= 25 THEN set_left <= '1'; ELSIF left_rscount <= 12 THEN set_left <= '0'; END IF; IF other_rscount < 25 THEN other_rscount <= other_rscount + NOT sout; END IF; right_rscount <= "00000"; WHEN OTHERS => NULL; END CASE; END PROCESS; PROCESS (set_left,clock_1Hz) BEGIN IF set_left = '1' THEN left <= '1'; ELSIF clock_1Hz'EVENT and clock_1Hz = '1' THEN left <= '0'; END IF; END PROCESS; PROCESS (set_right,clock_1Hz) BEGIN IF set_right = '1' THEN right <= '1'; ELSIF clock_1Hz'EVENT and clock_1Hz = '1' THEN right <= '0'; END IF; END PROCESS; END a; 18 ROBOT CONTROL library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_ARITH.all; use IEEE.STD_LOGIC_UNSIGNED.all; ENTITY robot IS PORT( clock_10hz : IN STD_LOGIC; left, right, mine : IN STD_LOGIC; lmotor_disable, rmotor_disable, cmotor_disable lmotor_dir, rmotor_dir, cmotor_dir STD_LOGIC); END robot; : OUT STD_LOGIC; : OUT ARCHITECTURE a OF robot IS TYPE STATE_TYPE IS (forward, forward2, larm, rarm, obstacle, rturn, lturn); SIGNAL state : STATE_TYPE; SIGNAL pb_pressed : STD_LOGIC; SIGNAL timer: STD_LOGIC_VECTOR(7 DOWNTO 0); BEGIN PROCESS (clock_10hz) BEGIN IF clock_10hz'EVENT AND clock_10hz = '1' THEN CASE state IS WHEN forward => IF NOT(LEFT='1' OR RIGHT='1' OR MINE = '1') THEN state <= forward2; timer <= "00000000"; ELSE state <= obstacle; END IF; WHEN forward2 => 19 IF NOT(LEFT='1' OR RIGHT='1' OR MINE = '1') THEN IF timer > 50 THEN state <= larm; timer <= "00000000"; ELSE timer <= timer + 1; state <= forward2; END IF; ELSE state <= obstacle; END IF; WHEN larm => IF NOT(LEFT ='1' OR RIGHT='1' OR MINE = '1') THEN IF timer > 50 THEN state <=rarm; timer <= "00000000"; ELSE timer <= timer + 1; state <=larm; END IF; ELSE state <= obstacle; END IF; WHEN rarm => IF NOT(LEFT ='1' OR RIGHT='1' OR MINE = '1') THEN IF timer > 50 THEN state <= forward; timer <= "00000000"; ELSE timer <= timer + 1; state <= rarm; END IF; ELSE state <=obstacle; END IF; WHEN obstacle => IF (LEFT='1' OR RIGHT='1' OR MINE = '1') THEN IF ( (LEFT = '1' AND RIGHT ='1') OR MINE = '1') THEN 20 state <= lturn; timer <= "00000000"; END IF; IF LEFT ='1' THEN state <= rturn; timer <= "00000000"; END IF; IF RIGHT ='1' THEN state <= lturn; timer <= "00000000"; END IF; ELSE state <= forward; END IF; WHEN rturn => IF NOT(LEFT='1' OR right ='1' OR MINE = '1') THEN IF timer > 20 THEN state <= forward; timer <= "00000000"; ELSE timer <= timer + 1; state <= rturn; END IF; ELSE state <= obstacle; END IF; WHEN lturn => IF NOT(LEFT='1' OR RIGHT='1' OR MINE = '1') THEN IF timer > 20 THEN state <= forward; timer <= "00000000"; ELSE timer <= timer + 1; state <= lturn; END IF; ELSE state <= obstacle; END IF; END CASE; END IF; 21 END PROCESS; -- Outputs of state machine WITH state SELECT lmotor_dir <= '1' WHEN forward, '1' WHEN forward2, '0' WHEN larm, '0' WHEN rarm, '1' WHEN rturn, '1' WHEN lturn, '0' WHEN obstacle; WITH state SELECT rmotor_dir <= '0' WHEN forward, '0' WHEN forward2, '1' WHEN larm, '1' WHEN rarm, '0' WHEN rturn, '0' WHEN lturn, '1' WHEN obstacle; WITH state SELECT cmotor_dir <= '1' WHEN forward, '1' WHEN forward2, '1' WHEN larm, '0' WHEN rarm, '1' WHEN rturn, '1' WHEN lturn, '1' WHEN obstacle; WITH state SELECT lmotor_disable <= '1' WHEN forward, '1' WHEN forward2, '0' WHEN larm, '0' WHEN rarm, '1' WHEN rturn, '0' WHEN lturn, '0' WHEN obstacle; WITH state SELECT rmotor_disable <= '1' WHEN forward, '1' WHEN forward2, '0' WHEN larm, '0' WHEN rarm, '0' WHEN rturn, '1' WHEN lturn, '0' WHEN obstacle; 22 WITH state SELECT cmotor_disable <= '0' WHEN forward, '0' WHEN forward2, '1' WHEN larm, '1' WHEN rarm, '0' WHEN rturn, '0' WHEN lturn, '0' WHEN obstacle; END a; 23