ChronoEngine:Demo friction

From ChronoWiki

(Redirected from Demo friction)
Jump to: navigation, search

This demo shows the feature of spinning friction (also known as 'drilling' friction) and rolling friction. These types of frictions are useful for rolling objects like wheels, spheres etc. and can be optionally turned on.

Note:

  • setting nonzero spinning friction and/or setting nonzero rolling friction affects the speed of the solver (each contact eats 2x of CPU time repsect to the case of simple sliding/static contact)
  • we suggest to avoid using zero spinning friction with nonzero rolling friction.

We do not report here the initial part of the source (includes, namespaces, etc. - see the first simplier demos).

The following function is used to create a bunch of spheres:

void create_some_falling_items(ChSystem& mphysicalSystem, ISceneManager* msceneManager, IVideoDriver* driver)
{
	ChBodySceneNode* mrigidBody;

	video::ITexture* sphereMapP = driver->getTexture("../data/pinkwhite.png");
	video::ITexture* sphereMapB = driver->getTexture("../data/bluwhite.png");

	double mradius = 0.5;
	double density = 1000;
	double mmass = (4./3.)*CH_C_PI*pow(mradius,3.)*density;
	double minert = (2./5.)* mmass * pow(mradius,2.);

	// Create some spheres that roll horizontally,
	// with increasing rolling friction values
	for (int bi = 0; bi < 10; bi++)
	{

		double initial_angspeed = 10;
		double initial_linspeed = initial_angspeed*mradius;

		mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easySphere(
											&mphysicalSystem, msceneManager,
											mmass, // mass
											ChVector<>(-7, mradius-0.5, -5+bi*mradius*2.5), // pos
											mradius, // radius
											20,  // hslices
											15); // vslices

		// set moment of inertia too (otherwise default is 1,1,1).
		mrigidBody->GetBody()->SetInertiaXX(ChVector<>(minert,minert,minert));

Note how to set initial velocity and angular velocity for rigid bodies (in this case, rolling in horizontal direction):

//
		mrigidBody->GetBody()->SetWvel_par(ChVector<>(0,0,-initial_angspeed));
		mrigidBody->GetBody()->SetPos_dt(ChVector<>(initial_linspeed,0,0));

For a first group of spheres, set the sliding friction with SetFriction() and set the rolling friction coefficient using SetRollingFriction(), the rolling friction will create a resisiting torque (alinged to rolling angular velocity) that is proportional to normal load and the abovementioned rolling friction coefficient:

.
		mrigidBody->GetBody()->SetFriction(0.4);
		mrigidBody->GetBody()->SetRollingFriction( ((double)bi/10.)*0.2 );

		// Some aesthetics for 3d view..
		mrigidBody->addShadowVolumeSceneNode();
		mrigidBody->setMaterialTexture(0,	sphereMapP);

	}

	// Create some spheres that spin on place, for a 'drilling friction' case,
	// with increasing spinning friction values
	for (int bi = 0; bi < 10; bi++)
	{
		mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easySphere(
											&mphysicalSystem, msceneManager,
											mmass, // mass
											ChVector<>(-8, mradius-0.5, -5+bi*mradius*2.5), // pos
											mradius, // radius
											20,  // hslices
											15); // vslices

		// set moment of inertia too (otherwise default is 1,1,1).
		mrigidBody->GetBody()->SetInertiaXX(ChVector<>(minert,minert,minert));
		// set initial speed: spinning in vertical direction
		mrigidBody->GetBody()->SetWvel_par(ChVector<>(0, 20,0));

For these other spheres, set the sliding friction with SetFriction() and set the spinning friction coefficient using SetSpinningFriction(), the spinning friction will create a resisiting torque (alinged to spinning angular velocity) that is proportional to normal load and the above mentioned spinning friction coefficient:

.
		mrigidBody->GetBody()->SetFriction(0.4);
		mrigidBody->GetBody()->SetSpinningFriction( ((double)bi/10.)*0.1 );

		// Some aesthetics for 3d view..
		mrigidBody->addShadowVolumeSceneNode();
		mrigidBody->setMaterialTexture(0,	sphereMapB);

	}

Create the five walls of the rectangular container, using fixed rigid bodies of 'box' type:

.
	mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox(
											&mphysicalSystem, msceneManager,
											1000.0,
											ChVector<>(0,-1,0),
											ChQuaternion<>(1,0,0,0),
											ChVector<>(20,1,20) );
	mrigidBody->GetBody()->SetBodyFixed(true);

	video::ITexture* cubeMap = driver->getTexture("../data/blu.png");
	mrigidBody->setMaterialTexture(0,	cubeMap);


	mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox(
											&mphysicalSystem, msceneManager,
											100.0,
											ChVector<>(-10,0,0),
											ChQuaternion<>(1,0,0,0),
											ChVector<>(1,2,20.99) );
	mrigidBody->GetBody()->SetBodyFixed(true);
	mrigidBody->setMaterialTexture(0,	cubeMap);


	mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox(
											&mphysicalSystem, msceneManager,
											100.0,
											ChVector<>(10,0,0),
											ChQuaternion<>(1,0,0,0),
											ChVector<>(1,2,20.99) );
	mrigidBody->GetBody()->SetBodyFixed(true);
	mrigidBody->setMaterialTexture(0,	cubeMap);

	mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox(
											&mphysicalSystem, msceneManager,
											100.0,
											ChVector<>(0,0,-10),
											ChQuaternion<>(1,0,0,0),
											ChVector<>(20.99,2,1) );
	mrigidBody->GetBody()->SetBodyFixed(true);
	mrigidBody->setMaterialTexture(0,	cubeMap);

	mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox(
											&mphysicalSystem, msceneManager,
											100.0,
											ChVector<>(0,0, 10),
											ChQuaternion<>(1,0,0,0),
											ChVector<>(20.99,2,1) );
	mrigidBody->GetBody()->SetBodyFixed(true);
	mrigidBody->setMaterialTexture(0,	cubeMap);



}

Here starts the main body of the program:

int main(int argc, char* argv[])
{
	// In CHRONO engine, The DLL_CreateGlobals() - DLL_DeleteGlobals(); pair is needed if
	// global functions are needed.
	DLL_CreateGlobals();

	// Create a ChronoENGINE physical system
	ChSystem mphysicalSystem;

	// Create the Irrlicht visualization (open the Irrlicht device,
	// bind a simple user interface, etc. etc.)
	ChIrrAppInterface application(&mphysicalSystem, L"Contacts with rolling friction",core::dimension2d<u32>(800,600),false, true);


	// Easy shortcuts to add camera, lights, logo and sky in Irrlicht scene:
	ChIrrWizard::add_typical_Logo(application.GetDevice());
	ChIrrWizard::add_typical_Sky(application.GetDevice());
	ChIrrWizard::add_typical_Lights(application.GetDevice());
	ChIrrWizard::add_typical_Camera(application.GetDevice(), core::vector3df(0,14,-20));


	// Create all the rigid bodies.
	create_some_falling_items(mphysicalSystem, application.GetSceneManager(), application.GetVideoDriver());


	// Modify some setting of the physical system for the simulation, if you want

	mphysicalSystem.SetIterLCPmaxItersSpeed(26);

This is the typical simulation loop:

//
	while(application.GetDevice()->run())
	{
		application.GetVideoDriver()->beginScene(true, true, SColor(255,140,161,192));

		application.DrawAll();

		// ChIrrTools::drawAllContactLabels(mphysicalSystem, application.GetDevice());

		mphysicalSystem.DoStepDynamics( 0.01);


		application.GetVideoDriver()->endScene();
	}


	DLL_DeleteGlobals();

	return 0;
}
Personal tools