1 1 Virtual Environments Virtual Environments ELG5124/CSI5151 ELG5124/CSI5151 – – Fall 2011 Fall 2011 Jochen Jochen Lang Lang SITE, University of Ottawa SITE, University of Ottawa Canada Canada
11
Virtual EnvironmentsVirtual Environments
ELG5124/CSI5151 ELG5124/CSI5151 –– Fall 2011Fall 2011
JochenJochen LangLang
SITE, University of OttawaSITE, University of Ottawa
CanadaCanada
22
Jochen LangJochen Lang
Introduction to CHAI3D Introduction to CHAI3D
HapticsHaptics SDKSDK•• computer computer hapticshaptics
–– interface to different hardware, extensible (see interface to different hardware, extensible (see assignment 3)assignment 3)
–– hapticshaptics rendering looprendering loop
–– haptichaptic effectseffects
•• visualizationvisualization
–– graphics support based on graphics support based on openGLopenGL and GLUTand GLUT
–– visual rendering loopvisual rendering loop
–– scenegraphscenegraph
•• interactive realinteractive real--time simulationtime simulation
–– collision detection, timers and thread managementcollision detection, timers and thread management
33
Jochen LangJochen Lang
Overview: Overview: HapticHaptic Control LoopsControl Loops
User ControlUser Control ActuatorsActuators
Device +Device +
BiomechanicsBiomechanics
HapticHaptic
RenderingRendering
ForceForce
PositionPositionPositionPosition
ForceForce
Input LoopInput Loop
Output LoopOutput Loop
Adapted from M.C. Lin and M.A. Adapted from M.C. Lin and M.A. OtaduyOtaduy, Recent advances in , Recent advances in haptichaptic rendering and applications, rendering and applications,
SIGGRAPH course notes, 2005.SIGGRAPH course notes, 2005.
44
Jochen LangJochen Lang
HapticHaptic Rendering Rendering
HapticHaptic
RenderingRendering
PositionPositionForceForce
Collision Collision
DetectionDetectionObject Object
ResponseResponseForce Force
ComputationComputation
55
Jochen LangJochen Lang
Generic Generic HapticHaptic Devices Devices ––
Key MethodsKey Methods
class cGenericHapticDevice : public cGenericDevice
// Read the position of the device. Units are meters [m].int getPosition(cVector3d& a_position) // Read the orientation frame of the device end-effector.int getRotation(cMatrix3d& a_rotation)
// Read the linear velocity of the device. Units are meters per second [m/s].int getLinearVelocity(cVector3d& a_linearVelocity) // Read the angular velocity of the device. Units are in radians per second [m/s].int getAngularVelocity(cVector3d& a_angularVelocity)
// Send a force [N] to the haptic device.int setForce(cVector3d& a_force) // Read a sensed force [N] from the haptic device.int getForce(cVector3d& a_force) // Send a torque [N*m] to the haptic device.int setTorque(cVector3d& a_torque)// Read a sensed torque [N*m] from the haptic device.int getTorque(cVector3d& a_torque)
// read the status of the user switch [\b true = \b ON / \b false = \b OFF].int getUserSwitch(int a_switchIndex, bool& a_status) // Get the specifications of the current device.cHapticDeviceInfo getSpecifications()
66
Jochen LangJochen Lang
Generic Generic HapticHaptic Devices Devices ––
StateState
class cGenericHapticDevice : public cGenericDevice
// Open connection to haptic device (0 indicates success).
int open()
// Close connection to haptic device (0 indicates success).
int close()
// Initialize or calibrate haptic device (0 indicates success).
int initialize(const bool a_resetEncoders=false)
// Get the specifications of the current device
cHapticDeviceInfo getSpecifications()}
77
Jochen LangJochen Lang
HapticHaptic Device HandlerDevice Handler
class class cHapticDeviceHandlercHapticDeviceHandler
// Returns the number of devices connected to your computer.// Returns the number of devices connected to your computer.
unsigned unsigned intint getNumDevicesgetNumDevices() ()
// Updates information regarding the devices that are connected // Updates information regarding the devices that are connected to your to your computer.computer.
void update();void update();
// Returns the specifications of the // Returns the specifications of the ithith device.device.
intint getDeviceSpecificationsgetDeviceSpecifications((
cHapticDeviceInfocHapticDeviceInfo& & a_deviceSpecificationsa_deviceSpecifications, ,
unsigned unsigned intint a_indexa_index = 0);= 0);
// Returns a handle to the // Returns a handle to the ithith device if available.device if available.
intint getDevice(cGenericHapticDevicegetDevice(cGenericHapticDevice*& *& a_hapticDevicea_hapticDevice, ,
unsigned unsigned intint a_indexa_index = 0); = 0);
88
Jochen LangJochen Lang
Connecting to a Connecting to a haptichaptic devicedevice
// 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= hapticDevice->getSpecifications();
cHapticDeviceInfo
string m_manufacturerName;
double m_maxForce;
double m_workspaceRadius;
bool m_sensedPosition;
bool m_sensedRotation;
bool m_actuatedPosition;
bool m_actuatedRotation;
99
Jochen LangJochen Lang
Chai3D Source File OrganizationChai3D Source File Organization
1010
Jochen LangJochen Lang
ScenegraphScenegraph NodesNodes
cGenericObjectcGenericObject
•• Parent of all Parent of all scenegraphscenegraph nodesnodes
cCameracCamera
•• Controls the position/orientation of Controls the position/orientation of the camera relative to the scenethe camera relative to the scene
cLightcLight
•• Light source position and Light source position and orientationorientation
cMeshcMesh, , cShapeSpherecShapeSphere, etc., etc.
•• Objects in the sceneObjects in the scene
cGenericToolcGenericTool
•• HapticHaptic toolstools
cWorldcWorld
•• Root of the sceneRoot of the scene
1111
Jochen LangJochen Lang
HapticHaptic ScenegraphScenegraph TraversalTraversal
1212
Jochen LangJochen Lang
Example: 12Example: 12--PolygonPolygon
•• Uses a triangle meshUses a triangle mesh
•• HapticHaptic finger proxy rendering finger proxy rendering algorithm of [algorithm of [RuspiniRuspini et al. et al. ’’97]97]
•• Collision detection with build in Collision detection with build in axisaxis--alignedaligned--boundingbounding--box treebox tree
©© Copyright Chai3DCopyright Chai3D
1313
Jochen LangJochen Lang
Credits, ReferencesCredits, References
Material from:Material from:
•• Francois Conti, Chai3D source codeFrancois Conti, Chai3D source code
•• Kenneth Salisbury, Federico Kenneth Salisbury, Federico BarbagliBarbagli and Franand Franççois ois Conti, CS 277 Conti, CS 277 -- Experimental Experimental HapticsHaptics, Lecture 4, , Lecture 4, ““Open Source Framework CHAI 3DOpen Source Framework CHAI 3D””, Stanford , Stanford UniversityUniversity