Skip to content

Commit 40f8d4a

Browse files
authored
fix(fr3,panda): franka control and franka hand proper close (#229)
* fix(fr3,panda): franka control and franka hand proper close - destructors properly close control threads - franka hand has proper close method - franka hand close method is used in gripper wrapper * fix: topological sort pybind to keep stub order
1 parent 5828820 commit 40f8d4a

11 files changed

Lines changed: 32 additions & 10 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ build
33
plugin.h
44
.session.vim
55
.projections.json
6-
pw.py
76
__pycache__
87
.ruff_cache
98
.mypy_cache
@@ -18,3 +17,5 @@ wheels
1817
.env
1918
settings.json
2019
*.egg-info
20+
video*
21+
GEMINI.md

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ clangcompile:
2929

3030
# Auto generation of CPP binding stub files
3131
stubgen:
32-
pybind11-stubgen -o python --numpy-array-use-type-var rcs
32+
pybind11-stubgen -o python --numpy-array-use-type-var --sort-by topological rcs
3333
find ./python -name '*.pyi' -print | xargs sed -i '1s/^/# ATTENTION: auto generated from C++ code, use `make stubgen` to update!\n/'
3434
find ./python -not -path "./python/rcs/_core/*" -name '*.pyi' -delete
3535
find ./python/rcs/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[typing\.Literal\[\([0-9]\+\)\], typing\.Literal\[1\]\]/tuple\[typing\.Literal[\1]\]/g'

extensions/rcs_fr3/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ clangcompile:
2222

2323
# Auto generation of CPP binding stub files
2424
stubgen:
25-
pybind11-stubgen -o src --numpy-array-use-type-var rcs_fr3
25+
pybind11-stubgen -o src --numpy-array-use-type-var --sort-by topological rcs_fr3
2626
find ./${PYSRC} -name '*.pyi' -print | xargs sed -i '1s/^/# ATTENTION: auto generated from C++ code, use `make stubgen` to update!\n/'
2727
find ./${PYSRC} -not -path "./${PYSRC}/_core/*" -name '*.pyi' -delete
2828
find ./${PYSRC}/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[typing\.Literal\[\([0-9]\+\)\], typing\.Literal\[1\]\]/tuple\[typing\.Literal[\1]\]/g'

extensions/rcs_fr3/src/hw/Franka.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ Franka::Franka(const std::string &ip,
3232
} // else default constructor
3333
}
3434

35-
Franka::~Franka() {}
35+
Franka::~Franka() {
36+
try {
37+
this->stop_control_thread();
38+
} catch (const franka::Exception &e) {
39+
std::cerr << "Exception in ~Franka(): " << e.what() << std::endl;
40+
}
41+
}
3642

3743
/**
3844
* @brief Set the parameters for the robot

extensions/rcs_fr3/src/hw/FrankaHand.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ FrankaHand::FrankaHand(const std::string &ip, const FHConfig &cfg)
1818
this->m_reset();
1919
}
2020

21-
FrankaHand::~FrankaHand() {}
21+
FrankaHand::~FrankaHand() {
22+
try {
23+
this->m_stop();
24+
} catch (const franka::Exception &e) {
25+
std::cerr << "Exception in ~FrankaHand(): " << e.what() << std::endl;
26+
}
27+
}
2228

2329
bool FrankaHand::set_config(const FHConfig &cfg) {
2430
franka::GripperState gripper_state = this->gripper.readOnce();
@@ -75,8 +81,8 @@ double FrankaHand::get_normalized_width() {
7581
void FrankaHand::m_stop() {
7682
try {
7783
this->gripper.stop();
78-
} catch (const franka::CommandException &e) {
79-
std::cerr << "franka hand command exception ignored stop" << std::endl;
84+
} catch (const franka::Exception &e) {
85+
std::cerr << "FrankaHand::m_stop: " << e.what() << std::endl;
8086
}
8187
this->m_wait();
8288
this->is_moving = false;
@@ -181,5 +187,7 @@ void FrankaHand::shut() {
181187
this->is_moving = false;
182188
});
183189
}
190+
191+
void FrankaHand::close() { this->m_stop(); }
184192
} // namespace hw
185193
} // namespace rcs

extensions/rcs_fr3/src/hw/FrankaHand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class FrankaHand : public common::Gripper {
7676
void grasp() override;
7777
void open() override;
7878
void shut() override;
79-
void close() override {};
79+
void close() override;
8080
};
8181
} // namespace hw
8282
} // namespace rcs

extensions/rcs_fr3/src/pybind/rcs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ PYBIND11_MODULE(_core, m) {
144144
.def("get_state", &rcs::hw::FrankaHand::get_state)
145145
.def("set_config", &rcs::hw::FrankaHand::set_config, py::arg("cfg"))
146146
.def("is_grasped", &rcs::hw::FrankaHand::is_grasped)
147-
.def("homing", &rcs::hw::FrankaHand::homing);
147+
.def("homing", &rcs::hw::FrankaHand::homing)
148+
.def("close", &rcs::hw::FrankaHand::close);
148149

149150
auto hw_except =
150151
hw.def_submodule("exceptions", "exceptions from the hardware module");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class FrankaConfig(rcs._core.common.RobotConfig):
9898

9999
class FrankaHand(rcs._core.common.Gripper):
100100
def __init__(self, ip: str, cfg: FHConfig) -> None: ...
101+
def close(self) -> None: ...
101102
def get_config(self) -> FHConfig: ...
102103
def get_state(self) -> FHState: ...
103104
def homing(self) -> bool: ...

extensions/rcs_panda/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ clangcompile:
2222

2323
# Auto generation of CPP binding stub files
2424
stubgen:
25-
pybind11-stubgen -o src --numpy-array-use-type-var rcs_panda
25+
pybind11-stubgen -o src --numpy-array-use-type-var --sort-by topological rcs_panda
2626
find ./${PYSRC} -name '*.pyi' -print | xargs sed -i '1s/^/# ATTENTION: auto generated from C++ code, use `make stubgen` to update!\n/'
2727
find ./${PYSRC} -not -path "./${PYSRC}/_core/*" -name '*.pyi' -delete
2828
find ./${PYSRC}/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[typing\.Literal\[\([0-9]\+\)\], typing\.Literal\[1\]\]/tuple\[typing\.Literal[\1]\]/g'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class FrankaConfig(rcs._core.common.RobotConfig):
9898

9999
class FrankaHand(rcs._core.common.Gripper):
100100
def __init__(self, ip: str, cfg: FHConfig) -> None: ...
101+
def close(self) -> None: ...
101102
def get_config(self) -> FHConfig: ...
102103
def get_state(self) -> FHState: ...
103104
def homing(self) -> bool: ...

0 commit comments

Comments
 (0)