Changing the speed of a "servo" from within child script

Typically: "How do I... ", "How can I... " questions
Post Reply
RobAtLab
Posts: 59
Joined: 10 Jan 2018, 17:49

Changing the speed of a "servo" from within child script

Post by RobAtLab » 19 Feb 2019, 16:48

I have a revolute joint in Torque/force mode, position is not cyclic and position has limits with a range of 180 degrees using -90 degrees as Pos.min.[deg] . Motor is enabeld in dynamic properties, a max torque is set and control loop is enabled. In my child script I need to set the position to move to using:

sim.setJointTargetPosition(MotorName,TargetAngle*math.pi/180)

But with my actual robotic hardware I have some control of how fast this (very slow moving, 2 degrees/sec max) joint actually moves. I can say "go there at 1.4 degrees/sec" or other such things. But I see no easy way to adjust the
Upper velocity limit [deg/s] parameter from my child script.

I cam across sim.jointfloatparam_upper_limit (2017) but found that joints need resetting whenever this is called, such a reset could end up causing my joint to experience physics engine drift over time, I'll be trying to change this upper speed limit many many times during my simulation runs. Is there any better way to set up a joint which I can command to a certain angle at a certain speed? I don't need complex control algorithms for this, my joint is very slow moving and I would expect it's turn velocity to be pretty constant throughout its motion between two positions. All I'm after is a basic "go to angle X at angular speed S (or at P% of the upper velocity limit)", ideally in a way where if, while that motion is in execution when a second "go to angle Y at speed Z" command gets sent then the joint would change direction and/or speed as necessary and head for the newly commanded position at the newly commanded speed.

Thanks

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

Re: Changing the speed of a "servo" from within child script

Post by coppelia » 20 Feb 2019, 14:02

Hello,

the easiest would be to use a joint control callback function. On that page, you have the script for a position control. You can use inData.velUpperLimit for your upper velocity limit.

Cheers

RobAtLab
Posts: 59
Joined: 10 Jan 2018, 17:49

Re: Changing the speed of a "servo" from within child script

Post by RobAtLab » 23 Feb 2019, 19:19

Ok, so I set a custom joint callback script and paste the contents of that webpage into it. I'm assuming that at that point what I'll have is a joint which has a cutom callback script but behaves exactly like the normal position control mode of a joint. Then how do I allow the child script on the joint's highest parent object (highest parent object is a robot base, joint itself is a few layers of heirachy down from it) to pass altered values of inData.velUpperLimit to the calback script? Would that be done with something like a custom datablock of the kind I've already been using to pass information between objects? Or is there a better way? As the webpage notes that the callback script runs 10 times more often than normal bits of child scripts what is the most efficient way for a parent object to transfer new values of inData.velUpperLimit into it. Thanks

RobAtLab
Posts: 59
Joined: 10 Jan 2018, 17:49

Re: Changing the speed of a "servo" from within child script

Post by RobAtLab » 27 Feb 2019, 16:07

Any more details on this, I can't see to find any clear tutorial telling me how to put a custom callback script onto a joint, even thought there is plenty of info about what the script should be like once it is there. Also, will using that script on the webpage, with thre addition of some sort of custom datablock code to let the parent object change the joint's maximum speed, be significantrly slower to simulate than a jopint without a custom callback? Or is the joint, by default, already using a custom calback of the kind shown on that webpage? Hencer the only additional slowing below default will be due to whatever extra computation is needed to handle the custom datablock bit? Thanks

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

Re: Changing the speed of a "servo" from within child script

Post by coppelia » 01 Mar 2019, 15:33

You have many different possibilities to transfer values or variables between scripts.

Unless you are doing heavy computation, there shouldn't be any impact at all in using a joint callback function.

Cheers

RobAtLab
Posts: 59
Joined: 10 Jan 2018, 17:49

Re: Changing the speed of a "servo" from within child script

Post by RobAtLab » 10 Mar 2019, 01:08

Thanks, all woking well now. Am passing data into the joint object via a custom datablock, I have set things up so the datablock gets set by the script of the robot's body during the actuation simulation step. Then in the simulation's sensing step the joint object reads the custom datablock and updates the value of the maximum allowable speed to be whatever is in the datablock. This variable value then gets used, just like inData.velUpperLimit used to in the original callback script, in joint callback simulation steps. This way I'm not having to check the datablock at a pointlessly high rate of 10 times per sim step when the fastest it can possibly be changed is once per sim step.

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

Re: Changing the speed of a "servo" from within child script

Post by coppelia » 13 Mar 2019, 13:47

by reading your custom data block in the sensing section, your upper velocity limit value will only be updated in the next simulation step. Better is to write and read the value in the actuation section of your child scripts. But make sure that your read operation is executed after the write operation. You can read more about this here.

Another possibility is to read your custom data block in the joint callback function, like:

Code: Select all

function sysCall_jointCallback(inData)
    if inData.passCnt==1 then
        -- read your custom data block here (once per simulation step)
    end

    ...

    return outData
end
Cheers

Post Reply