Skip to content

Commit e3f271c

Browse files
committed
Add moveP to instruction executor
1 parent 7f5fffc commit e3f271c

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

include/ur_client_library/ur/instruction_executor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class InstructionExecutor
9898
bool moveL(const urcl::Pose& target, const double acceleration = 1.4, const double velocity = 1.04,
9999
const double time = 0, const double blend_radius = 0);
100100

101+
bool moveP(const urcl::Pose& target, const double acceleration = 1.4, const double velocity = 1.04,
102+
const double blend_radius = 0.0);
103+
101104
/**
102105
* \brief Cancel the current motion.
103106
*

include/ur_client_library/ur/ur_driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <chrono>
3232
#include <functional>
33+
#include <memory>
3334

3435
#include "ur_client_library/rtde/rtde_client.h"
3536
#include "ur_client_library/control/reverse_interface.h"
@@ -531,6 +532,8 @@ class UrDriver
531532
*/
532533
bool writeTrajectorySplinePoint(const vector6d_t& positions, const float goal_time = 0.0);
533534

535+
bool writeMotionPrimitive(const std::shared_ptr<control::MotionPrimitive> motion_instruction);
536+
534537
/*!
535538
* \brief Writes a control message in trajectory forward mode.
536539
*

src/ur/instruction_executor.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,15 @@ bool urcl::InstructionExecutor::executeMotion(
6666

6767
for (const auto& primitive : motion_sequence)
6868
{
69-
switch (primitive->type)
69+
try
7070
{
71-
case control::MotionType::MOVEJ:
72-
{
73-
auto movej_primitive = std::static_pointer_cast<control::MoveJPrimitive>(primitive);
74-
driver_->writeTrajectoryPoint(movej_primitive->target_joint_configuration, primitive->acceleration,
75-
primitive->velocity, false, primitive->duration.count(), primitive->blend_radius);
76-
break;
77-
}
78-
case control::MotionType::MOVEL:
79-
{
80-
auto movel_primitive = std::static_pointer_cast<control::MoveLPrimitive>(primitive);
81-
urcl::vector6d_t pose_vec = { movel_primitive->target_pose.x, movel_primitive->target_pose.y,
82-
movel_primitive->target_pose.z, movel_primitive->target_pose.rx,
83-
movel_primitive->target_pose.ry, movel_primitive->target_pose.rz };
84-
driver_->writeTrajectoryPoint(pose_vec, primitive->acceleration, primitive->velocity, true,
85-
primitive->duration.count(), primitive->blend_radius);
86-
break;
87-
}
88-
default:
89-
URCL_LOG_ERROR("Unsupported motion type");
90-
// The hardware will complain about missing trajectory points and return a failure for
91-
// trajectory execution. Hence, we need to step into the running loop below.
71+
driver_->writeMotionPrimitive(primitive);
72+
}
73+
catch (const UnsupportedMotionType&)
74+
{
75+
URCL_LOG_ERROR("Unsupported motion type");
76+
// The hardware will complain about missing trajectory points and return a failure for
77+
// trajectory execution. Hence, we need to step into the running loop below.
9278
}
9379
}
9480
trajectory_running_ = true;
@@ -120,6 +106,12 @@ bool urcl::InstructionExecutor::moveL(const urcl::Pose& target, const double acc
120106
target, blend_radius, std::chrono::milliseconds(static_cast<int>(time * 1000)), acceleration, velocity) });
121107
}
122108

109+
bool urcl::InstructionExecutor::moveP(const urcl::Pose& target, const double acceleration, const double velocity,
110+
const double blend_radius)
111+
{
112+
return executeMotion({ std::make_shared<control::MovePPrimitive>(target, blend_radius, acceleration, velocity) });
113+
}
114+
123115
bool urcl::InstructionExecutor::cancelMotion()
124116
{
125117
cancel_requested_ = true;

src/ur/ur_driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ bool UrDriver::writeTrajectoryControlMessage(const control::TrajectoryControlMes
240240
return reverse_interface_->writeTrajectoryControlMessage(trajectory_action, point_number, robot_receive_timeout);
241241
}
242242

243+
bool UrDriver::writeMotionPrimitive(const std::shared_ptr<control::MotionPrimitive> motion_instruction)
244+
{
245+
return trajectory_interface_->writeMotionPrimitive(motion_instruction);
246+
}
247+
243248
bool UrDriver::writeFreedriveControlMessage(const control::FreedriveControlMessage freedrive_action,
244249
const RobotReceiveTimeout& robot_receive_timeout)
245250
{

tests/test_instruction_executor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ TEST_F(InstructionExecutorTest, empty_sequence_succeeds)
363363
ASSERT_TRUE(executor_->executeMotion(motion_sequence));
364364
}
365365

366+
TEST_F(InstructionExecutorTest, movep_succeeds)
367+
{
368+
// move to a feasible starting pose
369+
ASSERT_TRUE(executor_->moveJ({ -1.57, -1.6, 1.6, -0.7, 0.7, 0.2 }));
370+
371+
ASSERT_TRUE(executor_->moveP({ -0.203, 0.263, 0.559, 0.68, -1.083, -2.076 }, 2.0, 2.0));
372+
}
373+
366374
int main(int argc, char* argv[])
367375
{
368376
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)