Skip to content

Commit d0614f1

Browse files
Set type of joint dynamics limits to Vector7
1 parent 584e4c7 commit d0614f1

File tree

7 files changed

+37
-54
lines changed

7 files changed

+37
-54
lines changed

include/franky/dynamics_limit.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,14 @@ class DynamicsLimit {
7171
value_ = value;
7272
}
7373

74-
/**
75-
* @brief Get the current value of the limit as a different type.
76-
*
77-
* Retrieves the current value of the limit and converts it to a different type.
78-
*
79-
* @tparam AlternativeType The type to which the value should be converted.
80-
* @return The current value of the limit converted to the specified type.
81-
*/
82-
template <typename AlternativeType>
83-
AlternativeType getAs();
84-
8574
/**
8675
* @brief Get the current value of the limit.
8776
*
8877
* Retrieves the current value stored in this limit.
8978
*
9079
* @return The current value of the limit.
9180
*/
92-
LimitType get() { return value_; }
81+
[[nodiscard]] LimitType get() const { return value_; }
9382

9483
/**
9584
* @brief The maximum value this limit can take as defined by Franka.
@@ -114,7 +103,7 @@ class DynamicsLimit {
114103
*
115104
* @param value The value to check.
116105
*/
117-
void check(const LimitType& value);
106+
void check(const LimitType& value) const;
118107

119108
std::shared_ptr<std::mutex> write_mutex_; /**< Mutex for synchronizing writes to the limit. */
120109
LimitType value_; /**< Current value of the limit. */

include/franky/robot.hpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "franky/relative_dynamics_factor.hpp"
2525
#include "franky/joint_state.hpp"
2626
#include "franky/dynamics_limit.hpp"
27+
#include "franky/util.hpp"
2728

2829
namespace franky {
2930

@@ -37,13 +38,6 @@ struct InvalidMotionTypeException : std::runtime_error {
3738
using std::runtime_error::runtime_error;
3839
};
3940

40-
constexpr std::array<double, 7> scaleArr7(const std::array<double, 7> &arr, const double factor) {
41-
std::array<double, arr.size()> result{};
42-
for (size_t i = 0; i < arr.size(); ++i)
43-
result[i] = arr[i] * factor;
44-
return result;
45-
}
46-
4741
/**
4842
* @brief A class representing a Franka robot.
4943
*
@@ -155,31 +149,30 @@ class Robot : public franka::Robot {
155149
DynamicsLimit<double> elbow_jerk_limit{
156150
"elbow jerk", 5000.0, 800.0, control_mutex_, std::bind(&Robot::is_in_control_unsafe, this)};
157151

158-
159152
/**
160153
* @brief Joint velocity limit [rad/s].
161154
*/
162-
#define MAX_JOINT_VEL {2.175, 2.175, 2.175, 2.175, 2.610, 2.610, 2.610}
163-
DynamicsLimit<std::array<double, 7>> joint_velocity_limit{
155+
#define MAX_JOINT_VEL toEigenD<7>({2.175, 2.175, 2.175, 2.175, 2.610, 2.610, 2.610})
156+
DynamicsLimit<Vector7d> joint_velocity_limit{
164157
"joint_velocity", MAX_JOINT_VEL, MAX_JOINT_VEL, control_mutex_,
165158
std::bind(&Robot::is_in_control_unsafe, this)
166159
};
167160

168161
/**
169162
* @brief Joint acceleration limit [rad/s²].
170163
*/
171-
#define MAX_JOINT_ACC {15.0, 7.5, 10.0, 12.5, 15.0, 20.0, 20.0}
172-
DynamicsLimit<std::array<double, 7>> joint_acceleration_limit{
173-
"joint_acceleration", MAX_JOINT_ACC, scaleArr7(MAX_JOINT_ACC, 0.3), control_mutex_,
164+
#define MAX_JOINT_ACC toEigenD<7>({15.0, 7.5, 10.0, 12.5, 15.0, 20.0, 20.0})
165+
DynamicsLimit<Vector7d> joint_acceleration_limit{
166+
"joint_acceleration", MAX_JOINT_ACC, MAX_JOINT_ACC * 0.3, control_mutex_,
174167
std::bind(&Robot::is_in_control_unsafe, this)
175168
};
176169

177170
/**
178171
* @brief Joint jerk limit [rad/s³].
179172
*/
180-
#define MAX_JOINT_JERK {7500.0, 3750.0, 5000.0, 6250.0, 7500.0, 10000.0, 10000.0}
181-
DynamicsLimit<std::array<double, 7>> joint_jerk_limit{
182-
"joint_jerk", MAX_JOINT_JERK, scaleArr7(MAX_JOINT_JERK, 0.3), control_mutex_,
173+
#define MAX_JOINT_JERK toEigenD<7>({7500.0, 3750.0, 5000.0, 6250.0, 7500.0, 10000.0, 10000.0})
174+
DynamicsLimit<Vector7d> joint_jerk_limit{
175+
"joint_jerk", MAX_JOINT_JERK, MAX_JOINT_JERK * 0.3, control_mutex_,
183176
std::bind(&Robot::is_in_control_unsafe, this)
184177
};
185178

include/franky/util.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Eigen::Matrix<double, dims, 1> toEigenD(const std::array<double, dims> &vector)
2222
return Eigen::Matrix<double, dims, 1>::Map(vector.data());
2323
}
2424

25+
template<size_t dims>
26+
Eigen::Vector<double, dims> ensureEigen(const Array<dims> &input) {
27+
if (std::holds_alternative<Eigen::Vector<double, dims>>(input))
28+
return std::get<Eigen::Vector<double, dims>>(input);
29+
return toEigenD<dims>(std::get<std::array<double, dims >>(input));
30+
}
31+
2532
template<size_t dims>
2633
std::array<double, dims> ensureStd(const Array<dims> &input) {
2734
if (std::holds_alternative<std::array<double, dims >>(input))

python/bind_robot.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ void robotMove(Robot &robot, const std::shared_ptr<Motion<ControlSignalType>> &m
3434
}
3535

3636
void bind_robot(py::module &m) {
37-
py::class_<DynamicsLimit<std::array<double, 7>>>(m, "VectorDynamicsLimit")
38-
.def("set", &DynamicsLimit<std::array<double, 7>>::setFrom<Array<7>>, "value"_a)
39-
.def("get", &DynamicsLimit<std::array<double, 7>>::getAs<Vector7d>)
37+
py::class_<DynamicsLimit<Vector7d>>(m, "VectorDynamicsLimit")
38+
.def("set", &DynamicsLimit<Vector7d>::setFrom<Array<7>>, "value"_a)
39+
.def("get", &DynamicsLimit<Vector7d>::get)
4040
.def_property_readonly(
4141
"max",
42-
[](const DynamicsLimit<std::array<double, 7>> &dynamics_limit) {
42+
[](const DynamicsLimit<Vector7d> &dynamics_limit) {
4343
return Vector7d::Map(dynamics_limit.max.data());
4444
})
45-
.def_readonly("desc", &DynamicsLimit<std::array<double, 7>>::desc);
45+
.def_readonly("desc", &DynamicsLimit<Vector7d>::desc);
4646

4747
py::class_<DynamicsLimit<double>>(m, "DoubleDynamicsLimit")
4848
.def("set", &DynamicsLimit<double>::set, "value"_a)

src/dynamics_limit.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace franky {
99

10-
template <>
11-
void DynamicsLimit<double>::check(const double &value) {
10+
template<>
11+
void DynamicsLimit<double>::check(const double &value) const {
1212
if (value < 0) {
1313
std::stringstream ss;
1414
ss << desc << " limit cannot be negative.";
@@ -21,20 +21,14 @@ void DynamicsLimit<double>::check(const double &value) {
2121
}
2222
}
2323

24-
template <>
25-
template <>
26-
void DynamicsLimit<std::array<double, 7>>::setFrom<Array<7>>(const Array<7> &value) {
27-
set(ensureStd<7>(value));
24+
template<>
25+
template<>
26+
void DynamicsLimit<Vector7d>::setFrom<Array<7>>(const Array<7> &value) {
27+
set(ensureEigen<7>(value));
2828
}
2929

30-
template <>
31-
template <>
32-
Vector7d DynamicsLimit<std::array<double, 7>>::getAs<Vector7d>() {
33-
return Vector7d::Map(value_.data());
34-
}
35-
36-
template <>
37-
void DynamicsLimit<std::array<double, 7>>::check(const std::array<double, 7> &value) {
30+
template<>
31+
void DynamicsLimit<Vector7d>::check(const Vector7d &value) const {
3832
for (int i = 0; i < value.size(); i++) {
3933
if (value[i] < 0) {
4034
std::stringstream ss;

src/motion/joint_velocity_waypoint_motion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ void JointVelocityWaypointMotion::setNewWaypoint(const franka::RobotState &robot
4747
std::tuple<Vector7d, Vector7d, Vector7d> JointVelocityWaypointMotion::getAbsoluteInputLimits() const {
4848
const auto r = robot();
4949
return {
50-
r->joint_velocity_limit.getAs<Vector7d>(),
51-
r->joint_acceleration_limit.getAs<Vector7d>(),
52-
r->joint_jerk_limit.getAs<Vector7d>()
50+
r->joint_velocity_limit.get(),
51+
r->joint_acceleration_limit.get(),
52+
r->joint_jerk_limit.get()
5353
};
5454
}
5555
} // namespace franky

src/motion/joint_waypoint_motion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ void JointWaypointMotion::setNewWaypoint(
5050
std::tuple<Vector7d, Vector7d, Vector7d> JointWaypointMotion::getAbsoluteInputLimits() const {
5151
const auto r = robot();
5252
return {
53-
r->joint_velocity_limit.getAs<Vector7d>(),
54-
r->joint_acceleration_limit.getAs<Vector7d>(),
55-
r->joint_jerk_limit.getAs<Vector7d>()
53+
r->joint_velocity_limit.get(),
54+
r->joint_acceleration_limit.get(),
55+
r->joint_jerk_limit.get()
5656
};
5757
}
5858
} // namespace franky

0 commit comments

Comments
 (0)