## Lock a Joint / a Cuboid

Typically: "How do I... ", "How can I... " questions
qiushi.ji
Posts: 30
Joined: 28 Apr 2014, 10:45
Location: Deutschland

### Lock a Joint / a Cuboid

Hi Marc,

I want to dynamically lock a joint in the simulation (just like a mechanical clamping in real world), that means for example a revolute joint would be locked with a infinitely force, it can't rotate anymore. Further more if I set it back, this joint could rotate again.

The second question is, how can I switch a cuboid property in the simulation between "static" an "static/respondable"?

Cheers,
Ji

coppelia
Posts: 7605
Joined: 14 Dec 2012, 00:25

### Re: Lock a Joint / a Cuboid

Hello Ji,

in order to lock a joint you would switch the joint to a position control mode, maybe following two functions could be useful:

Code: Select all

setJointToHoldPosition=function(jointHandle)
simSetObjectIntParameter(jointHandle,2001,1) -- enable the control loop
simSetJointTargetPosition(jointHandle,simGetJointPosition(jointHandle)) -- make sure we hold current position
end

setJointToVelocityControl=function(jointHandle)
simSetObjectIntParameter(jointHandle,2001,0) -- disable the control loop
end
Optionally, if your joint motor is not enabled, you will also have to call simSetObjectIntParameter(jointHandle,2000,1) in the first function above, and simSetObjectIntParameter(jointHandle,2000,0) in the second function above.

For your second question, you would do this with:

Code: Select all

simSetObjectIntParameter(shapeHandle,3004,respondableState) -- change the respondable state of the shape
simResetDynamicObject(shapeHandle) -- this call is needed in order for the previous command to take effect
Cheers

qiushi.ji
Posts: 30
Joined: 28 Apr 2014, 10:45
Location: Deutschland

### Re: Lock a Joint / a Cuboid

Hi,

thanks for the algorithm.

I have designed a simpler UI to switch this function, such like:

Code: Select all

Lock_Joint=simGetObjectHandle('Revolute_joint')
buttonHandle,auxiliaryValues=simGetUIEventButton(Interface)
buttonprop_lock=simGetUIButtonProperty(Interface,28) --get prop of the function button

if sim_buttonproperty_isdown==simBoolAnd16(buttonprop_lock,sim_buttonproperty_isdown) then

--lock function (downclick)******************************************
setJointToHoldPosition=function(Lock_Joint)
simSetObjectIntParameter(Lock_Joint,2001,1) -- enable the control loop
simSetJointTargetPosition(Lock_Joint,simGetJointPosition(Lock_Joint)) -- hold current_pos
end

Mode=simGetObjectIntParameter(Lock_Joint,2001) --get the current loop mode
actPos=simGetJointPosition(Lock_Joint) --get the current pos
simAddStatusbarMessage("Lock-On:  "..Mode.."   act_Pos:  "..actPos) --show info in Bar

--unlock function (up click)**************************************
else
setJointToVelocityControl=function(Lock_Joint)
simSetObjectIntParameter(Lock_Joint,2001,0) -- disable the control loop
end

Mode=simGetObjectIntParameter(Lock_Joint,2001) --get the current loop mode
actPos=simGetJointPosition(Lock_Joint) --get the current pos
simAddStatusbarMessage("Lock-Off:  "..Mode.."   act_Pos:  "..actPos) --show info in Bar

end

From the status bar I read the loop mode is always in "1", although I switching the button:

Code: Select all

...
Lock-Off:  1   act_Pos:  -0.081999681890011
Lock-Off:  1   act_Pos:  -0.081999681890011
Lock-Off:  1   act_Pos:  -0.081979319453239
Lock-On:  1   act_Pos:  -0.081979319453239
Lock-On:  1   act_Pos:  -0.081979319453239
Lock-On:  1   act_Pos:  -0.081960193812847
...
`
1, Should I set the joint property into Motor enabled and Control loop enabled before simulation start?
2, did I put the function code in the right if loop?

Or should I set a JointForce for holding a current position?

coppelia