Skip to content

Conversation

@bayesian
Copy link
Contributor

@bayesian bayesian commented Oct 4, 2019

Expose 5 new parameters for full PID with clamp/smoothing.

test plans:

  1. verified the correctness, when client do not specify new parameters, PID behaves like P
  2. for mujoco_shadow_hand test, with global I/D settings, position errors after 100 steps become smaller.
  3. unit tests all with inverted pendulum

Copy link
Contributor

@MillionIntegrals MillionIntegrals left a 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.


for i in range(m.nu):
m.actuator_gaintype[i] = const.GAIN_USER
m.actuator_biastype[i] = const.BIAS_USER
Copy link
Contributor

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.

Copy link
Contributor

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.


# 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:
Copy link
Contributor

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?

Copy link
Contributor

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?

@arthurpetron
Copy link

arthurpetron commented Oct 4, 2019 via email

Copy link
Contributor Author

@bayesian bayesian left a 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

Copy link
Contributor

@MillionIntegrals MillionIntegrals left a 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

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]

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to IDX_

Copy link

@arthurpetron arthurpetron left a 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!!

@bayesian bayesian merged commit 83759c2 into master Oct 8, 2019
@MillionIntegrals MillionIntegrals deleted the tao_mujoco_pid branch October 8, 2019 23:45
@jborbik
Copy link

jborbik commented Oct 24, 2019

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.

@bayesian
Copy link
Contributor Author

bayesian commented Oct 24, 2019

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.

@jborbik
Copy link

jborbik commented Oct 25, 2019

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.

@bayesian
Copy link
Contributor Author

bayesian commented Oct 25, 2019

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:

    <general gaintype="user" biastype="user" class="asset_class" ctrlrange="0.0 1.5708" forcerange="-0.2 0.2" joint="FFJ2" gainprm="1.0 5.0 0.2 0.05 0.1 0.0" name="A_FFJ2" user="2002"/>

@brinij
Copy link

brinij commented Nov 15, 2019

Hi,
I would also like to have shadow hand mujoco simulation with PID controller.
My only question now is: are you using the same hand model that is in gym environments: robotics/assets/hand/shared.xml or some other? Because the joint names are not quite the same and I am wondering weather this PID parameters will work on other model as well?
Thank you in advance!

@bayesian
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants