## Joint Velocity Control using MatLab

Typically: "How do I... ", "How can I... " questions
Hotpot
Posts: 4
Joined: 16 Jan 2021, 12:23

### Joint Velocity Control using MatLab

Hi everyone,

I meet a problem when implemented velocity control using "simxSetJointTargetVelocity". As the instruction provided, the unit of velocity is rad/s. When I set the velocity to "pi" to the first joint, I expect it to rotate half round. However, it rotates more than 2 rounds. I wonder if I did any mistakes during the simulation setting? Could anyone have a quick look at it? I post my example code (example.m) and the scene on the following link.

Thank you so much

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

### Re: Joint Velocity Control using MatLab

Hello,

if you set a target velocity with sim.setJointTargetVelocity, then your joint will try to rotate at a specific velocity. Maybe you rather want to have your joint controlled in position. In that case Make sure your joint has the its control loop enabled, and Position control (PID) is selected. Then you can use sim.setJointTargetPosition instead.

Cheers

Hotpot
Posts: 4
Joined: 16 Jan 2021, 12:23

### Re: Joint Velocity Control using MatLab

Hello,

Thank you so much for the reply. I tried position control and that works. However, my project specified that we need to use velocity control as the real-world robot always move through velocity command.

My problem is that when I set the target joint velocity to a specific joint, it did not rotate as expected. When I set the velocity to 'pi rad/s', the robot did not rotate with the specific speed I set. I wonder if I did some mistakes? Or how can I move that joint with desire velocity (at least approximately the same velocity as I set).

Thank you

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

### Re: Joint Velocity Control using MatLab

The velocity of your joint will depend on several things, e.g. the load on the joint, its max. force/torque, etc. So of course if your load is large or the torque is small, then your joint will have a small acceleration and take some time to reach the desired velocity. On the other hand, if your load is small and/or the torque is large, then your target velocity will be quickly reached.

There could also be other reasons why the velocity is not the one expected... for instance adjacent objects colliding with each other, etc.

How do you know that the velocity is not the one you specified? How do you measure that?

Cheers

Hotpot
Posts: 4
Joined: 16 Jan 2021, 12:23

### Re: Joint Velocity Control using MatLab

I firstly set the velocity of first joint to be pi using following command:
res = vrep.simxSetJointTargetVelocity(id, handles.ur5Joints(1),pi,vrep.simx_opmode_oneshot);
Then I let the program run for one second and then stop joint by setting joint velocity to 0 by using following command:
pause(1)
res = vrep.simxSetJointTargetVelocity(id, handles.ur5Joints(1),0,vrep.simx_opmode_oneshot);
I visualize the simulation in VREP at the same time.
I set the joint velocity to "pi" for one second and stop, this means that the joint should rotate half round. However, the VREP simulation showed that the joint rotated more than two rounds in one second. I expect there might be a small offset. But the real velocity is far larger than what I set. Thus, I wonder if I made mistakes somewhere.

You could check my scene and example code via the link: https://drive.google.com/drive/folders/ ... sp=sharing

coppelia