-
Notifications
You must be signed in to change notification settings - Fork 12
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
RNEA method #125
RNEA method #125
Conversation
…nto fix-issue-102
Fix issue 102
Remove the extF and Tau
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.
Thanks @Tianhuanyu! This is great! I have some feedback (please see comments). Also, you should run black on the files you modify - this will ensure the code formatting is correct.
Please also address the todo list in the PR description above. |
Could you also make sure to add a unit test in |
Thanks, @cmower . I try black for reformatting my code. It's fantastic. All the following parts are done within this update. |
Sure, but I find there is always a small error between PyBullet output and our RNEA. (around 0.5% or less). Maybe Pybullet uses a different method for computing inverse dynamics or it may consider friction. Currently, the error doesn't have much effect on my application. It maybe a long-term work to find out why the numbers are slightly different. |
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.
Hi @Tianhuanyu, thanks for the updates. Just a couple more changes.
Also, could you please add a unit test (that compares RobotModel.rnea
to PyBullet) into tests/test_models.py
. The small error you see is fine. As you mention, PyBullet probably takes into account friction or maybe other things. The test is good to have though because it verifies i) you're implementation is working (i.e. the code runs), and ii) the values it outputs are "pretty much" what we expect. Take a look here for more details about the implementation of RNEA in PyBullet.
Comments modification
Thanks. @cmower I've submitted the modification for the two minor suggestion. I will submit the testing part as soon as possible. |
Great, thanks @Tianhuanyu. |
Testing part error threshold is 0.08
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.
Thanks @Tianhuanyu, some last requests. After you've made these changes we should be able to merge this PR :)
tests/test_rnea.py
Outdated
# Setup model (with no parameterized joints) | ||
model = optas.RobotModel(urdf_filename=urdf_path) | ||
|
||
pb.connect(*[pb.DIRECT]) |
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.
Replace line with:
pb.connect(pb.DIRECT)
tests/test_rnea.py
Outdated
def test_calculate_inverse_dynamics_symbol(self): | ||
for _ in range(NUM_RANDOM): | ||
q = optas.SX.sym("q", self.model.ndof) | ||
qd = optas.SX.sym("qd", self.model.ndof) | ||
qdd = optas.SX.sym("qdd", self.model.ndof) | ||
tau1 = self.model.rnea(q, qd, qdd) | ||
assert isinstance(tau1, optas.SX) |
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.
No need to run this in a loop, checking symbolic output only needs to be done once.
tests/test_rnea.py
Outdated
) | ||
# print(tau1) | ||
# print(tau2) | ||
assert isclose(tau1.T, tau2) |
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.
The value for tau1
is being returned as an optas.DM
variable, and is a vector. I suggest using
assert isclose(tau1.toarray().flatten(), tau2)
toarray
converts the optas.DM
variable to a numpy array
tests/test_rnea.py
Outdated
def main(q=None): | ||
test = TestRnea() | ||
test.test_calculate_inverse_dynamics_symbol() | ||
test.test_calculate_inverse_dynamics() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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.
Remove, pytest doesn't require a main
function.
tests/test_rnea.py
Outdated
NUM_RANDOM = 100 | ||
|
||
|
||
class TestRnea: |
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 move this class to tests/test_models.py
. No need for the additional script.
additional notes
Fixed test model
Torque Control Demo
Fix issue 102
Fix issue 102
Description
The RNEA method is added to model module of optas for computing inverseDynamics. Given q, qd, qdd, the function could return a external force vector.
The RNEA is tested with test_rnea.py
The current version of RNEA only supports the robots with:
Todo