WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   physics problem (https://forum.worldviz.com/showthread.php?t=3542)

fivel_lab 03-01-2011 02:34 PM

physics problem
 
hey, first time poster here

currently, i'm trying to setup a balance board type apparatus that includes the board, and a ball that rests on the center. the board tilts up and down and is controlled by a wii remote controller. as the board tilts, the ball rolls down accordingly. all that is working fine and dandy, but a problem keeps occuring where the ball suddenly drops through the board, and i haven't been able to figure out why. i've tried playing with the density, bounce, and hardness of both the board and the ball, but still no luck.

here's my script so far:
Code:

#create balance board
bar = vizshape.addBox(size=(20, 1,1))
bar.setPosition([0,2,5])
bar.color(1,0,0)
barCollideShape = bar.collideMesh()

#create ball
ball = viz.add('ball.wrl')
ball.setScale([1.5,1.5,1.5])
ball.setPosition([0, 7, 5])
ballCollideShape = ball.collideSphere()

as well as the scrip for the wii remote controls:
Code:

#Add wiimote extension
wii = viz.add('wiimote.dle')

#Connect to first available wiimote
w = wii.addWiimote()
def updateWiiMote():
        w.led = wii.LED_1 | wii.LED_4
        x,y,z = w.getAccel()
        x,y,z = threshIt(x,y,z)

        newEuler = (0,0,-x*10)
        print newEuler
        bar.setEuler(newEuler)
       
       
#poll joystick continuously
vizact.ontimer(0, updateWiiMote)

and i also created "guardrails" in front of and behind the balance board, to keep the ball from rolling off on the z-axis:
Code:

#create rear guiderail
farGuiderail = vizshape.addBox([30, 50, .01])
farGuiderail.setPosition([0,2,5.5])
farGuiderailMesh = farGuiderail.collideMesh()
farGuiderail.disable(viz.RENDERING)
farGuiderail.disable(viz.DEPTH_WRITE)

#creat front guiderail
nearGuiderail = vizshape.addBox([30, 50, .01])
nearGuiderail.setPosition([0,2,4.5])
nearGuiderailMesh = nearGuiderail.collideMesh()
nearGuiderail.disable(viz.RENDERING)
nearGuiderail.disable(viz.DEPTH_WRITE)

any help would be greatly appreciated. thanks in advance

Jeff 03-01-2011 05:28 PM

Try using a collideBox for the bar. Does that work?
Code:

barCollideShape = bar.collideBox()
bar.disable(viz.DYNAMICS)

The bar's collideMesh has no thickness to it. If the ball is moving fast and the physics engine does not detect the collision between the ball and bar one frame the ball will fall through.

fivel_lab 03-01-2011 07:31 PM

I tried the collide box but abandoned it because it made the balance board fall to the ground. I guess i could try using a fulcrum to support the board...

Jeff 03-02-2011 10:20 AM

Code:

bar.disable(viz.DYNAMICS)
will prevent forces like gravity from affecting the bar.

fivel_lab 03-02-2011 03:34 PM

thanks, but i'm still having the same problem. the ball passes through the balance board quite easily...

Jeff 03-03-2011 04:13 PM

In order to get the bar and the ball to collide correctly you'll need to move the bar by applying a force or torque to it:
Code:

import viz
import vizact
viz.go()

viz.phys.enable()

bar = viz.add('box.wrl')  # Add a box
bar.setScale(20,1,1) # Make it look more door like
shape = bar.collideBox() # Enable physics on the box
shape.setDensity(0.1)

ball = viz.add('ball.wrl')
ball.setScale([1.5,1.5,1.5])
ball.setPosition([0, 2, 0])
ballCollideShape = ball.collideSphere()

joint = viz.phys.addHingeJoint(bar,None,pos=[0,0,0],axis0=[0,0,1]) # Hinge joint attached to world

def push():
    bar.applyTorque([0,0,20],duration=0.2)
vizact.onkeydown('1',push)

def pushBack():
    bar.applyTorque([0,0,-20],duration=0.2)
vizact.onkeydown('2',pushBack)

def resetSimulation():
    if ball.getPosition()[1] < -5:       
        ball.reset()
        ball.setPosition([0, 2, 0])
        bar.reset()
        bar.setEuler([0,0,0])
   
vizact.ontimer(1,resetSimulation)

import vizcam
vizcam.PivotNavigate(center=[0,0,0],distance=30)


fivel_lab 03-04-2011 11:23 AM

i'm going to give this a try.

i was originally having the bar via the wiimote. so as the wiimote moved, the euler of the bar moved accordingly. could that be the reason, or at least one of the reasons why the ball kept falling through?

Jeff 03-04-2011 02:02 PM

To make sure the physics engine calculates the collisions correctly you should apply a force or torque to the bar rather than manually setting it's orientation using the setEuler command. You can still use the wiimote data to decide what torque to apply.

fivel_lab 03-07-2011 07:53 PM

it works :D

thanks so much for all your help, much appreciated!


All times are GMT -7. The time now is 12:07 AM.

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