Skip to content

Commit c01979c

Browse files
committed
feat(franka): add get_cartesian_flange_position method
1 parent ce4c2f9 commit c01979c

5 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎extensions/rcs_fr3/src/hw/Franka.cpp‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919

2020
namespace rcs {
2121
namespace hw {
22+
common::Pose GetFlangeInBaseFrame(const franka::RobotState& robot_state) {
23+
return common::Pose(robot_state.O_T_EE) *
24+
common::Pose(robot_state.F_T_EE).inverse();
25+
}
26+
2227
common::Pose GetTCPInBaseFrame(const franka::RobotState& robot_state,
2328
const std::optional<common::Pose>& tcp_offset) {
2429
if (!tcp_offset.has_value()) {
2530
return common::Pose(robot_state.O_T_EE);
2631
}
27-
return common::Pose(robot_state.O_T_EE) *
28-
common::Pose(robot_state.F_T_EE).inverse() * tcp_offset.value();
32+
return GetFlangeInBaseFrame(robot_state) * tcp_offset.value();
2933
}
3034

3135
Franka::Franka(const FrankaConfig& cfg,
@@ -120,6 +124,19 @@ common::Pose Franka::get_cartesian_position() {
120124
return GetTCPInBaseFrame(robot_state, this->m_cfg.tcp_offset);
121125
}
122126

127+
common::Pose Franka::get_cartesian_flange_position() {
128+
this->check_for_background_errors();
129+
franka::RobotState robot_state;
130+
if (this->running_controller.load() == Controller::none) {
131+
this->curr_state = this->robot.readOnce();
132+
robot_state = this->curr_state;
133+
} else {
134+
std::lock_guard<std::mutex> lock(this->interpolator_mutex);
135+
robot_state = this->curr_state;
136+
}
137+
return GetFlangeInBaseFrame(robot_state);
138+
}
139+
123140
void Franka::set_joint_position(const common::VectorXd& q) {
124141
if (this->m_cfg.async_control) {
125142
this->controller_set_joint_position(q);

‎extensions/rcs_fr3/src/hw/Franka.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class Franka : public common::Robot {
119119

120120
common::Pose get_cartesian_position() override;
121121

122+
common::Pose get_cartesian_flange_position();
123+
122124
void set_joint_position(const common::VectorXd& q) override;
123125

124126
common::VectorXd get_joint_position() override;

‎extensions/rcs_fr3/src/pybind/rcs.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ PYBIND11_MODULE(_core, m) {
301301
.def("set_config", &rcs::hw::Franka::set_config, py::arg("cfg"))
302302
.def("get_config", &rcs::hw::Franka::get_config)
303303
.def("get_state", &rcs::hw::Franka::get_state)
304+
.def("get_cartesian_flange_position",
305+
&rcs::hw::Franka::get_cartesian_flange_position)
304306
.def("set_default_robot_behavior",
305307
&rcs::hw::Franka::set_default_robot_behavior)
306308
.def("set_guiding_mode", &rcs::hw::Franka::set_guiding_mode,

‎extensions/rcs_fr3/src/rcs_fr3/_core/hw/__init__.pyi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Franka(rcs._core.common.Robot):
8080
self, desired_q: numpy.ndarray[tuple[typing.Literal[7]], numpy.dtype[numpy.float64]]
8181
) -> None: ...
8282
def double_tap_robot_to_continue(self) -> None: ...
83+
def get_cartesian_flange_position(self) -> rcs._core.common.Pose: ...
8384
def get_config(self) -> FrankaConfig: ...
8485
def get_state(self) -> FrankaState: ...
8586
def osc_set_cartesian_position(self, desired_pos_EE_in_base_frame: rcs._core.common.Pose) -> None: ...

‎extensions/rcs_panda/src/rcs_panda/_core/hw/__init__.pyi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Franka(rcs._core.common.Robot):
8080
self, desired_q: numpy.ndarray[tuple[typing.Literal[7]], numpy.dtype[numpy.float64]]
8181
) -> None: ...
8282
def double_tap_robot_to_continue(self) -> None: ...
83+
def get_cartesian_flange_position(self) -> rcs._core.common.Pose: ...
8384
def get_config(self) -> FrankaConfig: ...
8485
def get_state(self) -> FrankaState: ...
8586
def osc_set_cartesian_position(self, desired_pos_EE_in_base_frame: rcs._core.common.Pose) -> None: ...

0 commit comments

Comments
 (0)