Skip to content

Commit fd1a03b

Browse files
committed
first pass at adding new arm endpoint
1 parent 8bb7a82 commit fd1a03b

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

src/viam/sdk/components/arm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ Arm::KinematicsData Arm::from_proto(const viam::common::v1::GetKinematicsRespons
2727

2828
Arm::Arm(std::string name) : Component(std::move(name)) {}
2929

30+
3031
} // namespace sdk
3132
} // namespace viam

src/viam/sdk/components/arm.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ class Arm : public Component, public Stoppable {
103103
virtual void move_to_joint_positions(const std::vector<double>& positions,
104104
const ProtoStruct& extra) = 0;
105105

106+
/// @brief Move each joint on the arm through the positions specified in @param positions
107+
/// @param options optional specifications to be obeyed during the motion.
108+
inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
109+
const component::arm::v1::MoveOptions& options) {
110+
return move_through_joint_positions(positions, options, {});
111+
}
112+
113+
/// @brief Move each joint on the arm through the positions specified in @param positions
114+
/// @param options optional specifications to be obeyed during the motion.
115+
/// @param extra Any additional arguments to the method.
116+
virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
117+
const component::arm::v1::MoveOptions& options,
118+
const ProtoStruct& extra) = 0;
119+
106120
/// @brief Reports if the arm is in motion.
107121
virtual bool is_moving() = 0;
108122

src/viam/sdk/components/private/arm_client.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ void ArmClient::move_to_joint_positions(const std::vector<double>& positions,
4646
.invoke();
4747
}
4848

49+
void ArmClient::move_through_joint_positions(const std::vector<std::vector<double>>& positions,
50+
const component::arm::v1::MoveOptions& options,
51+
const ProtoStruct& extra) {
52+
return make_client_helper(this, *stub_, &StubType::MoveThroughJointPositions)
53+
.with(extra,
54+
// TODO: dont understand how to write this part
55+
[&](auto& request) {
56+
*(request.mutable_positions()->mutable_values()) = {};
57+
})
58+
.invoke();
59+
}
60+
4961
bool ArmClient::is_moving() {
5062
return make_client_helper(this, *stub_, &StubType::IsMoving).invoke([](auto& response) {
5163
return response.is_moving();

src/viam/sdk/components/private/arm_client.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ArmClient : public Arm {
2626
std::vector<double> get_joint_positions(const ProtoStruct& extra) override;
2727
void move_to_joint_positions(const std::vector<double>& positions,
2828
const ProtoStruct& extra) override;
29+
void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
30+
const component::arm::v1::MoveOptions& options,
31+
const ProtoStruct& extra) override;
2932
bool is_moving() override;
3033
void stop(const ProtoStruct& extra) override;
3134
ProtoStruct do_command(const ProtoStruct& command) override;
@@ -39,6 +42,7 @@ class ArmClient : public Arm {
3942
using Arm::get_joint_positions;
4043
using Arm::get_kinematics;
4144
using Arm::move_to_joint_positions;
45+
using Arm::move_through_joint_positions;
4246
using Arm::move_to_position;
4347
using Arm::stop;
4448

src/viam/sdk/components/private/arm_server.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ ::grpc::Status ArmServer::MoveToJointPositions(
5353
});
5454
}
5555

56+
::grpc::Status ArmServer::MoveThroughJointPositions(
57+
::grpc::ServerContext*,
58+
const ::viam::component::arm::v1::MoveThroughJointPositionsRequest* request,
59+
::viam::component::arm::v1::MoveThroughJointPositionsResponse*) noexcept {
60+
std::vector<std::vector<double>> positions;
61+
for (int i = 0; i < request->positions_size(); i++) {
62+
positions.push_back({request->positions(i).values().begin(), request->positions(i).values().end()});
63+
}
64+
return make_service_helper<Arm>(
65+
"ArmServer::MoveThroughJointPositions", this, request) ([&](auto& helper, auto& arm) {
66+
arm->move_through_joint_positions(positions, request->options(), helper.getExtra());
67+
});
68+
}
69+
5670
::grpc::Status ArmServer::Stop(::grpc::ServerContext*,
5771
const ::viam::component::arm::v1::StopRequest* request,
5872
::viam::component::arm::v1::StopResponse*) noexcept {

src/viam/sdk/components/private/arm_server.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class ArmServer : public ResourceServer, public viam::component::arm::v1::ArmSer
4444
const ::viam::component::arm::v1::MoveToJointPositionsRequest* request,
4545
::viam::component::arm::v1::MoveToJointPositionsResponse* response) noexcept override;
4646

47+
::grpc::Status MoveThroughJointPositions(
48+
::grpc::ServerContext* context,
49+
const ::viam::component::arm::v1::MoveThroughJointPositionsRequest* request,
50+
::viam::component::arm::v1::MoveThroughJointPositionsResponse* response) noexcept override;
51+
4752
::grpc::Status Stop(::grpc::ServerContext* context,
4853
const ::viam::component::arm::v1::StopRequest* request,
4954
::viam::component::arm::v1::StopResponse* response) noexcept override;

0 commit comments

Comments
 (0)