part i · pdf filetauchi – tampere unit for computer-human interaction forces usually...
TRANSCRIPT
TAUCHI – Tampere Unit for Computer-Human Interaction
Part I
IntroductionDevicesLibraries
X3D + Python basics
TAUCHI – Tampere Unit for Computer-Human Interaction
Haptics
● Incorporate sense of touch into computer use through force or tactile feedback.
● Can be achieved with special hardware: haptic devices.
● Wide spectrum of possible application areas: simulation, CAD / modeling, assistive tech., games.
TAUCHI – Tampere Unit for Computer-Human Interaction
Forces
● Usually used to resist or assist motion.
● Common approach is to monitor the location of
the device and it's relationship to the objects in
the virtual environment: a good range of possible
feedback effects.
● Two main classes of force feedback: motion and
time dependent feedback.
TAUCHI – Tampere Unit for Computer-Human Interaction
Motion dependent forces
● Spring - “force exerted by the spring is in direct opposition to the direction of displacement. It is called a "restoring force", as it tends to restore the system to equilibrium.”
● Damper - “a force synchronous with the velocity of the object but opposite in direction
to it... force F may be related to the velocity v by F = -cv, where c is the damping coefficient,
given in units of newton-seconds per meter.”
● Friction - “Friction is the force resisting the relative motion of solid surfaces, fluid
layers, and/or material elements sliding against each other.”
● Inertia - “In common usage the term "inertia" may refer to an object's "amount of
resistance to change in velocity" (which is quantified by its mass), or sometimes to its
momentum, depending on the context.”
TAUCHI – Tampere Unit for Computer-Human Interaction
Time dependent forces
● Constant
● Periodic
● Impulses - “the integral of a force with respect to time. When a force is applied to a
rigid body it changes the momentum of that body. A small force applied for a long time can
produce the same momentum change as a large force applied briefly”
TAUCHI – Tampere Unit for Computer-Human Interaction
Force basics
● The system tracks the end-effector.
● When the effector contacts a solid surface the virtual effector proxy is placed in the contact point.
● A spring force is created to push the end effector towards the proxy.
Solid Object
End EffectorContact point
(Source: OpenHaptics programmers guide)
TAUCHI – Tampere Unit for Computer-Human Interaction
Haptic devicesPhantom
● 6DOF● 2 devices: Desktop &
Premium● Large work-area● Very wide range for
feedback
Image by SensAble
TAUCHI – Tampere Unit for Computer-Human Interaction
Haptic devicesOmega
● 3DOF
● Sturdy
● Large work-area
● Wide range of feedback effects
TAUCHI – Tampere Unit for Computer-Human Interaction
Haptic devicesFalcon
● 3DOF
● Cheap
● Gaming
● Good range of feedback effects
● Small
TAUCHI – Tampere Unit for Computer-Human Interaction
Haptic libraries
● Chai3D OpenSource *● OpenHaptics Comm. / Free for academics *● Reachin Commercial ● H3D OpenSource *● Falcon SDK free for non-commercial use *
TAUCHI – Tampere Unit for Computer-Human Interaction
Haptic libraries
● Most of the libraries offer both the graphical and haptic output.
● There usually is two execution loops: one loop for graphics and the other for the haptics.
● Haptic loop must execute at least 1000 times per second. Dropping below 1000 Hz causes all kinds of problems ranging from solid surfaces being less solid to weird force-effects.
TAUCHI – Tampere Unit for Computer-Human Interaction
H3Dhttp://www.h3dapi.org
TAUCHI – Tampere Unit for Computer-Human Interaction
H3D
● Supports various haptic renderers such as Chai3D and OpenHaptics
● The bottom level is the haptic-only library HAPI
● Uses scene-graph for setting up the environment
● Available also: VHTK (volume haptics toolkit) and UI component library
OpenHaptics Chai3D
H3DApi
HAPI
H3DUtil
Falcon
TAUCHI – Tampere Unit for Computer-Human Interaction
Scene-graph the H3D way
• Single root node• Child nodes and grouping nodes• Transform has its local coordinate system• Possibility for scripting
Root
Group Transform Script
Object Object Object Object
TAUCHI – Tampere Unit for Computer-Human Interaction
Levels of H3D: X3D
<?xml version="1.0" encoding="UTF-8"?><Group> <Transform translation="−0.1 0 0"> <Shape> <Appearance> <Material DEF="MAT1"diffuseColor="1 0 0"/> </Appearance> <Box size="0.1 0.1 0.1"/> </Shape> </Transform></Group>
The highest level for creating virtual environment
TAUCHI – Tampere Unit for Computer-Human Interaction
Levels of H3D: X3D + Python
You can add scripted behavior to X3D files using Python
<?xml version="1.0" encoding="UTF-8"?><Group>
... <PythonScript DEF="PS" url="script.py" /></Group>
from H3D import *from H3DInterface import *
...
TAUCHI – Tampere Unit for Computer-Human Interaction
Levels of H3D: C++
You can use C++ on many levels, for example:
● Load a X3D file and display it
● Load X3D file + add some elements in it and display it
● Load X3D file + add some elements and route events to C++ handlers then display it
● Create scene-graph, add elements and display it
● Create custom shapes, surfaces etc. and use them in your application (from C++ or X3D)
TAUCHI – Tampere Unit for Computer-Human Interaction
Levels of H3D: C++
AutoRef< Scene > scene( new Scene );GLUTWindow *glwindow = new GLUTWindow;scene->window->push_back( glwindow );scene->sceneRoot->setValue( myGroup.get() );Scene::mainLoop();
TAUCHI – Tampere Unit for Computer-Human Interaction
Levels H3D: C++ + X3D + Python
● You can also include a Python script in the X3D file even when loading the file in C++.
● Transferring data from Python to C++ or vice versa is a very tricky, but not impossible
TAUCHI – Tampere Unit for Computer-Human Interaction
H3D basics
TAUCHI – Tampere Unit for Computer-Human Interaction
Loading X3D files
● H3D comes with two executable programs: H3DLoad and H3DView
● H3DLoad is a commandline program that you can execute (from command prompt with the x3d filename) or drop the x3d file over the executable
● H3DView is a graphical interface for loading and executing the x3d files
● Both programs come with source files. Extending H3DLoad is easy and preferred way of starting out (in case you need C++ functionality)
TAUCHI – Tampere Unit for Computer-Human Interaction
Fields
Fields are the fundamental building block. The application is built around a notion of network of connected fields.
Fields can:● Store data ● Be dependent of other field● Have functional behavior
TAUCHI – Tampere Unit for Computer-Human Interaction
Fields
● To make a connection between two fields one creates a route from a field to another
● Typically one can create a route only between the same type of fields
● Connections can be unrouted
TAUCHI – Tampere Unit for Computer-Human Interaction
Fields
Fields use lazy evaluation:
● the value is updated only when it is asked to (with the getValue() function for example).
● When the getValue() is called the field either returns current value (when the field is up to date) or update the field by calling the source field's update() function.
Field A
Field B
Field C
Field D Field E
TAUCHI – Tampere Unit for Computer-Human Interaction
Field template modifiers
AutoUpdate: process event immediately
Class MyField( AutoUpdate( SFFloat) ):def update(self, event):
return event.getValue()
TAUCHI – Tampere Unit for Computer-Human Interaction
Field template modifiers
TypedField● Typical fields has to be of same type the incoming connections are
● Multiple incoming connections● Specified return type may differ from the incoming connections
Class MyField( TypedField( SFBool, (SFFloat, SFVec3f ) ) ):def update(self, event):
routes_in = getRoutesIn()value = routes_in[0].getValue()return SFBool(True)
Return value 1st input2nd input
TAUCHI – Tampere Unit for Computer-Human Interaction
Field member functions
● route, connect field to another, trigger an event
● routeNoEvent, same as above, no event● unroute, disconnect a field from another● touch, trigger update event
TAUCHI – Tampere Unit for Computer-Human Interaction
Nodes
Nodes are collections of fields. Fields in a node can be:
● Inbound (write only)● Outbound (read only)● Inbound – Outbound (read / write)● Initialize only (set value only on init,
outbound)
TAUCHI – Tampere Unit for Computer-Human Interaction
Dissecting X3D file<?xml version="1.0" encoding="UTF-8"?>
<Scene>
<Transform DEF="TRANS" translation="0 0 0">
<Shape>
<Appearance>
<Material diffuseColor="1 0 0" DEF="PALLO1MAT"/>
</Appearance>
<Sphere radius="0.1" solid="true" DEF="SPHERE"/>
</Shape>
</Transform>
<TimeSensor cycleInterval="1" loop="true" enabled="true" DEF="TS"/>
<PositionInterpolator key="0.0, 0.5, 1.0"
keyValue="0.1 0 0 -0.1 0 0 0.1 0 0" DEF="PI"/>
<ROUTE fromNode="TS" fromField="fraction_changed" toNode="PI" toField="set_fraction"/>
<ROUTE fromNode="PI" fromField="value_changed" toNode="TRANS" toField="translation"/>
</Scene>
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: Group
A Group node contains children nodes without introducing a new transformation. It is equivalent to a Transform node containing an identity transform.
Useful fields: MFNode [in] addChildren MFNode [in] removeChildren MFNode [in,out] children[]
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: Transform
The Transform node is a grouping node that defines a coordinate system for its children. The coordinate system is relative to the coordinate systems of its ancestors.
Useful fields: SFRotation [in,out] rotationSFVec3f [in,out] scale SFRotation [in,out] scaleOrientation SFVec3f [in,out] translationAnd all the fields from the Group Node
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: Shape
The Shape node has two fields, appearance and geometry, which are used to create rendered objects in the world.
Geometry contains the graphical as well as (a possible) haptic geometry.
Appearance can contain for example:– Material and texture specification– Haptic representation information
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: Shape
<Group> <Shape> <Appearance> <Material diffuseColor="1 0 0" /> <SmoothSurface stiffness="0.1" /> </Appearance> <Sphere radius="0.1"/> </Shape></Group>
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: TimeSensor
TimeSensor nodes generate events as time passes. ● driving continuous simulations and animations● controlling periodic activities ● initiating single occurrence events
Useful fields:SFTime [in,out] cycleInterval SFBool [in,out] enabledSFBool [in,out] loop SFTime [out] cycleTimeSFFloat [out] fraction_changedSFTime [out] time
TAUCHI – Tampere Unit for Computer-Human Interaction
Sensors & interpolators: example
<Group>
<Shape>
<Appearance>
<Material diffuseColor="1 0 0" DEF="PALLO1MAT"/>
<SmoothSurface/>
</Appearance>
<Sphere radius="0.1" solid="true" DEF="SPHERE"/>
</Shape>
</Group>
<TimeSensor cycleInterval="1" loop="true" enabled="true" DEF="TS"/>
<ColorInterpolator key="0.0, 0.5, 1.0" keyValue="1 0 0 0 1 0 0 0 1" DEF="CI"/>
<ROUTE fromNode="TS" fromField="fraction_changed" toNode="CI" toField="set_fraction"/>
<ROUTE fromNode="CI" fromField="value_changed" toNode="PALLO1MAT" toField="diffuseColor"/>
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: Interpolators
–ColorInterpolator, color entries–CoordinateInterpolator, 3D coordinate entries–CoordinateInterpolator2D, 2D coordinate entries–NormalInterpolator, normalized vectors–OrientationInterpolator, rotation values–PositionInterpolator, 3D vectors –PositionInterpolator2D, 2D vectors–ScalarInterpolator, float values
TAUCHI – Tampere Unit for Computer-Human Interaction
More sensors
● VisibilitySensor: detects visibility changes of a rectangular box as the user navigates the world (enterTime, exitTime)
● ProximitySensor: generates events when the viewer enters, exits, and moves within a box-shaped region in space.
TAUCHI – Tampere Unit for Computer-Human Interaction
Important Nodes: DynamicTransform
The DynamicTransform node is a Shape container that has basic properties for defining rigid body motion. This includes a position, orientation, mass, etc.
Useful fields: SFVec3f [in, out] position
SFRotation [in, out] orientation
SFVec3f [out] velocity
SFVec3f [in, out] momentum
SFVec3f [in, out] force
SFVec3f [out] angularVelocity
SFVec3f [in, out] angularMomentum
SFSpin [out] spin
SFVec3f [in, out] torque
SFFloat [in, out] mass
SFMatrix3f [in, out] inertiaTensor
SFMotion [??] motion
And all the fields from the Group Node
TAUCHI – Tampere Unit for Computer-Human Interaction
X3D & Python
TAUCHI – Tampere Unit for Computer-Human Interaction
X3D & Python
● Define the scene with X3D markup language● Add scripted behavior with Python
Limitations: ● No new surfaces, geometries etc. ● Might slow down the larger systems if all functionality
is scripted
TAUCHI – Tampere Unit for Computer-Human Interaction
X3D + Python: example<?xml version="1.0" encoding="UTF-8"?><Transform translation="0 0 -0.1"><Group> <DynamicTransform mass="20" inertiaTensor="0.1 0 0 0 0.1 0 0 0 0.1"> <Shape> <Appearance> <Material diffuseColor="1 0 0" DEF="VARI"/> <FrictionalSurface dynamicFriction="0.6" staticFriction="0.2"/> </Appearance> <Box DEF="BOX" size="0.2 0.2 0.2"/> </Shape> </DynamicTransform> <PythonScript DEF="PS" url="pressure.py" /> <ROUTE fromNode="BOX" fromField="force" toNode="PS" toField="pressurePoint" /> <ROUTE fromNode="PS" fromField="pressurePoint" toNode="VARI" toField="diffuseColor" /></Group></Transform>
TAUCHI – Tampere Unit for Computer-Human Interaction
X3D + Python: example
from H3DInterface import *
class MyForceSensor(TypedField(SFColor,MFVec3f)):
def update(self,event):
force = event.getValue()
if(len(force)>0):force = max(force[0].x, force[0].y, force[0].z) / 25
else:
force = 0
if(force > 1.0):
force=1.0
return RGB(force, 0.3, 0.3)
pressurePoint = MyForceSensor()
TAUCHI – Tampere Unit for Computer-Human Interaction
Python tips
The field has member functions getRoutesIn and getRoutesOut.
Global field time contains the current time (from Scene::time)
eventSink is a global field that you can route your fields to. If you do so, the field will be updated once in each scene-graph loop.
TAUCHI – Tampere Unit for Computer-Human Interaction
More Python tips
PeriodicUpdate is a field template modifier that makes your field to update once in every scene-graph loop.
init function will be run once when the python file is loaded. traverseSG function is called once in every scene-graph loop.
TAUCHI – Tampere Unit for Computer-Human Interaction
PeriodicUpdate example
class Foobar(PeriodicUpdate(SFColor)):def update(self, event):
print "foo"return event.getValue()
class Func(TypedField(SFColor,SFTime)):def update(self,event):
print "UPDATE"return RGB(random(),random(),
random())periodicfunc = Func()time.route(periodicfunc)
TAUCHI – Tampere Unit for Computer-Human Interaction
Even More Python tips
The module H3DUtils has some very useful classes and functions. The most important one is the TimerCallback class for which you can add callback functions to be called after a certain period. This is “one-off” function call, that is, the function is removed from the TimerCallback once it has been called.
TAUCHI – Tampere Unit for Computer-Human Interaction
TimerCallback
from H3DUtil import *
def callfunc(): global timec print “boo!” timec.addCallback(time.getValue()+1, callfunc, [])
timec = TimeCallback()timec.addCallback(time.getValue()+1, callfunc, [])
TAUCHI – Tampere Unit for Computer-Human Interaction
Accessing the X3D side
You can do a lot of things from within the Python code. You can, for example, access the haptic device and the scene-graph. For example, to add an element to a scene-graph from Python do:
X3D:<Transform DEF="RYHMA">
</Transform>
<PythonScript url="mytimer.py" >
<Group USE="RYHMA" containerField="references"/>
</PythonScript>
Python:globgroup = references.getValue()[0] globgroup.children.push_back(mybox)
TAUCHI – Tampere Unit for Computer-Human Interaction
Possible applications
•Sculpting•Integrate physics engine to H3D•Implement collision detection (with mass & force?)•CAD / planning / decoration application•Block editor•Heightmap / tile / ?? editor•Origami editor!•A Game (Asteroids, Sokoban, LightsOff ...)•Your own idea?
TAUCHI – Tampere Unit for Computer-Human Interaction
Next...
–The C++ side of things–Introduction to programming haptics with C++–Simple custom geometries–Simple custom surfaces–And more!
TAUCHI – Tampere Unit for Computer-Human Interaction
Sample X3D file<?xml version="1.0" encoding="UTF-8"?>
<Scene>
<Transform DEF="TRANS" translation="0 0 0">
<Shape>
<Appearance>
<Material diffuseColor="1 0 0" DEF="PALLO1MAT"/>
</Appearance>
<Sphere radius="0.1" solid="true" DEF="SPHERE"/>
</Shape>
</Transform>
<TimeSensor cycleInterval="1" loop="true" enabled="true" DEF="TS"/>
<PositionInterpolator key="0.0, 0.5, 1.0" keyValue="0.1 0 0 -0.1 0 0 0.1 0 0" DEF="PI"/>
<ROUTE fromNode="TS" fromField="fraction_changed" toNode="PI" toField="set_fraction"/>
<ROUTE fromNode="PI" fromField="value_changed" toNode="TRANS" toField="translation"/>
</X3D>