Skip to content

Commit c056349

Browse files
committed
Add setPose and tests for setting Q and Pose values
1 parent 79ca4e9 commit c056349

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

include/ur_client_library/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class Pose
8787
const std::optional<Q>& getQNear() const;
8888
void setQNear(const Q& q_near);
8989

90+
void setPose(const double x, const double y, const double z, const double rx, const double ry, const double rz);
91+
9092
double x;
9193
double y;
9294
double z;

src/types.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,14 @@ bool operator==(const Q& lhs, const vector6d_t& rhs)
115115
std::equal(lhs.getValues().begin(), lhs.getValues().end(), rhs.begin());
116116
}
117117

118+
void Pose::setPose(const double x, const double y, const double z, const double rx, const double ry, const double rz)
119+
{
120+
this->x = x;
121+
this->y = y;
122+
this->z = z;
123+
this->rx = rx;
124+
this->ry = ry;
125+
this->rz = rz;
126+
}
127+
118128
} // namespace urcl

tests/test_types.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ TEST(TestTypes, Q_equals_vector6d)
6161
EXPECT_FALSE(q == mismatch);
6262
}
6363

64+
TEST(TestTypes, Q_setValues_and_getValues)
65+
{
66+
Q q{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
67+
68+
const vector6d_t from_array{ { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 } };
69+
q.setValues(from_array);
70+
EXPECT_TRUE(q == from_array);
71+
EXPECT_EQ(q.getValues().size(), 6u);
72+
73+
const std::vector<double> from_vector{ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 };
74+
q.setValues(from_vector);
75+
EXPECT_EQ(q.getValues(), from_vector);
76+
EXPECT_EQ(q.getValues().size(), 6u);
77+
}
78+
6479
TEST(TestTypes, Pose_default_and_constructors)
6580
{
6681
Pose default_pose;
@@ -111,6 +126,18 @@ TEST(TestTypes, Pose_equality)
111126
EXPECT_FALSE(with_q == different_hint);
112127
}
113128

129+
TEST(TestTypes, set_pose)
130+
{
131+
Pose p;
132+
p.setPose(1.0, 2.0, 3.0, 0.1, 0.2, 0.3);
133+
EXPECT_DOUBLE_EQ(p.x, 1.0);
134+
EXPECT_DOUBLE_EQ(p.y, 2.0);
135+
EXPECT_DOUBLE_EQ(p.z, 3.0);
136+
EXPECT_DOUBLE_EQ(p.rx, 0.1);
137+
EXPECT_DOUBLE_EQ(p.ry, 0.2);
138+
EXPECT_DOUBLE_EQ(p.rz, 0.3);
139+
}
140+
114141
TEST(TestTypes, MotionTarget_variant)
115142
{
116143
const MotionTarget joint_side = Q{ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5 };

0 commit comments

Comments
 (0)