programming concepts c: goto_beacon engr 10 introduction to engineering

25
Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering 1

Upload: urbain

Post on 05-Jan-2016

31 views

Category:

Documents


2 download

DESCRIPTION

Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering. Main() for GOTO_Beacon Program. Note: you need to change freq for the beacon you want to find!. Global Variables. Infinite loop. Call three functions. Main() for GOTO_Beacon Program Cortex. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Programming Concepts C:

GOTO_Beacon

ENGR 10Introduction to Engineering

1

Page 2: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

GlobalVariables

Main() for GOTO_Beacon Program

Call three functions

Note: you need to change freq for the beacon you want to find!

Infinite loop

2

Page 3: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

3

Main() for GOTO_Beacon ProgramCortex

The only difference between the two programs are the port assignments

Motor ports 1 and 10

Move function

Page 4: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

While Loop (1==1) { Read_PD(); //read 8 Photo-detector outputs find_max(); //find the max detector output move(); // move to the direction of max PD }

4

PD7 PD0

PD4

Right sideLeft side

The main body of the GOTO_Beacon programis an infinite loop with three functions in the loop

Page 5: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Read_PD()

This function reads the intensity of all 8 Infrared Photo-detectors and stores the intensity (0 to 1023) into PD0~PD7 variables. It also produces the sum of all 8 readings (PD_sum). The sensing sensitivity is set by expose_time.

find_max()

This function determines which variable (among PD0~PD7) has the greatest value. The PD number is saved in the variable max_no.

This function reads the intensity of either 1kHz or 10kHz infrared signal depending on the setting of digital output port 14, 12 on Cortex, (0=1kHz , 1=10kHz). You should set the digital output port #14 (#12 on Cortex) to the intended frequency before this function is called.

5

Page 6: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

move()

PD7PD0PD4

2. Turns the left wheel faster if max_no < 4 Turns the right wheel faster if max_no > 4 Same speed if max_no = 4

4. Stop if PD_sum > stop_level (6000)

3. Slows the forward motion to slow_speed if PD_sum > slow_level (5000)

1. If PD_sum < Ambient (noise level, 200), the robot spins at the speed spin_speed (50). If PD_sum > Ambient (beacon is in view), go forward at speed of forward_speed (35).

6

Page 7: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

(A) PD_Sum > Ambient

(B) PD_Sum > Stop_Level

(C) Speed < Slow_speed

(D) Speed == 0

(E) Spin_speed == 0

Clicker Question 1

Which of the following conditions indicates that the robot has reached the beacon?

7

Page 8: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

(A) Make the robot spin

(B) Turn both motor at the same speed

(C) Makes the right motor run faster

(D) Makes the left motor run faster

(E) Stop the motors

Clicker Question 2

If PD6 has the highest readout, what would the GOTO_Beacon program tell the robot to do?

8

Page 9: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

(A) Makes the robot spin

(B) Stop the motors

(C) Move at the Slow_speed level

(D) Makes the left motor run faster

(E) Makes the right motor run faster

Clicker Question 3

If PD_sum<Ambient, what would the GOTO_Beacon program do?

9

Page 10: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Read_PD() Function

1

1

0

0

10

Page 11: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Main() for GOTO_Beacon Program

Find maximum intensity

11

Page 12: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

find_max() Function

12

PD0

Page 13: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

(A) Ambiant

(B) Slow_level

(C) Stop_level

(D) Spin_speed

(E) PD_sum

Clicker Question 4

The value of expose_time will affect the value of which of the following variable?

13

Page 14: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Main() for GOTO_Beacon Program

Move the robot

14

Page 15: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Move() Program

15

Page 16: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

limit_pwm() Program

16

Page 17: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

PD2 reads max intensity max_no = 2 error = 4-2=2 steer=error*steer_sensitivity=2*20=40

Motor2 speed = 127+40+35=202, Motor3 speed=127+40-35=132, if motor 2 is on the left side the robot turns right

Example

17

Page 18: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

(A) freq =0;

(B) Stop_level=6000;

(C) Max_PD()

(D) Setdigitaloutput(14,1)

(E) Move()

Clicker Question 6

Which of the following instructions or functions selects the target beacon (red or green)?

18

Page 19: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Initialization

While state==1

Read PD();Find Max();

Move ();

Somewhere here, when red beacon is found, state=2.No infinite loop in all blocks!

While state==2

Try to turn off red beacon. when

confirmed, state=3

While state==3

Go to greenWhen confirmed,

state=4

How to add to the GOTO_beacon program to perform the required task?

Use state variable !

19

Page 20: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

While state==4

Capture green ,When confirmed.

state =5

STOP

While state==7

GO home,When confirmed.

state =6

20

Page 21: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

IR Receiver Board

Frequency select

Exposure control

Intensity output amplifier

selector

Tuning circuit

Exposure Control

Reset to detector #0

sensitivity

0 1 2 3 4 5 6 7

counter 8 4 2 1 reset

count

Infrared detectors VEX

Controller

AD1

AD14

AD15

AD16

Circuit board

Side view Top View

Longer lead

Board edge

21

Page 22: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

amplifierTuning circuit

From previous stage

1kHz To next stage

Beacon Frequency Selection(filter)

AD14Freq select (0=1kHz, 1=10kHz)

22

Page 23: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Infrared Detectors

Selector

1

10

To next stage

counterLEDs

1kHz

AD16 Counter reset

AD15 pulse

IR Detector Selection

1

1

0

Count output set to zero

Get ready to count

Increment count (0 to 1 transition)

23

Page 24: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

amplifierTuning circuit

From previous stage

1kHz To next stage

Beacon Frequency Selection(filter)

AD14Freq select (0=1kHz, 1=10kHz)

24

Page 25: Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering

Exposure Control Circuit

AD15

From previous stage

To AD1

(VEX Analog input)

Amplifier

1 Clear ‘film’ (discharge C14)

0 Open ‘shutter’ (allow C14 to charge)

25