49
Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Embed Size (px)

Citation preview

Page 1: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets™ programming framework

IAT 351

Week 8 Lecture/Lab 1

04.03.2008

Page 2: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

summary :

• traditional physical UI examples problems

• phidgets goals definition architecture API java API programming applications

• references bibliography programming resources

Page 3: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

traditional physical UI :examples

Walking pad (DIUF)

Page 4: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

traditional physical UI :examples

Lego Mindstorms

Page 5: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

traditional physical UI :examples

SmartHome

Page 6: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Motivation

• Pertaining to ubiquitous computing (ubicomp), two areas are relevant:

Context-aware computing

Tangible user interfaces

Page 7: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

What remains hard?

• Sensing…

• Actuation…

• We’ll get back to how Phidgets address this

Page 8: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

What is Context?

• Any information that can be used to characterize the situation of an entity• Who, what, where, when

• Why is it important? information, usually implicit, that applications do not have access to It’s input that you don’t get in a GUI

Page 9: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

How to Use Context

• To present relevant information to someone Mobile tour guide

• To perform an action automatically Print to nearest printer

• To show an action that use can choose Want to phone the number in this email?

Page 10: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Case Study: tour guides

• Very popular theme Location is an easy piece of context

• G. Abowd et al. Cyberguide: A mobile context-aware tour guide. Balzer/ACM Wireless Networks, Vol. 3(5), 1997, pp. 421-433.

Page 11: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Simple Example: In/Out Board

Page 12: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Simple Example: In/Out Board

Face Recognition

LocationWidget

LocationWidget

In/Out Board

Smart Card Reader

ID to NameInterpreter

Page 13: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Tangible User Interfaces

• Hiroshi Ishii (MIT)

Tangible Bits • physical form to digital information

Tangible User Interfaces • physical objects, surfaces, and spaces that act as tangible embodiments of

digital information

Page 14: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Triangles

• Pieces are connected together to trigger digital events influence the progress of a non-linear story organize media elements in order to create their own story space

Page 15: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

LumiTouch

• Two interactive picture frames

User’s touching of a local frame translates to a glow on remote frame

She’s thinking of him He’s thinking of her

Page 16: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Tangible Video Browser

• Tokens are used to: Act as container for videos Select a video Navigate within the video

Page 17: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

What remains hard?

• Well…everything according to the paper

While an exciting new area, everyday programmers still face considerable hurdles if they wish to create even simple physical user interfaces. Perhaps the biggest--but we believe easily solved---obstacle is the sheer difficulty of developing and combining physical devices and interfacing them to conventional programming languages.

Page 18: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Why is this hard?

• Steps Acquisition Representation Interpretation Storage Delivery Reaction

• Most of these steps repeated in all development.

Page 19: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Related Work

• Tools for working with physical input/output devices

• iRX Board

• Digital I/O boards

• Tini boards

Page 20: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

traditional physical UI :problems

1. Electronics (Difficult to write/debug w/o actual devices)2. missing API3. unsuited API (wrong abstraction level)4. commercial target (oriented to different markets)5. lack of simulation capabilities

• Hard to build

Page 21: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Goals

• Simple so developers concentrate on overall use, modification, and recombination

• Easy for average programmer

Page 22: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :goals

• simple devices• easy to program

… just as widgets make GUIs easy to develop, so could phidgets make the new generation of physical user interfaces

easy to develop.

Page 23: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :definition

• widget (1931) small mechanical device (today) ‘windows gadget’

• phidget (aka phydget) ‘physical widget’

Page 24: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :definition

Phidgets™, or physical widgets, are building blocks that help a developer construct physical user interfaces.

Page 25: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :architecture

Device

Device manager

API

Simulation

Phidget

Page 26: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :architecture

Device

Device manager

API

Simulation

Page 27: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :API

Int CountPhidget[] Item

OnAttach()OnDetach()OnError()

DeviceTypeIsAttached

SerialNumber

Phidget-specific properties, e.g.

NumMotorsPhidget-specific

events, e.g.OnTag

Generic phidget

Specific phidget

Phidgets manager

actuator

sensor

Page 28: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :java API

Page 29: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :java API

Page 30: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :programming (output)

Phidget COM Object

Application

creates

Device

opens

sets

sets

Page 31: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :programming (input)

Phidget COM Object

Listener

Application

creates

Device

opens

readsfire events

starts

Page 32: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Handling the Phidget

• 3 important basic events• ATTACH (USB connected) OnAttach(),attached()• DETACH (USB disconnected) OnDetach(),detached()• ERROR (help!) OnError(), error()

• Standard Java approach of listeners and adapters

• Specific events for each type of device E.g. rfid.OnTag() for detecting an RFID tag in range

Page 33: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

phidgets :programming

Implement OnEvent methods

Create OS ObjectAttach Listener

Open connection to device

Extend adapter

Start listening

Page 34: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

public class OpenIFKitExample

});}System.out.println("error event for " + ee);public void error(ErrorEvent ee) {ik.addErrorListener(new ErrorListener() {});}System.out.println("detachment of " + ae);public void detached(DetachEvent ae) {ik.addDetachListener(new DetachListener() {});}System.out.println("attachment of " + ae);public void attached(AttachEvent ae) {ik.addAttachListener(new AttachListener() {ik = new InterfaceKitPhidget();

System.out.println(Phidget.getLibraryVersion());

InterfaceKitPhidget ik;public static final void main(String args[]) throws Exception {

{

Basic listeners

Page 35: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

ik.addInputChangeListener(new InputChangeListener() {public void inputChanged(InputChangeEvent oe) {System.out.println(oe);}});

ik.addOutputChangeListener(new OutputChangeListener() {public void outputChanged(OutputChangeEvent oe) {System.out.println(oe);}});

ik.addSensorChangeListener(new SensorChangeListener() {public void sensorChanged(SensorChangeEvent se) {System.out.println(se);}});

IK listeners

Page 36: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

ik.openAny();System.out.println("waiting for InterfaceKit attachment...");ik.waitForAttachment();

System.out.println(ik.getDeviceName());

Thread.sleep(500);

ik.getOutputCount()Ik.getSensorCount()

ik.getOutputState(i);ik.setOutputState(i,<true/false>);

Ik.getSensorRawValue(i)Ik.getSensorValue(i)

Waits until a device is plugged in

Page 37: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Page 38: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Phidgets Requirement

• Connection manager• ID• Simulation mode

Page 39: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Phidget Manager

• onAttach()

• onDetach()

• Count

• Item

• DeviceType

• isAttached()

• SerialNumber

Page 40: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Phidget Servo

• MotorPosition• NumMotors• onPositionChanged()

Page 41: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Attaching the interface kit

// create the interface kit objectInterfaceKitPhidget ik = new InterfaceKitPhidget();

// look for an attachmentik.openAny();

// don’t continue until an attachment is foundik.waitForAttachment();

Page 42: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Digital Input

• Use the wires to hook one of the switches up to a digital input and one of the grounds (on either end of the row)

• The parameter is the index of the input• The result is a boolean (true for on, false for off)

// read the value of input 3ik.getInputState(3);

Page 43: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Analog Input

• Parameter is index of the device• The result is a value between 0 and around 1000 (I’m guessing the

max is 1024)

// get the value of the first analog deviceik.getSensorValue(0);

Page 44: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Digital Output

• Boolean values are used to set the output• Each output has an index: 0 - 7• The two slots at either end are grounds

// sets output 2 to “high”ik.setOutputState(2, true);

Page 45: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Ugly Java Stuff: Exceptions

• Almost everything in the phidget package throws exceptions• Solution #1: add “throws Exception” at the end of every method

signature, including the main method• Solution #2: wrap phidget calls in try/catch blocks

Page 46: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Pausing in Java

• If you want to pause execution of your program• The parameter is time in milliseconds

// pause for 2 secondsThread.sleep(2000);

Page 47: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

Drawbacks

• Need PC• Not mobile• Not easy to deploy

Page 48: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

references :bibliography

• Greenberg S. and Fitchet C., Phidgets : Easy developement of physical interfaces through physical widgets. Proceedings of the ACM UIST 2001 Symposium.

• Greenberg S. and Boyle M., Customizable physical interfaces for interacting with conventional applications. Proceedings of the ACM UIST 2002 Symposium.

• www.phidgets.com, www.phidgetsusa.com• www.wikipedia.org (phidget, widget)• www.smarthome.com, www.legomindstorms.com • Laroussi Bouguila, Evequoz Florian, Michèle Courant, Béat Hirsbrunner. Active Walking

Interface for Human-Scale Virtual Environment. HCII’05.

Page 49: Phidgets™ programming framework IAT 351 Week 8 Lecture/Lab 1 04.03.2008

Phidgets | IAT351 | 04.03.2008

references:programming resources

• documentation on www.phidgets.com : C_API_Manual : basic architecture

• http://phidgets.com/documentation/C_API_Manual.pdf COM_API_Manual : object model (VB)

• http://phidgets.com/documentation/COM_API_Manual.pdf Javadoc : java API, quite similar to COM

• http://phidgets.com/documentation/JavaDoc.zip For each particular phidget see its « hardware description » :

• Section labelled « Phidgets » on www.phidgets.com >> Documentation• software introduction and tutorials :

• www.phidgets.com >> Documentation• http://www.phidgetsusa.com/tutorials/tutorialhome.asp

• code examples :• www.phidgets.com >> Download >> Beta >> Examples.zip• www.phidgets.com >> Project / Examples