How can I override the PID control on a motor?

Typically: "How do I... ", "How can I... " questions
Post Reply
jvitolla
Posts: 9
Joined: 14 Feb 2013, 16:50

How can I override the PID control on a motor?

Post by jvitolla »

Hello,

I'm building a simulation in V-REP in combination with MATLAB. I would like to know whether it is possible to bypass the embedded PID control that a motor enabled joint has, in order to implement a different kind of control. It would be useful for me to be able to control the electrical part from MATLAB and see the mechanical performance of the system.

Thanks a lot for your help!

Joseph

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

Re: How can I override the PID control on a motor?

Post by coppelia »

Hello,

You can write your own control, but remember following:

1) The implemented PID control will be running 10x for each simulation step. (by default: simulation time step=50ms, dynamic engine time step=5ms)
2) if you implement your own control, it will be running only 1x for each simulation step (each time your child script is executed). Unless you modify the source code. Or unless.. (see next item)
3) of course if you set the simulation time step to 5ms instead of the default 50ms, then you will run your script also every 5ms, which corresponds to the default control frequency of the embedded PID controller

If this is requested by enough people, we can implement a callback function, so that everyone could implement an efficient custom control algorithm

Cheers

jvitolla
Posts: 9
Joined: 14 Feb 2013, 16:50

Re: How can I override the PID control on a motor?

Post by jvitolla »

I understand from the reply that it is possible indeed to override the PID control through a customized script. What it is not yet clear to me is how to do it. How can I prevent the default PID from acting for controlling the speed with the set point that is shown in the Joint Dynamic properties dialog?

Once again, thanks a lot!

Cheers,

Joseph

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

Re: How can I override the PID control on a motor?

Post by coppelia »

One quick way would be to set the joint in force/torque mode, enable the motor, and disable the built-in PID control.

Then, from a script, you can do the control by adjusting the torque or maximum velocity appropriately (i.e. do your own PID for instance).
Use following API functions:

simSetJointForce

and

simSetObjectFloatParameter(jointHandle,2017,maxVelocity)

We are currently thinking about having a callback mechanism in order to be able to conveniently write a custom control loop. Or even another mechanism in Lua.

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

Re: How can I override the PID control on a motor?

Post by coppelia »

Hello again,

We can confirm that from next release on (V3.0.2) there will be a callback mechanism that allows you to write custom low-level joint controllers in Lua.

Cheers

Post Reply