39
E C E 3 0 9 1 Engineering Design ENGINEERING REPORT TRIVIAL PURSUIT LINDA Joshua Stephens 19860846 josh3091.wordpress.com Loc Huynh 19001622 lhhuy1.wordpress.com Ahmed Hakim 19876149 ahak1.wordpress.com Joshua Stephens 19860846 Ahmed Hakim 19876149 Loc Huynh 19001622

ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

  • Upload
    lythien

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

E C E 3 0 9 1Engineering Design

ENGINEERING REPORTTRIVIAL PURSUIT

LINDAJoshua Stephens 19860846 josh3091.wordpress.com

Loc Huynh 19001622 lhhuy1.wordpress.com

Ahmed Hakim 19876149 ahak1.wordpress.com

Jo shua Stephens 19860846 • Ahmed Hak im 19876149 • Loc Huynh 19001622

Page 2: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Table of contentsChapter 1: The Project

2Introduction 2

What is the project? 3

The Competition 3

The Robot Design 3

The Maze Approach 4

The Ramp Approach 5

Chapter 2: The Robot – LINDA6

Chapter 3: The sensors8

Chapter 4: The Motor Drive9

Pro jec t L INDA ECE3091

1

Page 3: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Chapter 5: The Programming10

Appendix14A-1 : Schematic 14

A-2 : Schematic 15

B : Cost Analysis 16

C : The Test Points 17

D : The Pins 18

E : Gant Chart Original 19

F : Gant Chart Final 20

G : The Code 21

Chapter 1: The Project

IntroductionAs a requirement of Engineering Design ECE3091 that students must form a group of three and work together, co-operatively, and effectively in developing and building a robot to go through two similar mazes and two ramp tracks circuit. The robot will need to complete the circuit several times. The purpose of the report will give an overall view of the project from the designing stages through to the final testing stages. Pro jec t L INDA

2

Page 4: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

What is the project?The project is to design a robotic vehicle, with two wheels on its side, be able to navigate through the mouse mazes and the ramp tracks.

The robot must be able to complete the circuit using the most efficient approach and complete the circuit in the fastest time.

It must be able to complete the circuit going in a uni-direction.

The robot should be able to operate on its own with its own power source and not be connected by any external wiring.

It is a better if the robot does not collide into the walls or get stuck along the way and need guidance by the maker.

The robot should not fall off the ramp.

The competitionThe robot is designed to be efficient so therefore it can be pitted against another robot in the same track. The winner is the one that can catch its opponent by completing the task faster than the other. The competition is time trialled so if the one robot cannot catch the other in a short while then the winner is declared when one is clearly faster than the other.

The robot designThe robot is put together with a gearbox, the wheels and motors, as well as one circuit board with circuitry components soldered on. Below the circuit board is another board with six AAA batteries. The circuit board incorporates the main Altera chip with the 5V voltage regu-lator, the motor drive chip, the inverters, the sensor circuits, and other essential components like resistors, diodes, capacitors and inductors.

In order to improve the efficiency of the robot, it must be light weighted – trimming down the body chassis and using lightweight materials. The robot is programmed to be efficient, simplifying the code, and devising the best approaches and tweaking the code to make the robot complete the circuit as fast as possible.

Because the circuit is composed of two different parts, the ramp and the maze, robot is pro-grammed with two different modes in mind. The robot will switch from one mode to the next mode when it goes from one part of the circuit to the next part of the circuit, and switch modes accordingly.

The Maze Approach

Pro jec t L INDA ECE3091

3

Page 5: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

In order to navigate through the maze effectively, the robot is designed to follow one side of the walls. The robot is mounted with a sensor on the side in the middle, a sensor on the left front corner, a sensor on the right side at the top corner and a sensor at the front in the middle. The robot follows the left side of the wall and going in a forward motion, but it turns right and left very slightly along the way. When the left front corner sensor is detected, then it is turning to the right with the left wheel spinning at a slight faster speed. After it is turn-ing away from the wall, then the same left front corner sensor no long detecting the wall then it is turning left towards the wall, with the right wheel spinning slightly faster than the left wheel. And the process repeats again from what happens when the same sensor is de-tecting again. The reason for this operation is to get the robot to align itself when if it hap-pens to be in situations where the robot is about to collide into the wall or it deviates too much from the wall.

When the robot has to go through a gap in the wall or going around the bend then both sensors (left side and the corner sensors) will not be detected and then it will turn to the left, with the right wheel spinning at a much faster speed than the left wheel.

There is a situation where the robot meets a dead end and the front sensor is detected. When this happens, the robot will turn to the right on the spot until the front sensor no longer detects a wall. It spins on the spot with the left wheel going in reverse and the right wheel in a forward motion.

When the robot enters the maze from the ramp, the front right corner sensor is detected and the robot switches from the ramp mode and into a maze mode that has been detailed above. Besides from switching modes, it knows to turn left and away from the right wall, detected by the front right corner sensor.

The Ramp ApproachWhen the robot is in the maze, the program is switched into the maze mode when the left floor sensor is not detecting anymore because the robot is, initially, left wall-following. When the left floor sensor is not detecting, the robot turns to the right with the left wheel spinning faster than the right wheel. As a result, the robot will approach the right side of the ramp and then the right floor sensor will not detect anymore and the robot turns to the left side of the ramp with the right wheel spinning faster this time. The general idea is the robot will go through the ramp part in a zigzag fashion until it is inside the maze.

Pro jec t L INDA

4

Page 6: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Chapter 2: The Robot – LINDA

The following are the major components of the robot.

The Driveline

The Micro-controller Pro jec t L INDA ECE3091

5

Figure 2. The assembled Motor, Gearbox and wheels

Figure 3. The Cyclone 2 Microboard 2..1

Figure 1. A CAD mock-up of the final design.

Page 7: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

The Sensors

The Batteries / Voltage Regulator

Pro jec t L INDA

6

Figure 4. A CAD mock-up of the IR Sensors.

The batteries must me Nickel-Metal hydride rechargeable.

The total power of the batteries must not exceed 900mAh

The total voltage must not exceed 7.2 Volts eg. 6x1.2V

The Regulator must me a LM7805 1A 5V regulator

The micro-controller must be connected to the regulator.

Page 8: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Chapter 3: The SensorsThe sensor circuit simply utilizes a phototransistor and an infrared red transmitter. The infrared red transmitter (Z-3235) is connected in series with a 180 Ω resistor and is powered by 3.3V from the FPGA pin 1 VCC33 output. The infrared red light transmitted is able to activate the base terminal of the phototransistor close by and amplify the emitter current, which pulls down the voltage at the collector terminal of the transistor. The phototransistor is connected at the collector terminal with a pull-down resistor of 8.2 k Ω. The phototransistor is also connected to the same 3.3V rail of the FPGA.

Figure 5. The output voltage of the phototransistor when it is not detecting the infrared red

Figure 6. The output voltage of the phototransistor when it is detecting the infrared red

Pro jec t L INDA ECE3091

7

Page 9: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Chapter 4: The Motor Drive

Figure 7. The Motor Drive Circuit

The motor drive circuit is used to control the speed of the two motors and the direction at which they turn. The circuit incorporates the Texas Instrument L293 chip as wells as 8 diodes (inbuilt), 6 inverters (74HC04) and 2 motors. The circuit is powered by two different power sources – one by the 5V voltage regulator (VCC1), connected to the pin sixteen, and the other by the DC batteries (VC), connected to pin eight. The batteries power the motors directly and the voltage regulator powers circuitry in the L293 chip. It is a good approach to allow the motors have their own power supplies directly connected, otherwise, if powered by the voltage regulator, much power is lost in the transistor of the voltage regulator due to power loss in the switching process. Also a 5V power supply from the voltage regulator limits the high speed potential of the motor.

The first and the ninth pins in the diagram of Figure 3 response to an enable response and the inputs control the speed of the motor due to pulse-width modulated (PWM) pulses train. The second and the tenth pins control the forward direction of the motors, while the seventh and fifteenth pins control the reverse direction of the motors. The third, sixth, eleventh, and fourteenth pins are the output, and respond accordingly to their inputs – either a positive or negative pulse to command the motor spinning direction.

Pro jec t L INDA

8

Page 10: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

The PWM pulse train goes though two inverters that give the FPGA some isolation to the mo-tor driver.

Chapter 5: Programming

The program written up is to be downloaded into the robot and have been split up into two main parts - the maze and ramp functions. Both of these functions deal with its own part and united by the main function, with the help of the re-enter function.

The Maze function is split up into 3 sub-parts. It consists of the left section, right section, and the forward section.

The Ramp function is also split up, however, only in two sections one which deals with the left corner and one which deals with the right corner. Both of these functions also have sys-tematic checks to make sure they are in the correct part of the course.

The re-enter functions helps with the entrance of the robot into the maze from the ramp.

Finally the main function brings all of these functions together to allow the program to run continuously. An insight details of the program is presented in the Appendix section of this report with each line carefully commented.

To switch between the maze and ramp function the robot must set a flag. To do this as the robot exits the maze it will start to follow the left hand wall around, as it does this the left floor sensor will no long detect a floor and then set a flag and break out of the turn function allowing the robot to enter the ramp function.

As the robot approaches the entrance into the maze from the ramp, one of two things can happen, either it comes in with the left hand side closest to the wall and therefore will auto-matic unset the ramp flag and enter the maze function. But if the robot comes in will the right side closest to the wall it has a special sensor that will cause the robot to start to turn left until the front left sensor detects and from there will unset the ramp flag and enter the maze function.

Pro jec t L INDA ECE3091

9

Page 11: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Figure 8. BDF for the NIOS and PWM system

Pro jec t L INDA

10

This section is the PWM Controller. It is made up of a counter and a compare block. The counter counts up to 1024 and when the count value is equal or greater that that written to the compare block. The output goes high. In this way depending on what is written in the compare block will determine the PWM depth.

This section is the Unused Encoder counters.

Page 12: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Figure 9. The flow diagram shows what happens when the robot is in the maze

Pro jec t L INDA ECE3091

11

Page 13: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Figure 10. The flow diagram showing what happens when the robot is on the ramp

Pro jec t L INDA

12

Page 14: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix A-1: The Schematic

Pro jec t L INDA ECE3091

13

Page 15: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix A-2: The Schematic

Pro jec t L INDA

14

Page 16: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix B: Cost Analysis

Pro jec t L INDA ECE3091

Page 17: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix C: The Test points

The test points are taken off the back off the connector. To do this the crow must have the ‘hat’ left on it so the small hook may be used. In this way every input and the outputs can have a Test point.

The numbers refer to the connectors on the board.

Which are numbered and pin one is show on the female connector.

Pro jec t L INDA

16

Page 18: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix D: The Pins

Pro jec t L INDA ECE3091

Page 19: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix E: Gant Chart Original

Pro jec t L INDA

18

Page 20: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix F: Gant Chart Final

Pro jec t L INDA ECE3091

Page 21: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

Appendix G: The Code#include "sys/alt_stdio.h"

#include "altera_avalon_pio_regs.h"

#include "alt_types.h"

#include "system.h"

#include <stdio.h>

//all hash defines

#define MFORWARD 0 //defining motor moving forward to 0

#define MBACKWARD 1 //defining motor moving backwards to 1

#define DEFAULTMAZE 800 //default maze speed

#define DEFAULTRAMP 815 //default ramp speed

#define MAZE 1 //define MAZE section

#define RAMP 0 //define RAMP section

typedef struct Sensor

int senfront; //front sensor

int senleft1; //first left hand sensor

int senleft2; //second left hand sensor

int senright; //first right hand sensor

int sencornerleft; //left corner sensor

int sencornerright; //right corner sensor

sensor; //defining class sensor

sensor robot; //variable robot of class sensor

int vleftmotor; //left motor modulation

int vrightmotor; //right motor modulationPro jec t L INDA

20

Page 22: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

int i=0; //function flag

int z=0; //re-enter flag

int c; //counter variable

//MAZE FUNTION

void maze()

z=0; //initialise counter

IOWR_ALTERA_AVALON_PIO_DATA(STATELED_BASE, 1); //set state LED to maze

//get values

robot.senfront = IORD_ALTERA_AVALON_PIO_DATA(FRONTTAP_BASE); //get front sensor value

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

//left

if ( (robot.senleft1 != 0) && (robot.senleft2 != 0) ) //opening on left, go through it.

// set speed

vleftmotor = 675;

vrightmotor = 840;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, vleftmotor); //left motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor); //right motor modulation

while( IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE) != 0 ) //while top left wall sensor is not detecting wall

//get relevent sensor values

Pro jec t L INDA ECE3091

Page 23: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE);

robot.sencornerleft = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECETORLEFT_BASE);

if (robot.senleft1==0 || robot.sencornerleft!=0 ) //check to see if in RAMP section

if (robot.sencornerleft!=0) //check left corner sensor

//delay loop

int k;

for (k=1; k<=1000; k++)

robot.sencornerleft = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECETORLEFT_BASE); //get left corner sensor value

if (robot.sencornerleft!=0) //check left corner sensor value

i=1; //set flag to ramp

return;

break;

// set default speed

vleftmotor = DEFAULTMAZE;

vrightmotor = DEFAULTMAZE;

//right

Pro jec t L INDA

22

Page 24: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

else if ((robot.senleft2 == 0) && (robot.senfront == 0) ) //cant turn left or go forward, turn right

//delay loop

int l;

for (l=1;l<=100;l++)

robot.senfront = IORD_ALTERA_AVALON_PIO_DATA(FRONTTAP_BASE); //get front sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

if ( (robot.senleft2 == 0) && (robot.senfront == 0) ) //re-check values

//set speed

vleftmotor = 855;

vrightmotor = 780;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, vleftmotor); //left motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor); //right motor modulation

//set direction

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MFORWARD);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MBACKWARD);

while(1)

robot.senfront = IORD_ALTERA_AVALON_PIO_DATA(FRONTTAP_BASE); //get front sensor value

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

if ( (robot.senleft1 == 0) && (robot.senleft2 == 0) && (robot.senfront != 0) ) //check to see if it needs to turn right

for (c=1; c<=25; c++)//delay loop

Pro jec t L INDA ECE3091

Page 25: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

robot.senfront = IORD_ALTERA_AVALON_PIO_DATA(FRONTTAP_BASE); //get front sensor value

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

if ( (robot.senleft1 == 0) && (robot.senleft2 == 0) && (robot.senfront != 0) ) //check to see if loop should stop

break;

//set default speed

vleftmotor = DEFAULTMAZE;

vrightmotor = DEFAULTMAZE;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, vleftmotor); //left motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor); //right motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MFORWARD);//left motor direction

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MFORWARD);//right motor direction

else //straight function

//if close to wall, move away slightly

if ( (robot.senleft1 == 0) && (robot.senleft2 == 0) )

vleftmotor = DEFAULTMAZE;

vrightmotor = DEFAULTMAZE;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, (vleftmotor+70)); //left motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor); //right motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MFORWARD);

Pro jec t L INDA

24

Page 26: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MFORWARD);

//if TOO close to wall, move away quickly

else if ( (robot.senleft1 == 0) && (robot.senleft2 != 0) )

vleftmotor = DEFAULTMAZE;

vrightmotor = DEFAULTMAZE;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, (vleftmotor+120)); //left motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor); //right motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MFORWARD);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MFORWARD);

// if far away from wall, move closer

else

vleftmotor = DEFAULTMAZE;

vrightmotor = DEFAULTMAZE;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, (vleftmotor-60)); //left motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor); //right motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MFORWARD);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MFORWARD);

//RAMP function

void ramp()

Pro jec t L INDA ECE3091

Page 27: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

z=0; //set re-enter flag

IOWR_ALTERA_AVALON_PIO_DATA(STATELED_BASE, 0); //set state LED to RAMP

//set initial values for ramp

//direction

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MFORWARD);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MFORWARD);

//speed

vrightmotor = DEFAULTRAMP;

vleftmotor = DEFAULTRAMP;

//direction

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, vleftmotor);

//get values

robot.sencornerleft = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECETORLEFT_BASE); //get left corner sensor value

robot.sencornerright = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECTORRIGHT_BASE); //get right corner sensor value

//robot.senfront = IORD_ALTERA_AVALON_PIO_DATA(FRONTTAP_BASE); //get front sensor value

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

robot.senright = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR3_BASE); //get right sensor value

if (robot.senleft1==0 || robot.senleft2==0) //check to see if in maze section

//delay

int a;

for (a=0; a<=10000; a++)

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

Pro jec t L INDA

26

Page 28: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

if (robot.senleft1==0 || robot.senleft2==0) //check to see if in maze section

i=0; //set flag to maze

return;

if (robot.senright == 0) //right sensor check

delay

int b;

for(b=1; b<=1000;b++)

robot.senright = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR3_BASE); //check right sensor

if (robot.senright == 0) //right sensor check

z=1; //set re-enter flag

//left

if (robot.sencornerleft != 0)

Pro jec t L INDA ECE3091

Page 29: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

//set speed

vrightmotor = 700;

vleftmotor = 1020;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, vleftmotor);

//set direction

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONRIGHT_BASE, MBACKWARD);

//loop

while(1)

//check value

robot.sencornerleft = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECETORLEFT_BASE); //get left corner sensor value

//break if corrected

if (robot.sencornerleft == 0)

break;

//right

else if (robot.sencornerright != 0)

//set speed

vrightmotor = 1020;

vleftmotor = 700;

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, vrightmotor);

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, vleftmotor);

//set direction

Pro jec t L INDA

28

Page 30: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

IOWR_ALTERA_AVALON_PIO_DATA(MOTORDIRECTIONLEFT_BASE, MBACKWARD);

//loop

while(1)

//check value

robot.sencornerright = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECTORRIGHT_BASE); //get right corner sensor value

//break if corrected

if (robot.sencornerright == 0)

break;

//re-enter function

void reenter()

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMRIGHT_BASE, 900); //set right motor modulation

IOWR_ALTERA_AVALON_PIO_DATA(MOTORPWMLEFT_BASE, 700); //set left motor modulation

//loop

while (1)

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

if (robot.senleft1 == 0) //check to see left sensor value

//delay

int d;

Pro jec t L INDA ECE3091

Page 31: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

for (d=1;d<=1000;d++)

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //check left sensor value

if (robot.senleft1 == 0) //check to see left sensor value

break;

//main function

int main()

while(1)

robot.senfront = IORD_ALTERA_AVALON_PIO_DATA(FRONTTAP_BASE); //get front sensor value

robot.senleft1 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR1_BASE); //get first left hand sensor value

robot.senleft2 = IORD_ALTERA_AVALON_PIO_DATA(WALLDETECTOR2_BASE); //get second left hand sensor value

robot.sencornerleft = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECETORLEFT_BASE); //get left corner sensor value

robot.sencornerright = IORD_ALTERA_AVALON_PIO_DATA(FLOORDECTORRIGHT_BASE); //get right corner sensor value

if (z==1) //check to see if re-enter flag is set

reenter(); //go to re-enter function

Pro jec t L INDA

30

Page 32: ENGINEERING REPORT - josh3091.files.wordpress.com€¦ · Web viewEngineering Report. Trivial Pursuit. LINDA. Joshua Stephens 19860846 josh3091.wordpress.com. Loc Huynh 19001622 lhhuy1.wordpress.com

if (i==1) //check to see if ramp flag is set

ramp(); //go to ramp function

else if (i==0) //check to see if maze flag is set

maze(); //go to maze function

Pro jec t L INDA ECE3091