-
Notifications
You must be signed in to change notification settings - Fork 222
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
Forward trajectory controller #944
Open
URJala
wants to merge
55
commits into
UniversalRobots:main
Choose a base branch
from
URJala:forward_controller
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 50 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
76bee81
Started work on forward position controller
URJala 686ddbb
Controller is now able to run and read from speed_scale
URJala b8ef0a7
Communication between robot and passthrough controller is now functio…
URJala ad13110
Controller will now send over all received points, before sending the…
URJala 95db48b
Created more examples for the use of the controller. Controller no…
URJala fab4316
Finished the passthrough controller
URJala 7042157
Added passthrough controller to "initially loaded controller" options.
URJala 95173af
Fix test_common
URJala 4c9d9b6
Move functionality to update method
URJala 67e5c0d
Removing examples from this PR
URJala 95da869
Implemented some realtime boxes
URJala a19ac31
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch a61bd79
Updated to latest ControllerInterface API
fmauch caa8941
Rename controller's action topic to match the JTC
fmauch 3d461ae
Remove duplicate controller entry
fmauch 1ab4ed2
Rename controller action in tests
fmauch e1263a9
Use generate_parameters_library for joints and state interfaces
fmauch cf7aeaa
Use constants for transfer state in controller
fmauch dc85692
Use period directly instead of calculating it by hand
fmauch a050290
Change some stdout strings
fmauch 569e319
Remove unnecessary check
fmauch c319be7
Remove an unnecessary comment
fmauch 7b5f095
Do not require a controller active state inteface
fmauch c4a366f
Make action handling realtime-thread-safe
fmauch 416e190
Fix tolerances handling
fmauch e513fc6
String formatting
fmauch a5957fc
Remove unused interfaces
fmauch 5b1f7f3
Deactivate goal time check for now since ros2_control can report wron…
fmauch 5078c60
Simplify joint state configuration
fmauch 51fd002
Make controller robust against joint ordering
fmauch bd9652e
Make default config reflect the actual parameters
fmauch 1389c3c
Fix tolerance handling
fmauch e042de9
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch bc76a61
REVERT_ME: use fixed ros2_control until merged
fmauch 934ccc5
Make sure the abort state is reset when sending new trajectories
fmauch 0e9b37d
Restructure command interface exporting
fmauch e224dfa
REVERT_ME: Use passthrough branch of description
fmauch 6eb6def
Add documentation for the passthrough controller
fmauch 3a0f562
Store command interface instead of using indices
fmauch df7c9ab
Correctly handle preemptions
fmauch 197552a
Correctly abort and act on deactivate
fmauch 63bce67
Update documentation
fmauch d6df554
Improve result representation in example_move script
fmauch 0cf3249
Merge upstream main
fmauch 2121cf8
Re-Restructure command interface exporting
fmauch 17ab6d0
Revert "REVERT_ME: Use passthrough branch of description"
fmauch fdfcfab
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch ca7aff9
Fix command interface names
fmauch f887c09
Check passthrough trajectory controller from write function
fmauch ab62e4f
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch c7ebfad
Apply suggestions from code review
fmauch 5cca2f9
Add more docs
fmauch e2343c9
Improve duration output
fmauch 6b4ca4d
Revert "REVERT_ME: use fixed ros2_control until merged"
urfeex d706fa0
Fix if statement for claimed interfaces
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 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 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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,8 +13,8 @@ repositories: | |||||||||
version: humble-devel | ||||||||||
ros2_control: | ||||||||||
type: git | ||||||||||
url: https://github.com/ros-controls/ros2_control.git | ||||||||||
version: master | ||||||||||
url: https://github.com/pal-robotics-forks/ros2_control.git | ||||||||||
version: fix/controller_update_period | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
ros2_controllers: | ||||||||||
type: git | ||||||||||
url: https://github.com/ros-controls/ros2_controllers | ||||||||||
|
This file contains 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 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 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
184 changes: 184 additions & 0 deletions
184
ur_controllers/include/ur_controllers/passthrough_trajectory_controller.hpp
This file contains 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,184 @@ | ||
// Copyright 2024, 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 Jacob Larsen [email protected] | ||
* \date 2024-03-11 | ||
* | ||
* | ||
* | ||
* | ||
*/ | ||
//---------------------------------------------------------------------- | ||
|
||
#ifndef UR_CONTROLLERS__PASSTHROUGH_TRAJECTORY_CONTROLLER_HPP_ | ||
#define UR_CONTROLLERS__PASSTHROUGH_TRAJECTORY_CONTROLLER_HPP_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <realtime_tools/realtime_buffer.h> | ||
#include <realtime_tools/realtime_server_goal_handle.h> | ||
|
||
#include <functional> | ||
#include <limits> | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include <controller_interface/controller_interface.hpp> | ||
#include <rclcpp_action/server.hpp> | ||
#include <rclcpp_action/create_server.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
#include <rclcpp_action/server_goal_handle.hpp> | ||
#include <rclcpp/time.hpp> | ||
#include <rclcpp/duration.hpp> | ||
#include <rclcpp/clock.hpp> | ||
|
||
#include <trajectory_msgs/msg/joint_trajectory.hpp> | ||
#include <control_msgs/action/follow_joint_trajectory.hpp> | ||
|
||
#include "passthrough_trajectory_controller_parameters.hpp" | ||
|
||
namespace ur_controllers | ||
{ | ||
|
||
/* | ||
* 0.0: No trajectory to forward, the controller is idling and ready to receive a new trajectory. | ||
* 1.0: The controller has received and accepted a new trajecotry. When the state is 1.0, the controller will write a | ||
fmauch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* point to the hardware interface. | ||
* 2.0: The hardware interface will read the point written from the controller. The state will switch between 1.0 | ||
* and 2.0 until all points have been read by the hardware interface. | ||
* 3.0: The hardware interface has read all the points, and will now write all the points to the physical robot | ||
* controller. | ||
* 4.0: The robot is moving through the trajectory. | ||
* 5.0: The robot finished executing the trajectory. | ||
*/ | ||
const double TRANSFER_STATE_IDLE = 0.0; | ||
const double TRANSFER_STATE_WAITING_FOR_POINT = 1.0; | ||
const double TRANSFER_STATE_TRANSFERRING = 2.0; | ||
const double TRANSFER_STATE_TRANSFER_DONE = 3.0; | ||
const double TRANSFER_STATE_IN_MOTION = 4.0; | ||
const double TRANSFER_STATE_DONE = 5.0; | ||
|
||
using namespace std::chrono_literals; // NOLINT | ||
|
||
class PassthroughTrajectoryController : public controller_interface::ControllerInterface | ||
{ | ||
public: | ||
PassthroughTrajectoryController() = default; | ||
~PassthroughTrajectoryController() override = default; | ||
|
||
controller_interface::InterfaceConfiguration state_interface_configuration() const override; | ||
|
||
controller_interface::InterfaceConfiguration command_interface_configuration() const override; | ||
|
||
controller_interface::CallbackReturn on_init() override; | ||
|
||
controller_interface::CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) override; | ||
|
||
controller_interface::CallbackReturn on_activate(const rclcpp_lifecycle::State& state) override; | ||
|
||
controller_interface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State& state) override; | ||
|
||
controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override; | ||
|
||
private: | ||
using FollowJTrajAction = control_msgs::action::FollowJointTrajectory; | ||
using RealtimeGoalHandle = realtime_tools::RealtimeServerGoalHandle<FollowJTrajAction>; | ||
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); | ||
|
||
/* Start an action server with an action called: /passthrough_trajectory_controller/forward_joint_trajectory. */ | ||
void start_action_server(void); | ||
|
||
void end_goal(); | ||
|
||
bool check_goal_tolerance(); | ||
|
||
// Get a mapping between the trajectory's joint order and the internal one | ||
std::unordered_map<std::string, size_t> create_joint_mapping(const std::vector<std::string>& joint_names) const; | ||
|
||
std::shared_ptr<passthrough_trajectory_controller::ParamListener> passthrough_param_listener_; | ||
passthrough_trajectory_controller::Params passthrough_params_; | ||
|
||
rclcpp_action::Server<control_msgs::action::FollowJointTrajectory>::SharedPtr send_trajectory_action_server_; | ||
|
||
rclcpp_action::GoalResponse | ||
goal_received_callback(const rclcpp_action::GoalUUID& uuid, | ||
std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal); | ||
|
||
rclcpp_action::CancelResponse goal_cancelled_callback( | ||
const std::shared_ptr<rclcpp_action::ServerGoalHandle<control_msgs::action::FollowJointTrajectory>> goal_handle); | ||
|
||
void goal_accepted_callback( | ||
std::shared_ptr<rclcpp_action::ServerGoalHandle<control_msgs::action::FollowJointTrajectory>> goal_handle); | ||
|
||
realtime_tools::RealtimeBuffer<std::vector<std::string>> joint_names_; | ||
std::vector<std::string> state_interface_types_; | ||
|
||
std::vector<std::string> joint_state_interface_names_; | ||
std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> joint_position_state_interface_; | ||
std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> joint_velocity_state_interface_; | ||
std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> joint_acceleration_state_interface_; | ||
|
||
bool check_goal_tolerances(std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal); | ||
bool check_goal_positions(std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal); | ||
bool check_goal_velocities(std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal); | ||
bool check_goal_accelerations(std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal); | ||
|
||
trajectory_msgs::msg::JointTrajectory active_joint_traj_; | ||
// std::vector<control_msgs::msg::JointTolerance> path_tolerance_; | ||
realtime_tools::RealtimeBuffer<std::vector<control_msgs::msg::JointTolerance>> goal_tolerance_; | ||
realtime_tools::RealtimeBuffer<rclcpp::Duration> goal_time_tolerance_{ rclcpp::Duration(0, 0) }; | ||
|
||
std::atomic<size_t> current_index_; | ||
std::atomic<bool> trajectory_active_; | ||
rclcpp::Duration active_trajectory_elapsed_time_ = rclcpp::Duration::from_nanoseconds(0); | ||
rclcpp::Duration max_trajectory_time_ = rclcpp::Duration::from_nanoseconds(0); | ||
double scaling_factor_; | ||
std::atomic<size_t> number_of_joints_; | ||
static constexpr double NO_VAL = std::numeric_limits<double>::quiet_NaN(); | ||
|
||
std::optional<std::reference_wrapper<hardware_interface::LoanedStateInterface>> scaling_state_interface_; | ||
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> abort_command_interface_; | ||
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> transfer_command_interface_; | ||
std::optional<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> time_from_start_command_interface_; | ||
|
||
rclcpp::Clock::SharedPtr clock_; | ||
}; | ||
} // 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.