Skip to content

Commit 02f43d9

Browse files
committed
fix(franka): error forward to python
- fixed error forward from cpp to python - simplified fr3 desk helpers - added timestamp to storage wrapper
1 parent c52275e commit 02f43d9

File tree

4 files changed

+32
-46
lines changed

4 files changed

+32
-46
lines changed

extensions/rcs_fr3/src/hw/Franka.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void Franka::set_default_robot_behavior() {
100100
}
101101

102102
common::Pose Franka::get_cartesian_position() {
103+
this->check_for_background_errors();
103104
common::Pose x;
104105
if (this->running_controller == Controller::none) {
105106
this->curr_state = this->robot.readOnce();
@@ -123,6 +124,7 @@ void Franka::set_joint_position(const common::VectorXd& q) {
123124
}
124125

125126
common::VectorXd Franka::get_joint_position() {
127+
this->check_for_background_errors();
126128
common::Vector7d joints;
127129
if (this->running_controller == Controller::none) {
128130
this->curr_state = this->robot.readOnce();
@@ -210,6 +212,7 @@ void Franka::controller_set_joint_position(const common::Vector7d& desired_q) {
210212
void Franka::check_for_background_errors() {
211213
std::lock_guard<std::mutex> lock(this->exception_mutex);
212214
if (this->background_exception) {
215+
this->stop_control_thread();
213216
std::exception_ptr ex = this->background_exception;
214217
this->background_exception = nullptr;
215218
std::rethrow_exception(ex);
@@ -587,6 +590,7 @@ void Franka::joint_controller() {
587590
}
588591

589592
void Franka::zero_torque_guiding() {
593+
this->check_for_background_errors();
590594
if (this->running_controller != Controller::none) {
591595
throw std::runtime_error(
592596
"A controller is currently running. Please stop it first.");
@@ -605,18 +609,23 @@ void Franka::zero_torque_controller() {
605609
{{100.0, 100.0, 100.0, 100.0, 100.0, 100.0}});
606610

607611
this->controller_time = 0.0;
608-
this->robot.control([&](const franka::RobotState& robot_state,
609-
franka::Duration period) -> franka::Torques {
610-
this->interpolator_mutex.lock();
611-
this->curr_state = robot_state;
612-
this->controller_time += period.toSec();
613-
this->interpolator_mutex.unlock();
614-
if (this->running_controller == Controller::none) {
615-
// stop
616-
return franka::MotionFinished(franka::Torques({0, 0, 0, 0, 0, 0, 0}));
617-
}
618-
return franka::Torques({0, 0, 0, 0, 0, 0, 0});
619-
});
612+
try {
613+
this->robot.control([&](const franka::RobotState& robot_state,
614+
franka::Duration period) -> franka::Torques {
615+
this->interpolator_mutex.lock();
616+
this->curr_state = robot_state;
617+
this->controller_time += period.toSec();
618+
this->interpolator_mutex.unlock();
619+
if (this->running_controller == Controller::none) {
620+
// stop
621+
return franka::MotionFinished(franka::Torques({0, 0, 0, 0, 0, 0, 0}));
622+
}
623+
return franka::Torques({0, 0, 0, 0, 0, 0, 0});
624+
});
625+
} catch (...) {
626+
std::lock_guard<std::mutex> lock(this->exception_mutex);
627+
this->background_exception = std::current_exception();
628+
}
620629
}
621630

622631
void Franka::move_home() {

extensions/rcs_fr3/src/rcs_fr3/desk.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,10 @@ def load_creds_franka_desk(postfix: str = "") -> tuple[str, str]:
4949

5050
def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False):
5151
with Desk.fci(ip, username, password, unlock=unlock):
52-
robot_cfg = default_fr3_hw_robot_cfg()
53-
robot_cfg.tcp_offset = rcs.common.Pose(rcs.common.FrankaHandTCPOffset())
54-
robot_cfg.speed_factor = 0.2
55-
ik = rcs.common.Pin(
56-
robot_cfg.kinematic_model_path,
57-
robot_cfg.attachment_site,
58-
urdf=robot_cfg.kinematic_model_path.endswith(".urdf"),
59-
)
60-
f = rcs_fr3.hw.Franka(ip, ik)
61-
f.set_config(robot_cfg)
52+
f = rcs_fr3.hw.Franka(ip)
53+
config = rcs_fr3.hw.FR3Config()
54+
config.speed_factor = 0.2
55+
f.set_config(config)
6256
config_hand = rcs_fr3.hw.FHConfig()
6357
g = rcs_fr3.hw.FrankaHand(ip, config_hand)
6458
if shut:
@@ -70,15 +64,9 @@ def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False
7064

7165
def info(ip: str, username: str, password: str, include_hand: bool = False):
7266
with Desk.fci(ip, username, password):
73-
robot_cfg = default_fr3_hw_robot_cfg()
74-
robot_cfg.tcp_offset = rcs.common.Pose(rcs.common.FrankaHandTCPOffset())
67+
robot_cfg = rcs_fr3.hw.FR3Config()
7568
robot_cfg.speed_factor = 0.2
76-
ik = rcs.common.Pin(
77-
robot_cfg.kinematic_model_path,
78-
robot_cfg.attachment_site,
79-
urdf=robot_cfg.kinematic_model_path.endswith(".urdf"),
80-
)
81-
f = rcs_fr3.hw.Franka(ip, ik)
69+
f = rcs_fr3.hw.Franka(ip)
8270
f.set_config(robot_cfg)
8371
print("Robot info:")
8472
print("Current cartesian position:")

extensions/rcs_panda/src/rcs_panda/desk.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,9 @@ def load_creds_franka_desk(postfix: str = "") -> tuple[str, str]:
4949

5050
def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False):
5151
with Desk.fci(ip, username, password, unlock=unlock):
52-
robot_cfg = default_panda_hw_robot_cfg()
53-
robot_cfg.tcp_offset = rcs.common.Pose(rcs.common.FrankaHandTCPOffset())
52+
robot_cfg = rcs_panda.hw.PandaConfig()
5453
robot_cfg.speed_factor = 0.2
55-
ik = rcs.common.Pin(
56-
robot_cfg.kinematic_model_path,
57-
robot_cfg.attachment_site,
58-
urdf=robot_cfg.kinematic_model_path.endswith(".urdf"),
59-
)
60-
f = rcs_panda.hw.Franka(ip, ik)
54+
f = rcs_panda.hw.Franka(ip)
6155
f.set_config(robot_cfg)
6256
config_hand = rcs_panda.hw.FHConfig()
6357
g = rcs_panda.hw.FrankaHand(ip, config_hand)
@@ -70,15 +64,9 @@ def home(ip: str, username: str, password: str, shut: bool, unlock: bool = False
7064

7165
def info(ip: str, username: str, password: str, include_hand: bool = False):
7266
with Desk.fci(ip, username, password):
73-
robot_cfg = default_panda_hw_robot_cfg()
74-
robot_cfg.tcp_offset = rcs.common.Pose(rcs.common.FrankaHandTCPOffset())
67+
robot_cfg = rcs_panda.hw.PandaConfig()
7568
robot_cfg.speed_factor = 0.2
76-
ik = rcs.common.Pin(
77-
robot_cfg.kinematic_model_path,
78-
robot_cfg.attachment_site,
79-
urdf=robot_cfg.kinematic_model_path.endswith(".urdf"),
80-
)
81-
f = rcs_panda.hw.Franka(ip, ik)
69+
f = rcs_panda.hw.Franka(ip)
8270
f.set_config(robot_cfg)
8371
print("Robot info:")
8472
print("Current cartesian position:")

python/rcs/envs/storage_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def step(self, action):
263263
"success": self._success,
264264
"action": self._prev_action,
265265
"instruction": self.instruction,
266+
"timestamp": datetime.datetime.now().timestamp(),
266267
}
267268
)
268269
self._prev_action = action

0 commit comments

Comments
 (0)