Skip to content

Commit 727cf7b

Browse files
authored
Fix buggy FR3 state machine (#49)
* temporarily don't use the distance sensors in the fr3_pick task because they seem broken * add cases for negative, 0, and positive initial slider values
1 parent bfeaee4 commit 727cf7b

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

judo/gui.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ def _get_gui_element(
8888
# Create a slider for an integer-valued param.
8989
if field.type is int:
9090
if "ui_config" not in field.metadata:
91-
min_int, max_int, step_int = 1, 2 * init_value, DEFAULT_SLIDER_STEP_INT
91+
if init_value < 0:
92+
min_int, max_int, step_int = 2 * init_value, -1, DEFAULT_SLIDER_STEP_INT
93+
elif init_value == 0:
94+
min_int, max_int, step_int = -5, 5, DEFAULT_SLIDER_STEP_INT
95+
else:
96+
min_int, max_int, step_int = 1, 2 * init_value, DEFAULT_SLIDER_STEP_INT
9297
else:
9398
min_int, max_int, step_int = field.metadata["ui_config"]
9499

@@ -108,11 +113,12 @@ def _get_gui_element(
108113
# Create a slider for a float-valued param.
109114
elif field.type is float:
110115
if "ui_config" not in field.metadata:
111-
min_float, max_float, step_float = (
112-
0.0,
113-
2 * init_value,
114-
DEFAULT_SLIDER_STEP_FLOAT,
115-
)
116+
if init_value < 0.0:
117+
min_float, max_float, step_float = 2 * init_value, 0.0, DEFAULT_SLIDER_STEP_FLOAT
118+
elif init_value == 0.0:
119+
min_float, max_float, step_float = -5.0, 5.0, DEFAULT_SLIDER_STEP_FLOAT
120+
else:
121+
min_float, max_float, step_float = 0.0, 2 * init_value, DEFAULT_SLIDER_STEP_FLOAT
116122
else:
117123
min_float, max_float, step_float = field.metadata["ui_config"]
118124

judo/tasks/fr3_pick.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,16 @@ def pre_rollout(self, curr_state: np.ndarray, config: FR3PickConfig) -> None:
204204
self._data.qpos[:] = curr_state[: self.model.nq]
205205
self._data.qvel[:] = curr_state[self.model.nq : self.model.nq + self.model.nv]
206206
mujoco.mj_forward(self.model, self._data)
207-
curr_sensor = self._data.sensordata # (total_sensor_dim,)
207+
208+
# BUG: mujoco distance sensor seems to be broken and doesn't always return signed distance, so here we instead
209+
# check the object z position
210+
# curr_sensor = self._data.sensordata # (total_sensor_dim,)
208211

209212
phase = Phase.LIFT # default phase
210213

211214
# check whether the phase is MOVE
212-
obj_in_air = curr_sensor[self.obj_table_adr] > 0 # object is not touching the table
215+
# obj_in_air = curr_sensor[self.obj_table_adr] > 0 # object is not touching the table
216+
obj_in_air = curr_state[self.obj_pos_adr + 2] > 0.02 + 1e-3 # object z position is above the table
213217
if obj_in_air:
214218
phase = Phase.MOVE # if the object is in the air, we are in lift phase
215219

@@ -219,8 +223,11 @@ def pre_rollout(self, curr_state: np.ndarray, config: FR3PickConfig) -> None:
219223
phase = Phase.PLACE # if the object is in the goal xy, we are in place phase
220224

221225
# check whether the phase is HOMING
222-
obj_table_dist = curr_sensor[self.obj_table_adr]
223-
if in_goal_xy and obj_table_dist <= 0:
226+
# obj_table_dist = curr_sensor[self.obj_table_adr]
227+
# if in_goal_xy and obj_table_dist <= 0:
228+
# phase = Phase.HOMING
229+
obj_z_pos = curr_state[self.obj_pos_adr + 2] # z position of the object
230+
if in_goal_xy and obj_z_pos <= 0.02 + 1e-3: # the cube is 4cm wide and we allow a tolerance
224231
phase = Phase.HOMING
225232

226233
self.phase = phase

0 commit comments

Comments
 (0)