Skip to content

Commit ffcd084

Browse files
viambotgithub-actions[bot]
authored andcommitted
[WORKFLOW] AI update based on proto changes from commit b98ac2c
1 parent 3829c8f commit ffcd084

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

src/viam/sdk/services/motion.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,23 @@ class Motion : public Service {
179179
std::vector<allowed_frame_collisions> allows;
180180
};
181181

182+
/// @struct pseudolinear_constraint
183+
/// @brief Specifies that the component being moved should move pseudolinearly to its goal.
184+
struct pseudolinear_constraint {
185+
/// @brief The factor by which to multiply the default line tolerance.
186+
boost::optional<float> line_tolerance_factor;
187+
/// @brief The factor by which to multiply the default orientation tolerance.
188+
boost::optional<float> orientation_tolerance_factor;
189+
};
190+
182191
/// @struct constraints
183192
/// @brief Specifies all constraints to be passed to Viam's motion planning, along
184193
/// with any optional parameters.
185194
struct constraints {
186195
std::vector<linear_constraint> linear_constraints;
187196
std::vector<orientation_constraint> orientation_constraints;
188197
std::vector<collision_specification> collision_specifications;
198+
std::vector<pseudolinear_constraint> pseudolinear_constraints;
189199
};
190200

191201
API api() const override;
@@ -466,4 +476,4 @@ struct API::traits<Motion> {
466476
};
467477

468478
} // namespace sdk
469-
} // namespace viam
479+
} // namespace viam

src/viam/sdk/services/private/motion_client.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ service::motion::v1::MotionConfiguration to_proto(const motion_configuration& mc
5757
return proto;
5858
}
5959

60+
service::motion::v1::PseudolinearConstraint to_proto(const Motion::pseudolinear_constraint& plc) {
61+
service::motion::v1::PseudolinearConstraint proto;
62+
if (plc.line_tolerance_factor) {
63+
proto.set_line_tolerance_factor(*plc.line_tolerance_factor);
64+
}
65+
if (plc.orientation_tolerance_factor) {
66+
proto.set_orientation_tolerance_factor(*plc.orientation_tolerance_factor);
67+
}
68+
return proto;
69+
}
70+
6071
service::motion::v1::Constraints to_proto(const Motion::constraints& cs) {
6172
service::motion::v1::Constraints proto;
6273
for (const auto& lc : cs.linear_constraints) {
@@ -83,6 +94,10 @@ service::motion::v1::Constraints to_proto(const Motion::constraints& cs) {
8394
*proto.mutable_collision_specification()->Add() = std::move(proto_cs);
8495
}
8596

97+
for (const auto& plc : cs.pseudolinear_constraints) {
98+
*proto.mutable_pseudolinear_constraint()->Add() = to_proto(plc);
99+
}
100+
86101
return proto;
87102
}
88103

src/viam/sdk/services/private/motion_server.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ motion_configuration from_proto(const service::motion::v1::MotionConfiguration&
133133
return mc;
134134
}
135135

136+
Motion::pseudolinear_constraint from_proto(const service::motion::v1::PseudolinearConstraint& proto) {
137+
Motion::pseudolinear_constraint plc;
138+
if (proto.has_line_tolerance_factor()) {
139+
plc.line_tolerance_factor = proto.line_tolerance_factor();
140+
}
141+
if (proto.has_orientation_tolerance_factor()) {
142+
plc.orientation_tolerance_factor = proto.orientation_tolerance_factor();
143+
}
144+
return plc;
145+
}
146+
136147
MotionServer::MotionServer(std::shared_ptr<ResourceManager> manager)
137148
: ResourceServer(std::move(manager)) {}
138149

@@ -166,10 +177,16 @@ Motion::constraints from_proto(const service::motion::v1::Constraints& proto) {
166177
css.push_back(cs);
167178
}
168179

180+
std::vector<Motion::pseudolinear_constraint> plcs;
181+
for (const auto& proto_plc : proto.pseudolinear_constraint()) {
182+
plcs.push_back(from_proto(proto_plc));
183+
}
184+
169185
Motion::constraints constraints;
170186
constraints.linear_constraints = lcs;
171187
constraints.orientation_constraints = ocs;
172188
constraints.collision_specifications = css;
189+
constraints.pseudolineear_constraints = plcs;
173190

174191
return constraints;
175192
}
@@ -358,4 +375,4 @@ ::grpc::Status MotionServer::DoCommand(::grpc::ServerContext*,
358375

359376
} // namespace impl
360377
} // namespace sdk
361-
} // namespace viam
378+
} // namespace viam

src/viam/sdk/tests/mocks/mock_motion.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ std::vector<geo_geometry> fake_bounding_regions() {
180180
return {{fake_geo_point(), {std::move(gc)}}};
181181
}
182182

183+
Motion::pseudolinear_constraint fake_pseudolinear_constraint() {
184+
Motion::pseudolinear_constraint plc;
185+
plc.line_tolerance_factor = 0.5f;
186+
plc.orientation_tolerance_factor = 0.75f;
187+
return plc;
188+
}
189+
183190
} // namespace motion
184191
} // namespace sdktests
185-
} // namespace viam
192+
} // namespace viam

src/viam/sdk/tests/mocks/mock_motion.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ sdk::geo_point fake_geo_point();
2020
std::vector<sdk::geo_geometry> fake_obstacles();
2121
std::shared_ptr<sdk::motion_configuration> fake_motion_configuration();
2222
std::vector<sdk::geo_geometry> fake_bounding_regions();
23+
sdk::Motion::pseudolinear_constraint fake_pseudolinear_constraint();
2324

2425
class MockMotion : public sdk::Motion {
2526
public:
@@ -105,4 +106,4 @@ class MockMotion : public sdk::Motion {
105106

106107
} // namespace motion
107108
} // namespace sdktests
108-
} // namespace viam
109+
} // namespace viam

src/viam/sdk/tests/test_motion.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ WorldState mock_world_state() {
3434
return WorldState({obstacle}, {transform});
3535
}
3636

37+
// Add this function after `fake_bounding_regions()` or similar helper functions.
38+
Motion::pseudolinear_constraint fake_pseudolinear_constraint() {
39+
Motion::pseudolinear_constraint plc;
40+
plc.line_tolerance_factor = 0.5f;
41+
plc.orientation_tolerance_factor = 0.75f;
42+
return plc;
43+
}
44+
3745
BOOST_AUTO_TEST_SUITE(test_mock)
3846

3947
BOOST_AUTO_TEST_CASE(mock_get_api) {
@@ -175,11 +183,19 @@ BOOST_AUTO_TEST_CASE(test_move_and_get_pose) {
175183
BOOST_CHECK_EQUAL(pose, init_fake_pose());
176184

177185
auto ws = std::make_shared<WorldState>(mock_world_state());
178-
bool success = client.move(fake_pose(), fake_component_name(), ws, nullptr, fake_map());
186+
// Create a constraints object with the new pseudolinear constraint
187+
auto constraints = std::make_shared<Motion::constraints>();
188+
constraints->pseudolinear_constraints.push_back(fake_pseudolinear_constraint());
189+
bool success = client.move(fake_pose(), fake_component_name(), ws, constraints, fake_map()); // Pass the new constraints object
179190
BOOST_TEST(success);
180191

181192
pose = client.get_pose(fake_component_name(), destination_frame, transforms, fake_map());
182193
BOOST_CHECK_EQUAL(pose, fake_pose());
194+
// Add checks for the peek_constraints in the mock
195+
BOOST_CHECK(mock->peek_constraints != nullptr);
196+
BOOST_CHECK_EQUAL(mock->peek_constraints->pseudolinear_constraints.size(), 1);
197+
BOOST_CHECK_CLOSE(mock->peek_constraints->pseudolinear_constraints[0].line_tolerance_factor.get(), fake_pseudolinear_constraint().line_tolerance_factor.get(), 0.0001);
198+
BOOST_CHECK_CLOSE(mock->peek_constraints->pseudolinear_constraints[0].orientation_tolerance_factor.get(), fake_pseudolinear_constraint().orientation_tolerance_factor.get(), 0.0001);
183199
});
184200
}
185201

@@ -281,4 +297,4 @@ BOOST_AUTO_TEST_SUITE_END()
281297

282298
} // namespace motion
283299
} // namespace sdktests
284-
} // namespace viam
300+
} // namespace viam

0 commit comments

Comments
 (0)