programming with sensors bumper switch 1

22
VEX Robotics I Power Points Topic 09 Programming Design Basics Bumper Switch Sensing 1 www.pedagogics.ca

Upload: david-young

Post on 11-May-2015

3.834 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Programming with sensors   bumper switch 1

VEX Robotics I Power Points

Topic 09

Programming Design Basics

Bumper Switch Sensing 1www.pedagogics.ca

Page 2: Programming with sensors   bumper switch 1

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

Page 3: Programming with sensors   bumper switch 1

Bumper Switch

(digital sensor)

Usually positioned on front of robot.

Output is either a 1 (depressed) or a 0

0

Page 4: Programming with sensors   bumper switch 1

Bumper Switch

(digital sensor)

Usually positioned on front of robot.

Output is either a 1 (depressed) or a 0

1

Page 5: Programming with sensors   bumper switch 1

Bumper Switch

(digital sensor)

Usually positioned on front of robot.

Output is either a 1 (depressed) or a 0

0

Page 6: Programming with sensors   bumper switch 1

Bumper Switch

(digital sensor)

Usually positioned on front of robot.

Output is either a 1 (depressed) or a 0

1

Page 7: Programming with sensors   bumper switch 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

Page 8: Programming with sensors   bumper switch 1

Flowchart Symbols

Page 9: Programming with sensors   bumper switch 1

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

Page 10: Programming with sensors   bumper switch 1

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)

Page 11: Programming with sensors   bumper switch 1

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

Page 12: Programming with sensors   bumper switch 1

Valid “comparison operators” in ROBOTC

Page 13: Programming with sensors   bumper switch 1

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

Page 14: Programming with sensors   bumper switch 1
Page 15: Programming with sensors   bumper switch 1

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

Page 16: Programming with sensors   bumper switch 1
Page 17: Programming with sensors   bumper switch 1

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

Page 18: Programming with sensors   bumper switch 1
Page 19: Programming with sensors   bumper switch 1

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?)

Page 20: Programming with sensors   bumper switch 1
Page 21: Programming with sensors   bumper switch 1

DRIVE FORWARD

START

IF Switch

not pressed

?

Stop, reverse, 180 degree turn

TRUE

FALSE

WHILE LOOP ?

END

Move on

Always

infiniteloop

Page 22: Programming with sensors   bumper switch 1