@@ -100,6 +100,7 @@ void Franka::set_default_robot_behavior() {
100100}
101101
102102common::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
125126common::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) {
210212void 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
589592void 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
622631void Franka::move_home () {
0 commit comments