Skip to content

Conversation

@swuuu
Copy link

@swuuu swuuu commented Oct 30, 2022

Description

I added a method to get the next position for each foot of SOLO.

How I Tested

I have compiled and tested this repository 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

@Lhumd
Copy link
Member

Lhumd commented Nov 4, 2022

@swuuu thanks a lot for the improvements.
Could you add reactive_planners with ROS2 that you have written to this pull request or make a new one?

@swuuu
Copy link
Author

swuuu commented Jan 31, 2023

  • The ROS 2 python and C++ translation of this demo has been added.
  • 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.

This PR is related to this:

@swuuu swuuu changed the title Add method to get the next position for each foot of SOLO Add method to get the next position for each foot of SOLO and transform project to ROS2 package Jan 31, 2023
@swuuu swuuu changed the title Add method to get the next position for each foot of SOLO and transform project to ROS2 package Add method to get the next position for each foot of SOLO, add ROS 2 demos, and transform project to ROS2 package Jan 31, 2023
Copy link
Contributor

@MaximilienNaveau MaximilienNaveau left a comment

Choose a reason for hiding this comment

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

Overall this is nice, but I do not understand the need for ament cmake here

@Lhumd Lhumd self-requested a review February 7, 2023 14:26
"""Demo file for running the reactive planner on SOLO 12
The logic is the same as the demo_reactive_planners_solo12_step_adjustment_walk.ipynb
This file is used for ROS 2. An example of the usage of this class is here:
https://github.com/swuuu/ros2_controllers_solo12/blob/master/ros2_control_test_nodes/ros2_control_test_nodes/node.py
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure that you update ros2_controllers_solo12 in the stack-of-tasks organization here, not in your GitHub.
Replace the link above with the one in stack-of-tasks.

Copy link
Author

Choose a reason for hiding this comment

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

The problem is that Olivier Stasse didn't want the packages containing the controllers to be in that repository: stack-of-tasks/ros2_control_solo#1 (review). Perhaps we could ask him to create a new repository?

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 totally fine. It's important to make sure it won't be multiple versions of the same code to avoid bugs:)
Create a new repository on your GitHub ros2_demo_solo for all demo nodes that we will have (or any name that you think is good ). We will add it to McGill organization GitHub in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

then I suggest to use a name that represent you organisation like we had with the machines-in-motion group:
mim_control

class Demo:
"""
Based on https://github.com/machines-in-motion/reactive_planners/blob/master/demos/demo_reactive_planners_solo12_step_adjustment_walk.ipynb
The 4 parameters to control the direction of SOLO are y_des, yaw_des, com_des, and v_des.
Copy link
Member

Choose a reason for hiding this comment

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

I suggest changing y_des's name to yaw_velocity_des.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@@ -0,0 +1,317 @@
"""Demo file for running the reactive planner on SOLO 12
Copy link
Member

Choose a reason for hiding this comment

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

Usually, we write a demo as a runnable file with the possibility of changing parameters based on user preference.
Your Demo class looks easy to understand and useful for users. write a main which call Demo class.
@MaximilienNaveau Do you think it's better to put the Demo class in the python folder?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not it's fine here.
I would just write a small main at the bottom of the file to run 1 reversion of the demo

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I can write a main() function. But as @Lhumd suggested, could I move this file to the python/reactive_planners/demos folder so that CMake will install() the script so I can use it in another package?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah if you want this demo to be part of the public API (other package can use it) then you must move it to the python folder.
But then find another name than demo something saying it's specific to solo and that it's a controller.

Copy link
Author

Choose a reason for hiding this comment

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

In the main function, you want me to run the code in pybullet. Is that correct?

:return: torques to send to SOLO
"""
# normalize the quat (maybe not needed)
normalized_quat = pin.Quaternion(
Copy link
Member

Choose a reason for hiding this comment

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

If q comes from Pinocchio or simulation means you are sure that q is correct, there is no need to normalize the quaternion.

q[6] = normalized_quat[3]

# transform the base velocity to the local frame
curr_orientation = normalized_quat.matrix()
Copy link
Member

Choose a reason for hiding this comment

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

Same here

xd_com = self.robot.pin_robot.com(q, qdot)[1]

# update the relevant params for the centroidal controller depending on the command
if action == "forward":
Copy link
Member

Choose a reason for hiding this comment

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

Considering this class as a generic class, I prefer not to limit the motion to the actions you wrote here. I suggest writing this part in a more general way without 'action'

Copy link
Contributor

Choose a reason for hiding this comment

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

just input v_des = [v_x, v_y, v_yaw]

*
* @brief A C++ translation of the demos/demo_reactive_planners_solo12_step_adjustment_walk.ipynb script (the first part)
*
* The 4 fields to control the direction of SOLO are y_des, yaw_des, com_des, and v_des
Copy link
Member

Choose a reason for hiding this comment

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

Same here for y_des

*
* @brief Implement the
* reactive_planners::demo_reactive_planners_solo12_step_adjustment class
*/
Copy link
Member

Choose a reason for hiding this comment

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

As far as I remember, the goal was to write a demo using C++ for solo12 to publish the torque on ros2. I didn't find any demo which does it in your pull request:-?

Copy link
Contributor

Choose a reason for hiding this comment

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

well it wouldn't really be the place to put that in.
If you wanna ROS2 integration better create a ros2_reactive_planners package or a ros2_control_reactive_planners, whatever name is clear for you to use.

Copy link
Member

Choose a reason for hiding this comment

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

👍

*/
compute_torques(Eigen::Matrix<double, 19, 1> &q, Eigen::Matrix<double, 18, 1> &dq, double control_time, const std::string& direction);

void quadruped_dcm_reactive_stepper_start();
Copy link
Member

Choose a reason for hiding this comment

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

We use Doxygen to generate documentation. Please add comments for every function and variable that you defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

Choose a reason for hiding this comment

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

in vscode there are some tools to help you write the doc for method and attribute

@@ -0,0 +1,317 @@
"""Demo file for running the reactive planner on SOLO 12
The logic is the same as the demo_reactive_planners_solo12_step_adjustment_walk.ipynb
This file is used for ROS 2. An example of the usage of this class is here:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you say it is used for ROS2? do you depend on ROS2? do you use rclcpp or rclpy?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, we have a ROS 2 node that uses demo_reactive_planners_solo12_step_adjustment_walk.py and demo_reactive_planners_solo12_step_adjustment_walk.cpp. We use both rclcpp and rclpy. But I agree, both the c++ and Python reactive planner demo files do not need to be used in a ROS2 node.

<license>BSD-3-Clause</license>

<depend>mpi_cmake_modules</depend>
<depend>yaml_utils</depend>
Copy link
Contributor

Choose a reason for hiding this comment

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

make sure you list all dependencies if you use such package.xml

make sure you add the build_tool you want use and export it:

    <!-- The following tags are recommended by REP-136 -->
  <exec_depend condition="$ROS_VERSION == 1">catkin</exec_depend>
  <exec_depend condition="$ROS_VERSION == 2">ament_cmake</exec_depend>


    <buildtool_depend>cmake</buildtool_depend>
    <export>
        <build_type>cmake</build_type>
    </export>

package.xml Outdated
<depend>mpi_cmake_modules</depend>
<depend>yaml_utils</depend>

</package> No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

add a new line in the end of all files

Eigen::Vector3d hind_left_next_foot_position_ =
biped_stepper_.get_next_support_foot_position() + base_yaw_rot * hl_offset_;

next_step_feet_pos.row(0) << front_left_next_foot_position_(0), front_left_next_foot_position_(1), front_left_next_foot_position_(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

next_step_feet_pos.row(0) << front_left_next_foot_position_; works here

CMakeLists.txt Outdated
INCLUDES
DESTINATION include)

# Install the header files so other ROS packages can find them
Copy link
Contributor

Choose a reason for hiding this comment

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

# Install the header files so other ROS packages can find them should be:
# Install the header files so other packages depending on this one can find them

Copy link
Contributor

@MaximilienNaveau MaximilienNaveau left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the work implementing example of the code.
Now if you wanna implement this on a real quadruped I suggest you actually create a ros2_reactive_planners package using ament_cmake this time and use either ros2_control controller API or rclcpp API to publish you input torque to the robot.

@Lhumd
Copy link
Member

Lhumd commented Feb 8, 2023

@MaximilienNaveau Thanks for the review.
We will create a new repository as you suggested for ros2 nodes.

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