Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mecanum drive controller adding and ported to ros2 #4

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
27ed35d
compiling without error
Robotgir Jan 6, 2023
d327065
all tests working
Robotgir Jan 6, 2023
6adb982
reorganized publishers added code to print values for debug
Robotgir Jan 7, 2023
1d5f5e3
added meaning full param values
Robotgir Jan 8, 2023
ebe3525
next line in comment
Robotgir Jan 8, 2023
d2db9e4
Automated formatting files.
destogl Jan 9, 2023
3957f77
Manual changes of formatting.
destogl Jan 9, 2023
34845d5
Delete LICENSE
destogl Jan 9, 2023
a08a307
Apply suggestions from code review
Robotgir Jan 10, 2023
8f4d6a6
Apply suggestions from code review
Robotgir Jan 10, 2023
9d78f16
used the suggested structure
Robotgir Jan 10, 2023
8e6f7a6
general changes
Robotgir Jan 10, 2023
6e56813
removed bacc accumulators
Robotgir Jan 10, 2023
1e99467
renaming to more meaningful and readable variable names
Robotgir Jan 11, 2023
0f75e63
code review suggestions implementing
Robotgir Jan 11, 2023
dbc770f
Apply suggestions from code review
Robotgir Jan 11, 2023
23ef0ce
added description
Robotgir Jan 11, 2023
c3b211f
checked more values against the behavior of controller methods
Robotgir Jan 11, 2023
a535f3b
changed controller type to CtrlType
Robotgir Jan 11, 2023
4b8e759
Update mecanum_drive_controller/test/test_mecanum_drive_controller.cpp
destogl Jan 11, 2023
57a96ee
updated cmakelists structure
Robotgir Jan 12, 2023
c1fd834
renaming variables
Robotgir Jan 12, 2023
6aa2dde
changed description
Robotgir Jan 12, 2023
dfb960f
resetting msg if msg is valid after receiving a to old msg
Robotgir Jan 13, 2023
2c23123
estructuring parameters in yaml
Robotgir Jan 13, 2023
2382c10
comparing float values
Robotgir Jan 13, 2023
f58d12e
Apply suggestions from code review
Robotgir Jan 13, 2023
b8c5f48
added description for each test as comment
Robotgir Jan 13, 2023
100b3c4
added preceding controller tests
Robotgir Jan 14, 2023
4638622
reorganized reference_interfaces configuration method
Robotgir Jan 14, 2023
5db9123
configuration of interfaces in loop
Robotgir Jan 14, 2023
db9482c
final fixups
Robotgir Jan 14, 2023
163b95a
using control_msgs::msg::MecanumDriveControllerState and removing cus…
Robotgir Jan 16, 2023
b3cddbb
using control_msgs::msg::MecanumDriveControllerState and removing cus…
Robotgir Jan 16, 2023
32cd3b6
added chained mode test for update logic
Robotgir Jan 16, 2023
e71d025
changed wheel vl names to more descriptive
Robotgir Jan 16, 2023
622e60d
renamed rot and traslation matrix variable names
Robotgir Jan 16, 2023
8c5062e
renamed vl variable to more descriptive
Robotgir Jan 16, 2023
85278e9
ran pre-commit formatter
Robotgir Jan 16, 2023
dc77a31
set ref_itfces to 0 to stop vehicle in case of timeout
Robotgir Jan 16, 2023
4c11687
added description
Robotgir Jan 18, 2023
15c2430
check nan
Robotgir Jan 19, 2023
ce10fde
odom vel naming descriptive
Robotgir Jan 24, 2023
976f64c
removed outdated nomenclature
Robotgir Jan 24, 2023
eadabde
add comment
Robotgir Jan 24, 2023
8935e78
Apply suggestions from code review
destogl Jan 27, 2023
b77ee49
Update mecanum_drive_controller/src/mecanum_drive_controller.cpp
destogl Jan 27, 2023
a22266c
Update mecanum_drive_controller/src/mecanum_drive_controller.cpp
destogl Jan 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Expand Up @@ -15,7 +15,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -33,13 +33,13 @@ repos:

# Python hooks
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.12.0
hooks:
- id: black
args: ["--line-length=99"]
Expand All @@ -52,7 +52,7 @@ repos:
args: ["--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D404"]

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
args: ["--ignore=E501"]
Expand Down Expand Up @@ -119,14 +119,14 @@ repos:

# Docs - RestructuredText hooks
- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
rev: v1.1.1
hooks:
- id: doc8
args: ['--max-line-length=100', '--ignore=D001']
exclude: CHANGELOG\.rst$

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: rst-backticks
exclude: CHANGELOG\.rst$
Expand All @@ -136,7 +136,7 @@ repos:
# Spellcheck in comments and docs
# skipping of *.svg files is not working...
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.2
hooks:
- id: codespell
args: ['--write-changes', '--uri-ignore-words-list=ist']
Expand Down
112 changes: 112 additions & 0 deletions mecanum_drive_controller/CMakeLists.txt
@@ -0,0 +1,112 @@
cmake_minimum_required(VERSION 3.8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Robotgir please check that is change the same as ros-controls#510

Just to be fully aligned later.

project(mecanum_drive_controller)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
set(THIS_PACKAGE_INCLUDE_DEPENDS
control_msgs
controller_interface
geometry_msgs
hardware_interface
nav_msgs
pluginlib
rclcpp
rclcpp_lifecycle
realtime_tools
std_srvs
tf2
tf2_msgs
tf2_geometry_msgs
)

find_package(ament_cmake REQUIRED)
find_package(generate_parameter_library REQUIRED)
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
endforeach()

# Add mecanum_drive_controller library related compile commands
generate_parameter_library(mecanum_drive_controller_parameters
src/mecanum_drive_controller.yaml
)
add_library(
mecanum_drive_controller
SHARED
src/mecanum_drive_controller.cpp
src/odometry.cpp
)
target_include_directories(mecanum_drive_controller PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(mecanum_drive_controller mecanum_drive_controller_parameters)
ament_target_dependencies(mecanum_drive_controller ${THIS_PACKAGE_INCLUDE_DEPENDS})
target_compile_definitions(mecanum_drive_controller PRIVATE "MECANUM_DRIVE_CONTROLLER_BUILDING_DLL")

pluginlib_export_plugin_description_file(
controller_interface mecanum_drive_controller.xml)

install(
TARGETS
mecanum_drive_controller
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install(
DIRECTORY include/
DESTINATION include
destogl marked this conversation as resolved.
Show resolved Hide resolved
)

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
find_package(controller_manager REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(ros2_control_test_assets REQUIRED)

ament_add_gmock(test_load_mecanum_drive_controller test/test_load_mecanum_drive_controller.cpp)
target_include_directories(test_load_mecanum_drive_controller PRIVATE include)
ament_target_dependencies(
test_load_mecanum_drive_controller
controller_manager
hardware_interface
ros2_control_test_assets
)

add_rostest_with_parameters_gmock(
test_mecanum_drive_controller test/test_mecanum_drive_controller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/mecanum_drive_controller_params.yaml)
target_include_directories(test_mecanum_drive_controller PRIVATE include)
target_link_libraries(test_mecanum_drive_controller mecanum_drive_controller)
ament_target_dependencies(
test_mecanum_drive_controller
controller_interface
hardware_interface
)

add_rostest_with_parameters_gmock(
test_mecanum_drive_controller_preceeding test/test_mecanum_drive_controller_preceeding.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/mecanum_drive_controller_preceeding_params.yaml)
target_include_directories(test_mecanum_drive_controller_preceeding PRIVATE include)
target_link_libraries(test_mecanum_drive_controller_preceeding mecanum_drive_controller)
ament_target_dependencies(
test_mecanum_drive_controller_preceeding
controller_interface
hardware_interface
)
endif()

ament_export_include_directories(
include
)
ament_export_dependencies(
${THIS_PACKAGE_INCLUDE_DEPENDS}
)
ament_export_libraries(
mecanum_drive_controller
)

ament_package()
@@ -0,0 +1,137 @@
// Copyright (c) 2023, Stogl Robotics Consulting UG (haftungsbeschränkt)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef MECANUM_DRIVE_CONTROLLER__MECANUM_DRIVE_CONTROLLER_HPP_
#define MECANUM_DRIVE_CONTROLLER__MECANUM_DRIVE_CONTROLLER_HPP_

#include <chrono>
#include <cmath>
#include <memory>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#include "controller_interface/chainable_controller_interface.hpp"
#include "mecanum_drive_controller/odometry.hpp"
#include "mecanum_drive_controller/visibility_control.h"
#include "mecanum_drive_controller_parameters.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "realtime_tools/realtime_buffer.h"
#include "realtime_tools/realtime_publisher.h"
#include "std_srvs/srv/set_bool.hpp"

#include "control_msgs/msg/mecanum_drive_controller_state.hpp"
#include "geometry_msgs/msg/twist_stamped.hpp"
#include "nav_msgs/msg/odometry.hpp"
#include "tf2_msgs/msg/tf_message.hpp"
namespace mecanum_drive_controller
{
// name constants for state interfaces
static constexpr size_t NR_STATE_ITFS = 4;

// name constants for command interfaces
static constexpr size_t NR_CMD_ITFS = 4;

// name constants for reference interfaces
static constexpr size_t NR_REF_ITFS = 3;

class MecanumDriveController : public controller_interface::ChainableControllerInterface
{
public:
MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
MecanumDriveController();

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::CallbackReturn on_init() override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::InterfaceConfiguration command_interface_configuration() const override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::InterfaceConfiguration state_interface_configuration() const override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::CallbackReturn on_configure(
const rclcpp_lifecycle::State & previous_state) override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::CallbackReturn on_activate(
const rclcpp_lifecycle::State & previous_state) override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::CallbackReturn on_deactivate(
const rclcpp_lifecycle::State & previous_state) override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::return_type update_reference_from_subscribers(
const rclcpp::Time & time, const rclcpp::Duration & period) override;

MECANUM_DRIVE_CONTROLLER__VISIBILITY_PUBLIC
controller_interface::return_type update_and_write_commands(
const rclcpp::Time & time, const rclcpp::Duration & period) override;

using ControllerReferenceMsg = geometry_msgs::msg::TwistStamped;
using OdomStateMsg = nav_msgs::msg::Odometry;
using TfStateMsg = tf2_msgs::msg::TFMessage;
using ControllerStateMsg = control_msgs::msg::MecanumDriveControllerState;

protected:
std::shared_ptr<mecanum_drive_controller::ParamListener> param_listener_;
mecanum_drive_controller::Params params_;

// used for chained controller
std::vector<std::string> state_joint_names_;

//Names of the references, ex: high level vel commands from MoveIt, Nav2, etc. used for preceding controller
std::vector<std::string> reference_names_;

// Command subscribers and Controller State, odom state, tf state publishers
rclcpp::Subscription<ControllerReferenceMsg>::SharedPtr ref_subscriber_ = nullptr;
realtime_tools::RealtimeBuffer<std::shared_ptr<ControllerReferenceMsg>> input_ref_;
rclcpp::Duration ref_timeout_ = rclcpp::Duration::from_seconds(0.0);

using OdomStatePublisher = realtime_tools::RealtimePublisher<OdomStateMsg>;
rclcpp::Publisher<OdomStateMsg>::SharedPtr odom_s_publisher_;
std::unique_ptr<OdomStatePublisher> rt_odom_state_publisher_;

using TfStatePublisher = realtime_tools::RealtimePublisher<TfStateMsg>;
rclcpp::Publisher<TfStateMsg>::SharedPtr tf_odom_s_publisher_;
std::unique_ptr<TfStatePublisher> rt_tf_odom_state_publisher_;

using ControllerStatePublisher = realtime_tools::RealtimePublisher<ControllerStateMsg>;
rclcpp::Publisher<ControllerStateMsg>::SharedPtr controller_s_publisher_;
std::unique_ptr<ControllerStatePublisher> controller_state_publisher_;

// override methods from ChainableControllerInterface
std::vector<hardware_interface::CommandInterface> on_export_reference_interfaces() override;

bool on_set_chained_mode(bool chained_mode) override;

Odometry odometry_;

private:
// callback for topic interface
MECANUM_DRIVE_CONTROLLER__VISIBILITY_LOCAL
void reference_callback(const std::shared_ptr<ControllerReferenceMsg> msg);

double velocity_in_center_frame_linear_x_; // [m/s]
double velocity_in_center_frame_linear_y_; // [m/s]
double velocity_in_center_frame_angular_z_; // [rad/s]
};

} // namespace mecanum_drive_controller

#endif // MECANUM_DRIVE_CONTROLLER__MECANUM_DRIVE_CONTROLLER_HPP_