Skip to content

Commit 74dc8f7

Browse files
committed
feat(hw gripper): bool state and is moving
1 parent 6d70f16 commit 74dc8f7

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

python/rcsss/_core/hw/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ class FHConfig(rcsss._core.common.GConfig):
3737
class FHState(rcsss._core.common.GState):
3838
def __init__(self) -> None: ...
3939
@property
40+
def bool_state(self) -> bool: ...
41+
@property
4042
def is_grasped(self) -> bool: ...
4143
@property
44+
def is_moving(self) -> bool: ...
45+
@property
4246
def last_commanded_width(self) -> float: ...
4347
@property
4448
def max_unnormalized_width(self) -> float: ...

src/hw/FrankaHand.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ FHState *FrankaHand::get_state() {
4545
state->temperature = gripper_state.temperature;
4646
state->max_unnormalized_width = this->max_width;
4747
state->last_commanded_width = this->last_commanded_width;
48+
state->bool_state = this->last_commanded_width > 0;
49+
state->is_moving = this->is_moving;
4850
return state;
4951
}
5052

@@ -74,7 +76,7 @@ void FrankaHand::m_stop(){
7476
this->control_thread->join();
7577
this->control_thread.reset();
7678
}
77-
79+
this->is_moving = false;
7880
}
7981

8082
void FrankaHand::m_reset() {
@@ -83,7 +85,9 @@ void FrankaHand::m_reset() {
8385
franka::GripperState gripper_state = this->gripper.readOnce();
8486
this->max_width = gripper_state.max_width - 0.001;
8587
this->last_commanded_width = this->max_width;
88+
this->is_moving = true;
8689
this->gripper.move(this->max_width, this->cfg.speed);
90+
this->is_moving = false;
8791
}
8892
void FrankaHand::reset() { this->m_reset(); }
8993

@@ -95,36 +99,57 @@ bool FrankaHand::is_grasped() {
9599
bool FrankaHand::homing() {
96100
// Do a homing in order to estimate the maximum
97101
// grasping width with the current fingers.
98-
return this->gripper.homing();
102+
this->is_moving = true;
103+
bool success = this->gripper.homing();
104+
this->is_moving = false;
105+
return success;
99106
}
100107

101108
void FrankaHand::grasp() {
102109
this->last_commanded_width = 0;
103110
if (!this->cfg.async_control) {
111+
this->is_moving = true;
104112
this->gripper.grasp(0, this->cfg.speed, this->cfg.force, 1, 1);
113+
this->is_moving = false;
105114
return;
106115
}
107116
this->m_stop();
108-
this->control_thread = std::thread([&](){this->gripper.grasp(0, this->cfg.speed, this->cfg.force, 1, 1);});
117+
this->control_thread = std::thread([&](){
118+
this->is_moving = true;
119+
this->gripper.grasp(0, this->cfg.speed, this->cfg.force, 1, 1);
120+
this->is_moving = false;
121+
});
109122
}
110123

111124
void FrankaHand::open() {
112125
this->last_commanded_width = this->max_width;
113126
if (!this->cfg.async_control) {
127+
this->is_moving = true;
114128
this->gripper.move(this->max_width, this->cfg.speed);
129+
this->is_moving = false;
115130
return;
116131
}
117132
this->m_stop();
118-
this->control_thread = std::thread([&](){this->gripper.move(this->max_width, this->cfg.speed);});
133+
this->control_thread = std::thread([&](){
134+
this->is_moving = true;
135+
this->gripper.move(this->max_width, this->cfg.speed);
136+
this->is_moving = false;
137+
});
119138
}
120139
void FrankaHand::shut() {
121140
this->last_commanded_width = 0;
122141
if (!this->cfg.async_control) {
142+
this->is_moving = true;
123143
this->gripper.move(0, this->cfg.speed);
144+
this->is_moving = false;
124145
return;
125146
}
126147
this->m_stop();
127-
this->control_thread = std::thread([&](){this->gripper.move(0, this->cfg.speed);});
148+
this->control_thread = std::thread([&](){
149+
this->is_moving = true;
150+
this->gripper.move(0, this->cfg.speed);
151+
this->is_moving = false;
152+
});
128153
}
129154
} // namespace hw
130155
} // namespace rcs

src/hw/FrankaHand.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ struct FHConfig : common::GConfig {
3030

3131
struct FHState : common::GState {
3232
double width;
33+
// true is open
34+
bool bool_state;
3335
bool is_grasped;
3436
uint16_t temperature;
3537
double last_commanded_width;
3638
double max_unnormalized_width;
39+
bool is_moving;
3740
};
3841

3942
class FrankaHand : public common::Gripper {
@@ -42,6 +45,7 @@ class FrankaHand : public common::Gripper {
4245
FHConfig cfg;
4346
double max_width;
4447
double last_commanded_width;
48+
bool is_moving = false;
4549
std::optional<std::thread> control_thread = std::nullopt;
4650
void m_reset();
4751
void m_stop();

src/pybind/rcsss.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ PYBIND11_MODULE(_core, m) {
343343
.def(py::init<>())
344344
.def_readonly("width", &rcs::hw::FHState::width)
345345
.def_readonly("is_grasped", &rcs::hw::FHState::is_grasped)
346+
.def_readonly("is_moving", &rcs::hw::FHState::is_moving)
347+
.def_readonly("bool_state", &rcs::hw::FHState::bool_state)
346348
.def_readonly("last_commanded_width",
347349
&rcs::hw::FHState::last_commanded_width)
348350
.def_readonly("max_unnormalized_width",

0 commit comments

Comments
 (0)