Previous topic TOC

Use joints

Next topic

Joint In order to attach objects to each other with some degree of freedom, you can make use of Joint objects. Currently, three different types of rotational joints are available:  PointJoint, FixedAxisJoint and a FreeAxisJoint. The first one keeps two objects fixed one point, allowing free rotation. The FixedAxisJoint keeps two objects fixed on an axis, allowing rotation around the axis only. The last one, the FreeAxisJoint, also keeps two objects fixed on an axis, allowing rotation and shifting along the axis. In general, construction is done in two steps: First, the joint object is created and placed at the position where it should connect the two other objects. Second, the joint method attach is called in order to attach the joint to the two objects. Finally, joint properties like torque and dampening may be specified. Example:
// create a material for default use
factory.material = Material(1e-6, 1, .5, .4); 
factory.useDegrees = true;
// select yellow as color
factory.color = RGB(255,255,0);     
// create two objects to attach by a joint          
var a = Box(50, 100, 50);         
var b = Box({50,50,50}, {100,25,0});
// one object should not move now                 
a.static = true;                        
// this joint should keep the objects  a and b together
var j = PointJoint({10,10,50}, {25,25,0});     
// position joint and attach                                        
j.rotate(0,150,0);                             
j.attach(a, b);          
// simulate for 8 seconds                     
while(simulator.time < 8) 
{
	WaitFrame();
	simulator.run(.1);
};
A jont doesn't have a mass or volume, not can it collide to some other object.
Use a function to set torque A FreeAxisJoint and a FixedAxisJoint can produce a torque when its property torque is set. This can be a constant value, but also we can assign a function to this property. Example:
function control()
{
	return target_orientation - wheel.orientation[1];
};
j.torque = control;

Now the function 'control' will be evaluated at each simulation step, and the result of this function is used as the torque value to be applied. This method makes it possible to simulate a digital and/or analogue control system that interacts with a mechanical system. The assignment of functions is not limited to the torque member.