Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

39
Wiimotes and Robots David Lippman Pierce College Ft Steilacoom

Transcript of Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Page 1: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Wiimotes and Robots

David Lippman

Pierce College Ft Steilacoom

Page 2: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

“Real World” What do we mean by this? Capturing data for analysis is cool, but Can we solve a problem, and see it in action?

Page 3: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Wiimotes Can connect over Bluetooth to computer 3-axis accelerometer Infrared camera with blob detection (4 pts)

Page 4: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Interacting with the Wiimote

Low LevelWiiuse / WiiuseJ (C / Java)Wiimotelib (C#)

High LevelGlovePIE

Page 5: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #1

Prereq: AlgebraProblem: Wiimote returns dot values in the range x: 0-1023, y: 0-767 GlovePIE maps mouse position to a 0-1 scale in

the x and y How do we map Wiimote position to a mouse

position?

Page 6: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #1 Soln

Wiimote pointing left puts dots on the right, so need to invert x. Don’t need to invert y since Mouse.y measures down from the top of the screen

Mouse.x = 1 - wiimote.dot1x/1023 Mouse.y = wiimote.dot1y/767

Page 7: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #2

Prereq: TrigProblem: Wiimote returns dot values in the range x: 0-1023, y: 0-767, roll GlovePIE maps mouse position to a 0-1 scale in

the x and y How do we map Wiimote position to a mouse

position, compensating for roll?

Page 8: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #2 Soln

Angle = asin(Wiimote.gx/1) or use atan2 Angle is off horiz Find xcamera, ycamera

Convert to polar Adjust for roll angle Convert back to Cartesian,

map to mouse

Page 9: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #3

Prereq: Algebra

Problem:

How do we determine 3D position of Wiimote in space? (using triangles)

(Assume no roll for simplicity)

Page 10: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #3 SolnCalculate distance between dots

Distance from camera = 264/dot dist

Dist at 1m = 0.1mreal / 132 pxcamera

X position:

1 m

200 px = 200*0.1/132 = 0.1515 m

4 m

0.1515 0.606

1 4

m m

m m

Page 11: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #4

Prereq: TrigProblem: How do we determine 3D position of Wiimote in

space? (using trig) (Assume no roll for simplicity)

Could we have done this with 2 Wiimotes and one dot?

Page 12: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #4 Soln Camera FOV = about 45 degrees Pixels/degree = 1024/45 = 22.8

200px → 8.8 deg1 m

4 m

4sin(8.8 ) 0.611x m

0.1dist

1dot separation

2tan22.8 pixels/degree

m

Page 13: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

How different?Distance determination:

Dis

t (m

)

Dot separation (pixels)

Relative difference

X-location determination:

Pixel x

actual x

Relative difference

Page 14: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Johnny Lee's Youtube Video

Page 15: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.
Page 16: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #5Prereq: Linear Algebra

Problem:

Mark 4 points on a projected plane (projector image) that correspond to 4 points of a unit square (screen coordinates). Find the transformation that maps points on the projected plane to the unit square.

u

v

x

y

Page 17: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #5 SolnHomogenous Coordinates: , ,x y w

xx wyy w

u

v

x

y

, , , ,1

1

a d g

x y w u v b e h

c f

1

1

au bv cx

gu hv

du ev fy

gu hv

Page 18: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

1

1

au bv cx

gu hv

du ev fy

gu hv

x au bv c xgu xhv

y du ev f ygu yhv

0 0 0 0 0 0

1 1 1 1 1 1

2 2 2 2 2 2

3 3 3 3 3 3

0 0 0 0 0 0

1 1 1 1 1 1

2 2 2 2 2 2

3 3 3 3 3 3

1 0 0 0

1 0 0 0

1 0 0 0

1 0 0 0

0 0 0 1

0 0 0 1

0 0 0 1

0 0 0 1

u v u x v x a

u v u x v x b

u v u x v x c

u v u x v x d

u v u x v x e

u v u x v x f

u v u x v x g

u v u x v x h

0

1

2

3

0

1

2

3

x

x

x

x

y

y

y

y

Using 4 corner points, this gives:

Reduces further using unit square for (u,v)

Solve using Gaussian Elimination.

To map back to (u,v), find inverse of the mapping matrix.

Page 19: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #6

Prereq: Integral Calculus / DiffEq Problem:

Use the accelerometer readings to estimate distance the Wiimote moves.

Page 20: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #6 Soln

Simplistic approach:s0 = 0, v0 = 0. Step: Δt = .05 secLoop: vn = vn-1 + .05a sn = sn-1 + .05vn

However, accelerometers are very noisy, so this is not very accurate. In fact, it’s so horrible I’m not even going to show it!

Page 21: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Arduino

Computer on a chip 14 digital I/O, w/ 6

pseudo analog out 6 analog inputs 16KB storage 1KB RAM Serial over USB Open hardware Open software

Page 22: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #7

Prereq: Algebra

Problem: Create a car backup alarm using distance sensor and LED light.

Distance sensor can detect time (in microseconds) that a sound takes to echo back.

Page 23: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #7 Soln

dist = rate*timerate = experimentally determined, or speed

of sound converted to appropriate unitsblink delay proportional to distance

Does direct proportionality look good? Should it be quadratic? Logarithmic?

Page 24: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #8

Prereq: Algebra

Problem: Map Nunchuck joystick data (values -105 to 105) to PWM values (500 to 2500) for the Servos

Page 25: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #8 Soln

Joystick Servo

-105 2500

-105 500

500 2500 200

105 ( 105) 21

200Servo (Joystick 105) 2500

21

m

Page 26: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #9

Prereq: Trig

Problem: Use the Pan/Tilt laser pointer to draw a circle

Page 27: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #9 Soln

Use parametric equations:t=0Loop: x = cos(t) y = sin(t) map (x, y) to Servos t = t + .1 delay(20)

Page 28: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #10

Prereq: Pre-algebraProblem: In a robot with differential drive,

each wheel can turn at a different rate. If the wheels are 10cm apart and the outside wheel turns at full speed, at what fraction of full speed will the inside wheel need to turn to drive a circle with inner radius 50cm?

Page 29: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #10 Soln

10cm 50cm

Cinside = 2π(50) cm

Coutside = 2π(50+10) cm

Speedinside = (2π(50) cm)/unit time

Speedoutside = (2π(50+10) cm)/unit time

Ratio of speeds = 50 / (50 + 10) = 5/6

Page 30: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.
Page 31: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Problem #11

Prereq: Trig

Problem: Ballistics trajectories. Experimentally determine initial velocity, then adjust launch angle to hit a target.

Have a class competition to see who can come closest!

Page 32: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Prob #11 Soln0

20 0

0

0 0

0 00 0

00

To determine :

4.9

assuming 0

sin( )

4.9horizontal hit dist

sin( )cos( )

4.9

9.8

sin(2 )

v

hit

v

s t v t s

s

vt

d

vd v

dv

0

0

00

20

12

0

To find launch angle:

again assuming 0

sin( )

4.9to achieve horizontal hit dist

sin( )cos( )

4.9

sin(2 )

9.8

1 9.8sin

2

hit

s

vt

d

vd v

vd

d

v

Page 33: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Advanced ideas

Kalman filters Gesture recognition (hidden Markov

model) Augmented Reality

Page 34: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Playtime

Wii Quizzer Wii Buzzer

Page 35: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.

Correlation doesn't imply causation, but it does waggle its eyebrows suggestively and gesture furtively while mouthing 'look over there'.

Page 36: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.
Page 37: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.
Page 38: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.
Page 39: Wiimotes and Robots David Lippman Pierce College Ft Steilacoom.