diff --git a/.github/workflows/ros1-ci.yaml b/.github/workflows/ros2-ci.yaml
similarity index 62%
rename from .github/workflows/ros1-ci.yaml
rename to .github/workflows/ros2-ci.yaml
index 056436c..4e27f67 100644
--- a/.github/workflows/ros1-ci.yaml
+++ b/.github/workflows/ros2-ci.yaml
@@ -1,30 +1,34 @@
-name: ROS1 CI Workflow
+name: ROS2 CI Workflow
on:
pull_request:
+ branches:
+ - ros2
push:
branches:
- - main
+ - ros2
jobs:
- build-ros1:
- runs-on: ubuntu-latest
+ build-ros2:
strategy:
fail-fast: false
+ matrix:
+ config:
+ - {
+ ros_distro: "humble"
+ }
+ runs-on: ubuntu-latest
container:
- image: ros:melodic
+ image: ros:${{ matrix.config.ros_distro }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Create Workspace
run: |
- mkdir -p src_tmp/vesc; \
- mv `find -maxdepth 1 -not -name . -not -name src_tmp` src_tmp/vesc/; \
- mv src_tmp/ src/; \
- cd src; \
- bash -c 'source /opt/ros/$ROS_DISTRO/setup.bash; \
- catkin_init_workspace'
+ mkdir -p src_tmp/vesc
+ mv `find -maxdepth 1 -not -name . -not -name src_tmp` src_tmp/vesc/
+ mv src_tmp/ src/
- name: Install Dependencies
run: |
bash -c 'source /opt/ros/$ROS_DISTRO/setup.bash; \
@@ -33,9 +37,9 @@ jobs:
- name: Build Workspace
run: |
bash -c 'source /opt/ros/$ROS_DISTRO/setup.bash; \
- catkin_make'
+ colcon build --event-handlers console_cohesion+'
- name: Run Tests
run: |
bash -c 'source /opt/ros/$ROS_DISTRO/setup.bash; \
- catkin_make run_tests; \
- catkin_test_results --verbose'
+ colcon test --event-handlers console_cohesion+; \
+ colcon test-result --verbose'
diff --git a/README.md b/README.md
index 959c0dd..9cd4091 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,34 @@
# Veddar VESC Interface
-
+Vesc is a new repository that was forked to provide a local instance for developing minor changes required for the C1T system. The only update included in this release is negating the speed value sent to the vesc due to the motors being installed in the opposite direction.
Packages to interface with Veddar VESC motor controllers. See https://vesc-project.com/ for details
+
+This is a ROS2 implementation of the ROS1 driver using the new serial driver located in [transport drivers](https://github.com/ros-drivers/transport_drivers).
+
+## How to test
+
+1. Clone this repository and [transport drivers](https://github.com/ros-drivers/transport_drivers) into `src`.
+2. `rosdep update && rosdep install --from-paths src -i -y`
+3. Plug in the VESC with a USB cable.
+4. Modify `vesc/vesc_driver/params/vesc_config.yaml` to reflect any changes.
+5. Build the packages `colcon build`
+6. `ros2 launch vesc_driver vesc_driver_node.launch.py`
+7. If prompted "permission denied" on the serial port: `sudo chmod 777 /dev/ttyACM0`
+
+## Contribution
+Welcome to the CARMA contributing guide. Please read this guide to learn about our development process, how to propose pull requests and improvements, and how to build and test your changes to this project. [CARMA Contributing Guide](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Contributing.md)
+
+## Code of Conduct
+Please read our [CARMA Code of Conduct](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Code_of_Conduct.md) which outlines our expectations for participants within the CARMA community, as well as steps to reporting unacceptable behavior. We are committed to providing a welcoming and inspiring community for all and expect our code of conduct to be honored. Anyone who violates this code of conduct may be banned from the community.
+
+## Attribution
+The development team would like to acknowledge the people who have made direct contributions to the design and code in this repository. [CARMA Attribution](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/ATTRIBUTION.txt)
+
+## License
+By contributing to the Federal Highway Administration (FHWA) Connected Automated Research Mobility Applications (CARMA), you agree that your contributions will be licensed under its Apache License 2.0 license. [CARMA License](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/docs/License.md)
+
+## Contact
+Please click on the CARMA logo below to visit the Federal Highway Adminstration(FHWA) CARMA website. For technical support from the CARMA team, please contact the CARMA help desk at CAVSupportServices@dot.gov.
+
+[](https://highways.dot.gov/research/research-programs/operations/CARMA)
diff --git a/vesc/CMakeLists.txt b/vesc/CMakeLists.txt
index 13b2b81..1caee5d 100644
--- a/vesc/CMakeLists.txt
+++ b/vesc/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.3)
+cmake_minimum_required(VERSION 3.5)
project(vesc)
-find_package(catkin REQUIRED)
-catkin_metapackage()
+find_package(ament_cmake_auto REQUIRED)
+ament_auto_package()
diff --git a/vesc/package.xml b/vesc/package.xml
index e1deeb4..e4748c1 100644
--- a/vesc/package.xml
+++ b/vesc/package.xml
@@ -13,14 +13,15 @@
https://github.com/f1tenth/vesc/issues
Michael T. Boulet
Joshua Whitley
+ Haoru Xue
- catkin
+ ament_cmake_auto
vesc_driver
vesc_msgs
vesc_ackermann
-
+ ament_cmake
diff --git a/vesc_ackermann/CMakeLists.txt b/vesc_ackermann/CMakeLists.txt
index 166d201..9a5ba87 100644
--- a/vesc_ackermann/CMakeLists.txt
+++ b/vesc_ackermann/CMakeLists.txt
@@ -1,101 +1,48 @@
-cmake_minimum_required(VERSION 2.8.3)
+cmake_minimum_required(VERSION 3.5)
project(vesc_ackermann)
-# Setting C++ standard to 11
-if (NOT "${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}")
- message(STATUS "Changing CXX_STANDARD from C++98 to C++11")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-elseif ("${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}" STREQUAL "98")
- message(STATUS "Changing CXX_STANDARD from C++98 to C++11")
- set(CMAKE_CXX_STANDARD 11)
+# Setting C++ standard to 14
+if(NOT "${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}")
+ message(STATUS "Changing CXX_STANDARD from C++98 to C++14")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
+elseif("${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}" STREQUAL "98")
+ message(STATUS "Changing CXX_STANDARD from C++98 to C++14")
+ set(CMAKE_CXX_STANDARD 14)
endif()
-find_package(catkin REQUIRED COMPONENTS
- ackermann_msgs
- geometry_msgs
- nav_msgs
- nodelet
- pluginlib
- roscpp
- roslint
- std_msgs
- tf
- vesc_msgs
-)
-
-catkin_package(
- INCLUDE_DIRS include
- CATKIN_DEPENDS
- ackermann_msgs
- geometry_msgs
- nav_msgs
- nodelet
- pluginlib
- std_msgs
- tf
- vesc_msgs
-)
+find_package(ament_cmake_auto REQUIRED)
+ament_auto_find_build_dependencies()
###########
## Build ##
###########
-include_directories(
- include
- ${catkin_INCLUDE_DIRS}
+# nodes library
+ament_auto_add_library(${PROJECT_NAME} SHARED
+ src/ackermann_to_vesc.cpp
+ src/vesc_to_odom.cpp
)
-# node executable
-add_executable(vesc_to_odom_node src/vesc_to_odom_node.cpp
- src/vesc_to_odom.cpp)
-add_dependencies(vesc_to_odom_node ${catkin_EXPORTED_TARGETS})
-target_link_libraries(vesc_to_odom_node
- ${catkin_LIBRARIES}
+# register nodes as components
+rclcpp_components_register_node(${PROJECT_NAME}
+ PLUGIN vesc_ackermann::AckermannToVesc
+ EXECUTABLE ackermann_to_vesc_node
)
-
-add_executable(ackermann_to_vesc_node src/ackermann_to_vesc_node.cpp
- src/ackermann_to_vesc.cpp)
-add_dependencies(ackermann_to_vesc_node ${catkin_EXPORTED_TARGETS})
-target_link_libraries(ackermann_to_vesc_node
- ${catkin_LIBRARIES}
+rclcpp_components_register_node(${PROJECT_NAME}
+ PLUGIN vesc_ackermann::VescToOdom
+ EXECUTABLE vesc_to_odom_node
)
-# nodelet library
-add_library(vesc_ackermann_nodelet src/ackermann_to_vesc_nodelet.cpp
- src/ackermann_to_vesc.cpp
- src/vesc_to_odom_nodelet.cpp
- src/vesc_to_odom.cpp)
-add_dependencies(vesc_ackermann_nodelet ${catkin_EXPORTED_TARGETS})
-target_link_libraries(vesc_ackermann_nodelet
- ${catkin_LIBRARIES}
-)
-
-set(ROSLINT_CPP_OPTS "--filter=-build/c++11")
-roslint_cpp()
-
-#############
-## Install ##
-#############
-
-install(TARGETS vesc_to_odom_node ackermann_to_vesc_node
- RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
-)
-
-install(TARGETS vesc_ackermann_nodelet
- LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
-)
-
-install(DIRECTORY include/${PROJECT_NAME}/
- DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
-install(FILES vesc_ackermann_nodelet.xml
- DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
-install(DIRECTORY launch/
- DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch)
-
#############
## Testing ##
#############
-if(CATKIN_ENABLE_TESTING)
- roslint_add_test()
+if(BUILD_TESTING)
+ find_package(ament_lint_auto REQUIRED)
+ ament_lint_auto_find_test_dependencies()
endif()
+
+ament_auto_package(
+ INSTALL_TO_SHARE
+ launch
+)
diff --git a/vesc_ackermann/include/vesc_ackermann/ackermann_to_vesc.h b/vesc_ackermann/include/vesc_ackermann/ackermann_to_vesc.h
deleted file mode 100644
index 33c4d10..0000000
--- a/vesc_ackermann/include/vesc_ackermann/ackermann_to_vesc.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2020 F1TENTH Foundation
-//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// -*- mode:c++; fill-column: 100; -*-
-
-#ifndef VESC_ACKERMANN_ACKERMANN_TO_VESC_H_
-#define VESC_ACKERMANN_ACKERMANN_TO_VESC_H_
-
-#include
-#include
-
-namespace vesc_ackermann
-{
-
-class AckermannToVesc
-{
-public:
- AckermannToVesc(ros::NodeHandle nh, ros::NodeHandle private_nh);
-
-private:
- // ROS parameters
- // conversion gain and offset
- double speed_to_erpm_gain_, speed_to_erpm_offset_;
- double steering_to_servo_gain_, steering_to_servo_offset_;
-
- /** @todo consider also providing an interpolated look-up table conversion */
-
- // ROS services
- ros::Publisher erpm_pub_;
- ros::Publisher servo_pub_;
- ros::Subscriber ackermann_sub_;
-
- // ROS callbacks
- void ackermannCmdCallback(const ackermann_msgs::AckermannDriveStamped::ConstPtr& cmd);
-};
-
-} // namespace vesc_ackermann
-
-#endif // VESC_ACKERMANN_ACKERMANN_TO_VESC_H_
diff --git a/vesc_ackermann/include/vesc_ackermann/ackermann_to_vesc.hpp b/vesc_ackermann/include/vesc_ackermann/ackermann_to_vesc.hpp
new file mode 100644
index 0000000..b646c36
--- /dev/null
+++ b/vesc_ackermann/include/vesc_ackermann/ackermann_to_vesc.hpp
@@ -0,0 +1,68 @@
+// Copyright 2020 F1TENTH Foundation
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// * Neither the name of the {copyright_holder} nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+
+// -*- mode:c++; fill-column: 100; -*-
+
+#ifndef VESC_ACKERMANN__ACKERMANN_TO_VESC_HPP_
+#define VESC_ACKERMANN__ACKERMANN_TO_VESC_HPP_
+
+#include
+#include
+#include
+
+namespace vesc_ackermann
+{
+
+using ackermann_msgs::msg::AckermannDriveStamped;
+using std_msgs::msg::Float64;
+
+class AckermannToVesc : public rclcpp::Node
+{
+public:
+ explicit AckermannToVesc(const rclcpp::NodeOptions & options);
+
+private:
+ // ROS parameters
+ // conversion gain and offset
+ double speed_to_erpm_gain_, speed_to_erpm_offset_;
+ double steering_to_servo_gain_, steering_to_servo_offset_;
+
+ /** @todo consider also providing an interpolated look-up table conversion */
+
+ // ROS services
+ rclcpp::Publisher::SharedPtr erpm_pub_;
+ rclcpp::Publisher::SharedPtr servo_pub_;
+ rclcpp::Subscription::SharedPtr ackermann_sub_;
+
+ // ROS callbacks
+ void ackermannCmdCallback(const AckermannDriveStamped::SharedPtr cmd);
+};
+
+} // namespace vesc_ackermann
+
+#endif // VESC_ACKERMANN__ACKERMANN_TO_VESC_HPP_
diff --git a/vesc_ackermann/include/vesc_ackermann/vesc_to_odom.h b/vesc_ackermann/include/vesc_ackermann/vesc_to_odom.h
deleted file mode 100644
index f864833..0000000
--- a/vesc_ackermann/include/vesc_ackermann/vesc_to_odom.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright 2020 F1TENTH Foundation
-//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// -*- mode:c++; fill-column: 100; -*-
-
-#ifndef VESC_ACKERMANN_VESC_TO_ODOM_H_
-#define VESC_ACKERMANN_VESC_TO_ODOM_H_
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-namespace vesc_ackermann
-{
-
-class VescToOdom
-{
-public:
- VescToOdom(ros::NodeHandle nh, ros::NodeHandle private_nh);
-
-private:
- // ROS parameters
- std::string odom_frame_;
- std::string base_frame_;
- /** State message does not report servo position, so use the command instead */
- bool use_servo_cmd_;
- // conversion gain and offset
- double speed_to_erpm_gain_, speed_to_erpm_offset_;
- double steering_to_servo_gain_, steering_to_servo_offset_;
- double wheelbase_;
- bool publish_tf_;
-
- // odometry state
- double x_, y_, yaw_;
- std_msgs::Float64::ConstPtr last_servo_cmd_; ///< Last servo position commanded value
- vesc_msgs::VescStateStamped::ConstPtr last_state_; ///< Last received state message
-
- // ROS services
- ros::Publisher odom_pub_;
- ros::Subscriber vesc_state_sub_;
- ros::Subscriber servo_sub_;
- std::shared_ptr tf_pub_;
-
- // ROS callbacks
- void vescStateCallback(const vesc_msgs::VescStateStamped::ConstPtr& state);
- void servoCmdCallback(const std_msgs::Float64::ConstPtr& servo);
-};
-
-} // namespace vesc_ackermann
-
-#endif // VESC_ACKERMANN_VESC_TO_ODOM_H_
diff --git a/vesc_ackermann/include/vesc_ackermann/vesc_to_odom.hpp b/vesc_ackermann/include/vesc_ackermann/vesc_to_odom.hpp
new file mode 100644
index 0000000..60eb3a7
--- /dev/null
+++ b/vesc_ackermann/include/vesc_ackermann/vesc_to_odom.hpp
@@ -0,0 +1,86 @@
+// Copyright 2020 F1TENTH Foundation
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// * Neither the name of the {copyright_holder} nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+
+// -*- mode:c++; fill-column: 100; -*-
+
+#ifndef VESC_ACKERMANN__VESC_TO_ODOM_HPP_
+#define VESC_ACKERMANN__VESC_TO_ODOM_HPP_
+
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+namespace vesc_ackermann
+{
+
+using nav_msgs::msg::Odometry;
+using std_msgs::msg::Float64;
+using vesc_msgs::msg::VescStateStamped;
+
+class VescToOdom : public rclcpp::Node
+{
+public:
+ explicit VescToOdom(const rclcpp::NodeOptions & options);
+
+private:
+ // ROS parameters
+ std::string odom_frame_;
+ std::string base_frame_;
+ /** State message does not report servo position, so use the command instead */
+ bool use_servo_cmd_;
+ // conversion gain and offset
+ double speed_to_erpm_gain_, speed_to_erpm_offset_;
+ double steering_to_servo_gain_, steering_to_servo_offset_;
+ double wheelbase_;
+ bool publish_tf_;
+
+ // odometry state
+ double x_, y_, yaw_;
+ Float64::SharedPtr last_servo_cmd_; ///< Last servo position commanded value
+ VescStateStamped::SharedPtr last_state_; ///< Last received state message
+
+ // ROS services
+ rclcpp::Publisher::SharedPtr odom_pub_;
+ rclcpp::Subscription::SharedPtr vesc_state_sub_;
+ rclcpp::Subscription::SharedPtr servo_sub_;
+ std::shared_ptr tf_pub_;
+
+ // ROS callbacks
+ void vescStateCallback(const VescStateStamped::SharedPtr state);
+ void servoCmdCallback(const Float64::SharedPtr servo);
+};
+
+} // namespace vesc_ackermann
+
+#endif // VESC_ACKERMANN__VESC_TO_ODOM_HPP_
diff --git a/vesc_ackermann/launch/ackermann_to_vesc_node.launch b/vesc_ackermann/launch/ackermann_to_vesc_node.launch
deleted file mode 100644
index d0b2ea9..0000000
--- a/vesc_ackermann/launch/ackermann_to_vesc_node.launch
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/vesc_ackermann/launch/ackermann_to_vesc_node.launch.xml b/vesc_ackermann/launch/ackermann_to_vesc_node.launch.xml
new file mode 100644
index 0000000..4cbf7b7
--- /dev/null
+++ b/vesc_ackermann/launch/ackermann_to_vesc_node.launch.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vesc_ackermann/launch/ackermann_to_vesc_nodelet.launch b/vesc_ackermann/launch/ackermann_to_vesc_nodelet.launch
deleted file mode 100644
index 5060fe3..0000000
--- a/vesc_ackermann/launch/ackermann_to_vesc_nodelet.launch
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/vesc_ackermann/launch/vesc_to_odom_node.launch b/vesc_ackermann/launch/vesc_to_odom_node.launch
deleted file mode 100644
index a2cf374..0000000
--- a/vesc_ackermann/launch/vesc_to_odom_node.launch
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/vesc_ackermann/launch/vesc_to_odom_node.launch.xml b/vesc_ackermann/launch/vesc_to_odom_node.launch.xml
new file mode 100644
index 0000000..712d443
--- /dev/null
+++ b/vesc_ackermann/launch/vesc_to_odom_node.launch.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vesc_ackermann/launch/vesc_to_odom_nodelet.launch b/vesc_ackermann/launch/vesc_to_odom_nodelet.launch
deleted file mode 100644
index 19a3aab..0000000
--- a/vesc_ackermann/launch/vesc_to_odom_nodelet.launch
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/vesc_ackermann/package.xml b/vesc_ackermann/package.xml
index 34d1301..bd39777 100644
--- a/vesc_ackermann/package.xml
+++ b/vesc_ackermann/package.xml
@@ -14,21 +14,21 @@
Michael T. Boulet
Joshua Whitley
- catkin
-
- roslint
+ ament_cmake_auto
ackermann_msgs
geometry_msgs
nav_msgs
- nodelet
- pluginlib
- roscpp
+ rclcpp
+ rclcpp_components
std_msgs
- tf
+ tf2_ros
vesc_msgs
+ ament_lint_auto
+ ament_lint_common
+
-
+ ament_cmake
diff --git a/vesc_ackermann/src/ackermann_to_vesc.cpp b/vesc_ackermann/src/ackermann_to_vesc.cpp
index da29626..79863f8 100644
--- a/vesc_ackermann/src/ackermann_to_vesc.cpp
+++ b/vesc_ackermann/src/ackermann_to_vesc.cpp
@@ -1,91 +1,88 @@
// Copyright 2020 F1TENTH Foundation
//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
+// * Neither the name of the {copyright_holder} nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
// -*- mode:c++; fill-column: 100; -*-
-#include "vesc_ackermann/ackermann_to_vesc.h"
+#include "vesc_ackermann/ackermann_to_vesc.hpp"
#include
#include
#include
-#include
+#include
+#include
namespace vesc_ackermann
{
-template
-inline bool getRequiredParam(const ros::NodeHandle& nh, const std::string& name, T* value);
+using ackermann_msgs::msg::AckermannDriveStamped;
+using std::placeholders::_1;
+using std_msgs::msg::Float64;
-AckermannToVesc::AckermannToVesc(ros::NodeHandle nh, ros::NodeHandle private_nh)
+AckermannToVesc::AckermannToVesc(const rclcpp::NodeOptions & options)
+: Node("ackermann_to_vesc_node", options)
{
// get conversion parameters
- if (!getRequiredParam(nh, "speed_to_erpm_gain", &speed_to_erpm_gain_))
- return;
- if (!getRequiredParam(nh, "speed_to_erpm_offset", &speed_to_erpm_offset_))
- return;
- if (!getRequiredParam(nh, "steering_angle_to_servo_gain", &steering_to_servo_gain_))
- return;
- if (!getRequiredParam(nh, "steering_angle_to_servo_offset", &steering_to_servo_offset_))
- return;
+ speed_to_erpm_gain_ = declare_parameter("speed_to_erpm_gain");
+ speed_to_erpm_offset_ = declare_parameter("speed_to_erpm_offset");
+ steering_to_servo_gain_ =
+ declare_parameter("steering_angle_to_servo_gain");
+ steering_to_servo_offset_ =
+ declare_parameter("steering_angle_to_servo_offset");
// create publishers to vesc electric-RPM (speed) and servo commands
- erpm_pub_ = nh.advertise("commands/motor/speed", 10);
- servo_pub_ = nh.advertise("commands/servo/position", 10);
+ erpm_pub_ = create_publisher("commands/motor/speed", 10);
+ servo_pub_ = create_publisher("commands/servo/position", 10);
// subscribe to ackermann topic
- ackermann_sub_ = nh.subscribe("ackermann_cmd", 10, &AckermannToVesc::ackermannCmdCallback, this);
+ ackermann_sub_ = create_subscription(
+ "ackermann_cmd", 10, std::bind(&AckermannToVesc::ackermannCmdCallback, this, _1));
}
-typedef ackermann_msgs::AckermannDriveStamped::ConstPtr AckermannMsgPtr;
-void AckermannToVesc::ackermannCmdCallback(const AckermannMsgPtr& cmd)
+void AckermannToVesc::ackermannCmdCallback(const AckermannDriveStamped::SharedPtr cmd)
{
// calc vesc electric RPM (speed)
- std_msgs::Float64::Ptr erpm_msg(new std_msgs::Float64);
- erpm_msg->data = speed_to_erpm_gain_ * cmd->drive.speed + speed_to_erpm_offset_;
+ Float64 erpm_msg;
+ erpm_msg.data = speed_to_erpm_gain_ * cmd->drive.speed + speed_to_erpm_offset_;
// calc steering angle (servo)
- std_msgs::Float64::Ptr servo_msg(new std_msgs::Float64);
- servo_msg->data = steering_to_servo_gain_ * cmd->drive.steering_angle + steering_to_servo_offset_;
+ Float64 servo_msg;
+ servo_msg.data = steering_to_servo_gain_ * cmd->drive.steering_angle + steering_to_servo_offset_;
// publish
- if (ros::ok())
- {
- erpm_pub_.publish(erpm_msg);
- servo_pub_.publish(servo_msg);
+ if (rclcpp::ok()) {
+ erpm_pub_->publish(erpm_msg);
+ servo_pub_->publish(servo_msg);
}
}
-template
-inline bool getRequiredParam(const ros::NodeHandle& nh, const std::string& name, T* value)
-{
- if (nh.getParam(name, *value))
- return true;
+} // namespace vesc_ackermann
- ROS_FATAL("AckermannToVesc: Parameter %s is required.", name.c_str());
- return false;
-}
+#include "rclcpp_components/register_node_macro.hpp" // NOLINT
-} // namespace vesc_ackermann
+RCLCPP_COMPONENTS_REGISTER_NODE(vesc_ackermann::AckermannToVesc)
diff --git a/vesc_ackermann/src/ackermann_to_vesc_node.cpp b/vesc_ackermann/src/ackermann_to_vesc_node.cpp
deleted file mode 100644
index d7fcec0..0000000
--- a/vesc_ackermann/src/ackermann_to_vesc_node.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2020 F1TENTH Foundation
-//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include
-
-#include "vesc_ackermann/ackermann_to_vesc.h"
-
-int main(int argc, char** argv)
-{
- ros::init(argc, argv, "ackermann_to_vesc_node");
- ros::NodeHandle nh;
- ros::NodeHandle private_nh("~");
-
- vesc_ackermann::AckermannToVesc ackermann_to_vesc(nh, private_nh);
-
- ros::spin();
-
- return 0;
-}
diff --git a/vesc_ackermann/src/ackermann_to_vesc_nodelet.cpp b/vesc_ackermann/src/ackermann_to_vesc_nodelet.cpp
deleted file mode 100644
index 5b72582..0000000
--- a/vesc_ackermann/src/ackermann_to_vesc_nodelet.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2020 F1TENTH Foundation
-//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include
-#include
-#include
-
-#include
-
-#include "vesc_ackermann/ackermann_to_vesc.h"
-
-namespace vesc_ackermann
-{
-
-class AckermannToVescNodelet: public nodelet::Nodelet
-{
-public:
- AckermannToVescNodelet() {}
-
-private:
- virtual void onInit(void);
-
- std::shared_ptr ackermann_to_vesc_;
-}; // class AckermannToVescNodelet
-
-void AckermannToVescNodelet::onInit()
-{
- NODELET_DEBUG("Initializing ackermann to VESC nodelet");
- ackermann_to_vesc_.reset(new AckermannToVesc(getNodeHandle(), getPrivateNodeHandle()));
-}
-
-} // namespace vesc_ackermann
-
-PLUGINLIB_EXPORT_CLASS(vesc_ackermann::AckermannToVescNodelet, nodelet::Nodelet);
diff --git a/vesc_ackermann/src/vesc_to_odom.cpp b/vesc_ackermann/src/vesc_to_odom.cpp
index cca7d11..c136970 100644
--- a/vesc_ackermann/src/vesc_to_odom.cpp
+++ b/vesc_ackermann/src/vesc_to_odom.cpp
@@ -1,188 +1,197 @@
// Copyright 2020 F1TENTH Foundation
//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
+// * Neither the name of the {copyright_holder} nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
// -*- mode:c++; fill-column: 100; -*-
-#include "vesc_ackermann/vesc_to_odom.h"
+// Changes made from upstream
+// - negated current_speed value
+
+#include "vesc_ackermann/vesc_to_odom.hpp"
#include
#include
-#include
-#include
+#include
+#include
namespace vesc_ackermann
{
-template
-inline bool getRequiredParam(const ros::NodeHandle& nh, const std::string& name, T* value);
-
-VescToOdom::VescToOdom(ros::NodeHandle nh, ros::NodeHandle private_nh) :
- odom_frame_("odom"), base_frame_("base_link"),
- use_servo_cmd_(true), publish_tf_(false), x_(0.0), y_(0.0), yaw_(0.0)
+using geometry_msgs::msg::TransformStamped;
+using nav_msgs::msg::Odometry;
+using std::placeholders::_1;
+using std_msgs::msg::Float64;
+using vesc_msgs::msg::VescStateStamped;
+
+VescToOdom::VescToOdom(const rclcpp::NodeOptions & options)
+: Node("vesc_to_odom_node", options),
+ odom_frame_("odom"),
+ base_frame_("base_link"),
+ use_servo_cmd_(true),
+ publish_tf_(false),
+ x_(0.0),
+ y_(0.0),
+ yaw_(0.0)
{
// get ROS parameters
- private_nh.param("odom_frame", odom_frame_, odom_frame_);
- private_nh.param("base_frame", base_frame_, base_frame_);
- private_nh.param("use_servo_cmd_to_calc_angular_velocity", use_servo_cmd_, use_servo_cmd_);
- if (!getRequiredParam(nh, "speed_to_erpm_gain", &speed_to_erpm_gain_))
- return;
- if (!getRequiredParam(nh, "speed_to_erpm_offset", &speed_to_erpm_offset_))
- return;
- if (use_servo_cmd_)
- {
- if (!getRequiredParam(nh, "steering_angle_to_servo_gain", &steering_to_servo_gain_))
- return;
- if (!getRequiredParam(nh, "steering_angle_to_servo_offset", &steering_to_servo_offset_))
- return;
- if (!getRequiredParam(nh, "wheelbase", &wheelbase_))
- return;
+ odom_frame_ = declare_parameter("odom_frame", odom_frame_);
+ base_frame_ = declare_parameter("base_frame", base_frame_);
+ use_servo_cmd_ = declare_parameter("use_servo_cmd_to_calc_angular_velocity", use_servo_cmd_);
+
+ speed_to_erpm_gain_ = declare_parameter("speed_to_erpm_gain");
+ speed_to_erpm_offset_ = declare_parameter("speed_to_erpm_offset");
+
+ if (use_servo_cmd_) {
+ steering_to_servo_gain_ =
+ declare_parameter("steering_angle_to_servo_gain");
+ steering_to_servo_offset_ =
+ declare_parameter("steering_angle_to_servo_offset");
+ wheelbase_ = declare_parameter("wheelbase");
}
- private_nh.param("publish_tf", publish_tf_, publish_tf_);
+
+ publish_tf_ = declare_parameter("publish_tf", publish_tf_);
// create odom publisher
- odom_pub_ = nh.advertise("odom", 10);
+ odom_pub_ = create_publisher("odom", 10);
// create tf broadcaster
- if (publish_tf_)
- {
- tf_pub_.reset(new tf::TransformBroadcaster);
+ if (publish_tf_) {
+ tf_pub_.reset(new tf2_ros::TransformBroadcaster(this));
}
// subscribe to vesc state and. optionally, servo command
- vesc_state_sub_ = nh.subscribe("sensors/core", 10, &VescToOdom::vescStateCallback, this);
- if (use_servo_cmd_)
- {
- servo_sub_ = nh.subscribe("sensors/servo_position_command", 10,
- &VescToOdom::servoCmdCallback, this);
+ vesc_state_sub_ = create_subscription(
+ "sensors/core", 10, std::bind(&VescToOdom::vescStateCallback, this, _1));
+
+ if (use_servo_cmd_) {
+ servo_sub_ = create_subscription(
+ "sensors/servo_position_command", 10, std::bind(&VescToOdom::servoCmdCallback, this, _1));
}
}
-void VescToOdom::vescStateCallback(const vesc_msgs::VescStateStamped::ConstPtr& state)
+void VescToOdom::vescStateCallback(const VescStateStamped::SharedPtr state)
{
// check that we have a last servo command if we are depending on it for angular velocity
- if (use_servo_cmd_ && !last_servo_cmd_)
+ if (use_servo_cmd_ && !last_servo_cmd_) {
return;
+ }
+ // Begin change from upstream
// convert to engineering units
- double current_speed = (-state->state.speed - speed_to_erpm_offset_) / speed_to_erpm_gain_;
- if (std::fabs(current_speed) < 0.05)
- {
+ double current_speed = -(-state->state.speed - speed_to_erpm_offset_) / speed_to_erpm_gain_;
+ // End change from upstream
+ if (std::fabs(current_speed) < 0.05) {
current_speed = 0.0;
}
double current_steering_angle(0.0), current_angular_velocity(0.0);
- if (use_servo_cmd_)
- {
+ if (use_servo_cmd_) {
current_steering_angle =
(last_servo_cmd_->data - steering_to_servo_offset_) / steering_to_servo_gain_;
current_angular_velocity = current_speed * tan(current_steering_angle) / wheelbase_;
}
// use current state as last state if this is our first time here
- if (!last_state_)
+ if (!last_state_) {
last_state_ = state;
+ }
// calc elapsed time
- ros::Duration dt = state->header.stamp - last_state_->header.stamp;
+ auto dt = rclcpp::Time(state->header.stamp) - rclcpp::Time(last_state_->header.stamp);
/** @todo could probably do better propigating odometry, e.g. trapezoidal integration */
// propigate odometry
double x_dot = current_speed * cos(yaw_);
double y_dot = current_speed * sin(yaw_);
- x_ += x_dot * dt.toSec();
- y_ += y_dot * dt.toSec();
- if (use_servo_cmd_)
- yaw_ += current_angular_velocity * dt.toSec();
+ x_ += x_dot * dt.seconds();
+ y_ += y_dot * dt.seconds();
+ if (use_servo_cmd_) {
+ yaw_ += current_angular_velocity * dt.seconds();
+ }
// save state for next time
last_state_ = state;
// publish odometry message
- nav_msgs::Odometry::Ptr odom(new nav_msgs::Odometry);
- odom->header.frame_id = odom_frame_;
- odom->header.stamp = state->header.stamp;
- odom->child_frame_id = base_frame_;
+ Odometry odom;
+ odom.header.frame_id = odom_frame_;
+ odom.header.stamp = state->header.stamp;
+ odom.child_frame_id = base_frame_;
// Position
- odom->pose.pose.position.x = x_;
- odom->pose.pose.position.y = y_;
- odom->pose.pose.orientation.x = 0.0;
- odom->pose.pose.orientation.y = 0.0;
- odom->pose.pose.orientation.z = sin(yaw_ / 2.0);
- odom->pose.pose.orientation.w = cos(yaw_ / 2.0);
+ odom.pose.pose.position.x = x_;
+ odom.pose.pose.position.y = y_;
+ odom.pose.pose.orientation.x = 0.0;
+ odom.pose.pose.orientation.y = 0.0;
+ odom.pose.pose.orientation.z = sin(yaw_ / 2.0);
+ odom.pose.pose.orientation.w = cos(yaw_ / 2.0);
// Position uncertainty
/** @todo Think about position uncertainty, perhaps get from parameters? */
- odom->pose.covariance[0] = 0.2; ///< x
- odom->pose.covariance[7] = 0.2; ///< y
- odom->pose.covariance[35] = 0.4; ///< yaw
+ odom.pose.covariance[0] = 0.2; ///< x
+ odom.pose.covariance[7] = 0.2; ///< y
+ odom.pose.covariance[35] = 0.4; ///< yaw
// Velocity ("in the coordinate frame given by the child_frame_id")
- odom->twist.twist.linear.x = current_speed;
- odom->twist.twist.linear.y = 0.0;
- odom->twist.twist.angular.z = current_angular_velocity;
+ odom.twist.twist.linear.x = current_speed;
+ odom.twist.twist.linear.y = 0.0;
+ odom.twist.twist.angular.z = current_angular_velocity;
// Velocity uncertainty
/** @todo Think about velocity uncertainty */
- if (publish_tf_)
- {
- geometry_msgs::TransformStamped tf;
+ if (publish_tf_) {
+ TransformStamped tf;
tf.header.frame_id = odom_frame_;
tf.child_frame_id = base_frame_;
- tf.header.stamp = ros::Time::now();
+ tf.header.stamp = now();
tf.transform.translation.x = x_;
tf.transform.translation.y = y_;
tf.transform.translation.z = 0.0;
- tf.transform.rotation = odom->pose.pose.orientation;
- if (ros::ok())
- {
+ tf.transform.rotation = odom.pose.pose.orientation;
+
+ if (rclcpp::ok()) {
tf_pub_->sendTransform(tf);
}
}
- if (ros::ok())
- {
- odom_pub_.publish(odom);
+ if (rclcpp::ok()) {
+ odom_pub_->publish(odom);
}
}
-void VescToOdom::servoCmdCallback(const std_msgs::Float64::ConstPtr& servo)
+void VescToOdom::servoCmdCallback(const Float64::SharedPtr servo)
{
last_servo_cmd_ = servo;
}
-template
-inline bool getRequiredParam(const ros::NodeHandle& nh, const std::string& name, T* value)
-{
- if (nh.getParam(name, *value))
- return true;
+} // namespace vesc_ackermann
- ROS_FATAL("VescToOdom: Parameter %s is required.", name.c_str());
- return false;
-}
+#include "rclcpp_components/register_node_macro.hpp" // NOLINT
-} // namespace vesc_ackermann
+RCLCPP_COMPONENTS_REGISTER_NODE(vesc_ackermann::VescToOdom)
diff --git a/vesc_ackermann/src/vesc_to_odom_node.cpp b/vesc_ackermann/src/vesc_to_odom_node.cpp
deleted file mode 100644
index caea389..0000000
--- a/vesc_ackermann/src/vesc_to_odom_node.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2020 F1TENTH Foundation
-//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include
-
-#include "vesc_ackermann/vesc_to_odom.h"
-
-int main(int argc, char** argv)
-{
- ros::init(argc, argv, "vesc_to_odom_node");
- ros::NodeHandle nh;
- ros::NodeHandle private_nh("~");
-
- vesc_ackermann::VescToOdom vesc_to_odom(nh, private_nh);
-
- ros::spin();
-
- return 0;
-}
diff --git a/vesc_ackermann/src/vesc_to_odom_nodelet.cpp b/vesc_ackermann/src/vesc_to_odom_nodelet.cpp
deleted file mode 100644
index 5f21c85..0000000
--- a/vesc_ackermann/src/vesc_to_odom_nodelet.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2020 F1TENTH Foundation
-//
-// Redistribution and use in source and binary forms, with or without modification, are permitted
-// provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of conditions
-// and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include
-#include
-#include
-
-#include
-
-#include "vesc_ackermann/vesc_to_odom.h"
-
-namespace vesc_ackermann
-{
-
-class VescToOdomNodelet: public nodelet::Nodelet
-{
-public:
- VescToOdomNodelet() {}
-
-private:
- virtual void onInit(void);
-
- std::shared_ptr vesc_to_odom_;
-}; // class VescToOdomNodelet
-
-void VescToOdomNodelet::onInit()
-{
- NODELET_DEBUG("Initializing RACECAR VESC odometry estimator nodelet");
- vesc_to_odom_.reset(new VescToOdom(getNodeHandle(), getPrivateNodeHandle()));
-}
-
-} // namespace vesc_ackermann
-
-PLUGINLIB_EXPORT_CLASS(vesc_ackermann::VescToOdomNodelet, nodelet::Nodelet);
diff --git a/vesc_ackermann/vesc_ackermann_nodelet.xml b/vesc_ackermann/vesc_ackermann_nodelet.xml
deleted file mode 100644
index b12358a..0000000
--- a/vesc_ackermann/vesc_ackermann_nodelet.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- Nodelet for translating ackermann messages to VESC motor controller commands.
-
-
- Nodelet for translating VESC motor controller state to odometry messages.
-
-
diff --git a/vesc_driver/CMakeLists.txt b/vesc_driver/CMakeLists.txt
index 50221d3..5d3eac0 100644
--- a/vesc_driver/CMakeLists.txt
+++ b/vesc_driver/CMakeLists.txt
@@ -1,100 +1,56 @@
-cmake_minimum_required(VERSION 2.8.3)
+cmake_minimum_required(VERSION 3.5)
project(vesc_driver)
-# Set minimum C++ standard to C++11
-if (NOT "${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}")
- message(STATUS "Changing CXX_STANDARD from C++98 to C++11")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-elseif ("${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}" STREQUAL "98")
- message(STATUS "Changing CXX_STANDARD from C++98 to C++11")
- set(CMAKE_CXX_STANDARD 11)
+# Set minimum C++ standard to C++14
+if(NOT "${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}")
+ message(STATUS "Changing CXX_STANDARD from C++98 to C++14")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
+elseif("${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}" STREQUAL "98")
+ message(STATUS "Changing CXX_STANDARD from C++98 to C++14")
+ set(CMAKE_CXX_STANDARD 14)
endif()
-find_package(Boost REQUIRED)
+find_package(ament_cmake_auto REQUIRED)
+ament_auto_find_build_dependencies()
-find_package(catkin REQUIRED COMPONENTS
- nodelet
- pluginlib
- roscpp
- roslint
- serial
- std_msgs
- vesc_msgs
-)
-
-catkin_package(
- INCLUDE_DIRS include
- CATKIN_DEPENDS
- nodelet
- pluginlib
- std_msgs
- vesc_msgs serial
-)
+find_package(Threads)
###########
## Build ##
###########
-include_directories(
- include
- ${Boost_INCLUDE_DIRS}
- ${catkin_INCLUDE_DIRS}
+# node library
+ament_auto_add_library(${PROJECT_NAME} SHARED
+ src/vesc_driver.cpp
+ src/vesc_interface.cpp
+ src/vesc_packet.cpp
+ src/vesc_packet_factory.cpp
)
-
-# node executable
-add_executable(vesc_driver_node src/vesc_driver_node.cpp
- src/vesc_driver.cpp
- src/vesc_interface.cpp
- src/vesc_packet.cpp
- src/vesc_packet_factory.cpp)
-add_dependencies(vesc_driver_node ${catkin_EXPORTED_TARGETS})
-target_link_libraries(vesc_driver_node
- ${catkin_LIBRARIES}
+target_link_libraries(${PROJECT_NAME}
+ ${CMAKE_THREAD_LIBS_INIT}
)
-
-# nodelet library
-add_library(vesc_driver_nodelet src/vesc_driver_nodelet.cpp
- src/vesc_driver.cpp
- src/vesc_interface.cpp
- src/vesc_packet.cpp
- src/vesc_packet_factory.cpp)
-add_dependencies(vesc_driver_nodelet ${catkin_EXPORTED_TARGETS})
-target_link_libraries(vesc_driver_nodelet
- ${catkin_LIBRARIES}
+rclcpp_components_register_node(${PROJECT_NAME}
+ PLUGIN vesc_driver::VescDriver
+ EXECUTABLE ${PROJECT_NAME}_node
)
-file(GLOB_RECURSE ${PROJECT_NAME}_CPP_FILES
- RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- . *.cpp *.h)
-list(REMOVE_ITEM ${PROJECT_NAME}_CPP_FILES
- include/${PROJECT_NAME}/crc.h)
-
-set(ROSLINT_CPP_OPTS "--filter=-build/c++11")
-roslint_cpp(${${PROJECT_NAME}_CPP_FILES})
-
-#############
-## Install ##
-#############
-
-install(TARGETS vesc_driver_node
- RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
-)
-
-install(TARGETS vesc_driver_nodelet
- LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
+ament_auto_add_executable(
+ vesc_device_namer
+ src/vesc_device_namer.cpp
+ src/vesc_device_uuid_lookup.cpp
)
-install(DIRECTORY include/${PROJECT_NAME}/
- DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
-install(FILES vesc_driver_nodelet.xml
- DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
-install(DIRECTORY launch/
- DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch)
-
#############
## Testing ##
#############
-if(CATKIN_ENABLE_TESTING)
- roslint_add_test()
+if(BUILD_TESTING)
+ find_package(ament_lint_auto REQUIRED)
+ ament_lint_auto_find_test_dependencies()
endif()
+
+ament_auto_package(
+ INSTALL_TO_SHARE
+ launch
+ params
+)
diff --git a/vesc_driver/include/vesc_driver/crc.h b/vesc_driver/include/vesc_driver/crc.hpp
similarity index 57%
rename from vesc_driver/include/vesc_driver/crc.h
rename to vesc_driver/include/vesc_driver/crc.hpp
index 68e322d..1d85830 100644
--- a/vesc_driver/include/vesc_driver/crc.h
+++ b/vesc_driver/include/vesc_driver/crc.hpp
@@ -1,38 +1,36 @@
-/**
- @file CRC.h
+// Copyright (c) 2020, Daniel Bahr
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// * Neither the name of the {copyright_holder} nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+
+/**
+ @file CRC.hpp
@author Daniel Bahr
@version 1.0.1.0
@copyright
- @parblock
- CRC++
- Copyright (c) 2020, Daniel Bahr
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- * Neither the name of CRC++ nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- @endparblock
*/
/*
@@ -52,78 +50,78 @@
multiplication in the bit-by-bit calculation instead of a small conditional. The branchless implementation
may be faster on processor architectures which support single-instruction integer multiplication.
#define CRCPP_USE_CPP11 - Define to enables C++11 features (move semantics, constexpr, static_assert, etc.).
- #define CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - Define to include definitions for little-used CRCs.
+ #define CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - Define to include definitions for little-used CRCs.
*/
-#ifndef VESC_DRIVER_CRC_H_
-#define VESC_DRIVER_CRC_H_
+#ifndef VESC_DRIVER__CRC_HPP_
+#define VESC_DRIVER__CRC_HPP_
-#include // Includes CHAR_BIT
+#include // Includes CHAR_BIT
#ifdef CRCPP_USE_CPP11
-#include // Includes ::std::size_t
-#include // Includes ::std::uint8_t, ::std::uint16_t, ::std::uint32_t, ::std::uint64_t
+#include // Includes ::std::size_t
+#include // Includes ::std::uint8_t, ::std::uint16_t, ::std::uint32_t, ::std::uint64_t
#else
-#include // Includes size_t
-#include // Includes uint8_t, uint16_t, uint32_t, uint64_t
+#include // Includes size_t
+#include // Includes uint8_t, uint16_t, uint32_t, uint64_t
#endif
-#include // Includes ::std::numeric_limits
-#include // Includes ::std::move
+#include // Includes ::std::numeric_limits
+#include // Includes ::std::move
#ifndef crcpp_uint8
# ifdef CRCPP_USE_CPP11
- /// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint8 ::std::uint8_t
# else
- /// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint8 uint8_t
# endif
#endif
#ifndef crcpp_uint16
# ifdef CRCPP_USE_CPP11
- /// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint16 ::std::uint16_t
# else
- /// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint16 uint16_t
# endif
#endif
#ifndef crcpp_uint32
# ifdef CRCPP_USE_CPP11
- /// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint32 ::std::uint32_t
# else
- /// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint32 uint32_t
# endif
#endif
#ifndef crcpp_uint64
# ifdef CRCPP_USE_CPP11
- /// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint64 ::std::uint64_t
# else
- /// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
+/// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
# define crcpp_uint64 uint64_t
# endif
#endif
#ifndef crcpp_size
# ifdef CRCPP_USE_CPP11
- /// @brief Unsigned size definition, used for specifying data sizes.
+/// @brief Unsigned size definition, used for specifying data sizes.
# define crcpp_size ::std::size_t
# else
- /// @brief Unsigned size definition, used for specifying data sizes.
+/// @brief Unsigned size definition, used for specifying data sizes.
# define crcpp_size size_t
# endif
#endif
#ifdef CRCPP_USE_CPP11
- /// @brief Compile-time expression definition.
+/// @brief Compile-time expression definition.
# define crcpp_constexpr constexpr
#else
- /// @brief Compile-time expression definition.
+/// @brief Compile-time expression definition.
# define crcpp_constexpr const
#endif
@@ -142,163 +140,176 @@ namespace CRCPP
class CRC
{
public:
- // Forward declaration
- template
- struct Table;
-
- /**
- @brief CRC parameters.
- */
- template
- struct Parameters
- {
- CRCType polynomial; ///< CRC polynomial
- CRCType initialValue; ///< Initial CRC value
- CRCType finalXOR; ///< Value to XOR with the final CRC
- bool reflectInput; ///< true to reflect all input bytes
- bool reflectOutput; ///< true to reflect the output CRC (reflection occurs before the final XOR)
-
- Table MakeTable() const;
- };
-
- /**
- @brief CRC lookup table. After construction, the CRC parameters are fixed.
- @note A CRC table can be used for multiple CRC calculations.
- */
- template
- struct Table
- {
- // Constructors are intentionally NOT marked explicit.
- Table(const Parameters & parameters);
+ // Forward declaration
+ template
+ struct Table;
+
+ /**
+ @brief CRC parameters.
+ */
+ template
+ struct Parameters
+ {
+ CRCType polynomial; ///< CRC polynomial
+ CRCType initialValue; ///< Initial CRC value
+ CRCType finalXOR; ///< Value to XOR with the final CRC
+ bool reflectInput; ///< true to reflect all input bytes
+ bool reflectOutput; ///< true to reflect the output CRC (reflection occurs before the final XOR) // NOLINT
+
+ Table MakeTable() const;
+ };
+
+ /**
+ @brief CRC lookup table. After construction, the CRC parameters are fixed.
+ @note A CRC table can be used for multiple CRC calculations.
+ */
+ template
+ struct Table
+ {
+ // Constructors are intentionally NOT marked explicit.
+ explicit Table(const Parameters & parameters);
#ifdef CRCPP_USE_CPP11
- Table(Parameters && parameters);
+ explicit Table(Parameters && parameters);
#endif
- const Parameters & GetParameters() const;
-
- const CRCType * GetTable() const;
-
- CRCType operator[](unsigned char index) const;
-
- private:
- void InitTable();
-
- Parameters parameters; ///< CRC parameters used to construct the table
- CRCType table[1 << CHAR_BIT]; ///< CRC lookup table
- };
-
- // The number of bits in CRCType must be at least as large as CRCWidth.
- // CRCType must be an unsigned integer type or a custom type with operator overloads.
- template
- static CRCType Calculate(const void * data, crcpp_size size, const Parameters & parameters);
-
- template
- static CRCType Calculate(const void * data, crcpp_size size, const Parameters & parameters, CRCType crc);
+ const Parameters & GetParameters() const;
- template
- static CRCType Calculate(const void * data, crcpp_size size, const Table & lookupTable);
+ const CRCType * GetTable() const;
- template
- static CRCType Calculate(const void * data, crcpp_size size, const Table & lookupTable, CRCType crc);
+ CRCType operator[](unsigned char index) const;
- // Common CRCs up to 64 bits.
- // Note: Check values are the computed CRCs when given an ASCII input of "123456789" (without null terminator)
+private:
+ void InitTable();
+
+ Parameters parameters; ///< CRC parameters used to construct the table
+ CRCType table[1 << CHAR_BIT]; ///< CRC lookup table
+ };
+
+ // The number of bits in CRCType must be at least as large as CRCWidth.
+ // CRCType must be an unsigned integer type or a custom type with operator overloads.
+ template
+ static CRCType Calculate(
+ const void * data, crcpp_size size, const Parameters & parameters);
+
+ template
+ static CRCType Calculate(
+ const void * data, crcpp_size size, const Parameters & parameters, CRCType crc);
+
+ template
+ static CRCType Calculate(
+ const void * data, crcpp_size size, const Table & lookupTable);
+
+ template
+ static CRCType Calculate(
+ const void * data, crcpp_size size, const Table & lookupTable, CRCType crc);
+
+ // Common CRCs up to 64 bits.
+ // Note: Check values are the computed CRCs when given an ASCII input of "123456789"
+ // (without null terminator)
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters< crcpp_uint8, 4> & CRC_4_ITU();
- static const Parameters< crcpp_uint8, 5> & CRC_5_EPC();
- static const Parameters< crcpp_uint8, 5> & CRC_5_ITU();
- static const Parameters< crcpp_uint8, 5> & CRC_5_USB();
- static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000A();
- static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000B();
- static const Parameters< crcpp_uint8, 6> & CRC_6_ITU();
- static const Parameters< crcpp_uint8, 7> & CRC_7();
+ static const Parameters & CRC_4_ITU();
+ static const Parameters & CRC_5_EPC();
+ static const Parameters & CRC_5_ITU();
+ static const Parameters & CRC_5_USB();
+ static const Parameters & CRC_6_CDMA2000A();
+ static const Parameters & CRC_6_CDMA2000B();
+ static const Parameters & CRC_6_ITU();
+ static const Parameters & CRC_7();
#endif
- static const Parameters< crcpp_uint8, 8> & CRC_8();
+ static const Parameters & CRC_8();
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters< crcpp_uint8, 8> & CRC_8_EBU();
- static const Parameters< crcpp_uint8, 8> & CRC_8_MAXIM();
- static const Parameters< crcpp_uint8, 8> & CRC_8_WCDMA();
- static const Parameters & CRC_10();
- static const Parameters & CRC_10_CDMA2000();
- static const Parameters & CRC_11();
- static const Parameters & CRC_12_CDMA2000();
- static const Parameters & CRC_12_DECT();
- static const Parameters & CRC_12_UMTS();
- static const Parameters & CRC_13_BBC();
- static const Parameters & CRC_15();
- static const Parameters & CRC_15_MPT1327();
+ static const Parameters & CRC_8_EBU();
+ static const Parameters & CRC_8_MAXIM();
+ static const Parameters & CRC_8_WCDMA();
+ static const Parameters & CRC_10();
+ static const Parameters & CRC_10_CDMA2000();
+ static const Parameters & CRC_11();
+ static const Parameters & CRC_12_CDMA2000();
+ static const Parameters & CRC_12_DECT();
+ static const Parameters & CRC_12_UMTS();
+ static const Parameters & CRC_13_BBC();
+ static const Parameters & CRC_15();
+ static const Parameters & CRC_15_MPT1327();
#endif
- static const Parameters & CRC_16_ARC();
- static const Parameters & CRC_16_BUYPASS();
- static const Parameters & CRC_16_CCITTFALSE();
+ static const Parameters & CRC_16_ARC();
+ static const Parameters & CRC_16_BUYPASS();
+ static const Parameters & CRC_16_CCITTFALSE();
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters & CRC_16_CDMA2000();
- static const Parameters & CRC_16_CMS();
- static const Parameters & CRC_16_DECTR();
- static const Parameters & CRC_16_DECTX();
- static const Parameters & CRC_16_DNP();
+ static const Parameters & CRC_16_CDMA2000();
+ static const Parameters & CRC_16_CMS();
+ static const Parameters & CRC_16_DECTR();
+ static const Parameters & CRC_16_DECTX();
+ static const Parameters & CRC_16_DNP();
#endif
- static const Parameters & CRC_16_GENIBUS();
- static const Parameters & CRC_16_KERMIT();
+ static const Parameters & CRC_16_GENIBUS();
+ static const Parameters & CRC_16_KERMIT();
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters & CRC_16_MAXIM();
- static const Parameters & CRC_16_MODBUS();
- static const Parameters & CRC_16_T10DIF();
- static const Parameters & CRC_16_USB();
+ static const Parameters & CRC_16_MAXIM();
+ static const Parameters & CRC_16_MODBUS();
+ static const Parameters & CRC_16_T10DIF();
+ static const Parameters & CRC_16_USB();
#endif
- static const Parameters & CRC_16_X25();
- static const Parameters & CRC_16_XMODEM();
+ static const Parameters & CRC_16_X25();
+ static const Parameters & CRC_16_XMODEM();
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters & CRC_17_CAN();
- static const Parameters & CRC_21_CAN();
- static const Parameters & CRC_24();
- static const Parameters & CRC_24_FLEXRAYA();
- static const Parameters & CRC_24_FLEXRAYB();
- static const Parameters & CRC_30();
+ static const Parameters & CRC_17_CAN();
+ static const Parameters & CRC_21_CAN();
+ static const Parameters & CRC_24();
+ static const Parameters & CRC_24_FLEXRAYA();
+ static const Parameters & CRC_24_FLEXRAYB();
+ static const Parameters & CRC_30();
#endif
- static const Parameters & CRC_32();
- static const Parameters & CRC_32_BZIP2();
+ static const Parameters & CRC_32();
+ static const Parameters & CRC_32_BZIP2();
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters & CRC_32_C();
+ static const Parameters & CRC_32_C();
#endif
- static const Parameters & CRC_32_MPEG2();
- static const Parameters & CRC_32_POSIX();
+ static const Parameters & CRC_32_MPEG2();
+ static const Parameters & CRC_32_POSIX();
#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
- static const Parameters & CRC_32_Q();
- static const Parameters & CRC_40_GSM();
- static const Parameters & CRC_64();
+ static const Parameters & CRC_32_Q();
+ static const Parameters & CRC_40_GSM();
+ static const Parameters & CRC_64();
#endif
#ifdef CRCPP_USE_CPP11
- CRC() = delete;
- CRC(const CRC & other) = delete;
- CRC & operator=(const CRC & other) = delete;
- CRC(CRC && other) = delete;
- CRC & operator=(CRC && other) = delete;
+ CRC() = delete;
+ CRC(const CRC & other) = delete;
+ CRC & operator=(const CRC & other) = delete;
+ CRC(CRC && other) = delete;
+ CRC & operator=(CRC && other) = delete;
#endif
private:
#ifndef CRCPP_USE_CPP11
- CRC();
- CRC(const CRC & other);
- CRC & operator=(const CRC & other);
+ CRC();
+ CRC(const CRC & other);
+ CRC & operator=(const CRC & other);
#endif
- template
- static IntegerType Reflect(IntegerType value, crcpp_uint16 numBits);
+ template
+ static IntegerType Reflect(IntegerType value, crcpp_uint16 numBits);
- template
- static CRCType Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput);
+ template
+ static CRCType Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput);
- template
- static CRCType UndoFinalize(CRCType remainder, CRCType finalXOR, bool reflectOutput);
+ template
+ static CRCType UndoFinalize(CRCType remainder, CRCType finalXOR, bool reflectOutput);
- template
- static CRCType CalculateRemainder(const void * data, crcpp_size size, const Parameters & parameters, CRCType remainder);
+ template
+ static CRCType CalculateRemainder(
+ const void * data, crcpp_size size, const Parameters & parameters, CRCType remainder);
- template
- static CRCType CalculateRemainder(const void * data, crcpp_size size, const Table & lookupTable, CRCType remainder);
+ template
+ static CRCType CalculateRemainder(
+ const void * data, crcpp_size size, const Table & lookupTable, CRCType remainder);
};
/**
@@ -309,11 +320,11 @@ class CRC
@tparam CRCWidth Number of bits in the CRC
@return CRC lookup table
*/
-template
+template
inline CRC::Table CRC::Parameters::MakeTable() const
{
- // This should take advantage of RVO and optimize out the copy.
- return CRC::Table(*this);
+ // This should take advantage of RVO and optimize out the copy.
+ return CRC::Table(*this);
}
/**
@@ -322,11 +333,11 @@ inline CRC::Table CRC::Parameters::MakeTab
@tparam CRCType Integer type for storing the CRC result
@tparam CRCWidth Number of bits in the CRC
*/
-template
-inline CRC::Table::Table(const Parameters & params) :
- parameters(params)
+template
+inline CRC::Table::Table(const Parameters & params)
+: parameters(params)
{
- InitTable();
+ InitTable();
}
#ifdef CRCPP_USE_CPP11
@@ -336,11 +347,11 @@ inline CRC::Table::Table(const Parameters
@tparam CRCType Integer type for storing the CRC result
@tparam CRCWidth Number of bits in the CRC
*/
-template
-inline CRC::Table::Table(Parameters && params) :
- parameters(::std::move(params))
+template
+inline CRC::Table::Table(Parameters && params)
+: parameters(::std::move(params))
{
- InitTable();
+ InitTable();
}
#endif
@@ -350,10 +361,11 @@ inline CRC::Table::Table(Parameters && par
@tparam CRCWidth Number of bits in the CRC
@return CRC parameters
*/
-template
-inline const CRC::Parameters & CRC::Table::GetParameters() const
+template
+inline const CRC::Parameters & CRC::Table::GetParameters() const
{
- return parameters;
+ return parameters;
}
/**
@@ -362,10 +374,10 @@ inline const CRC::Parameters & CRC::Table:
@tparam CRCWidth Number of bits in the CRC
@return CRC table
*/
-template