├── .gitignore ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── jetbot_control.xml ├── description ├── urdf │ └── jetbot.urdf.xacro └── ros2_control │ └── jetbot.ros2_control.xacro ├── package.xml ├── hardware ├── include │ └── jetbot_control │ │ ├── i2c_device.hpp │ │ ├── motor.hpp │ │ ├── visibility_control.h │ │ └── jetbot_system.hpp ├── src │ ├── motor.cpp │ ├── i2c_device.cpp │ └── jetbot_system.cpp └── test │ └── test_jetbot_system.cpp ├── LICENSE ├── bringup ├── config │ └── jetbot_controllers.yaml └── launch │ └── jetbot.launch.py ├── README.md ├── CMakeLists.txt └── ROS2_CONTROL_LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | install/ 3 | log/ 4 | .vscode/ 5 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ros:humble-ros-base 2 | 3 | RUN apt update && \ 4 | apt upgrade -y && \ 5 | apt install -y \ 6 | ros-humble-ros2-control \ 7 | ros-humble-ros2-controllers \ 8 | ros-humble-xacro \ 9 | ros-humble-teleop-twist-keyboard \ 10 | gdb && \ 11 | apt clean 12 | 13 | ENTRYPOINT /ros_entrypoint.sh 14 | -------------------------------------------------------------------------------- /jetbot_control.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | The ros2_control system for driving a JetBot using I2C to move the motors. 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ROS2 Humble", 3 | "dockerFile": "Dockerfile", 4 | "runArgs": [ 5 | "--privileged", 6 | "--network=host" 7 | ], 8 | "workspaceMount": "source=${localWorkspaceFolder},target=/${localWorkspaceFolderBasename},type=bind", 9 | "workspaceFolder": "/${localWorkspaceFolderBasename}", 10 | "mounts": [ 11 | "source=${localEnv:HOME}${localEnv:USERPROFILE}/.bash_history,target=/home/vscode/.bash_history,type=bind" 12 | ] 13 | } -------------------------------------------------------------------------------- /description/urdf/jetbot.urdf.xacro: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jetbot_control 5 | 0.0.0 6 | ROS2 Node for controlling a JetBot via ROS Control interfaces. 7 | Mike Likes Robots 8 | MIT 9 | 10 | ament_cmake 11 | 12 | ament_lint_auto 13 | ament_lint_common 14 | 15 | rclcpp 16 | 17 | 18 | ament_cmake 19 | 20 | 21 | -------------------------------------------------------------------------------- /hardware/include/jetbot_control/i2c_device.hpp: -------------------------------------------------------------------------------- 1 | #ifndef JETBOT_CONTROL__I2C_DEVICE_HPP_ 2 | #define JETBOT_CONTROL__I2C_DEVICE_HPP_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace jetbot_control { 9 | 10 | class I2CDevice { 11 | public: 12 | I2CDevice(); 13 | ~I2CDevice(); 14 | bool tryEnableMotor(uint8_t pin); 15 | bool trySetDutyCycle(uint8_t pin, uint16_t duty_cycle); 16 | 17 | private: 18 | bool trySelectDevice(); 19 | bool tryWriteReg(uint8_t reg, uint8_t data); 20 | std::optional tryReadReg(uint8_t reg); 21 | bool trySetClock(); 22 | bool tryReset(); 23 | int i2c_fd_; 24 | uint8_t buf_[10]; 25 | }; 26 | 27 | } // namespace jetbot_control 28 | 29 | #endif // JETBOT_CONTROL__I2C_DEVICE_HPP_ 30 | -------------------------------------------------------------------------------- /hardware/include/jetbot_control/motor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef JETBOT_CONTROL__MOTOR_HPP_ 4 | #define JETBOT_CONTROL__MOTOR_HPP_ 5 | 6 | #include 7 | #include 8 | 9 | #include "jetbot_control/i2c_device.hpp" 10 | 11 | using u8 = uint8_t; 12 | using I2CDevicePtr = std::shared_ptr; 13 | using MotorPins = std::tuple; 14 | 15 | namespace jetbot_control { 16 | class Motor { 17 | public: 18 | Motor() = default; 19 | Motor(I2CDevicePtr i2c, MotorPins pins, std::string name); 20 | ~Motor(); 21 | bool trySetVelocity(double velocity); 22 | 23 | private: 24 | I2CDevicePtr i2c_; 25 | MotorPins pins_; 26 | std::string name_; 27 | }; 28 | } // namespace jetbot_control 29 | 30 | #endif // JETBOT_CONTROL__MOTOR_HPP_ 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 mikelikesrobots 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /description/ros2_control/jetbot.ros2_control.xacro: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | jetbot_control/JetBotSystemHardware 10 | 8 11 | 9 12 | 10 13 | 13 14 | 12 15 | 11 16 | 17 | 18 | 19 | 20 | mock_components/GenericSystem 21 | true 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /hardware/src/motor.cpp: -------------------------------------------------------------------------------- 1 | #include "jetbot_control/motor.hpp" 2 | 3 | using namespace jetbot_control; 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | Motor::Motor(I2CDevicePtr i2c, MotorPins pins, std::string name) 11 | : i2c_{i2c}, pins_{pins}, name_{name} { 12 | u8 enable_pin = std::get<0>(pins_); 13 | if (!i2c_->tryEnableMotor(enable_pin)) { 14 | std::string error = "Failed to enable motor " + name_ + "!"; 15 | std::__throw_runtime_error(error.c_str()); 16 | } 17 | } 18 | 19 | Motor::~Motor() { trySetVelocity(0); } 20 | 21 | bool Motor::trySetVelocity(double velocity) { 22 | u8 pos_pin = std::get<1>(pins_); 23 | u8 neg_pin = std::get<2>(pins_); 24 | 25 | // Interpret <1/1000 max speed as not spinning 26 | if (std::fabs(velocity) < 0.001) { 27 | if (!i2c_->trySetDutyCycle(pos_pin, 0xFFFF)) { 28 | return false; 29 | } 30 | if (!i2c_->trySetDutyCycle(neg_pin, 0xFFFF)) { 31 | return false; 32 | } 33 | return true; 34 | } 35 | 36 | uint16_t duty_cycle = 0xFFFF * std::fabs(velocity); 37 | 38 | // Use braking mode 39 | if (velocity > 0) { 40 | if (!i2c_->trySetDutyCycle(pos_pin, 0xFFFF)) { 41 | return false; 42 | } 43 | if (!i2c_->trySetDutyCycle(neg_pin, 0xFFFF - duty_cycle)) { 44 | return false; 45 | } 46 | } else { 47 | if (!i2c_->trySetDutyCycle(pos_pin, 0xFFFF - duty_cycle)) { 48 | return false; 49 | } 50 | if (!i2c_->trySetDutyCycle(neg_pin, 0xFFFF)) { 51 | return false; 52 | } 53 | } 54 | 55 | return true; 56 | } 57 | -------------------------------------------------------------------------------- /hardware/test/test_jetbot_system.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "hardware_interface/resource_manager.hpp" 4 | #include "ros2_control_test_assets/components_urdfs.hpp" 5 | #include "ros2_control_test_assets/descriptions.hpp" 6 | 7 | class TestJetBotSystem : public ::testing::Test { 8 | protected: 9 | void SetUp() override { 10 | mock_system_ = 11 | R"( 12 | 13 | 14 | jetbot_control/JetBotSystemHardware 15 | 1 16 | 2 17 | 3 18 | 4 19 | 5 20 | 6 21 | 22 | 23 | )"; 24 | } 25 | 26 | std::string mock_system_; 27 | }; 28 | 29 | class TestableResourceManager : public hardware_interface::ResourceManager { 30 | public: 31 | friend TestJetBotSystem; 32 | TestableResourceManager() : hardware_interface::ResourceManager() {} 33 | TestableResourceManager(const std::string& urdf, 34 | bool validate_interfaces = true, 35 | bool activate_all = false) 36 | : hardware_interface::ResourceManager(urdf, validate_interfaces, 37 | activate_all) {} 38 | }; 39 | 40 | TEST_F(TestJetBotSystem, load_generic_system) { 41 | auto urdf = ros2_control_test_assets::urdf_head + mock_system_ + 42 | ros2_control_test_assets::urdf_tail; 43 | ASSERT_NO_THROW(TestableResourceManager rm(urdf)); 44 | } 45 | -------------------------------------------------------------------------------- /bringup/config/jetbot_controllers.yaml: -------------------------------------------------------------------------------- 1 | controller_manager: 2 | ros__parameters: 3 | update_rate: 10 # Hz 4 | 5 | jetbot_base_controller: 6 | type: diff_drive_controller/DiffDriveController 7 | 8 | jetbot_base_controller: 9 | ros__parameters: 10 | left_wheel_names: ["left_wheel_joint"] 11 | right_wheel_names: ["right_wheel_joint"] 12 | 13 | wheel_separation: 0.104 14 | #wheels_per_side: 1 15 | wheel_radius: 0.032 16 | 17 | wheel_separation_multiplier: 1.0 18 | left_wheel_radius_multiplier: 1.0 19 | right_wheel_radius_multiplier: 1.0 20 | 21 | publish_rate: 50.0 22 | odom_frame_id: odom 23 | base_frame_id: base_link 24 | pose_covariance_diagonal : [0.001, 0.001, 0.001, 0.001, 0.001, 0.01] 25 | twist_covariance_diagonal: [0.001, 0.001, 0.001, 0.001, 0.001, 0.01] 26 | 27 | open_loop: true 28 | position_feedback: false 29 | enable_odom_tf: true 30 | 31 | cmd_vel_timeout: 0.5 32 | #publish_limited_velocity: true 33 | #velocity_rolling_window_size: 10 34 | 35 | # Velocity and acceleration limits 36 | # Whenever a min_* is unspecified, default to -max_* 37 | linear.x.has_velocity_limits: true 38 | linear.x.has_acceleration_limits: true 39 | linear.x.has_jerk_limits: false 40 | linear.x.max_velocity: 0.016 41 | linear.x.min_velocity: -0.016 42 | linear.x.max_acceleration: 0.07 43 | linear.x.max_jerk: 0.0 44 | linear.x.min_jerk: 0.0 45 | 46 | angular.z.has_velocity_limits: true 47 | angular.z.has_acceleration_limits: true 48 | angular.z.has_jerk_limits: false 49 | angular.z.max_velocity: 0.25 50 | angular.z.min_velocity: -0.25 51 | angular.z.max_acceleration: 1.0 52 | angular.z.min_acceleration: -1.0 53 | angular.z.max_jerk: 0.0 54 | angular.z.min_jerk: 0.0 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JetBot ROS Control 2 | 3 | ROS2 Node for controlling a JetBot via ROS Control interfaces. 4 | 5 | ## Setup 6 | 7 | From a WaveShare JetBot robot, clone this repository and open it over SSH. Install the Dev Containers extension and allow it to build the Docker container and open the workspace in that container. 8 | 9 | Then build the code using `colcon build` from the workspace root: 10 | 11 | ```bash 12 | source /opt/ros/humble/setup.bash 13 | colcon build 14 | ``` 15 | 16 | ## Testing the code 17 | 18 | Once built, you can run the test function to check that the library can be loaded correctly as follows: 19 | 20 | ```bash 21 | source install/setup.bash 22 | ./build/jetbot_control/test_jetbot_system 23 | ``` 24 | 25 | The test should pass with log messages showing a successful initialization of the control library. 26 | 27 | ## Running the code 28 | 29 | Once built, it should be possible to launch the jetbot controller using the provided launch file. Note that this will only run on a JetBot with the i2c-1 bus available. 30 | 31 | ```bash 32 | source install/setup.bash 33 | ros2 launch jetbot_control jetbot.launch.py 34 | ``` 35 | 36 | After this, the robot will respond to commands sent with `TwistStamped` type sent on the `/cmd_vel` topic. 37 | 38 | If you want to run mock hardware for any reason, such as not having a JetBot to run the code on, you can enable the flag as follows: 39 | 40 | ```bash 41 | ros2 launch jetbot_control jetbot.launch.py use_mock_hardware:=true 42 | ``` 43 | 44 | ## License 45 | 46 | The code in this repository is covered by the MIT license in the [LICENSE](./LICENSE) file. However, four files are included from the [ros2_control_demos](https://github.com/ros-controls/ros2_control_demos) repository, and so are covered by the [ROS2_CONTROL_LICENSE](./ROS2_CONTROL_LICENSE) file instead. These four files are as follows: 47 | 48 | 1. [jetbot.launch.py](./bringup/launch/jetbot.launch.py) 49 | 2. [jetbot_system.cpp](./hardware/src/jetbot_system.cpp) 50 | 3. [jetbot_system.hpp](./hardware/include/jetbot_control/jetbot_system.hpp) 51 | 4. [visibility_control.h](./hardware/include/jetbot_control/visibility_control.h) 52 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project(jetbot_control LANGUAGES CXX) 3 | 4 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 5 | add_compile_options(-Wall -Wextra -Wpedantic) 6 | endif() 7 | 8 | set(THIS_PACKAGE_INCLUDE_DEPENDS 9 | hardware_interface 10 | pluginlib 11 | rclcpp 12 | rclcpp_lifecycle 13 | ) 14 | 15 | find_package(ament_cmake REQUIRED) 16 | foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS}) 17 | find_package(${Dependency} REQUIRED) 18 | endforeach() 19 | 20 | add_library(${PROJECT_NAME} 21 | SHARED 22 | hardware/src/jetbot_system.cpp 23 | hardware/src/i2c_device.cpp 24 | hardware/src/motor.cpp 25 | ) 26 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 27 | target_include_directories(${PROJECT_NAME} PUBLIC 28 | $ 29 | $ 30 | ) 31 | ament_target_dependencies( 32 | ${PROJECT_NAME} PUBLIC 33 | ${THIS_PACKAGE_INCLUDE_DEPENDS} 34 | ) 35 | 36 | # Causes the visibility macros to use dllexport rather than dllimport, 37 | # which is appropriate when building the dll but not consuming it. 38 | target_compile_definitions(${PROJECT_NAME} PRIVATE "JETBOT_CONTROL_BUILDING_DLL") 39 | 40 | pluginlib_export_plugin_description_file(hardware_interface jetbot_control.xml) 41 | 42 | install( 43 | DIRECTORY hardware/include/ 44 | DESTINATION include/jetbot_control 45 | ) 46 | install( 47 | DIRECTORY description/ros2_control description/urdf 48 | DESTINATION share/jetbot_control 49 | ) 50 | install( 51 | DIRECTORY bringup/launch bringup/config 52 | DESTINATION share/jetbot_control 53 | ) 54 | 55 | install(TARGETS 56 | ${PROJECT_NAME} 57 | EXPORT export_jetbot_control 58 | ARCHIVE DESTINATION lib 59 | LIBRARY DESTINATION lib 60 | RUNTIME DESTINATION bin 61 | ) 62 | 63 | if(BUILD_TESTING) 64 | find_package(ament_cmake_gmock REQUIRED) 65 | find_package(ros2_control_test_assets REQUIRED) 66 | ament_add_gmock(test_jetbot_system hardware/test/test_jetbot_system.cpp) 67 | target_include_directories(test_jetbot_system PRIVATE include) 68 | target_link_libraries(test_jetbot_system ${PROJECT_NAME}) 69 | ament_target_dependencies(test_jetbot_system 70 | pluginlib 71 | ros2_control_test_assets 72 | ) 73 | endif() 74 | 75 | ament_export_targets(export_jetbot_control HAS_LIBRARY_TARGET) 76 | ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS}) 77 | ament_package() 78 | -------------------------------------------------------------------------------- /hardware/include/jetbot_control/visibility_control.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 ros2_control Development Team 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // This file was last modified by Michael Hart, a.k.a Mike Likes Robots 16 | // (mikelikesrobots@outlook.com), on 2024-03-07. 17 | 18 | /* This header must be included by all rclcpp headers which declare symbols 19 | * which are defined in the rclcpp library. When not building the rclcpp 20 | * library, i.e. when using the headers in other package's code, the contents 21 | * of this header change the visibility of certain symbols which the rclcpp 22 | * library cannot have, but the consuming code must have inorder to link. 23 | */ 24 | 25 | #ifndef JETBOT_CONTROL__VISIBILITY_CONTROL_H_ 26 | #define JETBOT_CONTROL__VISIBILITY_CONTROL_H_ 27 | 28 | // This logic was borrowed (then namespaced) from the examples on the gcc wiki: 29 | // https://gcc.gnu.org/wiki/Visibility 30 | 31 | #if defined _WIN32 || defined __CYGWIN__ 32 | #ifdef __GNUC__ 33 | #define JETBOT_CONTROL_EXPORT __attribute__((dllexport)) 34 | #define JETBOT_CONTROL_IMPORT __attribute__((dllimport)) 35 | #else 36 | #define JETBOT_CONTROL_EXPORT __declspec(dllexport) 37 | #define JETBOT_CONTROL_IMPORT __declspec(dllimport) 38 | #endif 39 | #ifdef JETBOT_CONTROL_BUILDING_DLL 40 | #define JETBOT_CONTROL_PUBLIC JETBOT_CONTROL_EXPORT 41 | #else 42 | #define JETBOT_CONTROL_PUBLIC JETBOT_CONTROL_IMPORT 43 | #endif 44 | #define JETBOT_CONTROL_PUBLIC_TYPE JETBOT_CONTROL_PUBLIC 45 | #define JETBOT_CONTROL_LOCAL 46 | #else 47 | #define JETBOT_CONTROL_EXPORT __attribute__((visibility("default"))) 48 | #define JETBOT_CONTROL_IMPORT 49 | #if __GNUC__ >= 4 50 | #define JETBOT_CONTROL_PUBLIC __attribute__((visibility("default"))) 51 | #define JETBOT_CONTROL_LOCAL __attribute__((visibility("hidden"))) 52 | #else 53 | #define JETBOT_CONTROL_PUBLIC 54 | #define JETBOT_CONTROL_LOCAL 55 | #endif 56 | #define JETBOT_CONTROL_PUBLIC_TYPE 57 | #endif 58 | 59 | #endif // JETBOT_CONTROL__VISIBILITY_CONTROL_H_ 60 | -------------------------------------------------------------------------------- /bringup/launch/jetbot.launch.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 ros2_control Development Team 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # This file was last modified by Michael Hart, a.k.a Mike Likes Robots 16 | # (mikelikesrobots@outlook.com), on 2024-03-07. 17 | 18 | from launch import LaunchDescription 19 | from launch.actions import DeclareLaunchArgument, RegisterEventHandler 20 | from launch.conditions import IfCondition 21 | from launch.event_handlers import OnProcessExit 22 | from launch.substitutions import ( 23 | Command, 24 | FindExecutable, 25 | PathJoinSubstitution, 26 | LaunchConfiguration, 27 | ) 28 | 29 | from launch_ros.actions import Node 30 | from launch_ros.substitutions import FindPackageShare 31 | 32 | 33 | def generate_launch_description(): 34 | # Declare arguments 35 | declared_arguments = [] 36 | declared_arguments.append( 37 | DeclareLaunchArgument( 38 | "use_mock_hardware", 39 | default_value="false", 40 | description="Start robot with mock hardware mirroring command to its states.", 41 | ) 42 | ) 43 | 44 | # Initialize Arguments 45 | use_mock_hardware = LaunchConfiguration("use_mock_hardware") 46 | 47 | # Get URDF via xacro 48 | robot_description_content = Command( 49 | [ 50 | PathJoinSubstitution([FindExecutable(name="xacro")]), 51 | " ", 52 | PathJoinSubstitution( 53 | [FindPackageShare("jetbot_control"), "urdf", "jetbot.urdf.xacro"] 54 | ), 55 | " ", 56 | "use_mock_hardware:=", 57 | use_mock_hardware, 58 | ] 59 | ) 60 | robot_description = {"robot_description": robot_description_content} 61 | 62 | robot_controllers = PathJoinSubstitution( 63 | [ 64 | FindPackageShare("jetbot_control"), 65 | "config", 66 | "jetbot_controllers.yaml", 67 | ] 68 | ) 69 | 70 | control_node = Node( 71 | package="controller_manager", 72 | executable="ros2_control_node", 73 | parameters=[robot_description, robot_controllers], 74 | output="both", 75 | ) 76 | robot_controller_spawner = Node( 77 | package="controller_manager", 78 | executable="spawner", 79 | arguments=[ 80 | "jetbot_base_controller", 81 | "--controller-manager", 82 | "/controller_manager", 83 | ], 84 | ) 85 | 86 | nodes = [ 87 | control_node, 88 | robot_controller_spawner, 89 | ] 90 | 91 | return LaunchDescription(declared_arguments + nodes) 92 | -------------------------------------------------------------------------------- /hardware/include/jetbot_control/jetbot_system.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 ros2_control Development Team 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // This file was last modified by Michael Hart, a.k.a Mike Likes Robots 16 | // (mikelikesrobots@outlook.com), on 2024-03-07. 17 | 18 | #ifndef JETBOT_CONTROL__JETBOT_SYSTEM_HPP_ 19 | #define JETBOT_CONTROL__JETBOT_SYSTEM_HPP_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "hardware_interface/handle.hpp" 26 | #include "hardware_interface/hardware_info.hpp" 27 | #include "hardware_interface/system_interface.hpp" 28 | #include "hardware_interface/types/hardware_interface_return_values.hpp" 29 | #include "jetbot_control/i2c_device.hpp" 30 | #include "jetbot_control/motor.hpp" 31 | #include "jetbot_control/visibility_control.h" 32 | #include "rclcpp/clock.hpp" 33 | #include "rclcpp/duration.hpp" 34 | #include "rclcpp/macros.hpp" 35 | #include "rclcpp/time.hpp" 36 | #include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp" 37 | #include "rclcpp_lifecycle/state.hpp" 38 | 39 | namespace jetbot_control { 40 | class JetBotSystemHardware : public hardware_interface::SystemInterface { 41 | public: 42 | RCLCPP_SHARED_PTR_DEFINITIONS(JetBotSystemHardware) 43 | 44 | JETBOT_CONTROL_PUBLIC 45 | hardware_interface::CallbackReturn on_init( 46 | const hardware_interface::HardwareInfo& info) override; 47 | 48 | JETBOT_CONTROL_PUBLIC 49 | std::vector export_state_interfaces() 50 | override; 51 | 52 | JETBOT_CONTROL_PUBLIC 53 | std::vector export_command_interfaces() 54 | override; 55 | 56 | JETBOT_CONTROL_PUBLIC 57 | hardware_interface::CallbackReturn on_activate( 58 | const rclcpp_lifecycle::State& previous_state) override; 59 | 60 | JETBOT_CONTROL_PUBLIC 61 | hardware_interface::CallbackReturn on_deactivate( 62 | const rclcpp_lifecycle::State& previous_state) override; 63 | 64 | JETBOT_CONTROL_PUBLIC 65 | hardware_interface::return_type read(const rclcpp::Time& time, 66 | const rclcpp::Duration& period) override; 67 | 68 | JETBOT_CONTROL_PUBLIC 69 | hardware_interface::return_type write( 70 | const rclcpp::Time& time, const rclcpp::Duration& period) override; 71 | 72 | private: 73 | std::vector motor_pin_sets_; 74 | std::vector motors_; 75 | std::shared_ptr i2c_device_; 76 | std::vector hw_commands_; 77 | std::vector hw_velocities_; 78 | }; 79 | 80 | } // namespace jetbot_control 81 | 82 | #endif // JETBOT_CONTROL__JETBOT_SYSTEM_HPP_ 83 | -------------------------------------------------------------------------------- /hardware/src/i2c_device.cpp: -------------------------------------------------------------------------------- 1 | #include "jetbot_control/i2c_device.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | const uint8_t kDefaultDeviceAddress = 0x60; 15 | const uint8_t kMode1Reg = 0x00; 16 | const uint8_t kMode2Reg = 0x01; 17 | const uint8_t kPrescaleReg = 0xFE; 18 | const uint8_t kPwmReg = 0x06; 19 | const float kReferenceClockSpeed = 25e6; 20 | const float kPwmFrequency = 1600.0; 21 | 22 | using namespace std::chrono_literals; 23 | using namespace jetbot_control; 24 | 25 | I2CDevice::I2CDevice() { 26 | i2c_fd_ = open("/dev/i2c-1", O_RDWR); 27 | if (!i2c_fd_) { 28 | std::__throw_runtime_error("Failed to open I2C interface!"); 29 | } 30 | 31 | // Select the PWM device 32 | if (!trySelectDevice()) 33 | std::__throw_runtime_error("Failed to select PWM device!"); 34 | 35 | // Reset the PWM device 36 | if (!tryReset()) std::__throw_runtime_error("Failed to reset PWM device!"); 37 | 38 | // Set the PWM device clock 39 | if (!trySetClock()) std::__throw_runtime_error("Failed to set PWM clock!"); 40 | } 41 | 42 | I2CDevice::~I2CDevice() { 43 | tryReset(); 44 | if (i2c_fd_) { 45 | close(i2c_fd_); 46 | } 47 | } 48 | 49 | bool I2CDevice::tryEnableMotor(uint8_t pin) { 50 | buf_[0] = kPwmReg + 4 * pin; 51 | buf_[1] = 0x00; 52 | buf_[2] = 0x10; 53 | buf_[3] = 0x00; 54 | buf_[4] = 0x00; 55 | return write(i2c_fd_, buf_, 5) == 5; 56 | } 57 | 58 | bool I2CDevice::trySetDutyCycle(uint8_t pin, uint16_t duty_cycle) { 59 | buf_[0] = kPwmReg + 4 * pin; 60 | 61 | if (duty_cycle == 0xFFFF) { 62 | // Special case - fully on 63 | buf_[1] = 0x00; 64 | buf_[2] = 0x10; 65 | buf_[3] = 0x00; 66 | buf_[4] = 0x00; 67 | } else if (duty_cycle < 0x0010) { 68 | // Special case - fully off 69 | buf_[1] = 0x00; 70 | buf_[2] = 0x00; 71 | buf_[3] = 0x00; 72 | buf_[4] = 0x10; 73 | } else { 74 | // Shift by 4 to fit 12-bit register 75 | uint16_t value = duty_cycle >> 4; 76 | buf_[1] = (uint8_t)0; 77 | buf_[2] = (uint8_t)0; 78 | buf_[3] = (uint8_t)(value & 0xFF); 79 | buf_[4] = (uint8_t)((value >> 8) & 0xFF); 80 | } 81 | 82 | return write(i2c_fd_, buf_, 5) == 5; 83 | } 84 | 85 | bool I2CDevice::tryWriteReg(uint8_t reg, uint8_t data) { 86 | buf_[0] = reg; 87 | buf_[1] = data; 88 | return write(i2c_fd_, buf_, 2) == 2; 89 | } 90 | std::optional I2CDevice::tryReadReg(uint8_t reg) { 91 | buf_[0] = reg; 92 | if (write(i2c_fd_, buf_, 1) != 1) { 93 | return std::nullopt; 94 | } 95 | if (read(i2c_fd_, buf_, 1) != 1) { 96 | return std::nullopt; 97 | } 98 | return buf_[0]; 99 | } 100 | 101 | bool I2CDevice::trySetClock() { 102 | const uint8_t prescale = 103 | (kReferenceClockSpeed / 4096.0 / kPwmFrequency + 0.5) - 1; 104 | if (prescale < 3) return false; 105 | 106 | // Read old mode 107 | const auto old_mode_op = tryReadReg(kMode1Reg); 108 | if (!old_mode_op.has_value()) return false; 109 | const uint8_t old_mode = *old_mode_op; 110 | 111 | // Set a new mode/prescaler, then sleep 112 | const uint8_t new_mode = (old_mode & 0x7F) | 0x10; 113 | if (!tryWriteReg(kMode1Reg, new_mode)) return false; 114 | if (!tryWriteReg(kPrescaleReg, prescale)) return false; 115 | if (!tryWriteReg(kMode1Reg, old_mode)) return false; 116 | std::this_thread::sleep_for(5ms); 117 | 118 | // Set mode 1 with autoincrement, fix to stop pca9685 from accepting commands 119 | // at all addresses 120 | if (!tryWriteReg(kMode1Reg, old_mode | 0xA0)) return false; 121 | 122 | return true; 123 | } 124 | 125 | bool I2CDevice::tryReset() { return tryWriteReg(kMode1Reg, 0x00); } 126 | 127 | bool I2CDevice::trySelectDevice() { 128 | return ioctl(i2c_fd_, I2C_SLAVE, kDefaultDeviceAddress) >= 0; 129 | } 130 | -------------------------------------------------------------------------------- /hardware/src/jetbot_system.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2021 ros2_control Development Team 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // This file was last modified by Michael Hart, a.k.a Mike Likes Robots 16 | // (mikelikesrobots@outlook.com), on 2024-03-07. 17 | 18 | #include "jetbot_control/jetbot_system.hpp" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "hardware_interface/types/hardware_interface_type_values.hpp" 28 | #include "rclcpp/rclcpp.hpp" 29 | 30 | using namespace jetbot_control; 31 | 32 | hardware_interface::CallbackReturn JetBotSystemHardware::on_init( 33 | const hardware_interface::HardwareInfo &info) { 34 | if (hardware_interface::SystemInterface::on_init(info) != 35 | hardware_interface::CallbackReturn::SUCCESS) { 36 | return hardware_interface::CallbackReturn::ERROR; 37 | } 38 | 39 | hw_velocities_.resize(info_.joints.size(), 40 | std::numeric_limits::quiet_NaN()); 41 | hw_commands_.resize(info_.joints.size(), 42 | std::numeric_limits::quiet_NaN()); 43 | 44 | for (auto i = 0u; i < info_.joints.size(); i++) { 45 | auto pin_en_ = 46 | stoi(info_.hardware_parameters["pin_enable_" + std::to_string(i)]); 47 | auto pin_pos_ = 48 | stoi(info_.hardware_parameters["pin_pos_" + std::to_string(i)]); 49 | auto pin_neg_ = 50 | stoi(info_.hardware_parameters["pin_neg_" + std::to_string(i)]); 51 | motor_pin_sets_.emplace_back(std::make_tuple(pin_en_, pin_pos_, pin_neg_)); 52 | } 53 | 54 | for (const hardware_interface::ComponentInfo &joint : info_.joints) { 55 | if (joint.command_interfaces.size() != 1) { 56 | RCLCPP_FATAL(rclcpp::get_logger("JetBotSystemHardware"), 57 | "Joint '%s' has %zu command interfaces found. 1 expected.", 58 | joint.name.c_str(), joint.command_interfaces.size()); 59 | return hardware_interface::CallbackReturn::ERROR; 60 | } 61 | 62 | if (joint.command_interfaces[0].name != 63 | hardware_interface::HW_IF_VELOCITY) { 64 | RCLCPP_FATAL( 65 | rclcpp::get_logger("JetBotSystemHardware"), 66 | "Joint '%s' have %s command interfaces found. '%s' expected.", 67 | joint.name.c_str(), joint.command_interfaces[0].name.c_str(), 68 | hardware_interface::HW_IF_VELOCITY); 69 | return hardware_interface::CallbackReturn::ERROR; 70 | } 71 | 72 | if (joint.state_interfaces.size() != 1) { 73 | RCLCPP_FATAL(rclcpp::get_logger("JetBotSystemHardware"), 74 | "Joint '%s' has %zu state interfaces. 1 expected.", 75 | joint.name.c_str(), joint.state_interfaces.size()); 76 | return hardware_interface::CallbackReturn::ERROR; 77 | } 78 | 79 | if (joint.state_interfaces[0].name != hardware_interface::HW_IF_VELOCITY) { 80 | RCLCPP_FATAL( 81 | rclcpp::get_logger("JetBotSystemHardware"), 82 | "Joint '%s' have '%s' as only state interface. '%s' expected.", 83 | joint.name.c_str(), joint.state_interfaces[0].name.c_str(), 84 | hardware_interface::HW_IF_VELOCITY); 85 | return hardware_interface::CallbackReturn::ERROR; 86 | } 87 | } 88 | 89 | // Initialize I2C and Motors 90 | try { 91 | i2c_device_ = std::make_shared(); 92 | for (auto i = 0u; i < info.joints.size(); i++) { 93 | motors_.emplace_back(i2c_device_, motor_pin_sets_[i], 94 | info.joints[i].name); 95 | } 96 | } catch (std::exception &ex) { 97 | RCLCPP_FATAL(rclcpp::get_logger("JetBotSystemHardware"), 98 | "Error while initializing I2C device or motors: '%s'", 99 | ex.what()); 100 | return hardware_interface::CallbackReturn::ERROR; 101 | } 102 | 103 | return hardware_interface::CallbackReturn::SUCCESS; 104 | } 105 | 106 | std::vector 107 | JetBotSystemHardware::export_state_interfaces() { 108 | std::vector state_interfaces; 109 | for (auto i = 0u; i < info_.joints.size(); i++) { 110 | state_interfaces.emplace_back(hardware_interface::StateInterface( 111 | info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, 112 | &hw_velocities_[i])); 113 | } 114 | 115 | return state_interfaces; 116 | } 117 | 118 | std::vector 119 | JetBotSystemHardware::export_command_interfaces() { 120 | std::vector command_interfaces; 121 | for (auto i = 0u; i < info_.joints.size(); i++) { 122 | command_interfaces.emplace_back(hardware_interface::CommandInterface( 123 | info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, 124 | &hw_commands_[i])); 125 | } 126 | 127 | return command_interfaces; 128 | } 129 | 130 | hardware_interface::CallbackReturn JetBotSystemHardware::on_activate( 131 | const rclcpp_lifecycle::State & /*previous_state*/) { 132 | // set 0s as default values 133 | for (auto i = 0u; i < hw_velocities_.size(); i++) { 134 | if (std::isnan(hw_velocities_[i])) { 135 | hw_velocities_[i] = 0; 136 | hw_commands_[i] = 0; 137 | } 138 | } 139 | 140 | bool success = true; 141 | for (auto motor : motors_) { 142 | success = success && motor.trySetVelocity(0); 143 | } 144 | if (!success) { 145 | RCLCPP_ERROR(rclcpp::get_logger("JetBotSystemHardware"), 146 | "Error setting velocity on motors while activating!"); 147 | return hardware_interface::CallbackReturn::ERROR; 148 | } 149 | 150 | RCLCPP_INFO(rclcpp::get_logger("JetBotSystemHardware"), 151 | "Successfully activated!"); 152 | return hardware_interface::CallbackReturn::SUCCESS; 153 | } 154 | 155 | hardware_interface::CallbackReturn JetBotSystemHardware::on_deactivate( 156 | const rclcpp_lifecycle::State & /*previous_state*/) { 157 | bool success = true; 158 | for (auto motor : motors_) { 159 | success = success && motor.trySetVelocity(0); 160 | } 161 | if (!success) { 162 | RCLCPP_ERROR(rclcpp::get_logger("JetBotSystemHardware"), 163 | "Error setting velocity on motors while deactivating!"); 164 | return hardware_interface::CallbackReturn::ERROR; 165 | } 166 | 167 | RCLCPP_INFO(rclcpp::get_logger("JetBotSystemHardware"), 168 | "Successfully deactivated!"); 169 | return hardware_interface::CallbackReturn::SUCCESS; 170 | } 171 | 172 | hardware_interface::return_type JetBotSystemHardware::read( 173 | const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) { 174 | return hardware_interface::return_type::OK; 175 | } 176 | 177 | hardware_interface::return_type JetBotSystemHardware::write( 178 | const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) { 179 | bool success = true; 180 | for (auto i = 0u; i < hw_commands_.size(); i++) { 181 | success = success && motors_[i].trySetVelocity(hw_commands_[i]); 182 | } 183 | if (!success) { 184 | RCLCPP_ERROR(rclcpp::get_logger("JetBotSystemHardware"), 185 | "Error setting velocity on motors during write step!"); 186 | return hardware_interface::return_type::ERROR; 187 | } 188 | 189 | return hardware_interface::return_type::OK; 190 | } 191 | 192 | #include "pluginlib/class_list_macros.hpp" 193 | PLUGINLIB_EXPORT_CLASS(jetbot_control::JetBotSystemHardware, 194 | hardware_interface::SystemInterface) 195 | -------------------------------------------------------------------------------- /ROS2_CONTROL_LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------