Skip to content

Commit

Permalink
twist_controller -> picknik_twist_controller (#3)
Browse files Browse the repository at this point in the history
* twist_controller -> picknik_twist_controller

1. prefix twist_controller with picknik_twist_controller

When we merge twist_controller into ros2_controllers we can depricate
this one and not have naming conflicts as users migrate

* cmake: 3.8 -> 3.16

bump to oldest version used on Ubuntu Focal + ROS 2 Humble
https://www.ros.org/reps/rep-2000.html#humble-hawksbill-may-2022-may-2027

---------

Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
  • Loading branch information
moriarty committed Jun 20, 2023
1 parent af740ca commit 3586843
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We plan to land this upstream in ros2_controllers: https://github.com/ros-contro
### Usage
Example of instance within `ros2_control` can be found in the [configuration file](https://github.com/PickNikRobotics/ros2_kortex/blob/main/kortex_description/arms/gen3/7dof/config/ros2_controllers.yaml).
Defined interfaces have to exist within the `hardware_interface::SystemInterface` implemented for the robot (e.g. driver).
Stop any commanding controller and then start `TwistController`to use kinova's builtin cartesian twist controller.
Stop any commanding controller and then start `PicknikTwistController`to forward twist msgs to the hardware's built-in cartesian twist controller.

#### Note on controllers
Exclusiveness logic is within the driver, and running joint-based and twist controller at the same time is not possible.
Expand Down
2 changes: 1 addition & 1 deletion picknik_reset_fault_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.16)
project(picknik_reset_fault_controller)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(twist_controller)
cmake_minimum_required(VERSION 3.16)
project(picknik_twist_controller)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
Expand All @@ -23,7 +23,7 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS

include_directories(include)

add_library(${PROJECT_NAME} SHARED src/twist_controller.cpp)
add_library(${PROJECT_NAME} SHARED src/picknik_twist_controller.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE
include
)
Expand All @@ -34,7 +34,7 @@ ament_target_dependencies(${PROJECT_NAME}

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "KORTEX2_CONTROLLERS_BUILDING_LIBRARY")
target_compile_definitions(${PROJECT_NAME} PRIVATE "PICKNIK_TWIST_CONTROLLER_BUILDING_LIBRARY")
pluginlib_export_plugin_description_file(controller_interface controller_plugins.xml)

install(TARGETS ${PROJECT_NAME}
Expand Down
7 changes: 7 additions & 0 deletions picknik_twist_controller/controller_plugins.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<library path="picknik_twist_controler">
<class name="picknik_twist_controler/PicknikTwistControler" type="picknik_twist_controler::PicknikTwistControler" base_class_type="controller_interface::ControllerInterface">
<description>
Subscribes to twist msg and forwards to hardware
</description>
</class>
</library>
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,48 @@
*/
//----------------------------------------------------------------------

#ifndef TWIST_CONTROLLER__TWIST_CONTROLLER_HPP_
#define TWIST_CONTROLLER__TWIST_CONTROLLER_HPP_
#ifndef PICKNIK_TWIST_CONTROLLER__PICKNIK_TWIST_CONTROLLER_HPP_
#define PICKNIK_TWIST_CONTROLLER__PICKNIK_TWIST_CONTROLLER_HPP_

#include <memory>
#include <string>
#include <vector>

#include "controller_interface/controller_interface.hpp"
#include "geometry_msgs/msg/twist_stamped.hpp"
#include "picknik_twist_controller/visibility_control.h"
#include "realtime_tools/realtime_buffer.h"
#include "twist_controller/visibility_control.h"

namespace twist_controller
namespace picknik_twist_controller
{
using CmdType = geometry_msgs::msg::TwistStamped;
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;

class TwistController : public controller_interface::ControllerInterface
class PicknikTwistControler : public controller_interface::ControllerInterface
{
public:
TWIST_CONTROLLER_PUBLIC
TwistController();
PICKNIK_TWIST_CONTROLLER_PUBLIC
PicknikTwistControler();

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
controller_interface::InterfaceConfiguration command_interface_configuration() const override;

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
controller_interface::InterfaceConfiguration state_interface_configuration() const override;

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
CallbackReturn on_init() override;

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;

TWIST_CONTROLLER_PUBLIC
PICKNIK_TWIST_CONTROLLER_PUBLIC
controller_interface::return_type update(
const rclcpp::Time & time, const rclcpp::Duration & period) override;

Expand All @@ -76,6 +76,6 @@ class TwistController : public controller_interface::ControllerInterface
std::string logger_name_;
};

} // namespace twist_controller
} // namespace picknik_twist_controller

#endif // TWIST_CONTROLLER__TWIST_CONTROLLER_HPP_
#endif // PICKNIK_TWIST_CONTROLLER__PICKNIK_TWIST_CONTROLLER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2021, PickNik Inc.
//
// 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 PICKNIK_TWIST_CONTROLLER__VISIBILITY_CONTROL_H_
#define PICKNIK_TWIST_CONTROLLER__VISIBILITY_CONTROL_H_

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define PICKNIK_TWIST_CONTROLLER_EXPORT __attribute__((dllexport))
#define PICKNIK_TWIST_CONTROLLER_IMPORT __attribute__((dllimport))
#else
#define PICKNIK_TWIST_CONTROLLER_EXPORT __declspec(dllexport)
#define PICKNIK_TWIST_CONTROLLER_IMPORT __declspec(dllimport)
#endif
#ifdef PICKNIK_TWIST_CONTROLLER_BUILDING_LIBRARY
#define PICKNIK_TWIST_CONTROLLER_PUBLIC PICKNIK_TWIST_CONTROLLER_EXPORT
#else
#define PICKNIK_TWIST_CONTROLLER_PUBLIC PICKNIK_TWIST_CONTROLLER_IMPORT
#endif
#define PICKNIK_TWIST_CONTROLLER_PUBLIC_TYPE PICKNIK_TWIST_CONTROLLER_PUBLIC
#define PICKNIK_TWIST_CONTROLLER_LOCAL
#else
#define PICKNIK_TWIST_CONTROLLER_EXPORT __attribute__((visibility("default")))
#define PICKNIK_TWIST_CONTROLLER_IMPORT
#if __GNUC__ >= 4
#define PICKNIK_TWIST_CONTROLLER_PUBLIC __attribute__((visibility("default")))
#define PICKNIK_TWIST_CONTROLLER_LOCAL __attribute__((visibility("hidden")))
#else
#define PICKNIK_TWIST_CONTROLLER_PUBLIC
#define PICKNIK_TWIST_CONTROLLER_LOCAL
#endif
#define PICKNIK_TWIST_CONTROLLER_PUBLIC_TYPE
#endif

#endif // PICKNIK_TWIST_CONTROLLER__VISIBILITY_CONTROL_H_
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>twist_controller</name>
<name>picknik_twist_controller</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<description>Subscribes to twist msg and forwards to hardware</description>
<maintainer email="lovro.ivanov@gmail.com">lovro</maintainer>
<license>TODO: License declaration</license>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake_ros</buildtool_depend>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
//----------------------------------------------------------------------

#include "twist_controller/twist_controller.hpp"
#include "picknik_twist_controller/picknik_twist_controller.hpp"

#include <memory>
#include <string>
Expand All @@ -30,19 +30,19 @@
#include "controller_interface/helpers.hpp"
#include "hardware_interface/loaned_command_interface.hpp"

namespace twist_controller
namespace picknik_twist_controller
{
using hardware_interface::LoanedCommandInterface;

TwistController::TwistController()
PicknikTwistControler::PicknikTwistControler()
: controller_interface::ControllerInterface(),
rt_command_ptr_(nullptr),
twist_command_subscriber_(nullptr)
{
}

controller_interface::InterfaceConfiguration TwistController::command_interface_configuration()
const
controller_interface::InterfaceConfiguration
PicknikTwistControler::command_interface_configuration() const
{
controller_interface::InterfaceConfiguration command_interfaces_config;
command_interfaces_config.type = controller_interface::interface_configuration_type::INDIVIDUAL;
Expand All @@ -55,13 +55,14 @@ controller_interface::InterfaceConfiguration TwistController::command_interface_
return command_interfaces_config;
}

controller_interface::InterfaceConfiguration TwistController::state_interface_configuration() const
controller_interface::InterfaceConfiguration PicknikTwistControler::state_interface_configuration()
const
{
return controller_interface::InterfaceConfiguration{
controller_interface::interface_configuration_type::NONE};
}

CallbackReturn TwistController::on_init()
CallbackReturn PicknikTwistControler::on_init()
{
try
{
Expand All @@ -78,7 +79,8 @@ CallbackReturn TwistController::on_init()
return CallbackReturn::SUCCESS;
}

CallbackReturn TwistController::on_configure(const rclcpp_lifecycle::State & /*previous_state*/)
CallbackReturn PicknikTwistControler::on_configure(
const rclcpp_lifecycle::State & /*previous_state*/)
{
joint_name_ = get_node()->get_parameter("joint").as_string();

Expand Down Expand Up @@ -108,21 +110,23 @@ CallbackReturn TwistController::on_configure(const rclcpp_lifecycle::State & /*p
return CallbackReturn::SUCCESS;
}

CallbackReturn TwistController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/)
CallbackReturn PicknikTwistControler::on_activate(
const rclcpp_lifecycle::State & /*previous_state*/)
{
// reset command buffer if a command came through callback when controller was inactive
rt_command_ptr_ = realtime_tools::RealtimeBuffer<std::shared_ptr<CmdType>>(nullptr);
return CallbackReturn::SUCCESS;
}

CallbackReturn TwistController::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/)
CallbackReturn PicknikTwistControler::on_deactivate(
const rclcpp_lifecycle::State & /*previous_state*/)
{
// reset command buffer
rt_command_ptr_ = realtime_tools::RealtimeBuffer<std::shared_ptr<CmdType>>(nullptr);
return CallbackReturn::SUCCESS;
}

controller_interface::return_type TwistController::update(
controller_interface::return_type PicknikTwistControler::update(
const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
{
auto twist_commands = rt_command_ptr_.readFromRT();
Expand Down Expand Up @@ -150,8 +154,9 @@ controller_interface::return_type TwistController::update(

return controller_interface::return_type::OK;
}
} // namespace twist_controller
} // namespace picknik_twist_controller

#include "pluginlib/class_list_macros.hpp"

PLUGINLIB_EXPORT_CLASS(twist_controller::TwistController, controller_interface::ControllerInterface)
PLUGINLIB_EXPORT_CLASS(
picknik_twist_controller::PicknikTwistControler, controller_interface::ControllerInterface)
7 changes: 0 additions & 7 deletions twist_controller/controller_plugins.xml

This file was deleted.

49 changes: 0 additions & 49 deletions twist_controller/include/twist_controller/visibility_control.h

This file was deleted.

0 comments on commit 3586843

Please sign in to comment.