-
Notifications
You must be signed in to change notification settings - Fork 825
PID implementation inside mujoco-py #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d0333f6 to
5999d90
Compare
MillionIntegrals
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments on this PR.
mujoco_py/mjpid.pyx
Outdated
|
|
||
| for i in range(m.nu): | ||
| m.actuator_gaintype[i] = const.GAIN_USER | ||
| m.actuator_biastype[i] = const.BIAS_USER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should override that manually for the actuators here. That should be specified in the XML file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also would like it to be opt-in, but on the XML level - then we can have multiple hands, one with PID Controller, one without. We can have even these two hand in the same simulation. Or we can have kuka arm with P controllers and a shadow hand with PID controllers. The more things we allow to configure via XML the better for flexibility.
mujoco_py/mjpid.pyx
Outdated
|
|
||
| # if user does not set, will chose default settings. | ||
| # for kp, it tries to use m.actuator_gainprm[i][0] | ||
| if m.actuator_user[i][PROPORTIONAL_GAIN] <= 0.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's not that important, but why not use gainprm for this purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also see this kind of as a good thing. If we keep the kp at the same position, just by changing the gaintype from user to position, we can change between the P and PID controller with the same P value. Pretty cool, isn't it?
|
No! They are that way for a reason!
…On Fri, Oct 4 2019 at 15:47, Jonas Schneider < ***@***.*** > wrote:
***@***.**** commented on this pull request.
Few comments on this PR.
In mujoco_py/mjpid.pyx (
#462 (comment) ) :
> + return fmax(-corrective_effort_limit, fmin(corrective_effort_limit,
f)) + + +def set_pid_control(m, d): + global mjcb_act_gain + global
mjcb_act_bias + + if m.nuserdata < m.nu * NUM_USER_DATA_PER_ACT: + raise
Exception('nuserdata is not set large enough to store PID internal
states') + + for i in range(m.nuserdata): + d.userdata[i] = 0.0 + + for i
in range(m.nu): + m.actuator_gaintype[i] = const.GAIN_USER +
m.actuator_biastype[i] = const.BIAS_USER
I don't think we should override that manually for the actuators here.
That should be specified in the XML file.
In mujoco_py/mjpid.pyx (
#462 (comment) ) :
> + global mjcb_act_gain + global mjcb_act_bias + + if m.nuserdata < m.nu
* NUM_USER_DATA_PER_ACT: + raise Exception('nuserdata is not set large
enough to store PID internal states') + + for i in range(m.nuserdata): +
d.userdata[i] = 0.0 + + for i in range(m.nu): + m.actuator_gaintype[i] =
const.GAIN_USER + m.actuator_biastype[i] = const.BIAS_USER + + # if user
does not set, will chose default settings. + # for kp, it tries to use
m.actuator_gainprm[i][0] + if m.actuator_user[i][PROPORTIONAL_GAIN] <=
0.0:
I know it's not that important, but why not use gainprm for this purpose?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub (
#462?email_source=notifications&email_token=AI2BVUG7OIRU6EGRC6MHYR3QM7BXRA5CNFSM4I5UQIR2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCG7UHXQ#pullrequestreview-297747422
) , or mute the thread (
https://github.com/notifications/unsubscribe-auth/AI2BVUCT3PUHR3Y3SE55HZTQM7BXRANCNFSM4I5UQIRQ
).
|
bayesian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update soon with Author's comments
MillionIntegrals
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve this change, but let's make sure @arthurpetron is also happy
53580d9 to
4394dcc
Compare
mujoco_py/mjpid.pyx
Outdated
| cdef double integral_time_const = m.actuator_gainprm[id * NGAIN + INTEGRAL_TIME_CONSTANT] | ||
| cdef double derivative_gain_smoothing = \ | ||
| m.actuator_gainprm[id * NGAIN + DERIVATIVE_GAIN_SMOOTHING] | ||
| cdef double derivate_time_const = m.actuator_gainprm[id * NGAIN + DERIVATIVE_TIME_CONSTANT] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By DERIVATIVE_TIME_CONSTANT do you actually mean DERIVATIVE_TIME_CONSTANT_ID? Same comment for lines 44 - 50 and lines 20 - 25 and lines 29 - 32. What is NGAIN? Is it also an ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DERIVATIVE_TIME_CONSTANT is the index for the field, NGAIN is the total number of parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to IDX_
arthurpetron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please label ID's as IDs to prevent future confusion. Otherwise looks good. Thanks!!
b7ba610 to
83a6d60
Compare
|
Thanks for a great PR! May I ask you if it is working fine with shadow robot hand? I was trying to use this PID control, but the finger control does not work anymore, the fingers don't move a bit. I tried also the P control equivalent case based on the commited pid_test, but the fingers are still immobile. If the shadow robot should work I will open a separate issue. |
|
yes, it works for us on our shadow hand simulation and policy training, it is also backward compatible. you need to change xml and call set_pid_control, like in the test_pid.py in the PR. |
|
Thank you for your quick answer! But are you always setting up both gaintype and biastype to "user"? If I define gaintype="user" the fingers stop any movement. Edit: would it be possible to share an example of the shadow robot dexterous hand model which uses PID so that I can find where my mistake lay? Edit2: I have created corresponding issue with the prepared repository for problem reproduction. |
|
you have to set biastype="user" and gaintype="user", as our pid implementation use user-defined callback: mjcb_act_gain and mjcb_act_bias to implement full PID control. you can read more about mujoco actuator model here: http://www.mujoco.org/book/XMLreference.html#actuator in our shadow robot model, it has something like: |
|
Hi, |
|
you are free to choose the PID settings, the example settings are from one of my experiments. our hand model used for sim2real is a bit different from gym version. |
Expose 5 new parameters for full PID with clamp/smoothing.
test plans: