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

Typically: "How do I... ", "How can I... " questions
Post Reply
biscuit122
Posts: 14
Joined: 23 Jan 2018, 16:16

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

Post by biscuit122 » 30 Jul 2018, 12:09

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?

coppelia
Site Admin
Posts: 6736
Joined: 14 Dec 2012, 00:25

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

Post by coppelia » 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

biscuit122
Posts: 14
Joined: 23 Jan 2018, 16:16

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

Post by biscuit122 » 01 Aug 2018, 04:04

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?

coppelia
Site Admin
Posts: 6736
Joined: 14 Dec 2012, 00:25

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

Post by coppelia » 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

biscuit122
Posts: 14
Joined: 23 Jan 2018, 16:16

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

Post by biscuit122 » 13 Aug 2018, 12:06

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.

Post Reply