Page 1 of 1

The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 30 Jul 2018, 12:09
by biscuit122
Hi, can you help me to distinguish the difference between force control and position control for a primastic joint?
I calculate the force to control a primastic joint. Can I use sim.setJointTargetPosition in script? How should I set the joint dynamic properties?( including motor enabled, control properties and so on.)
Otherwise, if I calculate a displacement to control a primastic joint. Which API function I should use? How shoud I set the joint dynamic properties?

Re: The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 31 Jul 2018, 06:52
by coppelia
Hello,

if your joint is in force/torque mode, your motor enabled and the control loop disabled, then you can adjust your joint's behaviour with sim.setJointForce: the joint will apply the specified force/torque until the target velocity has been reached. You can adjust the target velocity with sim.setJointTargetVelocity. If you need your joint to apply the force/torque in opposite direction, you should inverse the joint's target velocity.

if your joint is in force/torque mode, your motor enabled and the control loop is enabled and Position control (PID) checked, then your can adjust your joint's position with sim.setJointTargetPosition. If you want to write your own joint controller (be it in position, force/torque, damping, etc.), then your joint should be configured that way. In addition, you will have to use a joint callback function: it will allow you to implement virtually any type of controller.

Cheers

Re: The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 01 Aug 2018, 04:04
by biscuit122
coppelia wrote:
31 Jul 2018, 06:52
Hello,

if your joint is in force/torque mode, your motor enabled and the control loop disabled, then you can adjust your joint's behaviour with sim.setJointForce: the joint will apply the specified force/torque until the target velocity has been reached. You can adjust the target velocity with sim.setJointTargetVelocity. If you need your joint to apply the force/torque in opposite direction, you should inverse the joint's target velocity.

if your joint is in force/torque mode, your motor enabled and the control loop is enabled and Position control (PID) checked, then your can adjust your joint's position with sim.setJointTargetPosition. If you want to write your own joint controller (be it in position, force/torque, damping, etc.), then your joint should be configured that way. In addition, you will have to use a joint callback function: it will allow you to implement virtually any type of controller.

Cheers
Thank you for your help. I want to control the primastic joint to move along a sin function including positive and negative diretion. How can I make a setting?

Re: The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 03 Aug 2018, 05:55
by coppelia
Here a very simple example:

set your joint in force/torque mode, enable the motor and the control loop.
Then attach a threaded child script to the joint with following code:

Code: Select all

function sysCall_threadmain()
    local h=sim.getObjectAssociatedWithScript(sim.handle_self)
    local t=0
    while true do
        sim.setJointTargetPosition(h,0.2*math.sin(t))
        t=t+0.01
        sim.switchThread()
    end
end
Cheers

Re: The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 13 Aug 2018, 12:06
by biscuit122
coppelia wrote:
03 Aug 2018, 05:55
Here a very simple example:

set your joint in force/torque mode, enable the motor and the control loop.
Then attach a threaded child script to the joint with following code:

Code: Select all

function sysCall_threadmain()
    local h=sim.getObjectAssociatedWithScript(sim.handle_self)
    local t=0
    while true do
        sim.setJointTargetPosition(h,0.2*math.sin(t))
        t=t+0.01
        sim.switchThread()
    end
end
Cheers
Well, thanks for your example. But I want to know how to use function sim.setJointForce to achieve a force control loop with a sin function including positive and negative diretion.

Re: The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 17 Aug 2018, 13:21
by coppelia
To set a negative force, you'll have to set a negative target velocity (sim.setJointTargetVelocity). But you should keep the same amplitude of that target velocity.

Cheers

Re: The API function and joint dynamic properties of force control and position control for a primastic joint

Posted: 01 Sep 2018, 14:51
by biscuit122
coppelia wrote:
17 Aug 2018, 13:21
To set a negative force, you'll have to set a negative target velocity (sim.setJointTargetVelocity). But you should keep the same amplitude of that target velocity.

Cheers
Thanks for your help and time. In your words, it means that a force controller needs setting target velocity and force for a joint at the same time, doesn't it?