3434#include < chrono>
3535#include < optional>
3636#include < variant>
37- #include " ur_client_library/exceptions.h"
3837#include < ur_client_library/types.h>
3938
4039namespace urcl
@@ -76,6 +75,45 @@ enum class MotionType : uint8_t
7675 UNKNOWN = 255
7776};
7877
78+ inline std::string motionTypeToString (const MotionType type)
79+ {
80+ switch (type)
81+ {
82+ case MotionType::MOVEJ :
83+ return " MOVEJ" ;
84+ case MotionType::MOVEL :
85+ return " MOVEL" ;
86+ case MotionType::MOVEP :
87+ return " MOVEP" ;
88+ case MotionType::MOVEC :
89+ return " MOVEC" ;
90+ case MotionType::OPTIMOVEJ :
91+ return " OPTIMOVEJ" ;
92+ case MotionType::OPTIMOVEL :
93+ return " OPTIMOVEL" ;
94+ case MotionType::MOVEJ_POSE :
95+ return " MOVEJ_POSE" ;
96+ case MotionType::MOVEL_JOINT :
97+ return " MOVEL_JOINT" ;
98+ case MotionType::MOVEP_JOINT :
99+ return " MOVEP_JOINT" ;
100+ case MotionType::MOVEC_JOINT :
101+ return " MOVEC_JOINT" ;
102+ case MotionType::MOVEC_JOINT_POSE :
103+ return " MOVEC_JOINT_POSE" ;
104+ case MotionType::MOVEC_POSE_JOINT :
105+ return " MOVEC_POSE_JOINT" ;
106+ case MotionType::OPTIMOVEJ_POSE :
107+ return " OPTIMOVEJ_POSE" ;
108+ case MotionType::OPTIMOVEL_JOINT :
109+ return " OPTIMOVEL_JOINT" ;
110+ case MotionType::SPLINE :
111+ return " SPLINE" ;
112+ default :
113+ return " UNKNOWN" ;
114+ }
115+ }
116+
79117/* !
80118 * Spline types
81119 */
@@ -144,8 +182,8 @@ struct MoveJPrimitive : public MotionPrimitive
144182 target);
145183 }
146184
147- urcl::vector6d_t target_joint_configuration;
148- urcl::Pose target_pose;
185+ urcl::vector6d_t target_joint_configuration{} ;
186+ urcl::Pose target_pose{} ;
149187};
150188
151189struct MoveLPrimitive : public MotionPrimitive
@@ -195,8 +233,8 @@ struct MoveLPrimitive : public MotionPrimitive
195233 target);
196234 }
197235
198- urcl::Pose target_pose;
199- urcl::vector6d_t target_joint_configuration;
236+ urcl::Pose target_pose{} ;
237+ urcl::vector6d_t target_joint_configuration{} ;
200238};
201239
202240struct MovePPrimitive : public MotionPrimitive
@@ -239,8 +277,8 @@ struct MovePPrimitive : public MotionPrimitive
239277 this ->blend_radius = blend_radius;
240278 }
241279
242- urcl::Pose target_pose;
243- urcl::vector6d_t target_joint_configuration;
280+ urcl::Pose target_pose{} ;
281+ urcl::vector6d_t target_joint_configuration{} ;
244282};
245283
246284struct MoveCPrimitive : public MotionPrimitive
@@ -261,73 +299,62 @@ struct MoveCPrimitive : public MotionPrimitive
261299 * \brief Construct a MoveC primitive from two \ref urcl::MotionTarget values.
262300 *
263301 * Every combination of \ref urcl::Pose and \ref urcl::Q for the via point and the target is
264- * supported and mapped to the corresponding \ref MotionType (``MOVEC``,
265- * ``MOVEC_JOINT``, `` MOVEC_POSE_JOINT``, or ``MOVEC_JOINT_POSE``). When a joint configuration
266- * is used for either role, only the corresponding joint member is populated and the pose
267- * member is set to a default-constructed \ref urcl::Pose .
302+ * supported and mapped to the corresponding \ref MotionType (``MOVEC``, ``MOVEC_JOINT``,
303+ * ``MOVEC_POSE_JOINT``, or ``MOVEC_JOINT_POSE``). The naming convention is
304+ * ``MOVEC_<target>_<via>``, i.e. ``MOVEC_POSE_JOINT`` denotes a movec whose target is a pose
305+ * and whose via point is a joint configuration .
268306 *
269- * \throws urcl::UrException if either variant is ever extended with an alternative that is
270- * not handled here.
307+ * Unhandled variant alternatives are caught at compile time via ``static_assert``.
271308 */
272309 MoveCPrimitive (const MotionTarget& via_point, const MotionTarget& target, const double blend_radius = 0 ,
273310 const double acceleration = 1.4 , const double velocity = 1.04 , const int32_t mode = 0 )
274311 {
275- if (std::holds_alternative<Q>(via_point))
276- {
277- if (std::holds_alternative<Q>(target))
278- {
279- type = MotionType::MOVEC_JOINT ;
280- via_point_pose = urcl::Pose ();
281- target_pose = urcl::Pose ();
282- via_point_joint_configuration = std::get<Q>(via_point).values ;
283- target_joint_configuration = std::get<Q>(target).values ;
284- }
285- else if (std::holds_alternative<urcl::Pose>(target))
286- {
287- type = MotionType::MOVEC_POSE_JOINT ;
288- via_point_pose = urcl::Pose ();
289- target_pose = std::get<urcl::Pose>(target);
290- via_point_joint_configuration = std::get<Q>(via_point).values ;
291- }
292- else
293- {
294- throw urcl::UrException (" Unhandled motion target type for target point passed to MoveCPrimitive constructor" );
295- }
296- }
297- else if (std::holds_alternative<urcl::Pose>(via_point))
298- {
299- if (std::holds_alternative<Q>(target))
300- {
301- type = MotionType::MOVEC_JOINT_POSE ;
302- via_point_pose = std::get<urcl::Pose>(via_point);
303- target_pose = urcl::Pose ();
304- target_joint_configuration = std::get<Q>(target).values ;
305- }
306- else if (std::holds_alternative<urcl::Pose>(target))
307- {
308- type = MotionType::MOVEC ;
309- via_point_pose = std::get<urcl::Pose>(via_point);
310- target_pose = std::get<urcl::Pose>(target);
311- }
312- else
313- {
314- throw urcl::UrException (" Unhandled motion target type for target point passed to MoveCPrimitive constructor" );
315- }
316- }
317- else
318- {
319- throw urcl::UrException (" Unhandled motion target type for via_point passed to MoveCPrimitive constructor" );
320- }
312+ std::visit (
313+ [&](const auto & via_variant, const auto & target_variant) {
314+ using ViaT = std::decay_t <decltype (via_variant)>;
315+ using TargetT = std::decay_t <decltype (target_variant)>;
316+ static_assert (std::is_same_v<ViaT, Q> || std::is_same_v<ViaT, urcl::Pose>, " Unhandled MotionTarget "
317+ " alternative for via_point" );
318+ static_assert (std::is_same_v<TargetT, Q> || std::is_same_v<TargetT, urcl::Pose>, " Unhandled MotionTarget "
319+ " alternative for target" );
320+
321+ if constexpr (std::is_same_v<ViaT, urcl::Pose> && std::is_same_v<TargetT, urcl::Pose>)
322+ {
323+ type = MotionType::MOVEC ;
324+ via_point_pose = via_variant;
325+ target_pose = target_variant;
326+ }
327+ else if constexpr (std::is_same_v<ViaT, Q> && std::is_same_v<TargetT, Q>)
328+ {
329+ type = MotionType::MOVEC_JOINT ;
330+ via_point_joint_configuration = via_variant.values ;
331+ target_joint_configuration = target_variant.values ;
332+ }
333+ else if constexpr (std::is_same_v<ViaT, Q> && std::is_same_v<TargetT, urcl::Pose>)
334+ {
335+ type = MotionType::MOVEC_POSE_JOINT ;
336+ via_point_joint_configuration = via_variant.values ;
337+ target_pose = target_variant;
338+ }
339+ else if constexpr (std::is_same_v<ViaT, urcl::Pose> && std::is_same_v<TargetT, Q>)
340+ {
341+ type = MotionType::MOVEC_JOINT_POSE ;
342+ via_point_pose = via_variant;
343+ target_joint_configuration = target_variant.values ;
344+ }
345+ },
346+ via_point, target);
347+
321348 this ->acceleration = acceleration;
322349 this ->velocity = velocity;
323350 this ->blend_radius = blend_radius;
324351 this ->mode = mode;
325352 }
326353
327- urcl::Pose via_point_pose;
328- urcl::Pose target_pose;
329- urcl::vector6d_t via_point_joint_configuration;
330- urcl::vector6d_t target_joint_configuration;
354+ urcl::Pose via_point_pose{} ;
355+ urcl::Pose target_pose{} ;
356+ urcl::vector6d_t via_point_joint_configuration{} ;
357+ urcl::vector6d_t target_joint_configuration{} ;
331358 int32_t mode = 0 ;
332359};
333360
@@ -406,8 +433,8 @@ struct OptimoveJPrimitive : public MotionPrimitive
406433
407434 bool validate () const override ;
408435
409- urcl::vector6d_t target_joint_configuration;
410- Pose target_pose;
436+ urcl::vector6d_t target_joint_configuration{} ;
437+ Pose target_pose{} ;
411438};
412439
413440struct OptimoveLPrimitive : public MotionPrimitive
@@ -452,8 +479,8 @@ struct OptimoveLPrimitive : public MotionPrimitive
452479
453480 bool validate () const override ;
454481
455- urcl::Pose target_pose;
456- vector6d_t target_joint_configuration;
482+ urcl::Pose target_pose{} ;
483+ vector6d_t target_joint_configuration{} ;
457484};
458485} // namespace control
459486} // namespace urcl
0 commit comments