programming concepts c: goto_beacon engr 10 introduction to engineering
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 PresentationTRANSCRIPT
Programming Concepts C:
GOTO_Beacon
ENGR 10Introduction to Engineering
1
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
3
Main() for GOTO_Beacon ProgramCortex
The only difference between the two programs are the port assignments
Motor ports 1 and 10
Move function
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
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
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
(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
(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
(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
Read_PD() Function
1
1
0
0
10
Main() for GOTO_Beacon Program
Find maximum intensity
11
find_max() Function
12
PD0
(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
Main() for GOTO_Beacon Program
Move the robot
14
Move() Program
15
limit_pwm() Program
16
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
(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
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
While state==4
Capture green ,When confirmed.
state =5
STOP
While state==7
GO home,When confirmed.
state =6
20
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
amplifierTuning circuit
From previous stage
1kHz To next stage
Beacon Frequency Selection(filter)
AD14Freq select (0=1kHz, 1=10kHz)
22
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
amplifierTuning circuit
From previous stage
1kHz To next stage
Beacon Frequency Selection(filter)
AD14Freq select (0=1kHz, 1=10kHz)
24
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