Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, degenerate_762), 907 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
physX 6D joint examples and questions #392740
01/26/12 19:43
01/26/12 19:43
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
I've spent some time trying to figure out how to make motorized joints with limits using physX. I thought some people might find this example code useful. Use home and end keys to change the joint type (from 1-3 degrees of freedom with different combinations of swing1, swing2, and twist motions). Then use page up, page down, cursor left, cursor right, cursor up, or cursor down to drive the motors. Only the keys controlling the active degrees of freedom will work (e.g. for the fixed joint, no matter what you push the joint won't move). The code is completely self contained (no external model or levels, so just copy into an empty .c file and it should run with A8.30)
Click to reveal..

Code:
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
#include <windows.h>

#define PRAGMA_ZER0

var twist, swing1, swing2, index;

typedef struct JT {
	var motion[6];
	var drive[6];
} JT;

JT jt[8];

TEXT* jtxt = {
	string("fixed joint","twist only", "swing1 only", "swing2only", "twist and swing1", 
	       "twist and swing2", "swing1 and swing2", "twist, swing1, and swing2");
}

STRING* jstr = "fixed joint";

PANEL* displaypanel={
	digits(10, 10, "twist (cul ,cur ): %3.0f", "Courier#12b",1, twist);
	digits(10, 30, "swing2(cuu ,cud ): %3.0f", "Courier#12b",1, swing2);
	digits(10, 50, "swing1(pgup,pgdn): %3.0f", "Courier#12b",1, swing1);
	//digits(10, 80, "index(home,end)  : %3.0f", "Courier#12b",1, index);
	digits(10, 80, "index(home,end)  : %s", "Courier#12b",1, jstr);

	flags = SHOW;	
}


function main()
{

// set up a simple level  
  shadow_stencil = 1;
  d3d_antialias = 1;
  physX_open();
  level_load(""); // load an empty level
  pXent_settype(NULL,PH_STATIC,PH_PLANE); // create a static plane at groundlevel zero
  ENTITY* ground = ent_createterrain(NULL,NULL,32,32,1000);
  bmap_fill(bmap_for_entity(ground,0),COLOR_RED,100);  
  vec_set(camera.x,vector(-150,0,50));
  
  //set this to see the different types of rotational only joints
  var jointtype=1;
    
  //joint axis set to default (0,0,-1)
  //Motion: 
  //3: twist  >> swing1?
  //4: swing1 >> swing2?
  //5: swing2 >> twist ?
  //Drive: 
  //3: swing (swing1 and swing2)
  //4: slerp
  //5: twist
  //pXcon_setmotor(ent,vecParam,0);
  //vecParam: (twist?, swing2?, swing1?)
   
   //indicate where joint is located
   you = ent_create(SPHERE_MDL,vector(0,0,16),NULL);
   you.scale_x = you.scale_y = you.scale_z = 0.5;
   
   you = ent_create(CUBE_MDL,vector(0,0,32),NULL);
   set(you, SHADOW);
	you.scale_z = 2;   pXent_settype(you,PH_RIGID,PH_BOX);// define a joint with a twist motor
	 
	pXcon_add(PH_6DJOINT,you,NULL,0); 
	pXcon_setparams1(you,vector(0,0,16),NULL, NULL); 
	pXcon_setparams2(you,vector(45,45,0),vector(-45,45,0), NULL); 
	//set swing1 and swing2 limits to 45, set twist limits between -45 and 45.  
  
	//1: pan? (twist)
	jt[1].motion[5] = NX_D6JOINT_MOTION_LIMITED;
	jt[1].drive[5] = NX_D6JOINT_DRIVE_VELOCITY;
	//2: tilt? (swing1)
	jt[2].motion[3] = NX_D6JOINT_MOTION_LIMITED;
	jt[2].drive[3] = NX_D6JOINT_DRIVE_VELOCITY;
	//3: roll? (swing2)
	jt[3].motion[4] = NX_D6JOINT_MOTION_LIMITED;
	jt[3].drive[3] = NX_D6JOINT_DRIVE_VELOCITY;
	//4: pan and tilt? (twist and swing1)
	jt[4].motion[3] = jt[4].motion[5] = NX_D6JOINT_MOTION_LIMITED;
	jt[4].drive[3]  = jt[4].drive[5]  = NX_D6JOINT_DRIVE_VELOCITY;
	//5: pan and roll? (twist and swing2)
	jt[5].motion[4] = jt[5].motion[5] = NX_D6JOINT_MOTION_LIMITED;
	jt[5].drive[3]  = jt[5].drive[5]  = NX_D6JOINT_DRIVE_VELOCITY;
	//6: tilt and roll? (swing1 and swing2)
	jt[6].motion[3] = jt[6].motion[4] = NX_D6JOINT_MOTION_LIMITED;
	jt[6].drive[3]  = NX_D6JOINT_DRIVE_VELOCITY;
	//7: pan, tilt and roll? (twist, swing1, ad swing2)
	jt[7].motion[3] = jt[7].motion[4] = jt[7].motion[5] = NX_D6JOINT_MOTION_LIMITED;
	jt[7].drive[3]  = jt[7].drive[5]  = NX_D6JOINT_DRIVE_VELOCITY;
	
  var NoDrive[6] = { 0,0,0,0,0,0};
  
  while(1)
  {
  		twist=swing2=swing1=0;
  		
  		if(key_end)
  		{	
  			while(key_end) wait(1);
  			index = cycle(index+1, 0, 8);
  		}	
  		if(key_home)
  		{	
  			while(key_home) wait(1);
  			index = cycle(index-1, 0, 8);
  		}	
  		str_cpy(jstr, (jtxt.pstring)[index]);
  		if(key_any)
  		{
  			pXcon_set6djoint(you,jt[index].motion,jt[index].drive);
	  		twist=(key_cul-key_cur)*100;
	  		swing2=(key_cuu-key_cud)*100;
	  		swing1=(key_pgup-key_pgdn)*100;
	  		pXcon_setmotor(you,vector(twist, swing2, swing1),0);
  		}
  		else
  			pXcon_set6djoint(you,jt[index].motion,NoDrive);
  		
  		wait(1);	
  }
  	
}



I've found some discrepancies with the manual, and some things that weren't very clear to me from the manual:

1. in "pXcon_set6djoint", JointMotion[3-5] defines the swing1, swing2, and twist motion of the joint in that order (not pan,tilt, and roll)
2. also in "pXcon_set6djoint", an axis may be NX_D6JOINT_MOTION_FREE or NX_D6JOINT_MOTION_LIMITED in order to be driven by a motor
3. in "pXcon_setmotor", the vecParam specifies the twist, swing2, and swing1 motor values in that order
4. in "Constaints/PH_6DJOINT", parameter 4, x represents swing1 limit in either direction, y represents swing 2 limit in either direction
5. also in "Constaints/PH_6DJOINT", parameter 5, x represents lower twist limit, and y represents upper twist limit.

for a definition of the swing1, swing2, and twist you have to see the PhysXDocumentation ( http://server.conitec.net/down/physXdoc.zip)

Questions:
1. Is there a way to query what the current angles are? pXcon_getposition does not return the swing1, swing2, and twist angles. These must somehow be available within the engine in order to verify whether or not the joint is between its limits, but they do not seem to be exposed in GS.
2. Is there a way to motorize a simple hinge joint instead of using the more complicated 6d joint in GS. According to PhysX documentation this seems very simple but it does not appear to be exposed in GS and didn't work when I tried it.
3. Why can't the 6D Joint be motorized with a positional motor? (That is, attempt to drive to a certain angle, rather than angular velocity) I tried setting the appropriate JointDrive element to NX_D6JOINT_DRIVE_POSITION in pXcon_set6djoint, and setting mode=2 in pXcon_setmotor but it didn't work.

I hope that the PhysX plug-in for GS will be developed further and that more of the features available in PhysX will become available, and that the use of these features will be more clearly explained in the manual.

Thanks!


Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing
Re: physX 6D joint examples and questions [Re: yorisimo] #392743
01/26/12 20:28
01/26/12 20:28
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
I just became aware of the modified PhysX plug-in:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=384647#Post384647 which addresses these issues.
Thanks HeelX, rojart, Quad, and anyone else involved!

I hope these changes get moved into the official GS release soon


Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1