new experimental haptics lecture1 - stanford university · 2014. 4. 15. · d3} {d4} cs277 -...

51
CS277 - Experimental Haptics, Stanford University, Spring 2014 1 CS 277 - Experimental Haptics Lecture 5 CHAI3D

Upload: others

Post on 13-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 1

CS 277 - Experimental Haptics Lecture 5

CHAI3D

Page 2: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 2

Overview

• CHAI3D framework organization

• Haptic interfaces

• Coordinates

• Building a world

• Scene graph

• Objects

• Tools

• Force algorithms

• Examples

Page 3: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 3

Organization

• executable files

DLL libraries

• external libraries used

inside CHAI3D

• modules (ODE, GEL)

• application templates

• examples with source code

• additional libraries used by

examples

• CHAI3D source code

• utilities

• project and solution files

Page 4: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 4

Examples

Page 5: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 5

Examples

Page 6: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 6

Examples

Page 7: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Haptic Device Handler

haptic device handler (cHapticDeviceHandler)

application

Page 8: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 8

Haptic Devices class cGenericHapticDevice

int open()

int close()

int initialize()

int getPosition(cVector3d& a_position)

int getLinearVelocity(cVector3d& a_linearVelocity)

int getRotation(cMatrix3d& a_rotation)

int setForce(cVector3d& a_force)

int getUserSwitch(int a_switchIndex, bool& a_status)

cHapticDeviceInfo getSpecifications()

positions

forces

Page 9: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 9

Haptic Devices

// create a haptic device handler

handler = new cHapticDeviceHandler();

// get access to the first available haptic device

cGenericHapticDevice* hapticDevice;

handler->getDevice(hapticDevice, 0);

// retrieve information about the current haptic device

cHapticDeviceInfo info;

if (hapticDevice)

{

info = hapticDevice->getSpecifications();

}

(…)

cHapticDeviceInfo

string m_manufacturerName;

double m_maxForce;

double m_maxForceStiffness;

double m_workspaceRadius;

bool m_sensedPosition;

bool m_sensedRotation;

bool m_actuatedPosition;

bool m_actuatedRotation;

(…)

Page 10: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 10

Coordinate System

x

y

z

Page 11: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 11

Virtual World

camera

light

objects

world

Page 12: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 12

Reference frames

x y

z

x y

z

x y

z

Page 13: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Scene

13

• Defining independent objects in the world

• Defining relationships between these objects

Page 14: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

World Origin

14

XW

YW

Expressing the vertices of the

object (car) in reference with the

world coordinate system.

{W} : World Reference Frame

World Origin

Page 15: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Translation

15

{W} : World Reference Frame

World Origin

XW

YW

Moving the object would require

computing a new position for

each vertex.

Page 16: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Rotation

16

{W} : World Reference Frame

World Origin

XW

YW

Moving the object would require

computing a new position for

each vertex.

Page 17: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Reference Frames

17

{W} : World Reference Frame

World Origin

XW

YW

Defining a local reference frame

for each independent object.

XA

YA

{A} : Reference Frame of Object A

Page 18: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Reference Frames

18

World Origin

XW

YW

{W} : World Reference Frame

Defining a local reference frame

for each independent object.

{A} : Reference Frame of Object A

Page 19: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Reference Frames

19

World Origin

XW

YW

{D2}

{D1}

{D3}

{D4}

Page 20: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 20

Scene Graph

world (root node)

light

light

camera object

object

mesh shape

tool

Page 21: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 21

cGenericObject

Page 22: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 22

Shapes

Page 23: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 23

Shapes (cShapeSphere, cShapeCylinder, cShapeTorus, cShapeBox)

Page 24: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 24

Example

Page 25: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 25

Materials (cMaterial)

GRAPHIC PROPERTIES:

cColorf m_ambient; Ambient color.

cColorf m_diffuse; Diffuse color.

cColorf m_specular; Specular color.

cColorf m_emission; Emissive color.

GLuint m_shininess; Shininess

HAPTIC PROPERTIES:

double m_viscosity; Viscosity constant.

double m_stiffness; Stiffness constant.

double m_static_friction; Static friction constant.

double m_dynamic_friction; Dynamic friction constant.

double m_vibrationFrequency; Frequency of vibrations

double m_vibrationAmplitude; Amplitude of vibrations.

double m_magnetMaxForce; Maximum force applied by magnet effect.

double m_stickSlipForceMax; Force threshold for stick and slip effect.

double m_stickSlipStiffness; Spring stiffness of stick slip model.

Page 26: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 26

Materials (cMaterial)

GRAPHIC PROPERTIES:

cColorf m_ambient; Ambient color.

cColorf m_diffuse; Diffuse color.

cColorf m_specular; Specular color.

cColorf m_emission; Emissive color.

GLuint m_shininess; Shininess

Page 27: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 27

Colors

Page 28: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 28

Colors (cColorf)

// set material color by name

object->m_material->setBlueCornflower();

// set material color by values (R-G-B)

object->m_material->setColorf(0.2, 0.1, 0.1);

// set material color by components (R-G-B)

object->m_material->m_ambient->set(0.2, 0.2, 0.2);

object->m_material->m_diffuse>set(0.5, 0.5, 0.5);

object->m_material->m_specular>set(1.0, 1.0, 1.0);

// define color

cColorf color;

color.setRedFireBrick();

Page 29: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 29

Mesh

Page 30: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Creating Vertices

30

// create mesh

cMesh* mesh = new cMesh();

// add mesh to world

world->addChild(mesh);

// create 3 vertices

unsigned int vertexIndex0 = mesh->m_vertices->newVertex();

unsigned int vertexIndex1 = mesh->m_vertices->newVertex();

unsigned int vertexIndex2 = mesh->m_vertices->newVertex();

Vertex 0

Vertex 1

Vertex 2

Page 31: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Vertex Properties

31

// define vertex position

cVector3d position(2.0, 3.0, 4.0);

mesh->m_vertices->setLocalPos(vertexIndex0, position);

// define vertex normal

cVector3d normal(1.0, 0.0, 0.0);

mesh->m_vertices->setNormal(vertexIndex0, normal);

// define texture coordinate

mesh->m_vertices->setTexCoord(vertexIndex0, 0.2, 0.3);

// define vertex color

cColorf color;

color.setBlueCadet();

mesh->m_vertices->setColor(vertexIndex0, color);

Page 32: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Creating Triangles

32

// create triangle

mesh->m_triangles->newTriangle(vertexIndex0, vertexIndex1, vertexIndex2);

Vertex 0

Vertex 1

Vertex 2

Normal 2

Normal 0

Normal 1

Page 33: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 33

Textures

mesh object (cMesh) texture map (cTexture2D) mesh object with

texture properties defined

single textured triangle

and its 3 vertices

Page 34: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

cMultiMesh

34

Page 35: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 35

Haptic Effects (cGenericEffect)

HAPTIC PROPERTIES: (cMaterial)

double m_viscosity; Viscosity constant.

double m_stiffness; Stiffness constant.

double m_static_friction; Static friction constant.

double m_dynamic_friction; Dynamic friction constant.

double m_vibrationFrequency; Frequency of vibrations

double m_vibrationAmplitude; Amplitude of vibrations.

double m_magnetMaxForce; Maximum force applied by magnet effect.

double m_stickSlipForceMax; Force threshold for stick and slip effect.

double m_stickSlipStiffness; Spring stiffness of stick slip model.

Page 36: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 36

Haptic Effects (cGenericEffect)

// create a haptic vibration effect

object->createEffectVibration();

// create a haptic surface effect

object->createEffectSurface();

Page 37: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 37

Camera

Page 38: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 38

Camera

Page 39: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 39

Camera

Page 40: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 40

Camera (cCamera)

// create a camera and insert it into the virtual world

camera = new cCamera(world);

world->addChild(camera);

// position and orient the camera

camera->set( cVector3d (0.5, 0.0, 0.0), // camera position (eye)

cVector3d (0.0, 0.0, 0.0), // look at position (target)

cVector3d (0.0, 0.0, 1.0)); // direction of the (up) vector

// set the near and far clipping planes of the camera

camera->setClippingPlanes(0.01, 10.0);

Page 41: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 41

Stereo Camera

Page 42: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 42

Stereo Camera (cCamera)

// set stereo mode

camera->setStereoMode(stereoMode);

// set stereo eye separation and focal length (applies only if stereo is enabled)

camera->setStereoEyeSeparation(0.005);

camera->setStereoFocalLength(0.5);

// set vertical mirrored display mode

camera->setMirrorVertical(mirroredDisplay);

Page 43: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Example

43

cWorld

cCamera

cLight

cMesh cGenericTool

Page 44: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 44

Widgets

Page 45: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 45

Widgets cLabel

cLevel cScope

cDial

Page 46: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 46

Light Sources

Page 47: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 47

Tools

Page 48: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014

Example

48

Page 49: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 49

Traversing a Scene Graph

object

tool

Page 50: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 50

Traversing a Scene Graph

Page 51: New experimental haptics lecture1 - Stanford University · 2014. 4. 15. · D3} {D4} CS277 - Experimental Haptics, Stanford University, Spring 2014 20 Scene Graph world (root node)

CS277 - Experimental Haptics, Stanford University, Spring 2014 51

Traversing a Scene Graph

(1) Read the position of the haptic device

(2) For each object (potential field) in the environment, compute the

position of the tool in relation to the local reference frame

(3) Compute the reaction force in the local frame

(4) Convert the reaction force in the world frame

(5) Send the force to the haptic device