## Controlling velocity with MATLAB

Typically: "How do I... ", "How can I... " questions
codycichosz
Posts: 14
Joined: 06 Dec 2020, 00:39

### Re: Controlling velocity with MATLAB

Hello Coppelia,

I am trying to get my joint callback function working once again. I followed the instructions from the help files. I tried to send a float from MATLAB to Coppelia to change the upper velocity limit through the MATLAB remote API function "simxCallScriptFunction" but I received an error within Coppelia:

"[UR10_joint1@childScript:error] 55: attempt to perform arithmetic on field 'errorValue' (a nil value)
stack traceback:
[string "UR10_joint1@childScript"]:55: in function <[string "UR10_joint1@childScript"]:19>
[CoppeliaSim:error] External call to simCallScriptFunction failed (sysCall_jointCallback@UR10_joint1): Error in script function."

In MATLAB, I received a return code of "1" and it outputs rFloat as nothing. Here is my MATLAB code:

Code: Select all

upperVelocityLimit = deg2rad(120);
[R1,~,rFloat,~,~] = sim.simxCallScriptFunction(clientID, 'UR10_joint1', sim.sim_scripttype_childscript, 'sysCall_jointCallback', [], 'upperVelocityLimit', [], [], sim.simx_opmode_oneshot)

I am not entirely sure how to use a joint callback function and am wondering if I could get help. Below is the link to the scene.

Cody

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

### Re: Controlling velocity with MATLAB

Hello Cody,

you are mixing up several things. You have for your joint a joint callback function defined. That function is called by the system (i.e. CoppeliaSim) on a regular basis, with appropriate arguments. Of course if you try to call that function yourself, and you don't provide the expected arguments, you will get an error, i.e.

Code: Select all

[UR10_joint1@childScript:error] 55: attempt to perform arithmetic on field 'errorValue' (a nil value)
Those system callback function are not meant to be called by the user. If you do, their purpose and operation won't be what is expected.

Cheers

codycichosz
Posts: 14
Joined: 06 Dec 2020, 00:39

### Re: Controlling velocity with MATLAB

Thank you, that makes sense.

I went back to using the

Code: Select all

sim.simxSetFloatSignal
Remote API function and retrieving that float signal inside of the joint callback function. I was able to control the upper velocity limit of my joints by changing that float signal. It appeared that when I tried this previously, I was sending very small velocity changes and they were tough to notice in the simulation. Thank you for your help!

Cody

codycichosz
Posts: 14
Joined: 06 Dec 2020, 00:39

### Re: Controlling velocity with MATLAB

Coppelia,

I have 2 more questions.

First, in my current scene, my joints are in torque/force mode with the control loop enabled. When I set the upper velocity limit to zero, the UR10 stops moving, but then it starts to fall slowly, collapsing from it's own weight. Is there a way to avoid this by locking the joint motors? I see there is a way to lock the motor if the control loop is disabled, but in my scenes, I have found the control loop to help tremendously with the positioning.

Second, is there a way to control the joint or fingertip velocity of a UR10 with the same method of using joint callback functions? I have a separate scene working in IK and hybrid mode and when I change the upper velocity limit, the UR10 moves at the same speed.

Cody

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

### Re: Controlling velocity with MATLAB

When in position control, why do you want to set the upper velocity limit to zero? This effectively would be similar to not controlling the joint. If you want to keep the position, simply do... nothing! (the PID controller will simply try to keep the last target position).

About the fingertip velocity... what does that mean exactly? The UR10 doesn't have a gripper. You mean the end-effector velocity? But in that case it has nothing to do with the joint velocity...? Please clarify.

Cheers

codycichosz
Posts: 14
Joined: 06 Dec 2020, 00:39

### Re: Controlling velocity with MATLAB

I want to set the upper velocity limit to zero to stop the UR10. My goal is to detect an person in the work cell and stop the UR10 before a collision happens then maneuver around the person. I thought that would be the easiest way, but maybe not the most effective.

Yes, I meant the end-effector velocity. I am simply looking for any kind of velocity control, whether that is with the joints or the end-effector, when the UR10 is in inverse kinematics mode. Is this possible?

coppelia
If your joint is dynamically enabled and operating in position control, do not set the upper velocity limit to zero if you want to stop in a movement. Instead, set a new target position that is the current one, e.g. sim.setJointTargetPosition(sim.getJointPosition(jointHandle))
With inverse kinematics you need to compute the desired joint angles, then apply them. If your robot is dynamically enabled, then you would apply them with sim.setJointTargetPosition. Have a look at the demo scene scenes/ik_fk_simple_examples/10-applyingIkToDynamicallyEnabledModels.ttt