event-driven programming and sensor...

16
1 6 Y Chen 101 9/29/2015 Event-Driven Programming and Sensor Programming Yinong Chen Introduction to Engineering Using Robotics Laboratories

Upload: others

Post on 30-May-2020

64 views

Category:

Documents


0 download

TRANSCRIPT

1

6Y Chen

101

9/29/2015

Event-Driven Programming andSensor Programming

Yinong Chen

Introduction to Engineering Using Robotics Laboratories

2

6Y Chen

101

9/29/2015

Table of Contents

Event-Driven Sensor Programming2

Types of Sensors3

Program a Range Sensor4

Control Flow vs. Event-Driven1

3

6Y Chen

101

9/29/2015

Ro

uti

ne

of

aM

edic

al

Pro

fess

or

inC

on

tro

lF

low

Mo

de

Research

Write proposal

Consult students

Teaching Prep

See ICU patients

See out-patients

Teach a course

Read reports

See all in-patients

See ICU patients

Outside officeIn Office

4

6Y Chen

101

9/29/2015

Ro

uti

ne

of

Med

ica

lP

rofe

sso

rsin

Ev

ent-

Dri

ve

Mo

de

Research

Write proposal

Student questions

Teaching Prep

Answer studentquestions

ICU patient

Teach a course

See out-patients

Read reports

See all in-patients

Outside office

EventBoard

AlertBoard

ICU patient

ICU patient

Student questions

Student questions

Student questions

Student questions

Not

ific

atio

n

Inte

rrup

t/

Not

ific

atio

n

5

6Y Chen

101

9/29/2015

Event-Driven Programming

Event-driven programming is a computingparadigm which allows interaction between thecomputer program and the user;

The execution flow of the program isdetermined by• user actions, such as mouse clicks, key presses,

sensor outputs (e.g., touch sensor), and

• messages from other programs

It assumes that there are unlimited number ofprocessors available, and the events can behandled immediately.

6

6Y Chen

101

9/29/2015

Sensors and Actuatorsin Robotics Application

7

6Y Chen

101

9/29/2015

Eventemitter

Motorposition

M1Notify

handler M1

Motor 1control

Motor1

Eventemitter

T1

T2

Tm

Notify handler T1

Notify handler T2

Notify handler Tm

TouchSensor

Main programin a loop

HandlerTouch

HandlerSonar

Eventemitter

S1

S2

Sn

Notify handler S1

Notify handler S2

Notify handler Sn

SonarSensor

HandlerMotor 1

HandlerMotor 2

Eventemitter

Motorposition

Motor 2control

Motor2

Notifyhandler M2

M2

Frequency ofreading

Alert

LightSonar

Frequency ofreading

8

6Y Chen

101

9/29/2015

Communication betweenActivities / Services in VPL

Event!

Activity /Service

Activity /Diagram

0 0 0 0

1 1 1 1

Data

Signals

9

6Y Chen

101

9/29/2015

Variable and Data Flow

10

6Y Chen

101

9/29/2015

Data Output versus Notification Output

Control Flow

Queue

Set

Event Driven:All will be done atthe same time, but

11

6Y Chen

101

9/29/2015

Types of Sensors

Ranging sensors, such as

sonar,

ultrasonic,

IR, and

laser sensors:

These sensors return the distance tothe object.

They typically have two lens (eyes).One sends out a light beam and theother receives the reflected beam.

By measuring the time and angle ofreflected beam, as shown in theFigure on the right, the sensors canmeasure the distance to the object

12

6Y Chen

101

9/29/2015

Types of SensorsThere are many types of sensors

Contact (touch) sensor: A signal isgenerated when touched

Compass (magnetic) sensor

GPS (Global Positioning System)

Color sensor: return different valuefor different colors

Temperature sensorReturn the temperature

Vehicle accelerometer sensor

Vehicle tire pressure sensor

13

6Y Chen

101

9/29/2015

EV3 and Edison Robots

14

6Y Chen

101

9/29/2015

Example: NXT Robot and An Application

SonarSensor

TouchSensor

Actuator:Motor Effector:

Finger

While (true){

if touch sensor value == 1Trigger the motor;

elseif sonar distance < 3 feet{

while sonar distance < 5{}Trigger the motor;

}}

Image from: http://www.gadgetsireland.tv/2007/09/

This program will not be workingwithout event-driven programming:Touch sensor has no chance!

15

6Y Chen

101

9/29/2015

Test Sensors in ASU-VPL

16

6Y Chen

101

9/29/2015

A Line-Follower Program Using Color Sensor