Skip to content

Commit ab15a1e

Browse files
Made JointState a struct
1 parent a4f3cc4 commit ab15a1e

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

include/franky/joint_state.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ namespace franky {
1010
/**
1111
* @brief Joint state of a robot.
1212
*
13-
* This class encapsulates the joint state of a robot, which comprises the joint positions and the joint velocities.
13+
* This struct encapsulates the joint state of a robot, which comprises the joint positions and the joint velocities.
1414
*/
15-
class JointState {
16-
public:
15+
struct JointState {
1716
// Suppress implicit conversion warning
1817
#pragma clang diagnostic push
1918
#pragma clang diagnostic ignored "-Wimplicit-conversion"
@@ -22,15 +21,15 @@ class JointState {
2221
*
2322
* @param position The joint positions.
2423
*/
25-
JointState(Vector7d position) : position_(std::move(position)), velocity_(Vector7d::Zero()) {}
24+
JointState(Vector7d position) : position(std::move(position)), velocity(Vector7d::Zero()) {}
2625
#pragma clang diagnostic pop
2726

2827
/**
2928
* @param position The joint positions.
3029
* @param velocity The joint velocities.
3130
*/
3231
JointState(Vector7d position, Vector7d velocity)
33-
: position_(std::move(position)), velocity_(std::move(velocity)) {}
32+
: position(std::move(position)), velocity(std::move(velocity)) {}
3433

3534
JointState(const JointState &) = default;
3635

@@ -39,20 +38,12 @@ class JointState {
3938
/**
4039
* @brief The position component of the state.
4140
*/
42-
[[nodiscard]] inline Vector7d position() const {
43-
return position_;
44-
}
41+
const Vector7d position;
4542

4643
/**
4744
* @brief The velocity component of the state.
4845
*/
49-
[[nodiscard]] inline Vector7d velocity() const {
50-
return velocity_;
51-
}
52-
53-
private:
54-
Vector7d position_;
55-
Vector7d velocity_;
46+
const Vector7d velocity;
5647
};
5748

5849
} // namespace franky

python/bind_state_repr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,17 @@ void bind_state_repr(py::module &m) {
215215
.def(py::init<const Vector7d &>(), "position"_a)
216216
.def(py::init<const Vector7d &, const Vector7d &>(), "position"_a, "velocity"_a)
217217
.def(py::init<const JointState &>()) // Copy constructor
218-
.def_property_readonly("position", &JointState::position)
219-
.def_property_readonly("velocity", &JointState::velocity)
218+
.def_readonly("position", &JointState::position)
219+
.def_readonly("velocity", &JointState::velocity)
220220
.def("__repr__", [](const JointState &joint_state) {
221221
std::stringstream ss;
222-
ss << "JointState(position=" << vecToStr(joint_state.position())
223-
<< ", velocity=" << vecToStr(joint_state.velocity()) << ")";
222+
ss << "JointState(position=" << vecToStr(joint_state.position)
223+
<< ", velocity=" << vecToStr(joint_state.velocity) << ")";
224224
return ss.str();
225225
})
226226
.def(py::pickle(
227227
[](const JointState &joint_state) { // __getstate__
228-
return py::make_tuple(joint_state.position(), joint_state.velocity());
228+
return py::make_tuple(joint_state.position, joint_state.velocity);
229229
},
230230
[](const py::tuple &t) { // __setstate__
231231
if (t.size() != 2)

src/motion/joint_waypoint_motion.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ void JointWaypointMotion::setNewWaypoint(
3636
const PositionWaypoint<JointState> &new_waypoint,
3737
ruckig::InputParameter<7> &input_parameter) {
3838
auto new_target = new_waypoint.target;
39+
auto position = new_target.position;
3940
if (new_waypoint.reference_type == ReferenceType::Relative)
40-
new_target.position() += toEigen(input_parameter.current_position);
41-
input_parameter.target_position = toStd<7>(new_target.position());
42-
input_parameter.target_velocity = toStd<7>(new_target.velocity());
41+
position += toEigen(input_parameter.current_position);
42+
input_parameter.target_position = toStd<7>(position);
43+
input_parameter.target_velocity = toStd<7>(new_target.velocity);
4344
input_parameter.target_acceleration = toStd<7>(Vector7d::Zero());
4445
}
4546

src/robot.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ bool Robot::recoverFromErrors() {
2626

2727
JointState Robot::currentJointState() {
2828
auto s = state();
29-
return {Eigen::Map<const Vector7d>(state().q.data()), Eigen::Map<const Vector7d>(state().dq.data())};
29+
return JointState{Eigen::Map<const Vector7d>(state().q.data()), Eigen::Map<const Vector7d>(state().dq.data())};
3030
}
3131

3232
Vector7d Robot::currentJointPositions() {
33-
return currentJointState().position();
33+
return currentJointState().position;
3434
}
3535

3636
Vector7d Robot::currentJointVelocities() {
37-
return currentJointState().velocity();
37+
return currentJointState().velocity;
3838
}
3939

4040
Affine Robot::forwardKinematics(const Vector7d &q) {

0 commit comments

Comments
 (0)