Skip to content

Commit a37987f

Browse files
committed
Clean up and comments
1 parent 8f81b82 commit a37987f

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

ur_robot_driver/include/ur_robot_driver/trajectory_until_node.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ class TrajectoryUntilNode : public rclcpp::Node
6767
private:
6868
rclcpp_action::Server<ur_msgs::action::TrajectoryUntil>::SharedPtr action_server_;
6969
rclcpp_action::Client<control_msgs::action::FollowJointTrajectory>::SharedPtr trajectory_action_client_;
70-
// Add new until types here, when available
71-
// Append only, no changing the sequence
72-
using tc_client = rclcpp_action::Client<ur_msgs::action::ToolContact>::SharedPtr;
7370

74-
std::variant</* std::monostate, */tc_client> until_action_client_variant;
71+
// Add new until types here, when available
72+
using TCClient = rclcpp_action::Client<ur_msgs::action::ToolContact>::SharedPtr;
73+
std::variant<TCClient> until_action_client_variant;
7574

7675
rclcpp::CallbackGroup::SharedPtr server_callback_group;
7776
rclcpp::CallbackGroup::SharedPtr clients_callback_group;
@@ -110,8 +109,6 @@ class TrajectoryUntilNode : public rclcpp::Node
110109

111110
void send_trajectory_goal(std::shared_ptr<const ur_msgs::action::TrajectoryUntil::Goal> goal);
112111

113-
114-
115112
void report_goal(rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>::WrappedResult result);
116113

117114
template <typename UntilResult>

ur_robot_driver/src/trajectory_until_node.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@
4242
#include <functional>
4343
#include <thread>
4444

45-
template <class T>
46-
struct until_container
47-
{
48-
T until_client_type;
49-
};
50-
5145
namespace ur_robot_driver
5246
{
5347

@@ -82,7 +76,7 @@ TrajectoryUntilNode::TrajectoryUntilNode(const rclcpp::NodeOptions& options)
8276
"trajectory",
8377
clients_callback_group);
8478

85-
// Create action server to advertise the "/trajectory_until/execute"
79+
// Create action server to advertise the "/trajectory_until_node/execute"
8680
action_server_ = rclcpp_action::create_server<TrajectoryUntil>(
8781
this, std::string(this->get_name()) + "/execute",
8882
std::bind(&TrajectoryUntilNode::goal_received_callback, this, std::placeholders::_1, std::placeholders::_2),
@@ -95,6 +89,7 @@ TrajectoryUntilNode::~TrajectoryUntilNode()
9589
{
9690
}
9791

92+
// Assign the correct type of action client to the variant
9893
bool TrajectoryUntilNode::assign_until_action_client(std::shared_ptr<const TrajectoryUntil::Goal> goal)
9994
{
10095
int type = goal->until_type;
@@ -134,12 +129,12 @@ rclcpp_action::GoalResponse TrajectoryUntilNode::goal_received_callback(
134129
}
135130

136131
// Check until action server, send action goal to until-controller and wait for it to be accepted.
137-
if(std::holds_alternative<tc_client>(until_action_client_variant)){
138-
if (!std::get<tc_client>(until_action_client_variant)->wait_for_action_server(std::chrono::seconds(1))) {
132+
if(std::holds_alternative<TCClient>(until_action_client_variant)){
133+
if (!std::get<TCClient>(until_action_client_variant)->wait_for_action_server(std::chrono::seconds(1))) {
139134
RCLCPP_ERROR(this->get_logger(), "Until action server not available.");
140135
return rclcpp_action::GoalResponse::REJECT;
141136
}
142-
send_until_goal<TCAction, tc_client>(goal);
137+
send_until_goal<TCAction, TCClient>(goal);
143138
}
144139
else{
145140
throw std::runtime_error("Until type not implemented. This should not happen.");
@@ -186,8 +181,6 @@ TrajectoryUntilNode::goal_cancelled_callback(const std::shared_ptr<GoalHandleTra
186181
trajectory_action_client_->async_cancel_goal(current_trajectory_goal_handle_);
187182
}
188183

189-
//server_goal_handle_ = nullptr;
190-
191184
return rclcpp_action::CancelResponse::ACCEPT;
192185
}
193186

@@ -259,7 +252,7 @@ void TrajectoryUntilNode::until_response_callback(
259252
cv_until_.notify_one();
260253
}
261254

262-
/* Just forward feedback from trajectory controller */
255+
// Just forward feedback from trajectory controller. No feedback from until controllers so far.
263256
void TrajectoryUntilNode::trajectory_feedback_callback(
264257
const rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>::SharedPtr& /* goal_handle */,
265258
const std::shared_ptr<const control_msgs::action::FollowJointTrajectory::Feedback> feedback)
@@ -276,6 +269,7 @@ void TrajectoryUntilNode::trajectory_feedback_callback(
276269
}
277270
}
278271

272+
// When a result is received from either trajectory or until condition, report it back to user
279273
void TrajectoryUntilNode::trajectory_result_callback(
280274
const rclcpp_action::ClientGoalHandle<control_msgs::action::FollowJointTrajectory>::WrappedResult& result)
281275
{
@@ -312,7 +306,7 @@ void TrajectoryUntilNode::report_goal(TrajectoryResult result)
312306
prealloc_res->error_string += " Trajectory action was canceled.";
313307
server_goal_handle_->canceled(prealloc_res);
314308
break;
315-
309+
316310
default:
317311
prealloc_res->error_string += " Unknown result code received from trajectory action, this should not happen. "
318312
"Aborting goal.";

0 commit comments

Comments
 (0)