Skip to content

Commit 8dcfe27

Browse files
committed
Merge validation functions
Use the same validation function for most primitives, while providing a specialized validation function for spline primitives.
1 parent 82a8bc7 commit 8dcfe27

File tree

2 files changed

+10
-69
lines changed

2 files changed

+10
-69
lines changed

include/ur_client_library/control/motion_primitives.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ struct MoveJPrimitive : public MotionPrimitive
8787
this->blend_radius = blend_radius;
8888
}
8989

90-
bool validate() const override;
9190
urcl::vector6d_t target_joint_configuration;
9291
};
9392

@@ -105,8 +104,6 @@ struct MoveLPrimitive : public MotionPrimitive
105104
this->blend_radius = blend_radius;
106105
}
107106

108-
bool validate() const override;
109-
110107
urcl::Pose target_pose;
111108
};
112109

@@ -122,8 +119,6 @@ struct MovePPrimitive : public MotionPrimitive
122119
this->blend_radius = blend_radius;
123120
}
124121

125-
bool validate() const override;
126-
127122
urcl::Pose target_pose;
128123
};
129124

@@ -141,8 +136,6 @@ struct MoveCPrimitive : public MotionPrimitive
141136
this->mode = mode;
142137
}
143138

144-
bool validate() const override;
145-
146139
urcl::Pose via_point_pose;
147140
urcl::Pose target_pose;
148141
int32_t mode = 0;
@@ -172,6 +165,9 @@ struct SplinePrimitive : public MotionPrimitive
172165
return control::TrajectorySplineType::SPLINE_CUBIC;
173166
}
174167
}
168+
169+
bool validate() const override;
170+
175171
vector6d_t target_positions;
176172
vector6d_t target_velocities;
177173
std::optional<vector6d_t> target_accelerations;
@@ -189,9 +185,9 @@ struct OptimoveJPrimitive : public MotionPrimitive
189185
this->velocity = velocity_fraction;
190186
}
191187

192-
urcl::vector6d_t target_joint_configuration;
193-
194188
bool validate() const override;
189+
190+
urcl::vector6d_t target_joint_configuration;
195191
};
196192

197193
struct OptimoveLPrimitive : public MotionPrimitive

src/control/motion_primitives.cpp

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -41,83 +41,28 @@ bool MotionPrimitive::validate() const
4141
URCL_LOG_ERROR("Negative blend radius passed to motion primitive. This is not allowed.");
4242
return false;
4343
}
44-
return true;
45-
}
46-
bool MoveJPrimitive::validate() const
47-
{
48-
if (!MotionPrimitive::validate())
49-
{
50-
return false;
51-
}
52-
if (acceleration < 0)
53-
{
54-
URCL_LOG_ERROR("Negative acceleration passed to MoveJ primitive. This is not allowed.");
55-
return false;
56-
}
57-
if (velocity < 0)
58-
{
59-
URCL_LOG_ERROR("Negative velocity passed to MoveJ primitive. This is not allowed.");
60-
return false;
61-
}
62-
return true;
63-
}
64-
65-
bool MoveLPrimitive::validate() const
66-
{
67-
if (!MotionPrimitive::validate())
68-
{
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-
}
8944
if (acceleration < 0)
9045
{
91-
URCL_LOG_ERROR("Negative acceleration passed to MoveP primitive. This is not allowed.");
46+
URCL_LOG_ERROR("Negative acceleration passed to motion primitive. This is not allowed.");
9247
return false;
9348
}
9449
if (velocity < 0)
9550
{
96-
URCL_LOG_ERROR("Negative velocity passed to MoveP primitive. This is not allowed.");
51+
URCL_LOG_ERROR("Negative velocity passed to motion primitive. This is not allowed.");
9752
return false;
9853
}
9954
return true;
10055
}
10156

102-
bool MoveCPrimitive::validate() const
57+
bool SplinePrimitive::validate() const
10358
{
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)
59+
if (duration <= 0)
11460
{
115-
URCL_LOG_ERROR("Negative velocity passed to MoveC primitive. This is not allowed.");
61+
URCL_LOG_ERROR("Duration must be greater than zero.");
11662
return false;
11763
}
11864
return true;
11965
}
120-
12166
bool OptimoveJPrimitive::validate() const
12267
{
12368
if (!MotionPrimitive::validate())

0 commit comments

Comments
 (0)