Skip to content

Refactor the robotic manipulation package #11

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

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

Conversation

knicked
Copy link
Contributor

@knicked knicked commented Mar 24, 2025

This PR refactors the robotic manipulation package to improve the quality of the code. In particular, this PR:

  • Decouples service initialization code with node spinning code
  • Renames the StateController class to better mirror its purpose
  • Replaces magic values with constants
  • Formats all the files using clang-format
  • Adds a license note to every source code file
  • Fills the package description and license information in package.xml

@jhanca-robotecai jhanca-robotecai self-requested a review March 25, 2025 15:49
@jhanca-robotecai jhanca-robotecai removed their assignment Mar 25, 2025
Base automatically changed from kd/wait_for_clock to development March 28, 2025 12:02
@jhanca-robotecai
Copy link
Collaborator

Rebased and force-pushed your branch after integrating other changes to the repository.

rclcpp::executors::SingleThreadedExecutor m_executor;

std::vector<double> m_startingPose;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which configuration of clang-format did you use? It is quite strange the tool did not add a line break here.

Please add the configuration file to the repository to ensure every developer uses the same one. I suggest using the same one as in other projects within this namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a configuration file I found in the RAI repository and reformated the files again.

target_include_directories(robotic_manipulation PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_features(robotic_manipulation PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_compile_features(robotic_manipulation PUBLIC c_std_99 cxx_std_20) # Require C99 and C++20
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any particular reason for c++20?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

std::numbers::pi is the reason. Before C++20, no standard constant for π was defined.

auto logger = m_node->get_logger();

const int NumTries = 10;
int const NumTries = 10;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might have used constexpr for such value, hence the pre-compiler could use it directly in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced const with constexpr.


class RaiManipulationInterfaceNode {
public:
RaiManipulationInterfaceNode();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happened to the destructor? Don't you need to destroy the services anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The services will get destroyed automatically when the shared_ptrs stored in this class get destroyed. Previously the destructor was here to shut down the executor thread, which wasn't even used since we spin the node in the main thread now, so I removed it.

Comment on lines 22 to 30
// The joint values for the gripper to be open and closed.
double const OpenGripperJointValue = 0.038;
double const ClosedGripperJointValue = 0.002;

// The base orientation of the end effector resulting in the gripper pointing
// straight down.
double const EndEffectorBaseRoll = 0.0;
double const EndEffectorBasePitch = std::numbers::pi;
double const EndEffectorBaseYaw = tf2Radians(45.0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we define these within the header of the class in the private section (as static constexpr)? Or in the anonymous namespace? We do not want to populate it everywhere in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved these constants into the class header and made them constexpr.

@@ -12,16 +26,20 @@ int main(int argc, char *argv[]) {
auto armController = std::make_shared<ArmController>();
armController->Initialize();

armController->MoveThroughWaypoints({armController->CalculatePose(0.3, 0.0, 0.35)});
armController->MoveThroughWaypoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some magick numbers left here.

Signed-off-by: Kacper Dąbrowski <[email protected]>
knicked added 3 commits March 31, 2025 15:11
Signed-off-by: Kacper Dąbrowski <[email protected]>
Signed-off-by: Kacper Dąbrowski <[email protected]>
Signed-off-by: Kacper Dąbrowski <[email protected]>
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.

2 participants