Skip to content
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

Add impedance control method computed in local frame for c++, fix centroidal controller quaternion bug, and transform to ROS 2 package #29

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

swuuu
Copy link

@swuuu swuuu commented Oct 30, 2022

Description

I added a C++ impedance control method called ImpedanceController::run_local() that is equivalent to compute_impedance_torques() in the python/impedance_controller.py. This made it easier for me to write this file in C++.

How I Tested

I tested this on SOLO-12 in Gazebo.

I fulfilled the following requirements

  • All new code is formatted according to our style guide (for C++ run clang-format, for Python, run flake8 and fix all warnings).
  • All new functions/classes are documented and existing documentation is updated according to changes.
  • No commented code from testing/debugging is kept (unless there is a good reason to keep it).

@swuuu
Copy link
Author

swuuu commented Oct 30, 2022

@Lhumd

@swuuu swuuu marked this pull request as draft January 2, 2023 16:36
…dify c++ impedance algo in world frame, and modify cmake & package.xml so other ROS packages can use this
@swuuu swuuu marked this pull request as ready for review January 31, 2023 04:09
@swuuu
Copy link
Author

swuuu commented Jan 31, 2023

A few other changes:

  • In the centroidal controller python file, instead of using the local function to compute the quaternion difference, I called a Pinocchio helper function to do it instead (i.e., pin.log3()). It fixes a bug in this file here, where if SOLO 12 keeps on turning, it will become unstable and fall.
  • I added a package.xml and ament_cmake commands in the CMakeLists.txt for external ROS 2 C++ scripts to link with this package. Essentially, the changes transform this repository into a ROS 2 package so other ROS 2 packages can use it.

Related to this PR:

@swuuu swuuu changed the title Add impedance control method computed in local frame for c++ Add impedance control method computed in local frame for c++, fix centroidal controller quaternion bug, and transform to ROS 2 package Jan 31, 2023
CMakeLists.txt Outdated Show resolved Hide resolved
@Lhumd Lhumd self-requested a review February 8, 2023 03:52
@@ -4,7 +4,7 @@
* @copyright Copyright (c) 2020, New York University and Max Planck
* Gesellschaft
*
* @brief This is the implementation for impedance controller between any two
* @brief This is the implementation for mim_control_ controller between any two
Copy link
Member

Choose a reason for hiding this comment

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

I think impedance was correct.


/** @brief Output torques. */
Eigen::VectorXd joint_torques_;
class ImpedanceController
Copy link
Member

Choose a reason for hiding this comment

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

Use mpi_cmake_modules to change the format of your code and make it similar to others files in this repo.

Copy link
Member

Choose a reason for hiding this comment

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

It's not easy to review this package because of using a different format.

Copy link
Author

Choose a reason for hiding this comment

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

Are you referring to this: https://github.com/machines-in-motion/mpi_cmake_modules/blob/master/doc/clang_format.md? If so, I couldn't get it to work (command not found even though I sourced my workspace folder). For now, I just un-indented the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

try with dash instead of underscore
run-clang-format

Copy link
Author

Choose a reason for hiding this comment

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

After running run-clang-format absolute-path-to-file absolute-path-to-folder, I get this error message: run-clang-format: error: Command 'clang-format --version' failed to start: [Errno 2] No such file or directory: 'clang-format'. Do you know what is causing it?

Copy link
Contributor

Choose a reason for hiding this comment

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

sudo apt install clang-format?

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes, thank you


} // namespace mim_control
} // namespace mim_control_
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for changing this line 🤔

Copy link
Author

Choose a reason for hiding this comment

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

No reason, I think I did a search and replace which was wrong. I reverted it back.

@@ -1,10 +1,3 @@
##################################################################################################################
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for deleting this? You can use a different format if you want it to look like others.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what happened, I added it back.

@@ -70,7 +63,8 @@ def compute_com_wrench(self, q, dq, des_pos, des_vel, des_ori, des_angvel):
vcom = np.reshape(np.array(dq[0:3]), (3,))
Ib = robot.mass(q)[3:6, 3:6]

quat_diff = self.quaternion_difference(arr(q[3:7]), arr(des_ori))
tmp = pin.Quaternion(des_ori[3], des_ori[0], des_ori[1], des_ori[2]) * pin.Quaternion(q[6], q[3], q[4], q[5]).conjugate()
Copy link
Member

Choose a reason for hiding this comment

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

Does self.quaternion_difference work? If it doesn't work, please replace your code with the code in the function and here only call the function.

@Lhumd Lhumd self-requested a review February 8, 2023 04:12
@swuuu swuuu requested review from MaximilienNaveau and Lhumd and removed request for Lhumd and MaximilienNaveau February 23, 2023 21:33
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.

3 participants