How to simulate a conveyor?

Share with us how are you using the powerrrr of the force

Moderator: Alain

How to simulate a conveyor?

Postby PeterMacGonagan » Sun Dec 05, 2010 11:32 am

Hello,

Is anybody can tell me how to simulate a conveyor using Newton please? I just want to move some boxes on it...

Thanks in advance.
PeterMacGonagan
 
Posts: 1
Joined: Sun Dec 05, 2010 11:30 am

Re: How to simulate a conveyor?

Postby ledahut » Mon Dec 06, 2010 3:55 am

You need to create two materials (one for conveyor, one for boxes).
After that, you have to set the callback for this material pair.
---
In the callback:
You need a loop to iterate each contact point between materials.
Then you set the new tangent direction.
Finally you apply a acceleration in tangent.

Here an exemple in pascal:
Code: Select all
var
  dir: TVector;
  Material: PNewtonMaterial;
  ThisContact: PNewtonJoint;
begin
    dir := VectorMake(-1, 0, 0); // -X
    ThisContact := NewtonContactJointGetFirstContact(contact);
    while ThisContact <> nil do
    begin
      Material := NewtonContactGetMaterial(ThisContact);
      NewtonMaterialContactRotateTangentDirections(Material, @dir);
      NewtonMaterialSetContactTangentAcceleration(Material,
        10, 0);
      ThisContact := NewtonContactJointGetNextContact(contact, ThisContact);
    end;
 end;


This won't react as a reel conveyor because you boxes will accelerate again and again.
But you can set a constant speed with Control engineering, where 'ConveyorSpeed' is my wanted speed.

Code: Select all
procedure TProcess.ConvoyeurProcess(NGDMaterialPair: TNGDMaterialPair;
  contact: PNewtonJoint; timestep: Single);
var
  dir: TVector;
  Material: PNewtonMaterial;
  ThisContact: PNewtonJoint;
  ActualSpeed: Single;
begin
    dir := VectorMake(-1, 0, 0); // -X

    ThisContact := NewtonContactJointGetFirstContact(contact);
    while ThisContact <> nil do
    begin
      Material := NewtonContactGetMaterial(ThisContact);
      NewtonMaterialContactRotateTangentDirections(Material, @dir);
      ActualSpeed := NewtonMaterialGetContactTangentSpeed(Material, 0);
      NewtonMaterialSetContactElasticity(Material, 0);
      NewtonMaterialSetContactTangentAcceleration(Material,
        (ConvoyeurSpeed - ActualSpeed) / timestep, 0);
      ThisContact := NewtonContactJointGetNextContact(contact, ThisContact);
    end;
end;


NewtonMaterialSetContactTangentAcceleration wait for an acceleration value in [m.s^(-2)]
You give speed in [m.s^(-1)] but if you divide it by timestep in [s], your result is [m.s^(-1)]/[s]=[m.s^(-2)]
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: How to simulate a conveyor?

Postby Carli » Wed Jan 05, 2011 5:30 am

Julio: Why does newton not do this by itself?
I mean, a moving object with some contacts on it is like an inelastic collision which sould move the objects laying on it, too.

We need it for this minigame, too: http://www.youtube.com/watch?v=T-K6M4_M7Bg
(you don't see the not working conveyor plates in the teaser)
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: How to simulate a conveyor?

Postby Julio Jerez » Wed Jan 05, 2011 7:47 am

well is does, if you set the contact tanget velocity in teh contact call back, by setting a material.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to simulate a conveyor?

Postby Carli » Sat Jan 08, 2011 5:46 am

Julio Jerez wrote:well is does, if you set the contact tanget velocity in teh contact call back, by setting a material.


Which parameters do you suggest for

NewtonMaterialSetContactSoftness
NewtonMaterialSetContactElasticity
NewtonMaterialSetContactFrictionState
NewtonMaterialSetContactFrictionCoef

NewtonMaterialSetContactNormalAcceleration
NewtonMaterialSetContactNormalDirection

NewtonMaterialSetContactTangentAcceleration
NewtonMaterialContactRotateTangentDirections

Edit:
Sorry, i did not find the right callback (maybe commented out in the header). Do you have an example code?
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: How to simulate a conveyor?

Postby Julio Jerez » Sat Jan 08, 2011 10:46 am

here is a contact callback to make a convefor belt king of body
Code: Select all
void ConvejorBellMaterialCallback (OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
{
   Body* body0 = contactJoint.getBody0();
   Body* body1 = contactJoint.getBody1();

   // first, find which body represents the conveyor belt!
   ConveyorBelt* belt = NULL;
   OgreNewt::Body* object = NULL;

   // find which body is the body floor
   if (body0->getType() == mConveyorID)
   {
      belt = (ConveyorBelt*)body0->getUserData();
      object = body1;
   }
   else if (body1->getType() == mConveyorID)
   {
      belt = (ConveyorBelt*)body1->getUserData();
      object = body0;
   }

   if (belt)
   {
      // okay, found the belt... let's adjust the collision based on this.
      Ogre::Vector3 thedir = belt->getGlobalDir();
      for( OgreNewt::Contact contact = contactJoint.getFirstContact(); contact; contact = contact.getNext() )
      {
         contact.rotateTangentDirections (thedir);
         Vector3 contactPos, contactNorm;
         contact.getPositionAndNormal(contactPos, contactNorm);
         Vector3 objectPos;
         Quaternion objectOri;
         object->getPositionOrientation(objectPos, objectOri);
         Vector3 objectContactPointVel = object->getVelocity() + (contactPos - objectPos)*object->getOmega();
         float result_accel = belt->getSpeed() - thedir.dotProduct(objectContactPointVel);
         result_accel *= 10; // looks nicer
         contact.setTangentAcceleration( result_accel, 0 );
      }
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to simulate a conveyor?

Postby Carli » Sun Jan 09, 2011 3:38 pm

Julio Jerez wrote:here is a contact callback to make a convefor belt king of body
Code: Select all
void ConvejorBellMaterialCallback (OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
{
   Body* body0 = contactJoint.getBody0();
   Body* body1 = contactJoint.getBody1();

   // first, find which body represents the conveyor belt!
   ConveyorBelt* belt = NULL;
   OgreNewt::Body* object = NULL;

   // find which body is the body floor
   if (body0->getType() == mConveyorID)
   {
      belt = (ConveyorBelt*)body0->getUserData();
      object = body1;
   }
   else if (body1->getType() == mConveyorID)
   {
      belt = (ConveyorBelt*)body1->getUserData();
      object = body0;
   }

   if (belt)
   {
      // okay, found the belt... let's adjust the collision based on this.
      Ogre::Vector3 thedir = belt->getGlobalDir();
      for( OgreNewt::Contact contact = contactJoint.getFirstContact(); contact; contact = contact.getNext() )
      {
         contact.rotateTangentDirections (thedir);
         Vector3 contactPos, contactNorm;
         contact.getPositionAndNormal(contactPos, contactNorm);
         Vector3 objectPos;
         Quaternion objectOri;
         object->getPositionOrientation(objectPos, objectOri);
         Vector3 objectContactPointVel = object->getVelocity() + (contactPos - objectPos)*object->getOmega();
         float result_accel = belt->getSpeed() - thedir.dotProduct(objectContactPointVel);
         result_accel *= 10; // looks nicer
         contact.setTangentAcceleration( result_accel, 0 );
      }
   }
}


But I want every body to be able to carry things when it's in the right position. How does a generic solution look like? Thats what i ment with "solution in Newton lib"
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: How to simulate a conveyor?

Postby Julio Jerez » Sun Jan 09, 2011 3:57 pm

But that is a solution in newton.

you need to set the call back and in the call back for each contact you apply the velocity you wan the body to has.

that is what this code fragment does
I can add a demo to the SDK to do just that.

Maybe an asselmbly line with object falling on the line move ramp and fall on a pit,
will that clarify your problem.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to simulate a conveyor?

Postby Carli » Fri Jan 14, 2011 6:26 pm

Julio Jerez wrote:I can add a demo to the SDK to do just that.


that would be great, thanks
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am


Return to User Gallery

Who is online

Users browsing this forum: No registered users and 9 guests