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

Forward trajectory controller #944

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
76bee81
Started work on forward position controller
URJala Mar 11, 2024
686ddbb
Controller is now able to run and read from speed_scale
URJala Mar 11, 2024
b8ef0a7
Communication between robot and passthrough controller is now functio…
URJala Mar 25, 2024
ad13110
Controller will now send over all received points, before sending the…
URJala Apr 11, 2024
95db48b
Created more examples for the use of the controller. Controller no…
URJala May 2, 2024
fab4316
Finished the passthrough controller
URJala May 2, 2024
7042157
Added passthrough controller to "initially loaded controller" options.
URJala Jul 15, 2024
95173af
Fix test_common
URJala Jul 15, 2024
4c9d9b6
Move functionality to update method
URJala Sep 3, 2024
67e5c0d
Removing examples from this PR
URJala Sep 18, 2024
95da869
Implemented some realtime boxes
URJala Sep 18, 2024
a19ac31
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch Sep 25, 2024
a61bd79
Updated to latest ControllerInterface API
fmauch Sep 25, 2024
caa8941
Rename controller's action topic to match the JTC
fmauch Sep 25, 2024
3d461ae
Remove duplicate controller entry
fmauch Sep 25, 2024
1ab4ed2
Rename controller action in tests
fmauch Sep 26, 2024
e1263a9
Use generate_parameters_library for joints and state interfaces
fmauch Sep 27, 2024
cf7aeaa
Use constants for transfer state in controller
fmauch Sep 27, 2024
dc85692
Use period directly instead of calculating it by hand
fmauch Sep 27, 2024
a050290
Change some stdout strings
fmauch Sep 27, 2024
569e319
Remove unnecessary check
fmauch Sep 27, 2024
c319be7
Remove an unnecessary comment
fmauch Sep 27, 2024
7b5f095
Do not require a controller active state inteface
fmauch Sep 27, 2024
c4a366f
Make action handling realtime-thread-safe
fmauch Sep 30, 2024
416e190
Fix tolerances handling
fmauch Sep 30, 2024
e513fc6
String formatting
fmauch Sep 30, 2024
a5957fc
Remove unused interfaces
fmauch Sep 30, 2024
5b1f7f3
Deactivate goal time check for now since ros2_control can report wron…
fmauch Oct 1, 2024
5078c60
Simplify joint state configuration
fmauch Oct 1, 2024
51fd002
Make controller robust against joint ordering
fmauch Oct 2, 2024
bd9652e
Make default config reflect the actual parameters
fmauch Oct 2, 2024
1389c3c
Fix tolerance handling
fmauch Oct 2, 2024
e042de9
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch Oct 2, 2024
bc76a61
REVERT_ME: use fixed ros2_control until merged
fmauch Oct 2, 2024
934ccc5
Make sure the abort state is reset when sending new trajectories
fmauch Oct 2, 2024
0e9b37d
Restructure command interface exporting
fmauch Oct 3, 2024
e224dfa
REVERT_ME: Use passthrough branch of description
fmauch Oct 3, 2024
6eb6def
Add documentation for the passthrough controller
fmauch Oct 3, 2024
3a0f562
Store command interface instead of using indices
fmauch Oct 3, 2024
df7c9ab
Correctly handle preemptions
fmauch Oct 3, 2024
197552a
Correctly abort and act on deactivate
fmauch Oct 3, 2024
63bce67
Update documentation
fmauch Oct 3, 2024
d6df554
Improve result representation in example_move script
fmauch Oct 3, 2024
0cf3249
Merge upstream main
fmauch Oct 3, 2024
2121cf8
Re-Restructure command interface exporting
fmauch Oct 14, 2024
17ab6d0
Revert "REVERT_ME: Use passthrough branch of description"
fmauch Oct 14, 2024
fdfcfab
Merge remote-tracking branch 'origin/main' into forward_controller
fmauch Oct 16, 2024
ca7aff9
Fix command interface names
fmauch Oct 16, 2024
f887c09
Check passthrough trajectory controller from write function
fmauch Oct 16, 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
16 changes: 15 additions & 1 deletion ur_controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ find_package(std_srvs REQUIRED)
find_package(ur_dashboard_msgs REQUIRED)
find_package(ur_msgs REQUIRED)
find_package(generate_parameter_library REQUIRED)
find_package(trajectory_msgs REQUIRED)
find_package(control_msgs REQUIRED)
find_package(action_msgs REQUIRED)


set(THIS_PACKAGE_INCLUDE_DEPENDS
angles
Expand All @@ -34,6 +38,9 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
ur_dashboard_msgs
ur_msgs
generate_parameter_library
control_msgs
trajectory_msgs
action_msgs
)

include_directories(include)
Expand All @@ -54,10 +61,16 @@ generate_parameter_library(
src/scaled_joint_trajectory_controller_parameters.yaml
)

generate_parameter_library(
passthrough_trajectory_controller_parameters
src/passthrough_trajectory_controller_parameters.yaml
)

add_library(${PROJECT_NAME} SHARED
src/scaled_joint_trajectory_controller.cpp
src/speed_scaling_state_broadcaster.cpp
src/gpio_controller.cpp)
src/gpio_controller.cpp
src/passthrough_trajectory_controller.cpp)

target_include_directories(${PROJECT_NAME} PRIVATE
include
Expand All @@ -66,6 +79,7 @@ target_link_libraries(${PROJECT_NAME}
gpio_controller_parameters
speed_scaling_state_broadcaster_parameters
scaled_joint_trajectory_controller_parameters
passthrough_trajectory_controller_parameters
)
ament_target_dependencies(${PROJECT_NAME}
${THIS_PACKAGE_INCLUDE_DEPENDS}
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,4 +14,9 @@
This controller publishes the Tool IO.
</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.
</description>
</class>
</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// 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 <memory>
#include <string>
#include <vector>

#include <functional>
#include <realtime_tools/realtime_box_best_effort.h>

#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 "trajectory_msgs/msg/joint_trajectory.hpp"
#include "trajectory_msgs/msg/joint_trajectory_point.hpp"
#include "control_msgs/action/follow_joint_trajectory.hpp"
#include "control_msgs/action/joint_trajectory.hpp"

#include "passthrough_trajectory_controller_parameters.hpp"

namespace ur_controllers
{
enum CommandInterfaces
{
/* The PASSTHROUGH_TRAJECTORY_TRANSFER_STATE value is used to keep track of which stage the transfer is in.
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
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.
fmauch marked this conversation as resolved.
Show resolved Hide resolved
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. */
PASSTHROUGH_TRAJECTORY_TRANSFER_STATE = 0,
/* The PASSTHROUGH_TRAJECTORY_ABORT value is used to indicate whether the trajectory has been cancelled from the
* hardware interface.*/
fmauch marked this conversation as resolved.
Show resolved Hide resolved
PASSTHROUGH_TRAJECTORY_ABORT = 1,
/* Arrays to hold the values of a point. */
PASSTHROUGH_TRAJECTORY_POSITIONS_ = 2,
PASSTHROUGH_TRAJECTORY_VELOCITIES_ = 8,
PASSTHROUGH_TRAJECTORY_ACCELERATIONS_ = 14,
PASSTHROUGH_TRAJECTORY_TIME_FROM_START = 20
};

enum StateInterfaces
{
/* State interface 0 - 17 are joint state interfaces*/

SPEED_SCALING_FACTOR = 18,
CONTROLLER_RUNNING = 19
};

// Struct to hold data that has to be transferred between realtime thread and non-realtime threads
struct AsyncInfo
{
double transfer_state = 0;
double abort = 0;
double controller_running = 0;
bool info_updated = false;
};

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::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;

private:
/* 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();

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(
const std::shared_ptr<rclcpp_action::ServerGoalHandle<control_msgs::action::FollowJointTrajectory>> goal_handle);

std::vector<std::string> joint_names_;
std::vector<std::string> state_interface_types_;

std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> joint_position_state_interface_;
std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> joint_velocity_state_interface_;

bool check_positions(std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal);
bool check_velocities(std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Goal> goal);
bool check_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_;
std::vector<control_msgs::msg::JointTolerance> goal_tolerance_;
rclcpp::Duration goal_time_tolerance_ = rclcpp::Duration::from_nanoseconds(0);

realtime_tools::RealtimeBoxBestEffort<AsyncInfo> info_from_realtime_;
realtime_tools::RealtimeBoxBestEffort<AsyncInfo> info_to_realtime_;
fmauch marked this conversation as resolved.
Show resolved Hide resolved

uint32_t current_point_;
bool trajectory_active_;
uint64_t period_ns;
uint64_t last_time_ns;
uint64_t now_ns;
double active_trajectory_elapsed_time_;
double max_trajectory_time_;
double scaling_factor_;
uint32_t number_of_joints_;
std::shared_ptr<rclcpp_action::ServerGoalHandle<control_msgs::action::FollowJointTrajectory>> active_goal_;
static constexpr double NO_VAL = std::numeric_limits<double>::quiet_NaN();
};
} // namespace ur_controllers
#endif // UR_CONTROLLERS__PASSTHROUGH_TRAJECTORY_CONTROLLER_HPP_
4 changes: 4 additions & 0 deletions ur_controllers/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<depend>std_srvs</depend>
<depend>ur_dashboard_msgs</depend>
<depend>ur_msgs</depend>
<depend>control_msgs</depend>
<depend>trajectory_msgs</depend>
<depend>action_msgs</depend>


<export>
<build_type>ament_cmake</build_type>
Expand Down
Loading
Loading