hapi programming. hapi overview device handling geometry/shape haptics rendering surface/contact...

29
HAPI programming

Upload: julius-jefferson

Post on 18-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

HAPI programming

Page 2: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

HAPI overview

Device handling Geometry/shape haptics rendering Surface/contact handling Force effects

Page 3: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Overview

HAPI

Application

Haptics device drivers

Shapes, effects

Force, torque

Page 4: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Threads Servo thread(~1000Hz)◦ Handles communication with the haptics device.◦ Renders simple primitives and force effects.

Client thread(30-60 Hz)◦ User program.◦ Determines which primitives that should be rendered

haptically.

Page 5: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Threads

Servo thread

Client thread Application

HAPI

Haptic primitives

Force

30-60 Hz

1000 Hz

Page 6: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Device handling Simple device independent interface. AnyHapticsDevice

Page 7: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Device handling functions bool initHapticsDevice()◦ Initialize the device and start the haptics thread.

bool releaseHapticsDevice()◦ Stop the haptics thread and release all resources.

bool enableHapticsDevice()◦ Start sending forces and update state.

bool disableHapticsDevice()◦ Disable force rendering and state updates.

Page 8: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Example

AnyHapticsDevice hd;

if( hd.initDevice() != HAPIHapticsDevice::SUCCESS ) { // handle error } hd.enableDevice();

// main program code ...

hd.disableDevice(); hd.releaseDevice();}

Page 9: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Device functions Calibration(Device space -> world space)◦ setPositionCalibration◦ setOrientationCalibration

Values◦ getDeviceValues◦ getLastDeviceValues◦ getRawDeviceValues◦ getLastRawDeviceValues

Page 10: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Rendering methods Effect rendering◦ free space force effects

Shape rendering◦ touching geometries

Page 11: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Force effects

Examples:◦ Spring, force field, wind, recoil

Haptics device state(pos, vel, orn, buttons) force, torque

Page 12: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Available effects HapticForceField HapticSpring HapticViscosity HapticShapeConstraint HapticPositionFunctionEffect HapticTimeFunctionEffect

Page 13: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Functions void addEffect( HapticForceEffect *effect )◦ Add a haptic effect to render by the haptics device. The effect

will be rendered until removed.

void removeEffect( HapticForceEffect *effect )◦ Remove a haptic effect currently being rendered.

void clearEffects() ◦ Remove all haptic effects currently rendered.

Page 14: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Example AnyHapticsDevice hd;

if( hd.initDevice() != HAPIHapticsDevice::SUCCESS ) { // handle error } hd.enableDevice();

HapticForceField *force_field = new HapticForceField( Vec3( 1, 0, 0 ) ); hd.addEffect( force_field ); hd.transferObjects();

// wait for ENTER string temp_string; cerr << "Press ENTER to exit" << endl; getline( cin, temp_string );

hd.disableDevice(); hd.releaseDevice();

Page 15: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Custom force effect Inherit from HAPIForceEffect◦Override calculateForces method

EffectOutput virtual calculateForces(HAPIHapticsDevice *hd, HAPITime dt ) { return EffectOutput( Vec3( 1, 0, 0 ), Vec3( 1, 0, 0 ) );

}

Page 16: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Shape rendering HapticPrimitive◦ Sphere, Point, Line, Triangle, Plane

HapticTriangleSet HapticLineSet HapticPointSet HapticTriangleTree HapticPrimitiveTree

Page 17: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Shape rendering Surfaces determine the feeling of the object(hardness,

roughness etc)◦ FrictionSurface

Stiffness, damping, static friction, dynamic friction◦ DepthMapSurface(image determines surface depth)◦OpenHapticsSurface(only with OpenHapticsRenderer)

Page 18: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Layers Each layer has a separate renderer. Total force is sum of layers.

Layer 0

Layer 1

Page 19: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Rendering algorithm Internal◦ GodObjectRenderer◦ RuspiniRenderer

External◦OpenHaptics◦ Chai3D

Page 20: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Functions void addShape( HAPIHapticShape *shape,

unsigned int layer = 0 )◦ Render a shape on the given layer.

void removeShape( HAPIHapticShape *shape, unsigned int layer = 0 )◦ Remove a shape currently being rendered.

void clearShapes( unsigned int layer = 0 )◦ Remove all shapes on a layer.

Page 21: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Example AnyHapticsDevice hd;

if( hd.initDevice() != HAPIHapticsDevice::SUCCESS ) { // handle error } hd.enableDevice();

HapticPrimitive *sphere = new HapticPrimitive( new Collision::Sphere( 100 ), new FrictionSurface ); hd.addShape( sphere ); hd.transferObjects();

// wait for ENTER string temp_string; cerr << "Press ENTER to exit" << endl; getline( cin, temp_string );

hd.disableDevice(); hd.releaseDevice();

Page 22: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Custom shapes Inherit from HAPIHapticShape and implement◦ lineIntersectShape◦ getConstraintsOfShape◦movingSphereIntersectShape◦ glRenderShape

Page 23: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Custom surfaces Inherit from HAPISurfaceObject◦ Implement getProxyMovement and getForces functions

Page 24: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

FeedbackBufferCollector Uses the OpenGL feedback buffer to get geometric

primitives Example

vector< HAPI::Bounds::Triangle > triangles;

FeedbackBufferCollector::startCollecting();draw();FeedbackBufferCollector::endCollecting( triangles );

Page 25: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Exercise 1

Make a simple program that uses the available shapes to stop the haptics device from going under the y=0 plane.

Page 26: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Exercise 2

Make a simple program that uses the available force effects to lock it into position at position 0,0,0.

Page 27: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Exercise 3

Make a custom force effect that holds the haptics device to the plane y=0.

Page 28: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Exercise 4

Use the FeedbackBufferCollector to render a sphere haptically and graphically.

Page 29: HAPI programming. HAPI overview  Device handling  Geometry/shape haptics rendering  Surface/contact handling  Force effects

Exercise 5

Write a custom surface that ...