├── vesc
├── CMakeLists.txt
└── package.xml
├── vesc_msgs
├── msg
│ ├── VescStateStamped.msg
│ └── VescState.msg
├── package.xml
└── CMakeLists.txt
├── .github
├── ISSUE_TEMPLATE
│ ├── -------improvement-suggestions.md
│ └── -------bug-report.md
└── PULL_REQUEST_TEMPLATE.md
├── vesc_hw_interface
├── vesc_hw_interface_plugin.xml
├── config
│ ├── position_sample.yaml
│ └── velocity_duty_sample.yaml
├── package.xml
├── launch
│ ├── velocity_test.ros2_control.xacro
│ ├── position_test.ros2_control.xacro
│ ├── velocity_duty_test.ros2_control.xacro
│ ├── position_duty_test.ros2_control.xacro
│ ├── position_control_sample.launch.py
│ └── velocity_control_sample.launch.py
├── CMakeLists.txt
├── include
│ └── vesc_hw_interface
│ │ ├── vesc_step_difference.hpp
│ │ ├── visibility_control.h
│ │ ├── vesc_wheel_controller.hpp
│ │ ├── vesc_hw_interface.hpp
│ │ └── vesc_servo_controller.hpp
├── src
│ ├── vesc_step_difference.cpp
│ ├── vesc_wheel_controller.cpp
│ ├── vesc_hw_interface.cpp
│ └── vesc_servo_controller.cpp
└── README.md
├── vesc_driver
├── CMakeLists.txt
├── package.xml
├── launch
│ ├── vesc_driver_node.launch
│ └── vesc_driver_nodelet.launch
├── README.md
├── src
│ ├── vesc_driver_node.cpp
│ ├── vesc_driver_nodelet.cpp
│ ├── vesc_packet_factory.cpp
│ ├── vesc_interface.cpp
│ └── vesc_driver.cpp
└── include
│ └── vesc_driver
│ ├── vesc_packet_factory.hpp
│ ├── vesc_driver.h
│ ├── vesc_interface.hpp
│ ├── vesc_packet.hpp
│ └── data_map.hpp
├── .gitignore
├── README.md
└── LICENSE
/vesc/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(vesc)
3 | find_package(ament_cmake REQUIRED)
4 | ament_package()
5 |
--------------------------------------------------------------------------------
/vesc_msgs/msg/VescStateStamped.msg:
--------------------------------------------------------------------------------
1 | # Timestamped VESC open source motor controller state (telemetry)
2 |
3 | std_msgs/Header header
4 | VescState state
5 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/-------improvement-suggestions.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Improvement Suggestion
3 | about: New features, optimization, etc.
4 | title: ''
5 | labels: 'enhancement'
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 | ## Abstract
12 |
13 | ## Purpose
14 |
15 | ## Implementation Details
16 |
--------------------------------------------------------------------------------
/vesc_hw_interface/vesc_hw_interface_plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | plugin of VESC hardware interface
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ## Change Summary
5 |
6 | ## Details
7 |
8 | ## Impacts
9 |
10 |
11 | ## References
12 |
13 |
14 | ## Additional Information
15 |
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/-------bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug Report
3 | about: A problem due to a bug of algorithms or codes
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 | ## Abstract
12 |
13 | ## How to Reproduce the Bug
14 |
15 | ## Problem due to the Bug
16 |
17 | ## Factors
18 |
19 |
20 | ## Suggestion
21 |
22 |
--------------------------------------------------------------------------------
/vesc_hw_interface/config/position_sample.yaml:
--------------------------------------------------------------------------------
1 | controller_manager:
2 | ros__parameters:
3 | update_rate: 100 # Hz
4 | joint_state_broadcaster:
5 | type: joint_state_broadcaster/JointStateBroadcaster
6 | joint_position_controller:
7 | type: position_controllers/JointGroupPositionController
8 |
9 | # Publish all joint states -----------------------------------
10 | joint_state_broadcaster:
11 | ros__parameters:
12 | publish_rate: 100
13 |
14 | joint_position_controller:
15 | ros__parameters:
16 | joints:
17 | - vesc_joint
18 | publish_rate: 100
19 |
--------------------------------------------------------------------------------
/vesc_hw_interface/config/velocity_duty_sample.yaml:
--------------------------------------------------------------------------------
1 | controller_manager:
2 | ros__parameters:
3 | update_rate: 100 # Hz
4 | joint_state_broadcaster:
5 | type: joint_state_broadcaster/JointStateBroadcaster
6 | joint_velocity_controller:
7 | type: velocity_controllers/JointGroupVelocityController
8 |
9 | # Publish all joint states -----------------------------------
10 | joint_state_broadcaster:
11 | ros__parameters:
12 | publish_rate: 100
13 |
14 | joint_velocity_controller:
15 | ros__parameters:
16 | joints:
17 | - vesc_joint
18 | publish_rate: 100
19 |
--------------------------------------------------------------------------------
/vesc/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | vesc
5 | 1.0.0
6 | Metapackage of VESC packages.
7 | SoftBank Corp.
8 | Apache 2.0
9 |
10 | ament_cmake
11 |
12 | vesc_driver
13 | vesc_msgs
14 | vesc_hw_interface
15 |
16 |
17 | ament_cmake
18 |
19 |
20 |
--------------------------------------------------------------------------------
/vesc_driver/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(vesc_driver)
3 |
4 | add_compile_options(-std=c++17)
5 |
6 | if(CMAKE_COMPILER_IS_GNUCXX
7 | OR CMAKE_CXX_COMPILER_ID
8 | MATCHES
9 | "Clang"
10 | )
11 | add_compile_options(
12 | -Wall
13 | -Wextra
14 | -Wpedantic
15 | )
16 | endif()
17 |
18 | find_package(ament_cmake_auto REQUIRED)
19 | find_package(Threads)
20 | ament_auto_find_build_dependencies()
21 |
22 | ###########
23 | ## Build ##
24 | ###########
25 |
26 | # driver libraries
27 | ament_auto_add_library(
28 | ${PROJECT_NAME}
29 | SHARED
30 | src/vesc_interface.cpp
31 | src/vesc_packet.cpp
32 | src/vesc_packet_factory.cpp
33 | )
34 |
35 | ament_auto_package()
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | devel/
2 | logs/
3 | build/
4 | bin/
5 | lib/
6 | msg_gen/
7 | srv_gen/
8 | msg/*Action.msg
9 | msg/*ActionFeedback.msg
10 | msg/*ActionGoal.msg
11 | msg/*ActionResult.msg
12 | msg/*Feedback.msg
13 | msg/*Goal.msg
14 | msg/*Result.msg
15 | msg/_*.py
16 | build_isolated/
17 | devel_isolated/
18 |
19 | # Generated by dynamic reconfigure
20 | *.cfgc
21 | /cfg/cpp/
22 | /cfg/*.py
23 |
24 | # Ignore generated docs
25 | *.dox
26 | *.wikidoc
27 |
28 | # eclipse stuff
29 | .project
30 | .cproject
31 |
32 | # qcreator stuff
33 | CMakeLists.txt.user
34 |
35 | srv/_*.py
36 | *.pcd
37 | *.pyc
38 | qtcreator-*
39 | *.user
40 |
41 | /planning/cfg
42 | /planning/docs
43 | /planning/src
44 |
45 | *~
46 |
47 | # Emacs
48 | .#*
49 |
50 | # VS Code
51 | .vscode/
52 | */.vscode/
53 |
54 | # Catkin custom files
55 | CATKIN_IGNORE
--------------------------------------------------------------------------------
/vesc_driver/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | vesc_driver
5 | 1.0.0
6 | ROS device driver for VESC open source motor driver.
7 | SoftBank Corp.
8 | Apache 2.0
9 |
10 | ament_cmake_auto
11 | asio_cmake_module
12 |
13 | rclcpp
14 | rclcpp_components
15 | std_msgs
16 | vesc_msgs
17 | serial_driver
18 |
19 |
20 | ament_cmake
21 |
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VESC
2 | ## ROS Interfaces for VESC Motor Drivers
3 |
4 |
5 |
6 | ## Composition
7 | This repository is composed as follows:
8 |
9 | - `vesc` is a meta package to manage the other packages.
10 | - `vesc_driver` is the main library to drive VESCs.
11 | - `vesc_hw_interface` wraps `vesc_driver` as a hardware interface to use `ros_control` systems.
12 | - `vesc_msgs` defines messages to publish VESC status.
13 |
14 | ## License
15 | This repositry is licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.html).
16 |
17 | ## Note
18 | A part of these packages had been developed by Michael T. Boulet at MIT under the BSD 3-clause License until Dec. 2016 in the repository named [mit-racecar/vesc](https://github.com/mit-racecar/vesc). Since Nov. 2019, Softbank Corp. takes over development as new packages.
19 |
--------------------------------------------------------------------------------
/vesc_driver/launch/vesc_driver_node.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/vesc_msgs/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | vesc_msgs
5 | 1.0.0
6 | ROS message definitions for VESC open source motor driver.
7 | SoftBank Corp.
8 | Apache 2.0
9 |
10 | ament_cmake
11 | rosidl_default_generators
12 |
13 | builtin_interfaces
14 | std_msgs
15 |
16 | rosidl_default_runtime
17 |
18 | ament_lint_auto
19 | ament_lint_common
20 |
21 | rosidl_interface_packages
22 |
23 |
24 | ament_cmake
25 |
26 |
27 |
--------------------------------------------------------------------------------
/vesc_msgs/msg/VescState.msg:
--------------------------------------------------------------------------------
1 | # Vedder VESC open source motor controller state (telemetry)
2 |
3 | # fault codes
4 | int32 FAULT_CODE_NONE=0
5 | int32 FAULT_CODE_OVER_VOLTAGE=1
6 | int32 FAULT_CODE_UNDER_VOLTAGE=2
7 | int32 FAULT_CODE_DRV8302=3
8 | int32 FAULT_CODE_ABS_OVER_CURRENT=4
9 | int32 FAULT_CODE_OVER_TEMP_FET=5
10 | int32 FAULT_CODE_OVER_TEMP_MOTOR=6
11 |
12 | float64 voltage_input # input voltage (volt)
13 | float64 temperature_pcb # temperature of printed circuit board (degrees Celsius)
14 | float64 current_motor # motor current (ampere)
15 | float64 current_input # input current (ampere)
16 | float64 speed # motor velocity (rad/s)
17 | float64 duty_cycle # duty cycle (0 to 1)
18 | float64 charge_drawn # electric charge drawn from input (ampere-hour)
19 | float64 charge_regen # electric charge regenerated to input (ampere-hour)
20 | float64 energy_drawn # energy drawn from input (watt-hour)
21 | float64 energy_regen # energy regenerated to input (watt-hour)
22 | float64 displacement # net tachometer (counts)
23 | float64 distance_traveled # total tachnometer (counts)
24 | int32 fault_code
25 |
--------------------------------------------------------------------------------
/vesc_hw_interface/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | vesc_hw_interface
5 | 1.0.0
6 | VESC hardware interfaces
7 | SoftBank Corp.
8 | Apache 2.0
9 |
10 | Michael T. Boulet
11 | Yuki Onishi
12 |
13 | ament_cmake
14 |
15 | rclcpp
16 | rclcpp_lifecycle
17 | angles
18 | hardware_interface
19 | controller_manager
20 | velocity_controllers
21 | position_controllers
22 | joint_state_broadcaster
23 | joint_limits
24 | pluginlib
25 | std_msgs
26 | tinyxml2_vendor
27 | urdf
28 | vesc_driver
29 |
30 |
31 | ament_cmake
32 |
33 |
34 |
--------------------------------------------------------------------------------
/vesc_msgs/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(vesc_msgs)
3 |
4 | if(CMAKE_COMPILER_IS_GNUCXX
5 | OR CMAKE_CXX_COMPILER_ID
6 | MATCHES
7 | "Clang"
8 | )
9 | add_compile_options(
10 | -Wall
11 | -Wextra
12 | -Wpedantic
13 | )
14 | endif()
15 |
16 | find_package(ament_cmake REQUIRED)
17 | find_package(rosidl_default_generators REQUIRED)
18 | find_package(std_msgs REQUIRED)
19 |
20 | set(msg_files "msg/VescState.msg" "msg/VescStateStamped.msg")
21 |
22 | rosidl_generate_interfaces(
23 | ${PROJECT_NAME}
24 | ${msg_files}
25 | DEPENDENCIES
26 | std_msgs
27 | )
28 |
29 | ament_export_dependencies(rosidl_default_runtime)
30 |
31 | if(BUILD_TESTING)
32 | find_package(ament_lint_auto REQUIRED)
33 | # the following line skips the linter which checks for copyrights
34 | # comment the line when a copyright and license is added to all source files
35 | set(ament_cmake_copyright_FOUND TRUE)
36 | # the following line skips cpplint (only works in a git repo)
37 | # comment the line when this package is in a git repo and when
38 | # a copyright and license is added to all source files
39 | set(ament_cmake_cpplint_FOUND TRUE)
40 | ament_lint_auto_find_test_dependencies()
41 | endif()
42 |
43 | ament_package()
44 |
--------------------------------------------------------------------------------
/vesc_hw_interface/launch/velocity_test.ros2_control.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | vesc_hw_interface/VescHwInterface
15 | /dev/ttyACM0
16 | velocity
17 |
18 |
19 |
20 | -1
21 | 1
22 |
23 |
24 | -1
25 | 1
26 |
27 |
28 | -1
29 | 1
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/vesc_driver/README.md:
--------------------------------------------------------------------------------
1 | # VESC Driving Library
2 | `vesc_driver` is a basic library to drive motors with a VESC.
3 |
4 | ## Features
5 | - communicates with a VESC.
6 | - Position (PID), velocity, current, and duty-cycle control are supported.
7 | - Calibration and joint limitation are implemented for position control.
8 | - You can give torque constant and gear ratio of your geared motor
9 |
10 | ## Package Structures
11 | #### Dependency Diagram
12 | ```
13 | vesc_driver
14 | -> vesc_interface
15 | |-> vesc_packet_factory
16 | |-> vesc_packet
17 | ```
18 |
19 | #### Description
20 | - `vesc_packet` defines communication packets and the lowest interfaces via USB serial.
21 | - `vesc_packet_factory` creates packets defines in `vesc_packet`.
22 | - `vesc_interface` provides us with basic APIs to drive VESC moto drivers: API functions send commands including duty, reference current, brake, and reference velocity.
23 | - `vesc_driver` publishes all states using `vesc_msgs` and sends commands with callback functions.
24 |
25 |
26 | ## Installation
27 | This package depends on the following ROS packages.
28 |
29 | - nodelet
30 | - pluginlib
31 | - roscpp
32 | - std_msgs
33 | - serial
34 |
35 | Before building this, you have to install them (e.g. with `apt` command).
36 |
37 | ## Usage
38 | will be prepared ...
39 |
40 | ## License
41 | `vesc_driver` is licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.html).
42 |
--------------------------------------------------------------------------------
/vesc_driver/launch/vesc_driver_nodelet.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/vesc_hw_interface/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(vesc_hw_interface)
3 |
4 | add_compile_options(-std=c++17)
5 |
6 | if(CMAKE_COMPILER_IS_GNUCXX
7 | OR CMAKE_CXX_COMPILER_ID
8 | MATCHES
9 | "Clang"
10 | )
11 | add_compile_options(
12 | -Wall
13 | -Wextra
14 | -Wpedantic
15 | )
16 | endif()
17 |
18 | # find dependencies
19 | find_package(ament_cmake_auto REQUIRED)
20 | find_package(Threads)
21 | ament_auto_find_build_dependencies()
22 |
23 | ament_auto_add_library(
24 | ${PROJECT_NAME}
25 | SHARED
26 | src/vesc_hw_interface.cpp
27 | src/vesc_servo_controller.cpp
28 | src/vesc_wheel_controller.cpp
29 | src/vesc_step_difference.cpp
30 | )
31 |
32 | target_include_directories(${PROJECT_NAME} PUBLIC include)
33 |
34 | ament_target_dependencies(${PROJECT_NAME} ${DEPENDENCIES})
35 | target_compile_definitions(${PROJECT_NAME} PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")
36 |
37 | pluginlib_export_plugin_description_file(hardware_interface vesc_hw_interface_plugin.xml)
38 |
39 | install(
40 | DIRECTORY launch config
41 | DESTINATION share/${PROJECT_NAME}
42 | )
43 |
44 | if(BUILD_TESTING)
45 | find_package(ament_lint_auto REQUIRED)
46 | # the following line skips the linter which checks for copyrights
47 | # comment the line when a copyright and license is added to all source files
48 | set(ament_cmake_copyright_FOUND TRUE)
49 | # the following line skips cpplint (only works in a git repo)
50 | # comment the line when this package is in a git repo and when
51 | # a copyright and license is added to all source files
52 | set(ament_cmake_cpplint_FOUND TRUE)
53 | ament_lint_auto_find_test_dependencies()
54 | endif()
55 |
56 | ament_auto_package()
57 |
--------------------------------------------------------------------------------
/vesc_hw_interface/include/vesc_hw_interface/vesc_step_difference.hpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2023 SoftBank Corp.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | ********************************************************************/
17 |
18 | #ifndef VESC_STEP_DIFFERENCE_HPP_
19 | #define VESC_STEP_DIFFERENCE_HPP_
20 |
21 | #include
22 | #include
23 |
24 | namespace vesc_step_difference
25 | {
26 | class VescStepDifference
27 | {
28 | public:
29 | VescStepDifference();
30 | ~VescStepDifference();
31 | double getStepDifference(const double step_in);
32 | void resetStepDifference(const double step_in);
33 | void enableSmooth(double control_rate, double max_sampling_time, int max_step_diff);
34 |
35 | private:
36 | double stepDifferenceRaw(const double step_in, bool reset);
37 | double stepDifferenceVariableWindow(const double step_in, bool reset);
38 |
39 | // Enable smooth difference
40 | bool enable_smooth_;
41 | // Params for counterTDRaw
42 | int32_t step_in_previous_;
43 | // Params for counterTDVariableWindow
44 | int step_diff_vw_max_step_;
45 | std::deque step_input_queue_;
46 | };
47 | } // namespace vesc_step_difference
48 |
49 | #endif // VESC_STEP_DIFFERENCE_HPP_
50 |
--------------------------------------------------------------------------------
/vesc_hw_interface/launch/position_test.ros2_control.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | vesc_hw_interface/VescHwInterface
15 | /dev/ttyACM0
16 | false
17 | 1.0
18 | -0.08
19 | 0.01
20 | -0.08
21 | duty
22 | 0.0
23 | false
24 | 1
25 | 0.8
26 | 0.02
27 | position
28 |
29 |
30 |
31 | -1
32 | 1
33 |
34 |
35 | -1
36 | 1
37 |
38 |
39 | -1
40 | 1
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/vesc_hw_interface/launch/velocity_duty_test.ros2_control.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | vesc_hw_interface/VescHwInterface
15 | /dev/ttyACM0
16 | 0.230769
17 | 1.0
18 | 3
19 | 20
20 | 0.1
21 | 0.01
22 | 0.02
23 | 1.0
24 | 1.0
25 | true
26 | 100.0
27 | true
28 | 0.2
29 | 10
30 | velocity_duty
31 |
32 |
33 |
34 | -1
35 | 1
36 |
37 |
38 | -1
39 | 1
40 |
41 |
42 | -1
43 | 1
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/vesc_hw_interface/include/vesc_hw_interface/visibility_control.h:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Open Source Robotics Foundation, Inc.
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 | #ifndef VESC_HW_INTERFACE__VISIBILITY_H_
16 | #define VESC_HW_INTERFACE__VISIBILITY_H_
17 |
18 | #ifdef __cplusplus
19 | extern "C" {
20 | #endif
21 |
22 | // This logic was borrowed (then namespaced) from the examples on the gcc wiki:
23 | // https://gcc.gnu.org/wiki/Visibility
24 |
25 | #if defined _WIN32 || defined __CYGWIN__
26 |
27 | #ifdef __GNUC__
28 | #define VESC_HW_INTERFACE_EXPORT __attribute__((dllexport))
29 | #define VESC_HW_INTERFACE_IMPORT __attribute__((dllimport))
30 | #else
31 | #define VESC_HW_INTERFACE_EXPORT __declspec(dllexport)
32 | #define VESC_HW_INTERFACE_IMPORT __declspec(dllimport)
33 | #endif
34 |
35 | #ifdef VESC_HW_INTERFACE_DLL
36 | #define VESC_HW_INTERFACE_PUBLIC VESC_HW_INTERFACE_EXPORT
37 | #else
38 | #define VESC_HW_INTERFACE_PUBLIC VESC_HW_INTERFACE_IMPORT
39 | #endif
40 |
41 | #define VESC_HW_INTERFACE_PUBLIC_TYPE VESC_HW_INTERFACE_PUBLIC
42 |
43 | #define VESC_HW_INTERFACE_LOCAL
44 |
45 | #else
46 |
47 | #define VESC_HW_INTERFACE_EXPORT __attribute__((visibility("default")))
48 | #define VESC_HW_INTERFACE_IMPORT
49 |
50 | #if __GNUC__ >= 4
51 | #define VESC_HW_INTERFACE_PUBLIC __attribute__((visibility("default")))
52 | #define VESC_HW_INTERFACE_LOCAL __attribute__((visibility("hidden")))
53 | #else
54 | #define VESC_HW_INTERFACE_PUBLIC
55 | #define VESC_HW_INTERFACE_LOCAL
56 | #endif
57 |
58 | #define VESC_HW_INTERFACE_PUBLIC_TYPE
59 | #endif
60 |
61 | #ifdef __cplusplus
62 | }
63 | #endif
64 |
65 | #endif // VESC_HW_INTERFACE__VISIBILITY_H_
66 |
--------------------------------------------------------------------------------
/vesc_driver/src/vesc_driver_node.cpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2019, SoftBank Corp.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * * Neither the name of Softbank Corp. nor the names of its
14 | * contributors may be used to endorse or promote products derived from
15 | * this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | ********************************************************************/
29 |
30 | /** NOTE *************************************************************
31 | * This program had been developed by Michael T. Boulet at MIT under
32 | * the BSD 3-clause License until Dec. 2016. Since Nov. 2019, Softbank
33 | * Corp. takes over development as new packages.
34 | ********************************************************************/
35 |
36 | // TODO: Migrate to ROS2
37 | #include
38 |
39 | #include "vesc_driver/vesc_driver.h"
40 |
41 | int main(int argc, char** argv)
42 | {
43 | ros::init(argc, argv, "vesc_driver_node");
44 | ros::NodeHandle nh;
45 | ros::NodeHandle private_nh("~");
46 |
47 | vesc_driver::VescDriver vesc_driver(nh, private_nh);
48 |
49 | ros::spin();
50 |
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/vesc_hw_interface/launch/position_duty_test.ros2_control.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | vesc_hw_interface/VescHwInterface
15 | /dev/ttyACM0
16 | 0.230769
17 | 1.0
18 | 3
19 | 1.0
20 | 20
21 | 0.005
22 | 0.005
23 | 0.0025
24 | 1.0
25 | 1.0
26 | true
27 | 100.0
28 | false
29 | 1.0
30 | -0.08
31 | 0.01
32 | -0.08
33 | duty
34 | 0.0
35 | true
36 | 1.0
37 | 10
38 | false
39 | 1
40 | 0.8
41 | 0.02
42 | position_duty
43 |
44 |
45 |
46 | -1
47 | 1
48 |
49 |
50 | -1
51 | 1
52 |
53 |
54 | -1
55 | 1
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/vesc_hw_interface/include/vesc_hw_interface/vesc_wheel_controller.hpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2022 SoftBank Corp.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | ********************************************************************/
17 |
18 | #ifndef VESC_HW_INTERFACE_VESC_WHEEL_CONTROLLER_HPP_
19 | #define VESC_HW_INTERFACE_VESC_WHEEL_CONTROLLER_HPP_
20 |
21 | #include
22 | #include
23 | #include
24 | #include "vesc_hw_interface/vesc_step_difference.hpp"
25 |
26 | namespace vesc_hw_interface
27 | {
28 | using vesc_driver::VescInterface;
29 | using vesc_driver::VescPacket;
30 | using vesc_driver::VescPacketValues;
31 | using vesc_step_difference::VescStepDifference;
32 |
33 | class VescWheelController
34 | {
35 | public:
36 | void init(hardware_interface::HardwareInfo& info, const std::shared_ptr& interface);
37 | void control(const double control_rate);
38 | void setTargetVelocity(const double velocity);
39 | void setGearRatio(const double gear_ratio);
40 | void setTorqueConst(const double torque_const);
41 | void setRotorPoles(const int rotor_poles);
42 | void setHallSensors(const int hall_sensors);
43 | double getPositionSens();
44 | double getVelocitySens();
45 | double getEffortSens();
46 | void updateSensor(const std::shared_ptr& packet);
47 |
48 | private:
49 | std::shared_ptr interface_ptr_;
50 | VescStepDifference vesc_step_difference_;
51 |
52 | double kp_, ki_, kd_;
53 | double i_clamp_;
54 | bool antiwindup_;
55 | double duty_limiter_;
56 | double num_rotor_pole_pairs_, num_rotor_poles_;
57 | double num_hall_sensors_;
58 | double gear_ratio_, torque_const_;
59 |
60 | double target_velocity_;
61 | double position_steps_;
62 | int prev_steps_;
63 | double position_sens_;
64 | double velocity_sens_;
65 | double effort_sens_;
66 |
67 | double error_, error_dt_, error_integ_;
68 | double target_steps_;
69 | bool pid_initialize_;
70 | bool sensor_initialize_;
71 |
72 | double control_rate_;
73 | // rclcpp::Timer control_timer_;
74 | // void controlTimerCallback(const ros::TimerEvent& e);
75 | };
76 | } // namespace vesc_hw_interface
77 |
78 | #endif // VESC_HW_INTERFACE_VESC_WHEEL_CONTROLLER_HPP_
79 |
--------------------------------------------------------------------------------
/vesc_driver/src/vesc_driver_nodelet.cpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2019, SoftBank Corp.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * * Neither the name of Softbank Corp. nor the names of its
14 | * contributors may be used to endorse or promote products derived from
15 | * this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | ********************************************************************/
29 |
30 | /** NOTE *************************************************************
31 | * This program had been developed by Michael T. Boulet at MIT under
32 | * the BSD 3-clause License until Dec. 2016. Since Nov. 2019, Softbank
33 | * Corp. takes over development as new packages.
34 | ********************************************************************/
35 |
36 | // TODO: Migrate to ROS2
37 | #include
38 | #include
39 | #include
40 |
41 | #include "vesc_driver/vesc_driver.h"
42 |
43 | namespace vesc_driver
44 | {
45 | class VescDriverNodelet : public nodelet::Nodelet
46 | {
47 | public:
48 | VescDriverNodelet()
49 | {
50 | }
51 |
52 | private:
53 | virtual void onInit(void);
54 |
55 | std::shared_ptr vesc_driver_;
56 | }; // class VescDriverNodelet
57 |
58 | void VescDriverNodelet::onInit()
59 | {
60 | NODELET_DEBUG("Initializing VESC driver nodelet");
61 | vesc_driver_.reset(new VescDriver(getNodeHandle(), getPrivateNodeHandle()));
62 | }
63 |
64 | } // namespace vesc_driver
65 |
66 | PLUGINLIB_EXPORT_CLASS(vesc_driver::VescDriverNodelet, nodelet::Nodelet);
67 |
--------------------------------------------------------------------------------
/vesc_hw_interface/launch/position_control_sample.launch.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding:utf-8 -*-
3 |
4 | # Copyright (c) 2023 SoftBank Corp.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | import pathlib
20 |
21 | import xacro
22 | from launch import LaunchDescription
23 | from launch.actions import DeclareLaunchArgument
24 | from launch.actions import GroupAction
25 | from launch.actions import OpaqueFunction
26 | from launch.launch_context import LaunchContext
27 | from launch.substitutions import LaunchConfiguration
28 | from launch_ros.actions import Node
29 | from launch_ros.substitutions import FindPackageShare
30 |
31 |
32 | def launch_setup(context: LaunchContext, *args, **kwargs) -> list:
33 |
34 | vesc_pkg = FindPackageShare('vesc_hw_interface').find('vesc_hw_interface')
35 | doc = xacro.process_file(LaunchConfiguration('model').perform(context))
36 | robot_description = {'robot_description': doc.toprettyxml(indent=' ')}
37 |
38 | robot_controllers = [vesc_pkg, '/config/position_sample.yaml']
39 |
40 | control_node = Node(package='controller_manager',
41 | executable='ros2_control_node',
42 | parameters=[robot_description, robot_controllers],
43 | output='both')
44 |
45 | controllers = GroupAction(actions=[
46 | Node(package='controller_manager',
47 | executable='spawner',
48 | output='both',
49 | arguments=['--controller-manager', 'controller_manager', 'joint_state_broadcaster']),
50 | Node(package='controller_manager',
51 | executable='spawner',
52 | output='both',
53 | arguments=['--controller-manager', 'controller_manager', 'joint_position_controller'])
54 | ])
55 |
56 | robot_state = Node(package='robot_state_publisher',
57 | executable='robot_state_publisher',
58 | parameters=[robot_description],
59 | output='both')
60 |
61 | return [control_node, controllers, robot_state]
62 |
63 |
64 | def generate_launch_description() -> LaunchDescription:
65 | """Generate launch descriptions.
66 |
67 | Returns:
68 | Launch descriptions
69 | """
70 | vesc_pkg = pathlib.Path(FindPackageShare('vesc_hw_interface').find('vesc_hw_interface'))
71 | model_arg = DeclareLaunchArgument('model', default_value=str(vesc_pkg / 'launch/position_test.ros2_control.xacro'))
72 |
73 | return LaunchDescription([model_arg, OpaqueFunction(function=launch_setup)])
74 |
--------------------------------------------------------------------------------
/vesc_hw_interface/launch/velocity_control_sample.launch.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding:utf-8 -*-
3 |
4 | # Copyright (c) 2023 SoftBank Corp.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | import pathlib
20 |
21 | import xacro
22 | from launch import LaunchDescription
23 | from launch.actions import DeclareLaunchArgument
24 | from launch.actions import GroupAction
25 | from launch.actions import OpaqueFunction
26 | from launch.launch_context import LaunchContext
27 | from launch.substitutions import LaunchConfiguration
28 | from launch_ros.actions import Node
29 | from launch_ros.substitutions import FindPackageShare
30 |
31 |
32 | def launch_setup(context: LaunchContext, *args, **kwargs) -> list:
33 |
34 | vesc_pkg = FindPackageShare('vesc_hw_interface').find('vesc_hw_interface')
35 | doc = xacro.process_file(LaunchConfiguration('model').perform(context))
36 | robot_description = {"robot_description": doc.toprettyxml(indent=' ')}
37 |
38 | robot_controllers = [vesc_pkg, '/config/velocity_duty_sample.yaml']
39 |
40 | control_node = Node(package="controller_manager",
41 | executable="ros2_control_node",
42 | parameters=[robot_description, robot_controllers],
43 | output="both")
44 |
45 | controllers = GroupAction(actions=[Node(package='controller_manager',
46 | executable='spawner',
47 | output='both',
48 | arguments=["--controller-manager", "controller_manager",
49 | 'joint_state_broadcaster']),
50 | Node(package='controller_manager',
51 | executable='spawner',
52 | output='both',
53 | arguments=["--controller-manager", "controller_manager",
54 | 'joint_velocity_controller'])])
55 |
56 | robot_state = Node(package='robot_state_publisher',
57 | executable='robot_state_publisher',
58 | parameters=[robot_description],
59 | output='both')
60 |
61 | return [control_node, controllers, robot_state]
62 |
63 |
64 | def generate_launch_description() -> LaunchDescription:
65 | """Generate launch descriptions.
66 |
67 | Returns:
68 | Launch descriptions
69 | """
70 | vesc_pkg = pathlib.Path(FindPackageShare('vesc_hw_interface').find('vesc_hw_interface'))
71 | model_arg = DeclareLaunchArgument(
72 | 'model',
73 | default_value=str(vesc_pkg / 'launch/velocity_duty_test.ros2_control.xacro'))
74 |
75 | return LaunchDescription([
76 | model_arg,
77 | OpaqueFunction(function=launch_setup)
78 | ])
79 |
--------------------------------------------------------------------------------
/vesc_hw_interface/include/vesc_hw_interface/vesc_hw_interface.hpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2019, SoftBank Corp.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | ********************************************************************/
16 |
17 | #ifndef VESC_HW_INTERFACE_VESC_HW_INTERFACE_HPP_
18 | #define VESC_HW_INTERFACE_VESC_HW_INTERFACE_HPP_
19 |
20 | #include "visibility_control.h"
21 | #include
22 | // #include
23 | // #include
24 | // #include
25 | // #include
26 | #include
27 | #include
28 | #include
29 | #include "vesc_driver/vesc_interface.hpp"
30 | #include "vesc_hw_interface/vesc_servo_controller.hpp"
31 | #include "vesc_hw_interface/vesc_wheel_controller.hpp"
32 |
33 |
34 | namespace vesc_hw_interface
35 | {
36 | using vesc_driver::VescInterface;
37 | using vesc_driver::VescPacket;
38 | using vesc_driver::VescPacketValues;
39 | using vesc_driver::VescPacketMCConf;
40 | using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
41 |
42 | class VescHwInterface : public hardware_interface::ActuatorInterface
43 | {
44 | public:
45 | VescHwInterface();
46 |
47 | CallbackReturn on_init(const hardware_interface::HardwareInfo& info) override;
48 | CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) override;
49 | CallbackReturn on_cleanup(const rclcpp_lifecycle::State& previous_state) override;
50 | CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override;
51 | CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;
52 | CallbackReturn on_shutdown(const rclcpp_lifecycle::State& previous_state) override;
53 | CallbackReturn on_error(const rclcpp_lifecycle::State& previous_state) override;
54 | std::vector export_state_interfaces() override;
55 | std::vector export_command_interfaces() override;
56 | hardware_interface::return_type read(const rclcpp::Time& time, const rclcpp::Duration& period) override;
57 | hardware_interface::return_type write(const rclcpp::Time& time, const rclcpp::Duration& period) override;
58 | rclcpp::Time getTime() const;
59 |
60 | private:
61 | std::shared_ptr vesc_interface_;
62 | VescServoController servo_controller_;
63 | VescWheelController wheel_controller_;
64 |
65 | std::string joint_name_, command_mode_, port_;
66 | std::string joint_type_;
67 | double upper_limit_, lower_limit_;
68 | bool homing_enabled_;
69 | bool homing_done_;
70 | double homing_offset_;
71 | double homing_position_;
72 | int32_t prev_steps_;
73 | double position_steps_;
74 | bool sensor_initialize_;
75 |
76 | double command_;
77 | double position_, velocity_, effort_; // joint states
78 |
79 | int num_rotor_poles_; // the number of rotor poles
80 | int num_hall_sensors_; // the number of hall sensors
81 | double gear_ratio_, torque_const_; // physical params
82 | double screw_lead_; // linear distance (m) of 1 revolution
83 |
84 | // joint_limits_interface::PositionJointSaturationInterface limit_position_interface_;
85 | // joint_limits_interface::VelocityJointSaturationInterface limit_velocity_interface_;
86 | // joint_limits_interface::EffortJointSaturationInterface limit_effort_interface_;
87 |
88 | void packetCallback(const std::shared_ptr&);
89 | void errorCallback(const std::string&);
90 |
91 | static constexpr double VESC_POS_RANGE = 360.0; // Full angular range of the VESC PID position control
92 | static constexpr double VESC_POS_MAPPING_RANGE = 90.0; // Range for mapping the position to the VESC
93 | static constexpr double VESC_POS_WRAP_THRESHOLD = (VESC_POS_RANGE - VESC_POS_MAPPING_RANGE) / 2.0 + VESC_POS_MAPPING_RANGE; // Angle at which to wrap the position (overflow/underflow)
94 | };
95 |
96 | } // namespace vesc_hw_interface
97 |
98 | #endif // VESC_HW_INTERFACE_VESC_HW_INTERFACE_HPP_
99 |
--------------------------------------------------------------------------------
/vesc_hw_interface/include/vesc_hw_interface/vesc_servo_controller.hpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2019, SoftBank Corp.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | ********************************************************************/
16 |
17 | #ifndef VESC_HW_INTERFACE_VESC_SERVO_CONTROLLER_HPP_
18 | #define VESC_HW_INTERFACE_VESC_SERVO_CONTROLLER_HPP_
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include "vesc_hw_interface/vesc_step_difference.hpp"
25 | #include
26 |
27 | namespace vesc_hw_interface
28 | {
29 | using vesc_driver::VescInterface;
30 | using vesc_driver::VescPacket;
31 | using vesc_driver::VescPacketValues;
32 | using vesc_step_difference::VescStepDifference;
33 |
34 | class VescServoController
35 | {
36 | public:
37 | VescServoController();
38 | ~VescServoController();
39 |
40 | void init(hardware_interface::HardwareInfo& info, const std::shared_ptr& interface,
41 | const double gear_ratio = 0.0, const double torque_const = 0.0, const int rotor_poles = 0,
42 | const int hall_sensors = 0, const int joint_type = 0, const double screw_lead = 0.0,
43 | const double upper_endstop_position = 0.0, const double lower_endstop_position = 0.0);
44 | void control(const double control_rate);
45 | void setTargetPosition(const double position);
46 | void setGearRatio(const double gear_ratio);
47 | void setTorqueConst(const double torque_const);
48 | void setRotorPoles(const int rotor_poles);
49 | void setHallSensors(const int hall_sensors);
50 | void setJointType(const int joint_type);
51 | void setScrewLead(const double screw_lead);
52 | double getZeroPosition() const;
53 | void spinSensorData();
54 | double getPositionSens();
55 | double getVelocitySens();
56 | double getEffortSens();
57 | void executeCalibration();
58 | void updateSensor(const std::shared_ptr& packet);
59 | bool calibrate();
60 | struct CalibrationParameters
61 | {
62 | double calibration_position;
63 | bool enable_calibration;
64 | };
65 | CalibrationParameters getCalibrationParameters() const;
66 |
67 | private:
68 | rclcpp::Node::SharedPtr node_;
69 | std::shared_ptr interface_ptr_;
70 | VescStepDifference vesc_step_difference_;
71 |
72 | const std::string DUTY_ = "duty";
73 | const std::string CURRENT_ = "current";
74 |
75 | bool calibration_flag_;
76 | bool calibration_rewind_;
77 | double calibration_current_; // unit: A
78 | double calibration_strict_current_; // unit: A
79 | double calibration_duty_; // 0.0 ~ 1.0
80 | double calibration_strict_duty_; // 0.0 ~ 1.0
81 | std::string calibration_mode_; // "duty" or "current" (default: "current")
82 | double calibration_position_; // unit: rad or m
83 | double zero_position_; // unit: rad or m
84 | double kp_, ki_, kd_;
85 | double i_clamp_, duty_limiter_;
86 | bool antiwindup_;
87 | double control_rate_;
88 | int num_rotor_poles_; // the number of rotor poles
89 | int num_hall_sensors_; // the number of hall sensors
90 | double gear_ratio_, torque_const_; // physical params
91 | double screw_lead_; // linear distance (m) of 1 revolution
92 | int joint_type_;
93 | // ros::Timer control_timer_;
94 | // Internal variables for PID control
95 | double target_position_;
96 | double target_position_previous_;
97 | double sens_position_, sens_velocity_, sens_effort_;
98 | double position_steps_;
99 | double position_resolution_;
100 | int32_t steps_previous_;
101 | double error_integ_;
102 | // Internal variables for initialization
103 | bool sensor_initialize_;
104 | int calibration_steps_;
105 | double calibration_previous_position_;
106 | std::string calibration_result_path_;
107 | double upper_endstop_position_, lower_endstop_position_;
108 | rclcpp::Subscription::SharedPtr endstop_sub_;
109 | std::deque endstop_deque_;
110 | int endstop_window_;
111 | double endstop_threshold_;
112 | double endstop_margin_;
113 |
114 | // void controlTimerCallback(const ros::TimerEvent& e);
115 | void endstopCallback(const std_msgs::msg::Bool::ConstSharedPtr& msg);
116 | };
117 |
118 | } // namespace vesc_hw_interface
119 |
120 | #endif // VESC_HW_INTERFACE_VESC_SERVO_CONTROLLER_HPP_
121 |
--------------------------------------------------------------------------------
/vesc_driver/include/vesc_driver/vesc_packet_factory.hpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Copyright (c) 2019, SoftBank Corp.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * * Neither the name of Softbank Corp. nor the names of its
14 | * contributors may be used to endorse or promote products derived from
15 | * this software without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | * POSSIBILITY OF SUCH DAMAGE.
28 | ********************************************************************/
29 |
30 | /** NOTE *************************************************************
31 | * This program had been developed by Michael T. Boulet at MIT under
32 | * the BSD 3-clause License until Dec. 2016. Since Nov. 2019, Softbank
33 | * Corp. takes over development as new packages.
34 | ********************************************************************/
35 |
36 | #ifndef VESC_DRIVER_VESC_PACKET_FACTORY_HPP_
37 | #define VESC_DRIVER_VESC_PACKET_FACTORY_HPP_
38 |
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include