-
Notifications
You must be signed in to change notification settings - Fork 259
Add first example robot (rrbot as system) #37
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
f0d7186
Implementation of RRBot System Headless Hardware with only position j…
destogl 773d0c3
rrbot system position only after first testing.
destogl 89dbaef
Added description of rrbot and example ros2_control_manager.
destogl e6c9fbf
ROS2 Managers are moved to controller_interface package
destogl c0e60ab
Update README.md
destogl f6fddee
Add controlle to example 1 and adapt the hardware to provide more sen…
destogl 8336c52
Merge branch 'add_rrbot_system_position_joints' of https://github.com…
destogl bb0d4c3
Added controller to install path
destogl 4edaf31
Change parameter names because deprecated
destogl 87bf1fe
Reorganize controller's yaml to have correct parameters' namespace. C…
destogl 8eec4e0
Corrected licence header and add explicit type instead of auto
destogl 81f6551
Update README.md
destogl ccfb6e5
Update parameter and launch
destogl ec0f715
Merge branch 'add_rrbot_system_position_joints' of https://github.com…
destogl de05e13
Update README.md
destogl 75f5625
Reorganize to new RM structure
destogl 79c6323
Merge branch 'add_rrbot_system_position_joints' of https://github.com…
destogl c8935f0
Update README.md
destogl 0cb4877
Updated to new status
destogl 1e7fbb6
Adapt brances and additional output
destogl 7b818d3
Merge branch 'add_rrbot_system_position_joints' of https://github.com…
destogl f44d20b
Add parsing robot_description via xacro. (#45)
livanov93 84def18
Merge branch 'master' into add_rrbot_system_position_joints
destogl 01b428b
Remove URDF file
destogl 8fe9b66
Merge branch 'add_rrbot_system_position_joints' of https://github.com…
destogl 382bc1c
Update description
destogl bfeeeee
Update linters.yaml
destogl 4f0ddb1
Update ci.yml
destogl 5ba9659
Add dependencies
destogl 5f68b67
Update ci.yml
destogl f18145a
Update CMakeLists.txt
destogl ea5be37
Update package.xml
destogl 9f4a384
Delete code_coverage.yml
destogl b630ceb
Update ci.yml
destogl c69b80f
Update ci.yml
destogl 881c06a
Update linters.yaml
destogl 9cca40b
Update linters.yaml
destogl cd977b2
Update ros2_control_demo_hardware/include/ros2_control_demo_hardware/…
destogl 635ed68
Update ros2_control_demo_hardware/src/rrbot_system_position_only.cpp
destogl 732a3bc
Address review comments.
destogl 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
97 changes: 97 additions & 0 deletions
97
ros2_control_demo_hardware/include/ros2_control_demo_hardware/rrbot_system_position_only.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,97 @@ | ||
| // Copyright 2020 ROS2-Control Development Team | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
|
|
||
| #ifndef ROS2_CONTROL_DEMO_HARDWARE__RRBOT_SYSTEM_POSITION_ONLY_HPP_ | ||
| #define ROS2_CONTROL_DEMO_HARDWARE__RRBOT_SYSTEM_POSITION_ONLY_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "rclcpp/macros.hpp" | ||
|
|
||
| #include "hardware_interface/system_hardware_interface.hpp" | ||
| #include "hardware_interface/types/hardware_interface_return_values.hpp" | ||
| #include "hardware_interface/types/hardware_interface_status_values.hpp" | ||
| #include "ros2_control_demo_hardware/visibility_control.h" | ||
destogl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using hardware_interface::components::Joint; | ||
| using hardware_interface::components::Sensor; | ||
| using hardware_interface::HardwareInfo; | ||
| using hardware_interface::hardware_interface_status; | ||
| using hardware_interface::return_type; | ||
|
|
||
| namespace hardware_interface | ||
| { | ||
|
|
||
| // TODO(all): This could be templated for Joint, Sensor and System Interface | ||
| class BaseSystemHardwareInterface : public SystemHardwareInterface | ||
| { | ||
| public: | ||
| return_type configure(const HardwareInfo & system_info) override | ||
| { | ||
| info_ = system_info; | ||
| status_ = hardware_interface_status::CONFIGURED; | ||
| return return_type::OK; | ||
| } | ||
|
|
||
| std::string get_name() const final | ||
| { | ||
| return info_.name; | ||
| } | ||
|
|
||
| hardware_interface_status get_status() const final | ||
| { | ||
| return status_; | ||
| } | ||
|
|
||
| protected: | ||
| HardwareInfo info_; | ||
| hardware_interface_status status_; | ||
| }; | ||
|
|
||
| } // namespace hardware_interface | ||
|
|
||
| namespace ros2_control_demo_hardware | ||
| { | ||
| class RRBotSystemPositionOnlyHardware : public hardware_interface::BaseSystemHardwareInterface | ||
| { | ||
| public: | ||
| RCLCPP_SHARED_PTR_DEFINITIONS(RRBotSystemPositionOnlyHardware); | ||
|
|
||
| return_type configure(const HardwareInfo & system_info) override; | ||
|
|
||
| return_type start() override; | ||
|
|
||
| return_type stop() override; | ||
|
|
||
| // TODO(all): Add a new "sensor not exitst" error? | ||
| return_type read_sensors(std::vector<std::shared_ptr<Sensor>> & /*sensors*/) const override | ||
| { | ||
| return return_type::ERROR; | ||
| } | ||
|
|
||
| return_type read_joints(std::vector<std::shared_ptr<Joint>> & joints) const override; | ||
|
|
||
| return_type write_joints(const std::vector<std::shared_ptr<Joint>> & joints) override; | ||
|
|
||
| private: | ||
| double hw_write_time_, hw_read_time_; | ||
| std::vector<double> hw_values_; | ||
| }; | ||
|
|
||
| } // namespace ros2_control_demo_hardware | ||
|
|
||
| #endif // ROS2_CONTROL_DEMO_HARDWARE__RRBOT_SYSTEM_POSITION_ONLY_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 |
|---|---|---|
|
|
@@ -2,14 +2,17 @@ | |
| <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
| <package format="3"> | ||
| <name>ros2_control_demo_hardware</name> | ||
| <version>0.0.0</version> | ||
| <version>0.0.1</version> | ||
destogl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <description>Demo package of `ros2_control` Hardware. This package provides example on how to define hardware of your own robot for ROS2 control. The package is used with `demo_robot` from package `ros2_control_demo_robot`.</description> | ||
|
|
||
| <maintainer email="[email protected]">Denis Štogl</maintainer> | ||
|
|
||
| <license>Apache License 2.0</license> | ||
|
|
||
| <buildtool_depend>ament_cmake</buildtool_depend> | ||
| <buildtool_depend>hardware_interface</buildtool_depend> | ||
| <buildtool_depend>pluginlib</buildtool_depend> | ||
| <buildtool_depend>rclcpp</buildtool_depend> | ||
|
|
||
| <test_depend>ament_cmake_gtest</test_depend> | ||
|
|
||
|
|
||
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,9 @@ | ||
| <library path="ros2_control_demo_hardware"> | ||
| <class name="ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware" | ||
| type="ros2_control_demo_hardware::RRBotSystemPositionOnlyHardware" | ||
| base_class_type="hardware_interface::SystemHardwareInterface"> | ||
| <description> | ||
| The ROS2 Control minimal robot protocol. This is example for start porting the robot from ROS 1. | ||
| </description> | ||
| </class> | ||
| </library> |
175 changes: 175 additions & 0 deletions
175
ros2_control_demo_hardware/src/rrbot_system_position_only.cpp
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,175 @@ | ||
| // Copyright 2020 ROS2-Control Development Team | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <chrono> | ||
| #include <cmath> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "ros2_control_demo_hardware/rrbot_system_position_only.hpp" | ||
|
|
||
| #include "hardware_interface/components/component_info.hpp" | ||
| #include "hardware_interface/hardware_info.hpp" | ||
| #include "rclcpp/rclcpp.hpp" | ||
|
|
||
| namespace ros2_control_demo_hardware | ||
| { | ||
|
|
||
| return_type RRBotSystemPositionOnlyHardware::configure(const HardwareInfo & system_info) | ||
| { | ||
| if (hardware_interface::BaseSystemHardwareInterface::configure(system_info) != return_type::OK) { | ||
| return return_type::ERROR; | ||
| } | ||
|
|
||
| hw_read_time_ = stod(info_.hardware_parameters["example_param_read_for_sec"]); | ||
| hw_write_time_ = stod(info_.hardware_parameters["example_param_write_for_sec"]); | ||
| hw_values_.resize(info_.joints.size()); | ||
| for (uint i = 0; i < hw_values_.size(); i++) { | ||
| hw_values_[i] = std::numeric_limits<double>::quiet_NaN(); | ||
| } | ||
| for (auto joint : info_.joints) { | ||
destogl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (joint.class_type.compare("ros2_control_components/PositionJoint") != 0) { | ||
| status_ = hardware_interface_status::UNKNOWN; | ||
| // TODO(all): should we return specizalized error? | ||
| return return_type::ERROR; | ||
| } | ||
| } | ||
|
|
||
| status_ = hardware_interface_status::CONFIGURED; | ||
| return return_type::OK; | ||
| } | ||
|
|
||
| return_type RRBotSystemPositionOnlyHardware::start() | ||
| { | ||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "Starting ...please wait..."); | ||
|
|
||
| for (int i = 0; i < 3; i++) { | ||
| rclcpp::sleep_for(std::chrono::seconds(1)); | ||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "%d seconds left...", 3 - i); | ||
| } | ||
|
|
||
| // set some default values | ||
| for (uint i = 0; i < hw_values_.size(); i++) { | ||
| if (std::isnan(hw_values_[i])) { | ||
| hw_values_[i] = 0; | ||
| } | ||
| } | ||
|
|
||
| status_ = hardware_interface_status::STARTED; | ||
|
|
||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "System Sucessfully started!"); | ||
|
|
||
| return return_type::OK; | ||
| } | ||
|
|
||
| return_type RRBotSystemPositionOnlyHardware::stop() | ||
| { | ||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "Stopping ...please wait..."); | ||
|
|
||
| for (int i = 0; i < 4; i++) { | ||
| rclcpp::sleep_for(std::chrono::seconds(1)); | ||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "%d seconds left...", 3 - i); | ||
| } | ||
|
|
||
| status_ = hardware_interface_status::STOPPED; | ||
|
|
||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "System sucessfully stopped!"); | ||
|
|
||
| return return_type::OK; | ||
| } | ||
|
|
||
| return_type RRBotSystemPositionOnlyHardware::read_joints( | ||
| std::vector<std::shared_ptr<Joint>> & joints) const | ||
| { | ||
| if (joints.size() != hw_values_.size()) { | ||
| // TODO(all): return "wrong number of joints" error? | ||
| return return_type::ERROR; | ||
| } | ||
|
|
||
| return_type ret = return_type::OK; | ||
|
|
||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "Reading ...please wait..."); | ||
|
|
||
| for (int i = 0; i < hw_read_time_; i++) { | ||
| rclcpp::sleep_for(std::chrono::seconds(1)); | ||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "%.1f seconds for reading left...", hw_read_time_ - i); | ||
| } | ||
|
|
||
| // TODO(all): Should we check here joint names for the proper order? | ||
| std::vector<double> values; | ||
| values.resize(1); | ||
| for (uint i = 0; i < joints.size(); i++) { | ||
| values[0] = hw_values_[i] + 0.04; // Added number for "randomness" in the data | ||
| ret = joints[i]->set_state(values); | ||
| if (ret != return_type::OK) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "Joints sucessfully read!"); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| return_type RRBotSystemPositionOnlyHardware::write_joints( | ||
| const std::vector<std::shared_ptr<Joint>> & joints) | ||
| { | ||
| if (joints.size() != hw_values_.size()) { | ||
| // TODO(all): return wrong number of joints | ||
| return return_type::ERROR; | ||
| } | ||
|
|
||
| return_type ret = return_type::OK; | ||
|
|
||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "Writing ...please wait..."); | ||
|
|
||
| for (int i = 0; i < hw_write_time_; i++) { | ||
| rclcpp::sleep_for(std::chrono::seconds(1)); | ||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "%.1f seconds for writing left...", hw_write_time_ - i); | ||
| } | ||
|
|
||
| // TODO(anyone): here crashes the plugin, why... | ||
| // TODO(all): Should we check here joint names for the proper order? | ||
| std::vector<double> values; | ||
| for (uint i = 0; i < joints.size(); i++) { | ||
| ret = joints[i]->get_command(values); | ||
| if (ret != return_type::OK) { | ||
| break; | ||
| } | ||
| hw_values_[i] = values[0] + 0.023; // Added number for "randomness" in the data | ||
| } | ||
|
|
||
| RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), | ||
| "Joints sucessfully written!"); | ||
| return ret; | ||
| } | ||
|
|
||
| } // namespace ros2_control_demo_hardware | ||
|
|
||
| #include "pluginlib/class_list_macros.hpp" | ||
|
|
||
| PLUGINLIB_EXPORT_CLASS( | ||
| ros2_control_demo_hardware::RRBotSystemPositionOnlyHardware, | ||
| hardware_interface::SystemHardwareInterface | ||
| ) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.