Joint Velocity Control using MatLab

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

Joint Velocity Control using MatLab

Post by Hotpot »

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.
https://drive.google.com/drive/folders/ ... sp=sharing

Thank you so much

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

Re: Joint Velocity Control using MatLab

Post by coppelia »

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

Post by Hotpot »

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
Site Admin
Posts: 8446
Joined: 14 Dec 2012, 00:25

Re: Joint Velocity Control using MatLab

Post by coppelia »

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

Post by Hotpot »

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
Site Admin
Posts: 8446
Joined: 14 Dec 2012, 00:25

Re: Joint Velocity Control using MatLab

Post by coppelia »

Ok, you can't do that: you can't use real-time, when CoppeliaSim tries to simulate as fast as possible.

You have two options:
  • you can set CoppeliaSim in real-time mode (check the real-time toolbar button, in the horizontal toolbar). This way, CoppeliaSim will slow down the simulation in order to keep a pace similar to real-time. This is of course not perfect because CoppeliaSim runs with discreet simulation steps (by default 50ms per step). Also the other problem is if your simulation content is heavy, then CoppeliaSim won't be able to keep the pace with real-time
  • the better option is to run in synchronous mode. This way, you will run with a virtual time that you decide to step on the client side. And you can then trigger each simulation step of CoppeliaSim individually. In case of the legacy remote API, read more about the synchronous mode here. Have also a look at the synchronous mode example programming/remoteApiBindings/python/python/synchronousImageTransmission.py (the approach with Matlab is very similar). Make sure synchronousImageTransmissionViaRemoteApi.ttt is loaded. In the same folder you also have pController.py (that matches the scene pControllerViaRemoteApi.ttt). You have a similar python example for the B0-based remote API, in b0RemoteApiBindings/python.
If your controller is located in an external application, you simply have to run CoppeliaSim in synchronous mode, otherwise your controller won't be worth anything.

Cheers

Post Reply