How to create this robot !?

ngd3v

22-11-2006 19:41:05

Hi
What is the best way to create this robot?With shapegroup and simple shapes or covex?



This robot designed for Robocup and I have to program a simulator for my friends that they be able to test their AI algorithms before run them on real robots.
You can see that it has 3 wheels with 120 degree between them.These wheels can rotate only.The green part is a kicker to shoot ball.
I think I have to use Cylindrical Joint for wheels and Hinge for kicker.
I see a tutorial for hinge joint limits but How to limit wheels translational movement.
Simulator needs 8 or 10 of these robots or othrer robots like them.I want disable shadow and all unimportant things.Do you think that program can run with enough frame rate without PhysX hardware?
I am a Delphi programmer and newbie in C++.I had programmed a simulator with Delphi an ODE but it was undeterministic that it cause I try do it with OGRE and NxOgre.If you can give me some code for importnat things.
Thanks.

betajaen

22-11-2006 20:31:13

It would be fine, I'm sure PhysX could handle 100 of them without breaking a sweat.

As for code, that would be cheating. But my only advise as with all Physics engines, build it as you would built it in the real world.

ngd3v

23-11-2006 18:25:02

As for code, that would be cheating.
:shock: :shock: :shock:

Of course, thanks for your advise.Perhaps "Car simulation" topic can help me.

betajaen

23-11-2006 18:39:30

A car simulation may be overkill.

It literally is a collection of convexes, shape groups, nshapes and motor joints.

ngd3v

23-11-2006 18:43:06

Thanks again.I try to create it and post my problems here.

betajaen

23-11-2006 18:55:01

The tutorials on:

- Convex shapes (corners bits)
- Shapegroups (combing the shapes into one body)
- Motors (to control the wheels)
- nShapes (for the wheels)
- CustomContactReporters (for the contact bit on the front)

Should help you plenty. :D

ngd3v

25-11-2006 20:07:50

I test this code before to start main implementation and get several problems:


mWorld = new world(mRoot);
mScene = mWorld->createScene("Main",mSceneMgr);
mScene->hasGravityAndFloor();

body *chassis=mScene->createBody("mychassis","cube.1m.mesh",new cubeShape(Vector3(1,0.5,1)),6.0f,Vector3(0,2,0));
chassis->mNode->setScale(1,0.5,1);
body *wheel_front1=mScene->createBody("myCapsule1","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(0.4,1.6,0.4),Quaternion(Radian(Degree(90)),Vector3::UNIT_Z)));
wheel_front1->mNode->setScale(0.2,0.1,0.2);
body *wheel_front2=mScene->createBody("myCapsule2","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(-0.4,1.6,0.4),Quaternion(Radian(Degree(90)),Vector3::UNIT_Z)));
wheel_front2->mNode->setScale(0.2,0.1,0.2);
body *wheel_back=mScene->createBody("myCapsule3","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(0,1.6,-0.4),Quaternion(Radian(Degree(90)),Vector3::UNIT_Z)));
wheel_back->mNode->setScale(0.2,0.1,0.2);

mScene->createJoint(new motorisedJoint(chassis,wheel_front1,Vector3(0.4,1.6,0.4),Vector3(-1,0,0),true));
mScene->createJoint(new motorisedJoint(chassis,wheel_front2,Vector3(-0.4,1.6,0.4),Vector3(1,0,0),true));
mScene->createJoint(new motorisedJoint(chassis,wheel_back,Vector3(0,1.6,-0.4),Vector3(-1,0,0),true));


Semi-robot moves automatically(small jumps in wheels cause this).How to remove these jumps?
I use capsule for wheels and you recommend nShape.What is advantage?
Of course I replace capsule with nShape but automatic movements don't remove.

wheel_front1 and 2 must rotate 30 degree and wheel_back must rotate 90 degree.
I change Quaternion(Radian(Degree(90)),Vector3::UNIT_Z) like below line:
body *wheel_front1=mScene->createBody("myCapsule1","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(0.4,1.6,0.4),Quaternion(Radian(Degree(90)),Vector(1,0,0.5))));

But program crashes and I get this error:

** Warning **
NpScene::createJoint: desc.isValid() fails!

E:\p4\release\PhysX_2.5.1\novodex\SDKs\Physics\src\NpScene.cpp:730 : PhysXSDK(RE)

What's that?
How to rotate them?

Please help me.

betajaen

25-11-2006 20:22:05

I wish I could help.

Can anyone compile this for me? I've done something to the core of NxOgre which will take a day to finish.

I'll pay in shoes.

ngd3v

28-11-2006 19:32:38

After lots of trial and error I can't find problem and now I use wheelShape.

shapeGroup* robot=new shapeGroup();
robot->addShape(new cubeShape(Vector3(1,0.5,1),Vector3(0,0,0)));
wheelShape *wf1=new wheelShape(0.2,Vector3(0.4,-0.5,0.4),Quaternion(1,0,-0.5,0));
robot->addShape(wf1);
wheelShape *wf2=new wheelShape(0.2,Vector3(-0.4,-0.5,0.4),Quaternion(1,0,0.5,0));
robot->addShape(wf2);
wheelShape *wb1=new wheelShape(0.2,Vector3(0,-0.5,-0.4),Quaternion(1,0,1,0));
robot->addShape(wb1);
myrobot=mScene->createBody("myrobot","cube.1m.mesh",robot,7.0f,Vector3(0,2,0));
myrobot->mNode->setScale(1,0.5,1);

Now wheels are in correct positions and small jumps removed.
New problem: How to addTorque() to wheels?
PhysX tutorials used wheel->setMotorTorque() but it seems it doesn't implemented in Nxogre.

betajaen

28-11-2006 20:18:09

Alright, I spent some time, and fixed both of your code problems:

The first, is your robot using capsules and motor joints:


body *chassis=mScene->createBody("mychassis","cube.1m.mesh",new cubeShape(Vector3(1,0.5,1)),0.1f,Vector3(0,2,0));
chassis->mNode->setScale(1,0.5,1);
body *wheel_front1=mScene->createBody("myCapsule1","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(0.4,1.6,0.4),Quaternion(Radian(Degree(90)),Vector3::UNIT_Z)));
wheel_front1->mNode->setScale(0.2,0.1,0.2);
body *wheel_front2=mScene->createBody("myCapsule2","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(-0.4,1.6,0.4),Quaternion(Radian(Degree(90)),Vector3::UNIT_Z)));
wheel_front2->mNode->setScale(0.2,0.1,0.2);
body *wheel_back=mScene->createBody("myCapsule3","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1),1.0f,pose(Vector3(0,1.6,-0.4),Quaternion(Radian(Degree(90)),Vector3::UNIT_Z)));
wheel_back->mNode->setScale(0.2,0.1,0.2);

motorisedJoint* j1 = new motorisedJoint(chassis,wheel_front1,Vector3(0.4,1.6,0.4),Vector3(-1,0,0),true);
j1->setVelocityTarget(10);
j1->setFreeSpin(true);
j1->setMaxForce(10);

mScene->createJoint(j1);

motorisedJoint* j2 = new motorisedJoint(chassis,wheel_front2,Vector3(-0.4,1.6,0.4),Vector3(-1,0,0),true);
j2->setVelocityTarget(10);
j2->setFreeSpin(true);
j2->setMaxForce(10);

mScene->createJoint(j2);


motorisedJoint* j3 = new motorisedJoint(chassis,wheel_back,Vector3(0,1.6,-0.4),Vector3(-1,0,0),true);
j3->setVelocityTarget(10);
j3->setFreeSpin(true);
j3->setMaxForce(10);

mScene->createJoint(j3);



The second is the NxWheelShape version which is a better implementation, however not very integrated into NxOgre.

This way uses PhysX directly.


shapeGroup* robot =new shapeGroup();
robot->addShape(new cubeShape(Vector3(1,0.5,1),Vector3(0,0,0)));
wheelShape *wf1=new wheelShape(0.2,Vector3(0.4,-0.5,0.4),Quaternion(1,0,-0.5,0));
robot->addShape(wf1);
wheelShape *wf2=new wheelShape(0.2,Vector3(-0.4,-0.5,0.4),Quaternion(1,0,0.5,0));
robot->addShape(wf2);
wheelShape *wb1=new wheelShape(0.2,Vector3(0,-0.5,-0.4),Quaternion(1,0,1,0));
robot->addShape(wb1);
body *myrobot=mScene->createBody("myrobot","cube.1m.mesh",robot,7.0f,Vector3(0,2,0));
myrobot->mNode->setScale(1,0.5,1);

NxU32 nbShapes = myrobot->mActor->getNbShapes();
NxShape*const* shapes = myrobot->mActor->getShapes();

while (nbShapes--) {
if (shapes[nbShapes]->isWheel()) {
NxWheelShape *theWheel = reinterpret_cast<NxWheelShape*>(shapes[nbShapes]);
theWheel->setMotorTorque(250.0f);
}
}

myrobot->wakeUp();


Now this just loops through all the shapes in the body/NxActor and if it is a wheel, it sets the motor torque.

What you should do is first, loop through the wheels and store the pointers seperatly (ideally they should be in the same order as you created them), but check. There is no identifier to shapes, so I'd use the position as some sort of identifier.

From using the NxWheelShape, you can fiddle around with MotorTorque, Breaking (reverse the torque), suspension and if the wheel turns or not (for steering).

Oh, when you adjust any of the NxWheelShape, remember to wake up the body, else it won't be noticed.

Apologies for not wrapping up the NxWheelShapes yet, but it's low priority at the moment.

ngd3v

01-12-2006 18:01:22

Thanks
I test your codes and add some codes to it and now new question:
Can we use PhysX for scientific simulations?

I store pointers and test this:


if (isKeyDown(FORCE)) {
theWheel[1]->setMotorTorque(300);
theWheel[2]->setMotorTorque(300);
myrobot->wakeUp();
}


Robot doesn't move.

Other code:


t=0.0;
body *chassis=mScene->createBody("mychassis","cube.1m.mesh",new cubeShape(Vector3(1,0.5,1)),0.1f,Vector3(0,2,0));
chassis->mNode->setScale(1,0.5,1);
material *wf_mat=mScene->createMaterial("wf_mat",0.8,0.7,0);
body *wheel_front1=mScene->createBody("myCapsule1","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1,wf_mat),1.0f);
wheel_front1->mNode->setScale(0.2,0.1,0.2);
wheel_front1->setGlobalPosition(0.4,1.6,0.4);
wheel_front1->setGlobalOrientation(Quaternion(Radian(Degree(90)),Vector3(Ogre::Math::Sin(Radian(Degree(-30))),0,Ogre::Math::Cos(Radian(Degree(-30))))));

body *wheel_front2=mScene->createBody("myCapsule2","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1,wf_mat),1.0f);
wheel_front2->mNode->setScale(0.2,0.1,0.2);
wheel_front2->setGlobalPosition(-0.4,1.6,0.4);
wheel_front2->setGlobalOrientation(Quaternion(Radian(Degree(90)),Vector3(Ogre::Math::Sin(Radian(Degree(-150))),0,Ogre::Math::Cos(Radian(Degree(-150))))));

body *wheel_back=mScene->createBody("myCapsule2","capsule.50cmx1m.mesh",new capsuleShape(0.1,0.1,wf_mat),1.0f);
wheel_back->mNode->setScale(0.2,0.1,0.2);
wheel_back->setGlobalPosition(0,1.6,-0.4);
wheel_back->setGlobalOrientation(Quaternion(Radian(Degree(90)),Vector3(Ogre::Math::Sin(Radian(Degree(90))),0,Ogre::Math::Cos(Radian(Degree(90))))));

j1 = new motorisedJoint(chassis,wheel_front1,Vector3(0.4,1.6,0.4),Vector3(Ogre::Math::Cos(Radian(Degree(-30)))*-1,0,Ogre::Math::Sin(Radian(Degree(-30)))),true);
j2 = new motorisedJoint(chassis,wheel_front2,Vector3(-0.4,1.6,0.4),Vector3(Ogre::Math::Cos(Radian(Degree(-150)))*-1,0,Ogre::Math::Sin(Radian(Degree(-150)))),true);
j3 = new motorisedJoint(chassis,wheel_back,Vector3(0,1.6,-0.4),Vector3(0,0,-1),true);

j1->setFreeSpin(false);
j2->setFreeSpin(false);
j3->setFreeSpin(false);

/*
j1->setMaxForce(100);
j2->setMaxForce(100);
j3->setMaxForce(100);
*/



if (isKeyDown(FORCE)) {
t++;
j1->setVelocityTarget(t);
j2->setVelocityTarget(-t);
}


Before achieve to 6 m/s (my goal) ,robot rotates and doesn't move on line.

Now I think I must remove wheels and use simple shapes and forces.

Comments from lesson 409:

Lesson 409 – Articulated Truck

We build a fully articulated tractor-trailer truck. The truck is comprised of a tractor actor and a trailer actor. The tractor actor is hitched to the trailer actor by a revolute joint. Each wheel is connected by a revolute joint to a shapeless roll-axis actor. The roll-axis actor is connected to the tractor (or trailer) by a prismatic joint and the roll-axis actor is held to the tractor (or trailer) by a tight spring, which simulates the vehicle's suspension. The two front steering wheels are differentiated from the regular wheels in that they are connected to their roll-axis actor by an additional steer-axis actor via a revolute “steering joint”, whose global axis is set along the y-axis.

Is needed this complex structure?

NickM

01-12-2006 21:07:58

Thanks
I store pointers and test this:


if (isKeyDown(FORCE)) {
theWheel[1]->setMotorTorque(300);
theWheel[2]->setMotorTorque(300);
myrobot->wakeUp();
}


Robot doesn't move.


I'm using wheelShapes and code very similar to yours above, it works ok for me, the only difference with my code is I call 'wakeUp' before setting the motorTorque, not sure if that will make any difference.

ngd3v

03-12-2006 17:24:26


I'm using wheelShapes and code very similar to yours above, it works ok for me, the only difference with my code is I call 'wakeUp' before setting the motorTorque, not sure if that will make any difference.

It isn't effective.I believe robot doesn't move bacause wheels are in non standard directions and wheelshape is useful only for standard car simulations.

betajaen

03-12-2006 17:41:27

When I used your code for the first time, I got the robot to work.

However in both versions, the wheels are locked in a certain angle so the robot will only spin around and will not move forward.

You'll need to, make them so they can steer. Almost like a shopping trolley with a motor attached to each wheel. In the case above, a hinge joint attached to a small non-collidable cube, which then has the motor joint attached to the capsule.

ngd3v

03-12-2006 18:00:07

Thanks
I try learn more and test your advise before ask other questions.