WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-28-2010, 03:53 AM
Andy Andy is offline
Member
 
Join Date: Mar 2008
Location: Germany
Posts: 36
telescopic cylinder sim

Hey,
has somebody an idea how to create an realistic telescopic cylinder?
I would like to create a platform for lifting persons but I have problems to create the telescopic arm of this platform.

I have created an example of my problem. I use the joints of the opal physical engine. There are very useful but instable in this case. I need a realistically behaviour of the physic and also a collision detection with my environment, so that I see no other way as using the opal engine.

Can somebody help me?
thanks andy

Code:
import viz
import vizact
import vizinfo

PHYSICS_SIM_TIMER = 2

viz.go()

viz.phys.enable()
viz.clearcolor(viz.SKYBLUE)
viz.MainView.setPosition(0,1.5,-10)

#environment
###########
info = vizinfo.add('use up/down/leftr/right for control \n r for reset')
info.translate( .35, .1 )
info.scale(0.7, 0.7)

ground = viz.add( 'tut_ground.wrl' )
ground.collidePlane() #Make ground collide with objects as if it were an infinite plane

#some gui elements for parametrize the material characteristics
###############################################################
obj1Info = vizinfo.add( 'Center Material Characteristics' )
obj1Info.translate( .35, .96 )
obj1Info.scale(0.7, 0.7)
obj1Density = obj1Info.add( viz.SLIDER, 'Density' )
obj1Friction = obj1Info.add( viz.SLIDER, 'Friction' )
obj1Hardness = obj1Info.add( viz.SLIDER, 'Hardness' )
obj1Bounce = obj1Info.add( viz.SLIDER, 'Bounce' )
#Initial material settings
obj1Density.set( 1 )
obj1Friction.set( .001 )
obj1Hardness.set( 1 )
obj1Bounce.set( 0 )

obj2Info = vizinfo.add( 'Tube1 Material Characteristics' )
obj2Info.translate( .62, .96 )
obj2Info.scale(0.7, 0.7)
obj2Density = obj2Info.add( viz.SLIDER, 'Density' )
obj2Friction = obj2Info.add( viz.SLIDER, 'Friction' )
obj2Hardness = obj2Info.add( viz.SLIDER, 'Hardness' )
obj2Bounce = obj2Info.add( viz.SLIDER, 'Bounce' )
#Initial material settings
obj2Density.set( .3 )
obj2Friction.set( .001 )
obj2Hardness.set( 1 )
obj2Bounce.set( 0 )

#Interface to change ball characteristics
obj3Info = vizinfo.add( 'Tube2 Material Characteristics' )
obj3Info.translate( .9, .96 )
obj3Info.scale(0.7, 0.7)
obj3Density = obj3Info.add( viz.SLIDER, 'Density' )
obj3Friction = obj3Info.add( viz.SLIDER, 'Friction' )
obj3Hardness = obj3Info.add( viz.SLIDER, 'Hardness' )
obj3Bounce = obj3Info.add( viz.SLIDER, 'Bounce' )
#Initial material settings
obj3Density.set( .3 )
obj3Friction.set( .001 )
obj3Hardness.set( 1 )
obj3Bounce.set( 0 )

#telescopic cylinder platform
##############################
center = viz.add('box.wrl', scale=[1,2,1], pos=[2,1.2,0], color=viz.BLUE)
centerCollideBox = center.collideBox(density=obj1Density.get(), friction=obj1Friction.get(),hardness=obj1Hardness.get(), bounce=obj1Bounce.get())

tupe1Pos = [0,2,0]
tupe1AxisLimit = [-10,60]
tube1 = viz.add('box.wrl', scale=[4,0.2,0.2], pos=tupe1Pos, color=viz.YELLOW)
tube1CollideBox = tube1.collideBox(density=obj2Density.get(), friction=obj2Friction.get(),hardness=obj2Hardness.get(), bounce=obj2Bounce.get())

upDownAngle = 0
tube1Joint = viz.phys.addHingeJoint(center, tube1, pos=[tupe1Pos[0]+2,tupe1Pos[1],tupe1Pos[2]], axis0=[0,0,1]) 

tube2Pos = [-0.5,2,0]
tube2InOutLimit = [0.2,3]
tube2 = viz.add('box.wrl', scale=[4,0.15,0.15], pos=tube2Pos, color=viz.GREEN)
tube2CollideBox = tube2.collideBox(density=obj3Density.get(), friction=obj3Friction.get(), hardness=obj3Hardness.get(), bounce=obj3Bounce.get())

inOutPos = 0
tube2Joint = viz.phys.addSliderJoint(tube1, tube2,pos=[tube2Pos[0], tube2Pos[1], tube2Pos[2]],axis0=(1,0,0))


def applyPhysics():
	global upDownAngle, inOutPos
	
	if upDownAngle > tupe1AxisLimit[1]:
		upDownAngle = tupe1AxisLimit[1]
	elif upDownAngle < tupe1AxisLimit[0]:
		upDownAngle = tupe1AxisLimit[0]
	
	if inOutPos > tube2InOutLimit[1]:
		inOutPos = tube2InOutLimit[1]
	elif inOutPos < tube2InOutLimit[0]:
		inOutPos = tube2InOutLimit[0]
	
	#apply phys for UpDown-tube
	print 'current upDown-angle: ', upDownAngle
	print 'current inOut-position: ', inOutPos
	tube1Joint.setMotorAngle(0, upDownAngle,0xFF,0.3)
	tube2Joint.setMotorAngle(0, inOutPos,0xFF,0.8)

def update(num):
	if num == PHYSICS_SIM_TIMER:
		applyPhysics()
viz.callback(viz.TIMER_EVENT, update)

def reset():
	global upDownAngle, inOutPos
	upDownAngle = 0
	inOutPos = 0
	center.reset()
	tube1Joint.reset()
	tube2Joint.reset()

def mykeyboard(key):
	global upDownAngle, inOutPos
	if key == viz.KEY_UP:
		upDownAngle = upDownAngle + (viz.elapsed()* 10.0)
	if key == viz.KEY_DOWN:
		upDownAngle = upDownAngle - (viz.elapsed()* 10.0)
	if key == viz.KEY_LEFT:
		inOutPos = inOutPos + (viz.elapsed()* 10.0)
	if key == viz.KEY_RIGHT:
		inOutPos = inOutPos - (viz.elapsed()* 10.0)
	
	if key == 'r':
		reset()
viz.callback(viz.KEYBOARD_EVENT, mykeyboard)

def onSlider(obj,pos):
	if obj1Density.get() > 0:
		centerCollideBox.setDensity(obj1Density.get())
	centerCollideBox.setFriction(obj1Friction.get())
	centerCollideBox.setHardness(obj1Hardness.get())
	centerCollideBox.setBounce(obj1Bounce.get())
	
	if obj2Density.get() > 0:
		tube1CollideBox.setDensity(obj2Density.get())
	tube1CollideBox.setFriction(obj2Friction.get())
	tube1CollideBox.setHardness(obj2Hardness.get())
	tube1CollideBox.setBounce(obj2Bounce.get())
	
	if obj3Density.get() > 0:
		tube2CollideBox.setDensity(obj3Density.get())
	tube2CollideBox.setFriction(obj3Friction.get())
	tube2CollideBox.setHardness(obj3Hardness.get())
	tube2CollideBox.setBounce(obj3Bounce.get())
viz.callback(viz.SLIDER_EVENT,onSlider) 

viz.starttimer(PHYSICS_SIM_TIMER, .01, viz.FOREVER)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Intersect vs collision Jerry Vizard 8 07-17-2010 01:57 AM


All times are GMT -7. The time now is 03:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC