-
Notifications
You must be signed in to change notification settings - Fork 288
Freedrive Controller #1114
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
Merged
Merged
Freedrive Controller #1114
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
e989cf4
Initial Draft
VinDp c83203c
Basic version for the new action server implementation
VinDp 69e44ff
Added state interfaces and related vars
VinDp 34582ee
Updated on_configure, on_activate, on_deactivate
VinDp 2b2ecdf
Adapted update to action server usage
VinDp ae0ae0e
Added callback functions and clean up
VinDp fb684f8
First version of activation/deactivation of freedrive
VinDp 9b88517
Updated to custom action EnableFreedriveMode
VinDp dafb640
Removed previous version code
VinDp a3902a6
Adding retries for the sleep
VinDp 469ee94
Added missing includes
VinDp ad80107
Fixed wrong names and missing declarations
VinDp 910990f
Added parameters and freedrive_mode_controller to list
VinDp 475b761
Added interfaces to hardware_interface
VinDp 9aca570
Removed useless dependencies from old version
VinDp 5883fcb
Removed joint-related command and state interfaces
VinDp 9d62717
Added WaitForAsyncCommand
VinDp 816f5a3
Missing dependencies and removed result reference
VinDp 4931a59
Added freedrive to launch files
VinDp 7719944
First version of the hardware interface
VinDp 409a9e8
Updated command interfaces and fixed overlapping name
VinDp 24f644b
Added enable interface
VinDp e952d5f
Update logic
VinDp e819ada
Fixed not updating async value
VinDp 9a3bad2
Code cleanup
VinDp f302220
Make sure to reset the abort command interface when starting the cont…
fmauch e292058
Merge branch 'main' into freedrive_mode
VinDp b1b35b0
Removed legacy from action server version
VinDp cf50251
Fixed format from merge and removed old version
VinDp 673df98
Adapted freedrive to new command_switch
VinDp 6eda9a5
First of version of the topic-based implementation
VinDp d02513c
Fix format
VinDp 22c1a05
Fixed print location for received commands
VinDp 3d906dd
First version with timer
VinDp b7efaa4
Fix to start timer only for relevant msgs
VinDp e269518
Fix Format
VinDp d12cbdf
Cleanup and more name convention
VinDp 2976181
Proper handling of controller conflicts
VinDp 920e60f
Updated variable name to meaningful one
VinDp 5a4ecff
Fixed timer issue: starting only if active and for enable msgs
VinDp c388e4a
Added initial documentation
VinDp 4b834c0
Added inactive_timeout as parameter
VinDp 6869b56
Added async thread to log outside of update()
VinDp 4065035
Format docs
VinDp 82328ca
Added check on active condition
VinDp b965673
Initial tests
VinDp a8cb789
Merge remote-tracking branch 'origin/main' into freedrive_mode
urfeex 67f2256
Fix formatting
urfeex 8e85c2a
Fix resource claiming in hw interface
urfeex 5a8ef90
Update ur_controllers/doc/index.rst
VinDp 3eab80c
Update ur_controllers/include/ur_controllers/freedrive_mode_controlle…
VinDp b187719
Update ur_controllers/include/ur_controllers/freedrive_mode_controlle…
VinDp 167526c
Update ur_controllers/src/freedrive_mode_controller.cpp
VinDp 5e5e0ef
Update ur_controllers/src/freedrive_mode_controller.cpp
VinDp b1106f0
Added on_cleanup to guarantee RT safety and fixed flag init
VinDp d4c0ed5
Updated callback name and added comment for Command Intefaces
VinDp 49c265d
Merge branch 'main' into freedrive_mode
urfeex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
ur_controllers/include/ur_controllers/freedrive_mode_controller.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright 2024, 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 Vincenzo Di Pentima [email protected] | ||
* \date 2024-09-26 | ||
*/ | ||
//---------------------------------------------------------------------- | ||
#ifndef UR_CONTROLLERS__FREEDRIVE_MODE_CONTROLLER_HPP_ | ||
#define UR_CONTROLLERS__FREEDRIVE_MODE_CONTROLLER_HPP_ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
#include <thread> | ||
#include <mutex> | ||
|
||
#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 "std_msgs/msg/bool.hpp" | ||
|
||
#include "freedrive_mode_controller_parameters.hpp" | ||
|
||
namespace ur_controllers | ||
{ | ||
enum CommandInterfaces | ||
{ | ||
FREEDRIVE_MODE_ASYNC_SUCCESS = 0u, | ||
FREEDRIVE_MODE_ENABLE = 1, | ||
FREEDRIVE_MODE_ABORT = 2, | ||
}; | ||
|
||
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_cleanup(const rclcpp_lifecycle::State& previous_state) override; | ||
|
||
CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; | ||
|
||
CallbackReturn on_init() override; | ||
|
||
private: | ||
// Command interfaces: optional is used only to avoid adding reference initialization | ||
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_; | ||
|
||
std::shared_ptr<rclcpp::Subscription<std_msgs::msg::Bool>> enable_freedrive_mode_sub_; | ||
|
||
rclcpp::TimerBase::SharedPtr freedrive_sub_timer_; ///< Timer to check for timeout on input | ||
mutable std::chrono::seconds timeout_interval_; | ||
void freedrive_cmd_callback(const std_msgs::msg::Bool::SharedPtr msg); | ||
|
||
std::shared_ptr<freedrive_mode_controller::ParamListener> freedrive_param_listener_; | ||
freedrive_mode_controller::Params freedrive_params_; | ||
|
||
std::atomic<bool> freedrive_active_; | ||
std::atomic<bool> change_requested_; | ||
std::atomic<double> async_state_; | ||
std::atomic<double> first_log_; | ||
std::atomic<double> timer_started_; | ||
|
||
void start_timer(); | ||
void timeout_callback(); | ||
|
||
std::thread logging_thread_; | ||
std::atomic<bool> logging_thread_running_; | ||
std::atomic<bool> logging_requested_; | ||
std::condition_variable logging_condition_; | ||
std::mutex log_mutex_; | ||
void log_task(); | ||
void start_logging_thread(); | ||
void stop_logging_thread(); | ||
|
||
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_ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.