Spring settings for a catapult

bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Spring settings for a catapult

Post by bwelch »

Hello. I'm trying to construct a catapult to launch my newly created ragdoll as I learn Bullet, but I'm having some problems getting the desired behavior.

If viewing the catapult from the side, where it fires objects to the right, I want the arm to push back to -45 degrees, lying against the base of the catapult. After some event (whether a keypress or a collision or a certain time has passed; this part isn't important), I want the catapult arm to be propelled rapidly to vertical, 90 degrees. I'd like to be able to vary that second angle so I can launch things at different trajectories. My gut reaction was to use a generic 6 degrees of freedom constraint with a spring between the launch arm and the beam that supports it. But I can't seem to get the values to give me the result that I want. Even after playing with the numbers, they don't seem to make sense.

Here's my code for the constraint in question:

Code: Select all

//launchBeam-crossBeam constraint
	frameInA = btTransform::getIdentity();
	frameInA.setOrigin(btVector3(0, 0, scale*1));
	frameInB = btTransform::getIdentity();
	frameInB.setOrigin(btVector3(0, 0, 0));
	launchBeam->body->setActivationState(DISABLE_DEACTIVATION);
	btGeneric6DofSpringConstraint* pGen6DOF3 = new btGeneric6DofSpringConstraint(*launchBeam->body, *crossBeam->body, frameInA, frameInB, true);
	pGen6DOF3->setAngularLowerLimit(btVector3(-.841, -SIMD_EPSILON,-SIMD_EPSILON));
	pGen6DOF3->setAngularUpperLimit(btVector3(90*(SIMD_PI/180), SIMD_EPSILON,SIMD_EPSILON));

	world->addConstraint(pGen6DOF3, true);
	
	pGen6DOF3->enableSpring(3, true);
	pGen6DOF3->setStiffness(3, 39.478f);
	pGen6DOF3->setDamping(3, .3f);
	pGen6DOF3->setEquilibriumPoint(3,SIMD_HALF_PI);
Can someone shed some light on what my values for the angular limits, stiffness, damping, and equilibrium point should be? The values you see were what my intuition suggested, but this gives incorrect behavior (it appears as the picture below, with an oscillation of roughly 10 degrees once a second). I've tried lots of values for each variable, but they don't seem to behave consistently... What are the units on damping and stiffness? I have no idea what range of values for these are.

I'd be open to suggestions on alternative ways to get my desired behavior as well.

Thanks for any help.
You do not have the required permissions to view the files attached to this post.
Ateocinico
Posts: 12
Joined: Sat Jun 29, 2013 5:55 pm

Re: Spring settings for a catapult

Post by Ateocinico »

Intuition is no substitute for physics and proper calculations. Solve the problem on paper first. :)
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Spring settings for a catapult

Post by bwelch »

Certainly not, but I'm asking if Bullet has any quirks that may differ from my pencil and paper, where I define everything. Starting simply, with something that should be easy to test, does my angular upper limit of 90 degrees correspond to a vertical catapult? In Bullet, is that limit a hard limit, or can it be "broken" with enough force? I've tried changing my limits to test this, of course, but I have to apply a force in order to see the catapult move, and I have just as many questions about the force application as the angles.

Does the damping value correspond to the damping coefficient (where 1 is critically damped and 0 is no damping)?

The value in setEquilibriumPoint() is an angle, right? If I want my catapult to rest at its angular upper limit, that value should go here as well, I think.

I'm not asking for anyone to set this up for me, just for some general guidance on what values would get me to the behavior I want.

Thanks again.
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Spring settings for a catapult

Post by bwelch »

So, I figured out the angle settings from my previous post (I was right), but still have some questions. Here's the code I'm using for this example:

Code: Select all

//launchBeam * crossBeam
	frameInA = btTransform::getIdentity();
	frameInA.setOrigin(btVector3(0, 0, scale*1.5));
	frameInB = btTransform::getIdentity();
	frameInB.setOrigin(btVector3(0, 0, 0));
	launchBeam->body->setActivationState(DISABLE_DEACTIVATION);
	btGeneric6DofSpringConstraint* pGen6DOF3 = new btGeneric6DofSpringConstraint(*launchBeam->body, *crossBeam->body, frameInA, frameInB, true);

        //These angles are what I want the catapult's limits to be (strictly)
	//pGen6DOF3->setAngularLowerLimit(btVector3(-.841, -SIMD_EPSILON,-SIMD_EPSILON));
	//pGen6DOF3->setAngularUpperLimit(btVector3(launchAngle*(SIMD_PI/180), SIMD_EPSILON,SIMD_EPSILON));
	
        //These angles (the initial position) are for this example
	pGen6DOF3->setAngularLowerLimit(btVector3(-SIMD_EPSILON, -SIMD_EPSILON,-SIMD_EPSILON));
	pGen6DOF3->setAngularUpperLimit(btVector3(SIMD_EPSILON, SIMD_EPSILON,SIMD_EPSILON));

	world->addConstraint(pGen6DOF3, true);
	
	pGen6DOF3->enableSpring(3, true);
	pGen6DOF3->setStiffness(3, 300000.0f);    //I want the spring to be ultra-stiff so it will launch to the equilibrium point quickly
	pGen6DOF3->setDamping(3, 1.0f);            //I assume this is critical damping... I want little to no oscillation
	pGen6DOF3->setEquilibriumPoint(3,launchAngle*(SIMD_PI/180));
So, setting launchAngle to 0 degrees, the catapult should start horizontal, the equilibrium point should be horizontal, and the angular limits are set so it should stay just about horizontal. However, when I run the simulation (I added a bucket and counterweight to my model), it rests in the position in the attached screenshot with slight oscillation. Obviously, the mass of the counterweight is pulling it down, but it's breaking the angular limits I set. If I lock them (by not defining them) the entire catapult explodes and flies all over the place.

So, how would you Bullet gurus suggest I set up this catapult to have very strict angular limits at -.841 (fully depressed) and 90 (vertical)? Is there a way I can set the bounds so they absolutely cannot be broken? Also, I picked an arbitrarily large number for my spring stiffness, but there doesn't seem to be any difference in behavior between 3000, 30000, and 300000. Any suggestions for making the launch very springy?

I know this forum is kind of slow, but this is the problem occupying my work day, so I hope you'll excuse a few posts while I work on the problem. Thanks again for any help.
You do not have the required permissions to view the files attached to this post.
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Spring settings for a catapult

Post by bwelch »

I managed to work out an inelegant but workable solution. I stuck a static block on top of the catapult base to physically stop the butt end of the launch arm when it goes too far. I also added a "latch" constraint between the launch arm and the base (just a 6Dof constraint with all degrees blocked), and upon any collision detected in the launch bucket, the latch constraint is disabled. Also on collision, the launcher's vertical velocity is set to 100 since the spring is so wimpy. Haha. So basically the spring constraint was worthless to me. :?

Anyway, I'd still like to know what I did wrong with the spring for future reference, so I'll leave this thread open for a while in the hopes that I'll get some info after the holidays.
You do not have the required permissions to view the files attached to this post.