-
Notifications
You must be signed in to change notification settings - Fork 0
584 task gripper controller merge into main we want juicy gripper inside of main #10
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
ApatShe
wants to merge
25
commits into
main
Choose a base branch
from
584-task-gripper-controller
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0c60579
refactor: renamed from encoder_read to read_encoders
forrisdahl 92ae9de
refactor: added num_servos constant and simplified uint16 to uint8 co…
forrisdahl b906d74
initial: initial commit
ApatShe 0fa7bd3
refactor: remove exceptions, send data in little endian
forrisdahl 7921014
fix: wrong offset in memcpy
forrisdahl af50e2c
moved controller module related files originally made in interface fo…
ApatShe 92e2ac6
Moved controller module to new, dedicated folder, added contents were…
ApatShe 3cc7138
made a guidance module which closely relates to reference_filter_dp i…
ApatShe c304c50
feat: add can interface
forrisdahl 2c3f684
feat: convert from i2c to can
forrisdahl 429ee30
feat: gripper controller skeleton implemented, builds and can launch …
ApatShe 8adf510
can -adjusted gripper interface n driver
ApatShe 4cd64cf
Merge remote-tracking branch 'origin/refactor/gripper_driver' into 58…
ApatShe 71848df
feat: implemented skeleton for can hardware interface a.w.a gripper s…
ApatShe 11842fe
idk
ApatShe 3b5ae25
Modified gripper controller to actually interface with gripper state …
ApatShe cd8e56c
guidance(gripper): refactor reference filter ROS node per PR review
ApatShe 080574a
guidance(gripper): const-correct local variables in filter math
ApatShe a9e3c7a
controller(gripper): apply const, lambdas and unique_ptr publish
ApatShe 6a33621
controller(gripper): const-correct local variables in control law
ApatShe eeebeb6
gripper: rename time step variables to include unit suffix
ApatShe 9e0bca5
guidance(gripper): move filter state ownership into GripperReferenceF…
ApatShe 6ff86a2
guidance(gripper): refactor reference filter ROS node per PR review
ApatShe 4dd1980
feat(gripper): add open-loop gripper controller package
ApatShe 6856962
gripper: fix short variable names per Code Complete ch. 6/11
ApatShe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| cmake_minimum_required(VERSION 3.8) | ||
| project(gripper_controller) | ||
|
|
||
| if(NOT CMAKE_CXX_STANDARD) | ||
| set(CMAKE_CXX_STANDARD 20) | ||
| endif() | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| add_compile_options(-Wall -Wextra -Wpedantic) | ||
| endif() | ||
|
|
||
| find_package(ament_cmake REQUIRED) | ||
| find_package(rclcpp REQUIRED) | ||
| find_package(rclcpp_action REQUIRED) | ||
| find_package(rclcpp_components REQUIRED) | ||
| find_package(vortex_msgs REQUIRED) | ||
| find_package(vortex_utils REQUIRED) | ||
| find_package(vortex_utils_ros REQUIRED) | ||
| find_package(Eigen3 REQUIRED) | ||
| find_package(spdlog REQUIRED) | ||
| find_package(fmt REQUIRED) | ||
|
|
||
| include_directories(include) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 1. Component Library (Shared) | ||
| # --------------------------------------------------------------------------- | ||
| set(LIB_NAME "${PROJECT_NAME}_component") | ||
|
|
||
| add_library(${LIB_NAME} SHARED | ||
| src/gripper_controller.cpp | ||
| src/gripper_controller_ros.cpp | ||
| ) | ||
|
|
||
| ament_target_dependencies(${LIB_NAME} PUBLIC | ||
| rclcpp | ||
| rclcpp_components | ||
| rclcpp_action | ||
| Eigen3 | ||
| vortex_msgs | ||
| vortex_utils | ||
| vortex_utils_ros | ||
| spdlog | ||
| fmt | ||
| ) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 2. Core Library (Static) - Used for Unit Testing | ||
| # --------------------------------------------------------------------------- | ||
| set(CORE_LIB_NAME "${PROJECT_NAME}_core") | ||
|
|
||
| add_library(${CORE_LIB_NAME} STATIC | ||
| src/gripper_controller.cpp | ||
| ) | ||
|
|
||
| ament_target_dependencies(${CORE_LIB_NAME} PUBLIC | ||
| Eigen3 | ||
| vortex_utils | ||
| ) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 3. Component Registration | ||
| # --------------------------------------------------------------------------- | ||
| rclcpp_components_register_node( | ||
| ${LIB_NAME} | ||
| PLUGIN "vortex::controller::GripperControllerNode" | ||
| EXECUTABLE ${PROJECT_NAME}_node | ||
| ) | ||
| # --------------------------------------------------------------------------- | ||
| # 4. Standalone Executable | ||
| # --------------------------------------------------------------------------- | ||
| add_executable(${PROJECT_NAME}_standalone | ||
| src/gripper_controller_node.cpp | ||
| ) | ||
| target_link_libraries(${PROJECT_NAME}_standalone PUBLIC | ||
| ${LIB_NAME} | ||
| ) | ||
| ament_target_dependencies(${PROJECT_NAME}_standalone PUBLIC | ||
| rclcpp | ||
| ) | ||
|
|
||
| ament_export_targets(export_${LIB_NAME}) | ||
| install(TARGETS ${LIB_NAME} ${PROJECT_NAME}_standalone | ||
| EXPORT export_${LIB_NAME} | ||
| ARCHIVE DESTINATION lib | ||
| LIBRARY DESTINATION lib | ||
| RUNTIME DESTINATION lib/${PROJECT_NAME} | ||
| ) | ||
|
|
||
| install(DIRECTORY include/ DESTINATION include) | ||
| install(DIRECTORY launch config DESTINATION share/${PROJECT_NAME}/) | ||
|
|
||
| if(BUILD_TESTING) | ||
| add_subdirectory(test) | ||
| endif() | ||
|
|
||
| ament_package() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /**: | ||
| ros__parameters: | ||
| # Control loop timing | ||
| time_step_ms: 10 # milliseconds — must match reference filter time step | ||
|
|
||
| # Proportional gain — tune after gear ratio calibration | ||
| # Diagonal P-controller: vel = diag(kp_roll, kp_pinch) * position_error | ||
| kp: | ||
| roll: 1.0 # TODO: tune | ||
| pinch: 1.0 # TODO: tune | ||
|
|
||
| # Topics | ||
| topics: | ||
| # Input: smoothed reference from the gripper reference filter | ||
| reference: "nautilus/gripper/guidance" | ||
| # Input: raw measured gripper state from the interface node | ||
| state: "nautilus/gripper/state" | ||
| # Output: velocity command to the interface node | ||
| control: "nautilus/gripper/control" |
32 changes: 32 additions & 0 deletions
32
gripper_controller/include/gripper_controller/gripper_controller.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_HPP_ | ||
| #define GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_HPP_ | ||
|
|
||
| #include "gripper_controller/gripper_controller_typedefs.hpp" | ||
|
|
||
|
|
||
| class GripperController { | ||
| public: | ||
| GripperController(); | ||
|
|
||
| // @brief Calculate velocity command from position error | ||
| // @param state: struct containing measured gripper state [roll, pinch] | ||
| // @param reference: struct containing desired gripper state [roll, pinch] | ||
| // @return 2D vector containing velocity commands [roll_vel, pinch_vel] | ||
| types::Vector2d calculate_velocity(const types::GripperState& state, | ||
| const types::GripperState& reference); | ||
|
|
||
| // @brief Set the proportional gain matrix | ||
| // @param Kp: 2x2 matrix containing the proportional gain matrix | ||
| void set_kp(const types::Matrix2d& Kp); | ||
|
|
||
| // @brief Set the time step | ||
| // @param dt: time step in seconds | ||
| void set_time_step(double timestep); | ||
|
|
||
| private: | ||
| types::Matrix2d Kp_; | ||
| double timestep_; | ||
| }; | ||
|
|
||
|
|
||
| #endif // GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_HPP_ | ||
64 changes: 64 additions & 0 deletions
64
gripper_controller/include/gripper_controller/gripper_controller_ros.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #ifndef GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_ROS_HPP_ | ||
| #define GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_ROS_HPP_ | ||
|
|
||
| #include <chrono> | ||
| #include <functional> | ||
| #include <mutex> | ||
| #include <rclcpp/rclcpp.hpp> | ||
| #include <rclcpp_components/register_node_macro.hpp> | ||
| #include <vortex_msgs/msg/gripper_reference_filter.hpp> | ||
| #include <vortex_msgs/msg/gripper_state.hpp> | ||
| #include <vortex_msgs/msg/gripper_state_velocity_command.hpp> | ||
| #include <vortex/utils/ros/qos_profiles.hpp> | ||
| #include "gripper_controller/gripper_controller.hpp" | ||
| #include "gripper_controller/gripper_controller_translator.hpp" | ||
| #include "gripper_controller/gripper_controller_typedefs.hpp" | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Responsibility: ROS wiring only — subscriptions, publications, parameter | ||
| // loading, and timer setup. All control mathematics live in GripperController. | ||
| // All message translation lives in gripper_controller::translator. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| namespace vortex::controller { | ||
|
|
||
| class GripperControllerNode : public rclcpp::Node { | ||
| public: | ||
| explicit GripperControllerNode(const rclcpp::NodeOptions & options); | ||
|
|
||
| private: | ||
| void reference_callback( | ||
| const vortex_msgs::msg::GripperReferenceFilter::SharedPtr reference_msg); | ||
|
|
||
| void state_callback( | ||
| const vortex_msgs::msg::GripperState::SharedPtr state_msg); | ||
|
|
||
| void publish_control(); | ||
|
|
||
| void set_controller_params(); | ||
|
|
||
| void set_subscribers_and_publisher(); | ||
|
|
||
| GripperController controller_; | ||
|
|
||
| rclcpp::Subscription<vortex_msgs::msg::GripperReferenceFilter>::SharedPtr | ||
| reference_sub_; | ||
| rclcpp::Subscription<vortex_msgs::msg::GripperState>::SharedPtr | ||
| state_sub_; | ||
| rclcpp::Publisher<vortex_msgs::msg::GripperStateVelocityCommand>::SharedPtr | ||
| control_pub_; | ||
|
|
||
| rclcpp::TimerBase::SharedPtr control_timer_; | ||
| std::chrono::milliseconds time_step_; | ||
|
|
||
| std::mutex state_mutex_; | ||
|
|
||
| double roll_ref_ = 0.0; | ||
| double pinch_ref_ = 0.0; | ||
| double roll_measured_ = 0.0; | ||
| double pinch_measured_ = 0.0; | ||
| }; | ||
|
|
||
| } // namespace vortex::controller | ||
|
|
||
| #endif // GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_ROS_HPP_ |
49 changes: 49 additions & 0 deletions
49
gripper_controller/include/gripper_controller/gripper_controller_translator.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #ifndef GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_TRANSLATOR_HPP_ | ||
| #define GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_TRANSLATOR_HPP_ | ||
|
|
||
| #include <vortex_msgs/msg/gripper_reference_filter.hpp> | ||
| #include <vortex_msgs/msg/gripper_state.hpp> | ||
| #include <vortex_msgs/msg/gripper_state_velocity_command.hpp> | ||
| #include "gripper_controller/gripper_controller_typedefs.hpp" | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Responsibility: translate between domain structs and ROS message types. | ||
| // This is intentionally a namespace of stateless free functions rather than | ||
| // a class — there is no invariant to maintain, no state to encapsulate. | ||
| // Keeping translation logic here (instead of inside the node) satisfies SRP: | ||
| // the node only orchestrates, the translator only converts. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| namespace gripper_controller::translator { | ||
|
|
||
| /// @brief Extract position-only GripperState from a smoothed reference message. | ||
| inline types::GripperState reference_filter_msg_to_gripper_state( | ||
| const vortex_msgs::msg::GripperReferenceFilter& reference_filter_msg) { | ||
| types::GripperState gripper_state; | ||
| gripper_state.roll = reference_filter_msg.roll; | ||
| gripper_state.pinch = reference_filter_msg.pinch; | ||
| return gripper_state; | ||
| } | ||
|
|
||
| /// @brief Convert a raw GripperState ROS message to the domain GripperState struct. | ||
| inline types::GripperState gripper_state_msg_to_gripper_state( | ||
| const vortex_msgs::msg::GripperState& gripper_state_msg) { | ||
| types::GripperState gripper_state; | ||
| gripper_state.roll = gripper_state_msg.roll; | ||
| gripper_state.pinch = gripper_state_msg.pinch; | ||
| return gripper_state; | ||
| } | ||
|
|
||
| /// @brief Pack a 2D velocity command vector into a GripperStateVelocityCommand message. | ||
| inline vortex_msgs::msg::GripperStateVelocityCommand | ||
| velocity_command_to_gripper_velocity_command_msg( | ||
| const types::Vector2d& velocity_command) { | ||
| vortex_msgs::msg::GripperStateVelocityCommand velocity_command_msg; | ||
| velocity_command_msg.roll_velocity = velocity_command(0); | ||
| velocity_command_msg.pinch_velocity = velocity_command(1); | ||
| return velocity_command_msg; | ||
| } | ||
|
|
||
| } // namespace gripper_controller::translator | ||
|
|
||
| #endif // GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_TRANSLATOR_HPP_ |
22 changes: 22 additions & 0 deletions
22
gripper_controller/include/gripper_controller/gripper_controller_typedefs.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_TYPEDEFS_HPP_ | ||
| #define GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_TYPEDEFS_HPP_ | ||
|
|
||
| #include <eigen3/Eigen/Dense> | ||
|
|
||
| namespace types { | ||
|
|
||
| using Vector2d = Eigen::Vector2d; | ||
| using Matrix2d = Eigen::Matrix2d; | ||
|
|
||
| struct GripperState { | ||
| double roll = 0.0; | ||
| double pinch = 0.0; | ||
| }; | ||
|
|
||
| // Velocity saturation limits — tune after gear ratio calibration | ||
| constexpr double MAX_ROLL_VEL = 1.0; // TODO: tune | ||
| constexpr double MAX_PINCH_VEL = 1.0; // TODO: tune | ||
|
|
||
| } // namespace types | ||
|
|
||
| #endif // GRIPPER_CONTROLLER__GRIPPER_CONTROLLER_TYPEDEFS_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import os | ||
| from ament_index_python.packages import get_package_share_directory | ||
| from launch import LaunchDescription | ||
| from launch_ros.actions import Node | ||
|
|
||
| def generate_launch_description(): | ||
| config_file_path = os.path.join( | ||
| get_package_share_directory("gripper_controller"), | ||
| "config", | ||
| "gripper_controller_params.yaml", | ||
| ) | ||
|
|
||
| gripper_controller_node = Node( | ||
| package="gripper_controller", | ||
| executable="gripper_controller_standalone", | ||
| name="gripper_controller_node", | ||
| parameters=[config_file_path], | ||
| output="screen", | ||
| ) | ||
|
|
||
| return LaunchDescription([gripper_controller_node]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0"?> | ||
| <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
| <package format="3"> | ||
| <name>gripper_controller</name> | ||
| <version>0.0.0</version> | ||
| <description>Package for the control algorithm of the gripper</description> | ||
| <maintainer email="patricsh@stud.ntnu.no">patricsh</maintainer> | ||
| <license>MIT</license> | ||
|
|
||
| <buildtool_depend>ament_cmake</buildtool_depend> | ||
|
|
||
| <depend>rclcpp</depend> | ||
| <depend>rclcpp_action</depend> | ||
| <depend>rclcpp_components</depend> <depend>geometry_msgs</depend> | ||
| <depend>vortex_msgs</depend> | ||
| <depend>vortex_utils</depend> | ||
| <depend>vortex_utils_ros</depend> | ||
|
|
||
| <depend>eigen</depend> | ||
| <depend>spdlog</depend> | ||
| <depend>fmt</depend> | ||
|
|
||
| <test_depend>ament_cmake_gtest</test_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
| </export> | ||
| </package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include "gripper_controller/gripper_controller.hpp" | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| GripperController::GripperController() | ||
| : Kp_(types::Matrix2d::Identity()), timestep_(0.01) {} | ||
|
|
||
| types::Vector2d GripperController::calculate_velocity( | ||
| const types::GripperState& measured_state, | ||
| const types::GripperState& reference_state) { | ||
|
|
||
| const types::Vector2d position_error = [&] { | ||
| types::Vector2d error; | ||
| error(0) = reference_state.roll - measured_state.roll; | ||
| error(1) = reference_state.pinch - measured_state.pinch; | ||
| return error; | ||
| }(); | ||
|
|
||
| types::Vector2d velocity_command = Kp_ * position_error; | ||
|
|
||
| velocity_command(0) = std::clamp(velocity_command(0), | ||
| -types::MAX_ROLL_VEL, | ||
| types::MAX_ROLL_VEL); | ||
| velocity_command(1) = std::clamp(velocity_command(1), | ||
| -types::MAX_PINCH_VEL, | ||
| types::MAX_PINCH_VEL); | ||
|
|
||
| return velocity_command; | ||
| } | ||
|
|
||
| void GripperController::set_kp(const types::Matrix2d& proportional_gain_matrix) { | ||
| Kp_ = proportional_gain_matrix; | ||
| } | ||
|
|
||
| void GripperController::set_time_step(double timestep) { | ||
| timestep_ = timestep; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #include <rclcpp/rclcpp.hpp> | ||
| #include "gripper_controller/gripper_controller_ros.hpp" | ||
|
|
||
| int main(int argc, char** argv) { | ||
| rclcpp::init(argc, argv); | ||
|
|
||
| auto gripper_controller_node = | ||
| std::make_shared<vortex::controller::GripperControllerNode>( | ||
| rclcpp::NodeOptions()); | ||
|
|
||
| rclcpp::spin(gripper_controller_node); | ||
| rclcpp::shutdown(); | ||
| return 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
timestep_s_?