programming with sensors bumper switch 1
TRANSCRIPT
VEX Robotics I Power Points
Topic 09
Programming Design Basics
Bumper Switch Sensing 1www.pedagogics.ca
Topics Covered in this Presentation
Topic 09
• Introduction to the bumper switch
• flowcharting and writing pseudocode
•program sketch #1
• while loops and Boolean logic
• if else loops and sensor input
Bumper Switch
(digital sensor)
Usually positioned on front of robot.
Output is either a 1 (depressed) or a 0
0
Bumper Switch
(digital sensor)
Usually positioned on front of robot.
Output is either a 1 (depressed) or a 0
1
Bumper Switch
(digital sensor)
Usually positioned on front of robot.
Output is either a 1 (depressed) or a 0
0
Bumper Switch
(digital sensor)
Usually positioned on front of robot.
Output is either a 1 (depressed) or a 0
1
Program sketch #1
Write a simple program to make your robot drive
forward indefinitely , but will stop, turn 180o and
continue driving if the robot encounters an obstacle.
STEP 1 – FLOWCHART
• thinking about how ROBOTC
works
STEP 2 – PSEUDOCODE
STEP 3 – ACTUAL CODE
Flowchart Symbols
Flow chart describes behavior
sequence.
This flowchart gives us the basic
idea of what behaviors we want to
see in our robot.
The flowchart however is overly
simplified and needs a few extras
to make it easily transferable to
code.
DRIVE FORWARD
START
Switch pressed
?
Stop, reverse, 180 degree turn
NO
YES
DRIVE FORWARD
START
IF Switch
not pressed
?
Stop, reverse, 180 degree turn
TRUE
FALSE
WHILE LOOP ?
END
Move on
Always
infiniteloop
Cannot use a wait statement because we want the robot to perform two functions alternately (essentially simultaneously)
DECISIONS must be thought of as questions that
can be answered YES or NO
TRUE or FALSE
This type of question is called a Boolean statement.
The answer is called a “truth value” and the answer is only valid at the time the question is asked.
You used a Boolean statement in the remote control coding for Tumbler
Valid “comparison operators” in ROBOTC
START
Pseudo code - basic commands, comments about functions and behaviors
This code will never compile
Forms the backbone of your program and translates from the flowchart to ROBOTC
DRIVE FORWARD
START
IF Switch
not pressed
?
TRUEWHILE LOOP ?
Always
infiniteloop
IF , ELSE boolean statement used to check bumper switch. If switch is not pressed, robot drives forward
DRIVE FORWARD
START
IF Switch
not pressed
?
TRUEWHILE LOOP ?
Always
infiniteloop
IF , ELSE boolean statement used to check bumper switch. If switch is not pressed, robot drives forward
DRIVE FORWARD
START
IF Switch
not pressed
?
Stop, reverse, 180 degree turn
TRUE
FALSE
WHILE LOOP ?
Always
infiniteloop
If switch is pressed – ELSE – the stop and turn behavior occurs, then robot returns to moving forward (unless what is happening?)
DRIVE FORWARD
START
IF Switch
not pressed
?
Stop, reverse, 180 degree turn
TRUE
FALSE
WHILE LOOP ?
END
Move on
Always
infiniteloop