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

Freedrive Controller #1114

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e989cf4
Initial Draft
VinDp Sep 25, 2024
c83203c
Basic version for the new action server implementation
VinDp Oct 10, 2024
69e44ff
Added state interfaces and related vars
VinDp Oct 12, 2024
34582ee
Updated on_configure, on_activate, on_deactivate
VinDp Oct 12, 2024
2b2ecdf
Adapted update to action server usage
VinDp Oct 12, 2024
ae0ae0e
Added callback functions and clean up
VinDp Oct 13, 2024
fb684f8
First version of activation/deactivation of freedrive
VinDp Oct 13, 2024
9b88517
Updated to custom action EnableFreedriveMode
VinDp Oct 14, 2024
dafb640
Removed previous version code
VinDp Oct 14, 2024
a3902a6
Adding retries for the sleep
VinDp Oct 14, 2024
469ee94
Added missing includes
VinDp Oct 14, 2024
ad80107
Fixed wrong names and missing declarations
VinDp Oct 14, 2024
910990f
Added parameters and freedrive_mode_controller to list
VinDp Oct 14, 2024
475b761
Added interfaces to hardware_interface
VinDp Oct 14, 2024
9aca570
Removed useless dependencies from old version
VinDp Oct 15, 2024
5883fcb
Removed joint-related command and state interfaces
VinDp Oct 15, 2024
9d62717
Added WaitForAsyncCommand
VinDp Oct 15, 2024
816f5a3
Missing dependencies and removed result reference
VinDp Oct 15, 2024
4931a59
Added freedrive to launch files
VinDp Oct 16, 2024
7719944
First version of the hardware interface
VinDp Oct 16, 2024
409a9e8
Updated command interfaces and fixed overlapping name
VinDp Oct 16, 2024
24f644b
Added enable interface
VinDp Oct 16, 2024
e952d5f
Update logic
VinDp Oct 16, 2024
e819ada
Fixed not updating async value
VinDp Oct 16, 2024
9a3bad2
Code cleanup
VinDp Oct 17, 2024
f302220
Make sure to reset the abort command interface when starting the cont…
fmauch Oct 18, 2024
e292058
Merge branch 'main' into freedrive_mode
VinDp Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ur_controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ generate_parameter_library(
src/scaled_joint_trajectory_controller_parameters.yaml
)

generate_parameter_library(
freedrive_mode_controller_parameters
src/freedrive_mode_controller_parameters.yaml
)

generate_parameter_library(
passthrough_trajectory_controller_parameters
src/passthrough_trajectory_controller_parameters.yaml
Expand All @@ -74,6 +79,7 @@ generate_parameter_library(
add_library(${PROJECT_NAME} SHARED
src/scaled_joint_trajectory_controller.cpp
src/speed_scaling_state_broadcaster.cpp
src/freedrive_mode_controller.cpp
src/gpio_controller.cpp
src/passthrough_trajectory_controller.cpp
src/ur_configuration_controller.cpp)
Expand All @@ -85,6 +91,7 @@ target_link_libraries(${PROJECT_NAME}
gpio_controller_parameters
speed_scaling_state_broadcaster_parameters
scaled_joint_trajectory_controller_parameters
freedrive_mode_controller_parameters
passthrough_trajectory_controller_parameters
ur_configuration_controller_parameters
)
Expand Down
5 changes: 5 additions & 0 deletions ur_controllers/controller_plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
This controller publishes the Tool IO.
</description>
</class>
<class name="ur_controllers/FreedriveModeController" type="ur_controllers::FreedriveModeController" base_class_type="controller_interface::ControllerInterface">
<description>
This controller handles the activation of the freedrive mode.
</description>
</class>
<class name="ur_controllers/PassthroughTrajectoryController" type="ur_controllers::PassthroughTrajectoryController" base_class_type="controller_interface::ControllerInterface">
<description>
This controller forwards a joint-based trajectory to the robot controller for interpolation.
Expand Down
137 changes: 137 additions & 0 deletions ur_controllers/include/ur_controllers/freedrive_mode_controller.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright 2023, FZI Forschungszentrum Informatik, Created on behalf of Universal Robots A/S
//
// 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
*
* \author Felix Exner [email protected]
* \date 2023-06-29
*/
//----------------------------------------------------------------------
#ifndef UR_CONTROLLERS__FREEDRIVE_MODE_CONTROLLER_HPP_
#define UR_CONTROLLERS__FREEDRIVE_MODE_CONTROLLER_HPP_

#pragma once

#include <realtime_tools/realtime_buffer.h>
#include <realtime_tools/realtime_server_goal_handle.h>

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

#include <controller_interface/controller_interface.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_action/server.hpp>
#include <rclcpp_action/create_server.hpp>
#include <rclcpp_action/server_goal_handle.hpp>
#include <rclcpp/time.hpp>
#include <rclcpp/duration.hpp>

#include <ur_msgs/action/enable_freedrive_mode.hpp>
#include "freedrive_mode_controller_parameters.hpp"

namespace ur_controllers
{
enum CommandInterfaces
{
FREEDRIVE_MODE_ASYNC_SUCCESS = 25,
FREEDRIVE_MODE_CMD = 26,
};
enum StateInterfaces
{
INITIALIZED_FLAG = 0u,
};

using namespace std::chrono_literals; // NOLINT

class FreedriveModeController : public controller_interface::ControllerInterface
{
public:
controller_interface::InterfaceConfiguration command_interface_configuration() const override;

controller_interface::InterfaceConfiguration state_interface_configuration() const override;

// Change the input for the update function
controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;

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

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

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

CallbackReturn on_init() override;

private:
// Command interfaces
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> async_success_command_interface_;
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> enable_command_interface_;
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> abort_command_interface_;

// Everything related to the RT action server
using FreedriveModeAction = ur_msgs::action::EnableFreedriveMode;
using RealtimeGoalHandle = realtime_tools::RealtimeServerGoalHandle<FreedriveModeAction>;
using RealtimeGoalHandlePtr = std::shared_ptr<RealtimeGoalHandle>;
using RealtimeGoalHandleBuffer = realtime_tools::RealtimeBuffer<RealtimeGoalHandlePtr>;

RealtimeGoalHandleBuffer rt_active_goal_; ///< Currently active action goal, if any.
rclcpp::TimerBase::SharedPtr goal_handle_timer_; ///< Timer to frequently check on the running goal
realtime_tools::RealtimeBuffer<std::unordered_map<std::string, size_t>> joint_trajectory_mapping_;
rclcpp::Duration action_monitor_period_ = rclcpp::Duration(50ms);

rclcpp_action::Server<ur_msgs::action::EnableFreedriveMode>::SharedPtr freedrive_mode_action_server_;
rclcpp_action::GoalResponse
goal_received_callback(const rclcpp_action::GoalUUID& uuid,
std::shared_ptr<const ur_msgs::action::EnableFreedriveMode::Goal> goal);

rclcpp_action::CancelResponse goal_cancelled_callback(
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::EnableFreedriveMode>> goal_handle);

void goal_accepted_callback(
std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::EnableFreedriveMode>> goal_handle);

std::shared_ptr<freedrive_mode_controller::ParamListener> freedrive_param_listener_;
freedrive_mode_controller::Params freedrive_params_;

/* Start an action server with an action called: /freedrive_mode_controller/start_freedrive_mode. */
void start_action_server(void);

std::atomic<bool> freedrive_active_;
std::atomic<bool> change_requested_;
std::atomic<double> async_state_;

static constexpr double ASYNC_WAITING = 2.0;
/**
* @brief wait until a command interface isn't in state ASYNC_WAITING anymore or until the parameter maximum_retries
* have been reached
*/
bool waitForAsyncCommand(std::function<double(void)> get_value);
};
} // namespace ur_controllers
#endif // UR_CONTROLLERS__PASSTHROUGH_TRAJECTORY_CONTROLLER_HPP_
Loading
Loading