Skip to content

Commit eb0ae05

Browse files
committed
Fix motion primitive validation
Have individual validation functions for each primitive type.
1 parent afcf1a4 commit eb0ae05

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

include/ur_client_library/control/motion_primitives.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum class TrajectorySplineType : int32_t
6363

6464
struct MotionPrimitive
6565
{
66+
virtual ~MotionPrimitive() = default;
6667
MotionType type = MotionType::UNKNOWN;
6768
std::chrono::duration<double> duration;
6869
double acceleration;
@@ -86,6 +87,7 @@ struct MoveJPrimitive : public MotionPrimitive
8687
this->blend_radius = blend_radius;
8788
}
8889

90+
bool validate() const override;
8991
urcl::vector6d_t target_joint_configuration;
9092
};
9193

@@ -103,6 +105,8 @@ struct MoveLPrimitive : public MotionPrimitive
103105
this->blend_radius = blend_radius;
104106
}
105107

108+
bool validate() const override;
109+
106110
urcl::Pose target_pose;
107111
};
108112

@@ -117,6 +121,9 @@ struct MovePPrimitive : public MotionPrimitive
117121
this->velocity = velocity;
118122
this->blend_radius = blend_radius;
119123
}
124+
125+
bool validate() const override;
126+
120127
urcl::Pose target_pose;
121128
};
122129

@@ -133,6 +140,9 @@ struct MoveCPrimitive : public MotionPrimitive
133140
this->blend_radius = blend_radius;
134141
this->mode = mode;
135142
}
143+
144+
bool validate() const override;
145+
136146
urcl::Pose via_point_pose;
137147
urcl::Pose target_pose;
138148
int32_t mode = 0;
@@ -202,4 +212,4 @@ struct OptimoveLPrimitive : public MotionPrimitive
202212
};
203213
} // namespace control
204214
} // namespace urcl
205-
#endif // UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED
215+
#endif // UR_CLIENT_LIBRARY_MOTION_PRIMITIVES_H_INCLUDED

src/control/motion_primitives.cpp

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,83 @@ namespace urcl::control
3636

3737
bool MotionPrimitive::validate() const
3838
{
39+
if (blend_radius < 0)
40+
{
41+
URCL_LOG_ERROR("Negative blend radius passed to motion primitive. This is not allowed.");
42+
return false;
43+
}
44+
return true;
45+
}
46+
bool MoveJPrimitive::validate() const
47+
{
48+
if (!MotionPrimitive::validate())
49+
{
50+
return false;
51+
}
3952
if (acceleration < 0)
4053
{
41-
URCL_LOG_ERROR("Negative acceleration passed to motion primitive. This is not allowed.");
54+
URCL_LOG_ERROR("Negative acceleration passed to MoveJ primitive. This is not allowed.");
4255
return false;
4356
}
4457
if (velocity < 0)
4558
{
46-
URCL_LOG_ERROR("Negative velocity passed to motion primitive. This is not allowed.");
59+
URCL_LOG_ERROR("Negative velocity passed to MoveJ primitive. This is not allowed.");
4760
return false;
4861
}
49-
if (blend_radius < 0)
62+
return true;
63+
}
64+
65+
bool MoveLPrimitive::validate() const
66+
{
67+
if (!MotionPrimitive::validate())
5068
{
51-
URCL_LOG_ERROR("Negative blend radius passed to motion primitive. This is not allowed.");
69+
return false;
70+
}
71+
if (acceleration < 0)
72+
{
73+
URCL_LOG_ERROR("Negative acceleration passed to MoveL primitive. This is not allowed.");
74+
return false;
75+
}
76+
if (velocity < 0)
77+
{
78+
URCL_LOG_ERROR("Negative velocity passed to MoveL primitive. This is not allowed.");
79+
return false;
80+
}
81+
return true;
82+
}
83+
bool MovePPrimitive::validate() const
84+
{
85+
if (!MotionPrimitive::validate())
86+
{
87+
return false;
88+
}
89+
if (acceleration < 0)
90+
{
91+
URCL_LOG_ERROR("Negative acceleration passed to MoveP primitive. This is not allowed.");
92+
return false;
93+
}
94+
if (velocity < 0)
95+
{
96+
URCL_LOG_ERROR("Negative velocity passed to MoveP primitive. This is not allowed.");
97+
return false;
98+
}
99+
return true;
100+
}
101+
102+
bool MoveCPrimitive::validate() const
103+
{
104+
if (!MotionPrimitive::validate())
105+
{
106+
return false;
107+
}
108+
if (acceleration < 0)
109+
{
110+
URCL_LOG_ERROR("Negative acceleration passed to MoveC primitive. This is not allowed.");
111+
return false;
112+
}
113+
if (velocity < 0)
114+
{
115+
URCL_LOG_ERROR("Negative velocity passed to MoveC primitive. This is not allowed.");
52116
return false;
53117
}
54118
return true;

0 commit comments

Comments
 (0)