Skip to content

Commit 9635122

Browse files
authored
Add functionality to send MoveP and MoveC instructions to the robot (#303)
This PR aims at supporting to send MoveP and MoveC commands to the robot directly through the TrajectoryPointInterface and the InstructionExecutor.
1 parent 1632f6d commit 9635122

16 files changed

+546
-157
lines changed

doc/architecture/instruction_executor.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ Instruction Executor
66
The Instruction Executor is a convenience wrapper to make common robot instructions such as point
77
to point motions easily accessible. Currently, it supports the following instructions:
88

9-
* Excecute MoveJ point to point motions
9+
* Execute MoveJ point to point motions
1010
* Execute MoveL point to point motions
11-
* Execute sequences consisting of MoveJ and MoveL instructions
11+
* Execute MoveP point to point motions
12+
* Execute MoveC circular motions
13+
* Execute sequences consisting of the motion primitives above
1214

1315
The Instruction Executor uses the :ref:`trajectory_point_interface` and the
1416
:ref:`reverse_interface`

doc/architecture/trajectory_point_interface.rst

+26-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,32 @@ representations in 21 datafields. The data fields have the following meaning:
3939
===== =====
4040
index meaning
4141
===== =====
42-
0-5 trajectory point positions (floating point)
43-
6-11 trajectory point velocities (floating point)
44-
12-17 trajectory point accelerations (floating point)
45-
18 trajectory point type (0: JOINT, 1: CARTESIAN, 2: JOINT_SPLINE)
46-
19 trajectory point time (in seconds, floating point)
42+
0-5 trajectory point positions (Multiplied by ``MULT_JOINTSTATE``)
43+
6-11 trajectory point velocities (Multiplied by ``MULT_JOINTSTATE``). For MOVEC, this contains the "via pose".
44+
12-17 trajectory point accelerations (Multiplied by ``MULT_JOINTSTATE``).
45+
46+
For MOVEC:
47+
48+
- 12: velocity (Multiplied by ``MULT_JOINTSTATE``)
49+
- 13: acceleration (Multiplied by ``MULT_JOINTSTATE``)
50+
- 14: mode (Multiplied by ``MULT_JOINTSTATE``)
51+
52+
18 trajectory point type
53+
54+
- 0: MOVEJ
55+
- 1: MOVEL
56+
- 2: MOVEP
57+
- 3: MOVEC
58+
- 51: SPLINE)
59+
60+
19 trajectory point time (in seconds, multiplied by ``MULT_TIME``)
4761
20 depending on trajectory point type
4862

49-
- JOINT, CARTESIAN: point blend radius (in meters, floating point)
50-
- JOINT_SPLINE: spline type (1: CUBIC, 2: QUINTIC)
63+
- MOVEJ, MOVEL, MOVEP and MOVEC: point blend radius (in meters, multiplied by ``MULT_TIME``)
64+
- SPLINE: spline type (1: CUBIC, 2: QUINTIC)
5165
===== =====
66+
67+
where
68+
69+
- ``MULT_JOINTSTATE``: 1000000
70+
- ``MULT_TIME``: 1000

doc/examples/instruction_executor.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ To run a sequence of motions, create an
4444
:end-at: instruction_executor->executeMotion(motion_sequence);
4545

4646
Each element in the motion sequence can be a different motion type. In the example, there are two
47-
``MoveJ`` motions and two ``MoveL`` motion. The primitives' parameters are directly forwarded to
47+
``MoveJ`` motions, a ``MoveL`` motion and a ``MoveP`` motion. The primitives' parameters are directly forwarded to
4848
the underlying script functions, so the parameter descriptions for them apply, as well.
4949
Particularly, you may want to choose between either a time-based execution speed or an acceleration
50-
/ velocity parametrization. The latter will be ignored if a time > 0 is given.
50+
/ velocity parametrization for some move functions. The latter will be ignored if a time > 0 is given.
51+
52+
Please refer to the script manual for details.
5153

5254
Execute a single motion
5355
-----------------------

examples/instruction_executor.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ int main(int argc, char* argv[])
8989

9090
std::make_shared<urcl::control::MoveLPrimitive>(urcl::Pose(-0.203, 0.263, 0.559, 0.68, -1.083, -2.076), 0.1,
9191
std::chrono::seconds(2)),
92-
std::make_shared<urcl::control::MoveLPrimitive>(urcl::Pose{ -0.203, 0.463, 0.559, 0.68, -1.083, -2.076 }, 0.1,
93-
std::chrono::seconds(2)),
92+
std::make_shared<urcl::control::MovePPrimitive>(urcl::Pose{ -0.203, 0.463, 0.559, 0.68, -1.083, -2.076 }, 0.1, 0.4,
93+
0.4),
9494
};
9595
instruction_executor->executeMotion(motion_sequence);
9696

@@ -105,6 +105,8 @@ int main(int argc, char* argv[])
105105
// goal time parametrization -- acceleration and velocity will be ignored
106106
instruction_executor->moveL({ -0.203, 0.463, 0.559, 0.68, -1.083, -2.076 }, 0.1, 0.1, goal_time_sec);
107107

108+
instruction_executor->moveP({ -0.203, 0.463, 0.759, 0.68, -1.083, -2.076 }, 1.5, 1.5);
109+
108110
g_my_robot->getUrDriver()->stopControl();
109111
return 0;
110112
}

include/ur_client_library/control/motion_primitives.h

+74-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED
3333

3434
#include <chrono>
35+
#include <optional>
3536
#include <ur_client_library/types.h>
3637

3738
namespace urcl
@@ -48,9 +49,19 @@ enum class MotionType : uint8_t
4849
SPLINE = 51,
4950
UNKNOWN = 255
5051
};
52+
53+
/*!
54+
* Spline types
55+
*/
56+
enum class TrajectorySplineType : int32_t
57+
{
58+
SPLINE_CUBIC = 1,
59+
SPLINE_QUINTIC = 2
60+
};
61+
5162
struct MotionPrimitive
5263
{
53-
MotionType type;
64+
MotionType type = MotionType::UNKNOWN;
5465
std::chrono::duration<double> duration;
5566
double acceleration;
5667
double velocity;
@@ -90,6 +101,67 @@ struct MoveLPrimitive : public MotionPrimitive
90101

91102
urcl::Pose target_pose;
92103
};
104+
105+
struct MovePPrimitive : public MotionPrimitive
106+
{
107+
MovePPrimitive(const urcl::Pose& target, const double blend_radius = 0, const double acceleration = 1.4,
108+
const double velocity = 1.04)
109+
{
110+
type = MotionType::MOVEP;
111+
target_pose = target;
112+
this->acceleration = acceleration;
113+
this->velocity = velocity;
114+
this->blend_radius = blend_radius;
115+
}
116+
urcl::Pose target_pose;
117+
};
118+
119+
struct MoveCPrimitive : public MotionPrimitive
120+
{
121+
MoveCPrimitive(const urcl::Pose& via_point, const urcl::Pose& target, const double blend_radius = 0,
122+
const double acceleration = 1.4, const double velocity = 1.04, const int32_t mode = 0)
123+
{
124+
type = MotionType::MOVEC;
125+
via_point_pose = via_point;
126+
target_pose = target;
127+
this->acceleration = acceleration;
128+
this->velocity = velocity;
129+
this->blend_radius = blend_radius;
130+
this->mode = mode;
131+
}
132+
urcl::Pose via_point_pose;
133+
urcl::Pose target_pose;
134+
int32_t mode = 0;
135+
};
136+
137+
struct SplinePrimitive : public MotionPrimitive
138+
{
139+
SplinePrimitive(const urcl::vector6d_t& target_positions, const vector6d_t& target_velocities,
140+
const std::optional<vector6d_t>& target_accelerations,
141+
const std::chrono::duration<double> duration = std::chrono::milliseconds(0))
142+
{
143+
type = MotionType::SPLINE;
144+
this->target_positions = target_positions;
145+
this->target_velocities = target_velocities;
146+
this->target_accelerations = target_accelerations;
147+
this->duration = duration;
148+
}
149+
150+
control::TrajectorySplineType getSplineType() const
151+
{
152+
if (target_accelerations.has_value())
153+
{
154+
return control::TrajectorySplineType::SPLINE_QUINTIC;
155+
}
156+
else
157+
{
158+
return control::TrajectorySplineType::SPLINE_CUBIC;
159+
}
160+
}
161+
vector6d_t target_positions;
162+
vector6d_t target_velocities;
163+
std::optional<vector6d_t> target_accelerations;
164+
};
93165
} // namespace control
94166
} // namespace urcl
95-
#endif // UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED
167+
#endif // UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED

include/ur_client_library/control/trajectory_point_interface.h

+11-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <optional>
3333

34+
#include "ur_client_library/control/motion_primitives.h"
3435
#include "ur_client_library/control/reverse_interface.h"
3536
#include "ur_client_library/comm/control_mode.h"
3637
#include "ur_client_library/types.h"
@@ -54,25 +55,6 @@ enum class TrajectoryResult : int32_t
5455

5556
std::string trajectoryResultToString(const TrajectoryResult result);
5657

57-
/*!
58-
* Spline types
59-
*/
60-
enum class TrajectorySplineType : int32_t
61-
{
62-
SPLINE_CUBIC = 1,
63-
SPLINE_QUINTIC = 2
64-
};
65-
66-
/*!
67-
* Motion Types
68-
*/
69-
enum class TrajectoryMotionType : int32_t
70-
{
71-
JOINT_POINT = 0,
72-
CARTESIAN_POINT = 1,
73-
JOINT_POINT_SPLINE = 2
74-
};
75-
7658
/*!
7759
* \brief The TrajectoryPointInterface class handles trajectory forwarding to the robot. Full
7860
* trajectories are forwarded to the robot controller and are executed there.
@@ -141,6 +123,16 @@ class TrajectoryPointInterface : public ReverseInterface
141123
bool writeTrajectorySplinePoint(const vector6d_t* positions, const vector6d_t* velocities,
142124
const vector6d_t* accelerations, const float goal_time);
143125

126+
/*!
127+
* \brief Writes a motion primitive to the robot to be read by the URScript program.
128+
*
129+
* \param primitive A shared pointer to a motion primitive object. This can contain any motion
130+
* primitive type that is supported. Currently, that is MoveJ, MoveL, MoveP and MoveC.
131+
*
132+
* \returns True, if the write was performed successfully, false otherwise.
133+
*/
134+
bool writeMotionPrimitive(const std::shared_ptr<control::MotionPrimitive> primitive);
135+
144136
void setTrajectoryEndCallback(std::function<void(TrajectoryResult)> callback)
145137
{
146138
handle_trajectory_end_ = callback;

include/ur_client_library/exceptions.h

+8
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,13 @@ class MissingArgument : public UrException
205205
return text_.c_str();
206206
}
207207
};
208+
209+
class UnsupportedMotionType : public UrException
210+
{
211+
public:
212+
explicit UnsupportedMotionType() : std::runtime_error("Unsupported motion type")
213+
{
214+
}
215+
};
208216
} // namespace urcl
209217
#endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED

include/ur_client_library/types.h

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ struct Pose
4646
double rx;
4747
double ry;
4848
double rz;
49+
50+
bool operator==(const Pose& other) const
51+
{
52+
return x == other.x && y == other.y && z == other.z && rx == other.rx && ry == other.ry && rz == other.rz;
53+
}
4954
};
5055

5156
template <class T, std::size_t N>

include/ur_client_library/ur/instruction_executor.h

+36-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class InstructionExecutor
8282
const double time = 0, const double blend_radius = 0);
8383

8484
/**
85-
* \brief Move the robot to a pose target.
85+
* \brief Move the robot to a pose target using movel
8686
*
8787
* This function will move the robot to the given pose target. The robot will move with the given acceleration and
88-
* velocity. The function will return once the robot has reached the target.
88+
* velocity or a motion time. The function will return once the robot has reached the target.
8989
*
9090
* \param target The pose target to move to.
9191
* \param acceleration Tool acceleration [m/s^2]
@@ -98,6 +98,40 @@ 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+
/**
102+
* \brief Move the robot to a pose target using movep
103+
*
104+
* This function will move the robot to the given pose target. The robot will move with the given acceleration and
105+
* velocity. The function will return once the robot has reached the target.
106+
*
107+
* \param target The pose target to move to.
108+
* \param acceleration Tool acceleration [m/s^2]
109+
* \param velocity Tool speed [m/s]
110+
* \param blend_radius The blend radius to use for the motion.
111+
*
112+
* \return True if the robot has reached the target, false otherwise.
113+
*/
114+
bool moveP(const urcl::Pose& target, const double acceleration = 1.4, const double velocity = 1.04,
115+
const double blend_radius = 0.0);
116+
117+
/**
118+
* \brief Move the robot to a pose target using movec
119+
*
120+
* This function will move the robot to the given pose target in a circular motion going through via. The robot will
121+
* move with the given acceleration and velocity. The function will return once the robot has reached the target.
122+
*
123+
* \param via The circle will be defined by the current pose (the end pose of the previous motion), the target and the
124+
* via point.
125+
* \param target The pose target to move to.
126+
* \param acceleration Tool acceleration [m/s^2]
127+
* \param velocity Tool speed [m/s]
128+
* \param blend_radius The blend radius to use for the motion.
129+
*
130+
* \return True if the robot has reached the target, false otherwise.
131+
*/
132+
bool moveC(const urcl::Pose& via, const urcl::Pose& target, const double acceleration = 1.4,
133+
const double velocity = 1.04, const double blend_radius = 0.0, const int32_t mode = 0);
134+
101135
/**
102136
* \brief Cancel the current motion.
103137
*

include/ur_client_library/ur/ur_driver.h

+13
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,18 @@ class UrDriver
531532
*/
532533
bool writeTrajectorySplinePoint(const vector6d_t& positions, const float goal_time = 0.0);
533534

535+
/*!
536+
* \brief Writes a motion command to the trajectory point interface
537+
*
538+
* The motion command corresponds directly to a URScript move function such as `movej` or
539+
* `movel`. See the MotionPrimitive's header for all possible motion primitives.
540+
*
541+
* \param motion_instruction The motion primitive to be sent to the robot.
542+
*
543+
* \returns True on successful write.
544+
*/
545+
bool writeMotionPrimitive(const std::shared_ptr<control::MotionPrimitive> motion_instruction);
546+
534547
/*!
535548
* \brief Writes a control message in trajectory forward mode.
536549
*

0 commit comments

Comments
 (0)