Skip to content

Commit ae21c2c

Browse files
committed
update arm components
1 parent 97cfba9 commit ae21c2c

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

src/viam/sdk/components/arm.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
#include <string>
77

8+
#include <boost/optional/optional.hpp>
89
#include <boost/variant/variant.hpp>
910

1011
#include <viam/api/common/v1/common.pb.h>
11-
#include <viam/api/component/arm/v1/arm.pb.h>
1212

1313
#include <viam/sdk/common/pose.hpp>
1414
#include <viam/sdk/resource/stoppable.hpp>
@@ -61,6 +61,12 @@ class Arm : public Component, public Stoppable {
6161
using KinematicsData =
6262
boost::variant<KinematicsDataUnspecified, KinematicsDataSVA, KinematicsDataURDF>;
6363

64+
/// @brief Movement specifications for move_through_join_positions.
65+
struct MoveOptions {
66+
boost::optional<double> max_vel_degs_per_sec;
67+
boost::optional<double> max_acc_degs_per_sec2;
68+
};
69+
6470
static KinematicsData from_proto(const viam::common::v1::GetKinematicsResponse& proto);
6571

6672
/// @brief Get the current position of the end of the arm.
@@ -105,16 +111,16 @@ class Arm : public Component, public Stoppable {
105111

106112
/// @brief Move each joint on the arm through the positions specified in @param positions
107113
/// @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) {
114+
inline void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
115+
const MoveOptions& options) {
110116
return move_through_joint_positions(positions, options, {});
111117
}
112118

113119
/// @brief Move each joint on the arm through the positions specified in @param positions
114120
/// @param options optional specifications to be obeyed during the motion.
115121
/// @param extra Any additional arguments to the method.
116122
virtual void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
117-
const component::arm::v1::MoveOptions& options,
123+
const MoveOptions& options,
118124
const ProtoStruct& extra) = 0;
119125

120126
/// @brief Reports if the arm is in motion.

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,26 @@ void ArmClient::move_to_joint_positions(const std::vector<double>& positions,
4747
}
4848

4949
void ArmClient::move_through_joint_positions(const std::vector<std::vector<double>>& positions,
50-
const component::arm::v1::MoveOptions& options,
50+
const Arm::MoveOptions& options,
5151
const ProtoStruct& extra) {
5252
return make_client_helper(this, *stub_, &StubType::MoveThroughJointPositions)
5353
.with(extra,
54-
// TODO: dont understand how to write this part
55-
[&](auto& request) {
56-
*(request.mutable_positions()->mutable_values()) = {};
54+
[&](viam::component::arm::v1::MoveThroughJointPositionsRequest& request) {
55+
if (options.max_vel_degs_per_sec) {
56+
request.mutable_options()->set_max_vel_degs_per_sec(
57+
*options.max_vel_degs_per_sec);
58+
}
59+
60+
if (options.max_acc_degs_per_sec2) {
61+
request.mutable_options()->set_max_acc_degs_per_sec2(
62+
*options.max_acc_degs_per_sec2);
63+
}
64+
65+
for (const std::vector<double>& pos : positions) {
66+
viam::component::arm::v1::JointPositions jpos;
67+
jpos.mutable_values()->Assign(pos.begin(), pos.end());
68+
request.mutable_positions()->Add(std::move(jpos));
69+
}
5770
})
5871
.invoke();
5972
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ArmClient : public Arm {
2727
void move_to_joint_positions(const std::vector<double>& positions,
2828
const ProtoStruct& extra) override;
2929
void move_through_joint_positions(const std::vector<std::vector<double>>& positions,
30-
const component::arm::v1::MoveOptions& options,
30+
const Arm::MoveOptions& options,
3131
const ProtoStruct& extra) override;
3232
bool is_moving() override;
3333
void stop(const ProtoStruct& extra) override;
@@ -41,8 +41,8 @@ class ArmClient : public Arm {
4141
using Arm::get_geometries;
4242
using Arm::get_joint_positions;
4343
using Arm::get_kinematics;
44-
using Arm::move_to_joint_positions;
4544
using Arm::move_through_joint_positions;
45+
using Arm::move_to_joint_positions;
4646
using Arm::move_to_position;
4747
using Arm::stop;
4848

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,28 @@ ::grpc::Status ArmServer::MoveThroughJointPositions(
5959
::viam::component::arm::v1::MoveThroughJointPositionsResponse*) noexcept {
6060
std::vector<std::vector<double>> positions;
6161
for (int i = 0; i < request->positions_size(); i++) {
62-
positions.push_back({request->positions(i).values().begin(), request->positions(i).values().end()});
62+
positions.push_back(
63+
{request->positions(i).values().begin(), request->positions(i).values().end()});
6364
}
6465
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());
66+
"ArmServer::MoveThroughJointPositions", this, request)([&](auto& helper, auto& arm) {
67+
std::vector<std::vector<double>> positions;
68+
69+
positions.reserve(request->positions_size());
70+
for (const auto& values : request->positions()) {
71+
positions.push_back({values.values().begin(), values.values().end()});
72+
}
73+
74+
Arm::MoveOptions opts;
75+
if (request->options().has_max_vel_degs_per_sec()) {
76+
opts.max_vel_degs_per_sec = request->options().max_vel_degs_per_sec();
77+
}
78+
79+
if (request->options().has_max_acc_degs_per_sec2()) {
80+
opts.max_acc_degs_per_sec2 = request->options().max_acc_degs_per_sec2();
81+
}
82+
83+
arm->move_through_joint_positions(positions, opts, helper.getExtra());
6784
});
6885
}
6986

0 commit comments

Comments
 (0)