View Single Post
  #1  
Old 11-10-2014, 03:28 AM
pradeep pradeep is offline
Member
 
Join Date: Jun 2014
Posts: 14
Working in Haptic device (PHANTOM)

Hello

I am working with "sensable PHANTON Omni" & "Worldviz 5".

I have created boundary for the car which will not allow the car to go beyond that walls (cube1 & cube2).

I want to implement fillowing effects in the code
1) When car touch/strike with boundary, I want to generate opposite force in haptic device that give the feel of the wall.
2) I want to add spring effect from the point [0,0,0] in all direction

Kindly give your suggestions to implement bounding ares for car.

The code is:

Code:
import viz
import vizact
import vizshape

viz.setMultiSample(4)
viz.fov(60)
viz.go()

viz.phys.enable()
viz.collision(viz.ON)

car = viz.add( 'mini.osg' )
car.collideBox()

ViewCarLink = viz.link(car,viz.MainView)
ViewCarLink.preEuler( [0,30,0] )
ViewCarLink.preTrans( [0,0,-10] )
ViewCarLink.preEuler( [0,-20,0] )

ground = viz.addChild('ground.osgb')
ground.collidePlane()

sensable = viz.add('sensable.dle')
device = sensable.addHapticDevice()
device.workspace.setScale([20,20,20])
device.addNode(ground)

#right boundary for car
cube1 = vizshape.addCube(size=1)
cube1.setPosition([2,0.5,8])
cube1.setScale(20,1,0.2)
cube1.setEuler(90,0,0)
RightB=cube1.collideBox([20,1,0.2])
RightB.density=10000

#left boundary for car
cube2 = vizshape.addCube(size=1)
cube2.setPosition([-2,0.5,8])
cube2.setScale(20,1,0.2)
cube2.setEuler(90,0,0)
LeftB=cube2.collideBox([20,1,0.2])
LeftB.density=10000

def UpdateMovement():
    elapsed = viz.elapsed()
    x,y,z = device.getPosition()
    forwardMovementAmount = viz.elapsed() * (z+0.5)
    car.setPosition( [ 0, 0, forwardMovementAmount], viz.REL_LOCAL )
    rotationAmount = viz.elapsed() *(x)*10
    car.setEuler( [ rotationAmount, 0 , 0 ],viz.REL_LOCAL)
    #add spring effect
    device.addSpringEffect( gain=10,magnitude=10,position=[0,0,0])

vizact.ontimer(0, UpdateMovement)
Reply With Quote