Skip to content

Commit 41a6101

Browse files
fix-jackal-jaco
1 parent b760051 commit 41a6101

File tree

11 files changed

+44
-29
lines changed

11 files changed

+44
-29
lines changed

igibson/controllers/controller_base.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ def update_command(self, command):
193193
:param command: Array[float], inputted command to store internally in this controller
194194
"""
195195
# Sanity check the command
196-
assert len(command) == self.command_dim, "Commands must be dimension {}, got dim {} instead.".format(
197-
self.command_dim, len(command)
198-
)
196+
# assert len(command) == self.command_dim, "Commands must be dimension {}, got dim {} instead.".format(
197+
# self.command_dim, len(command)
198+
# )
199199
# Preprocess and store inputted command
200200
self._command = self._preprocess_command(np.array(command))
201201

@@ -228,7 +228,14 @@ def step(self, control_dict):
228228
229229
:return Array[float]: numpy array of outputted control signals
230230
"""
231-
control = self._command_to_control(command=self._command, control_dict=control_dict)
231+
print('$$$$$$$$$$$$$$$$$ in control base $$$$$$$$$$$$$$$')
232+
print(self.control_dim)
233+
print('dict', control_dict)
234+
print('command', self._command)
235+
if self.control_dim == 4 and len(self._command) == 2:
236+
control = self._command_to_control(command=self._command, control_dict=control_dict, dd_4 = True)
237+
else:
238+
control = self._command_to_control(command=self._command, control_dict=control_dict)
232239
self.control = self.clip_control(control=control)
233240
return self.control
234241

@@ -242,6 +249,7 @@ def dump_state(self):
242249
"""
243250
:return Any: the state of the object other than what's not included in pybullet state.
244251
"""
252+
245253
return None
246254

247255
def load_state(self, dump):
@@ -252,7 +260,7 @@ def load_state(self, dump):
252260
"""
253261
return
254262

255-
def _command_to_control(self, command, control_dict):
263+
def _command_to_control(self, command, control_dict, dd_4=False):
256264
"""
257265
Converts the (already preprocessed) inputted @command into deployable (non-clipped!) control signal.
258266
Should be implemented by subclass.

igibson/controllers/dd_controller.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def reset(self):
8383
# No-op
8484
pass
8585

86-
def _command_to_control(self, command, control_dict):
86+
def _command_to_control(self, command, control_dict, dd_4=False):
8787
"""
8888
Converts the (already preprocessed) inputted @command into deployable (non-clipped!) joint control signal.
8989
This processes converts the desired (lin_vel, ang_vel) command into (left, right) wheel joint velocity control
@@ -97,12 +97,14 @@ def _command_to_control(self, command, control_dict):
9797
:return: Array[float], outputted (non-clipped!) velocity control signal to deploy
9898
to the [left, right] wheel joints
9999
"""
100+
print('!!!!!!!!!!! dd4', dd_4)
100101
lin_vel, ang_vel = command
101102

102103
# Convert to wheel velocities
103104
left_wheel_joint_vel = (lin_vel - ang_vel * self.wheel_axle_halflength) / self.wheel_radius
104105
right_wheel_joint_vel = (lin_vel + ang_vel * self.wheel_axle_halflength) / self.wheel_radius
105-
106+
if dd_4 == True:
107+
return np.array([left_wheel_joint_vel, right_wheel_joint_vel, left_wheel_joint_vel, right_wheel_joint_vel])
106108
# Return desired velocities
107109
return np.array([left_wheel_joint_vel, right_wheel_joint_vel])
108110

igibson/controllers/ik_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _pose_in_base_to_pose_in_world(pose_in_base, base_in_world):
173173
pose_in_world_mat = T.pose_in_A_to_pose_in_B(pose_A=pose_in_base_mat, pose_A_in_B=base_pose_in_world_mat)
174174
return T.mat2pose(pose_in_world_mat)
175175

176-
def _command_to_control(self, command, control_dict):
176+
def _command_to_control(self, command, control_dict, dd_4 = False):
177177
"""
178178
Converts the (already preprocessed) inputted @command into deployable (non-clipped!) joint control signal.
179179
This processes the command based on self.mode, possibly clips the command based on self.workspace_pose_limiter,

igibson/controllers/joint_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def reset(self):
9797
# Nothing to reset.
9898
pass
9999

100-
def _command_to_control(self, command, control_dict):
100+
def _command_to_control(self, command, control_dict, dd_4 = False):
101101
"""
102102
Converts the (already preprocessed) inputted @command into deployable (non-clipped!) joint control signal
103103

igibson/controllers/multi_finger_gripper_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def reset(self):
8888
# No-op
8989
pass
9090

91-
def _command_to_control(self, command, control_dict):
91+
def _command_to_control(self, command, control_dict, dd_4=False):
9292
"""
9393
Converts the (already preprocessed) inputted @command into deployable (non-clipped!) gripper
9494
joint control signal

igibson/controllers/null_gripper_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def clip_control(self, control):
6565
# No action
6666
return control
6767

68-
def _command_to_control(self, command, control_dict):
68+
def _command_to_control(self, command, control_dict, dd_4=False):
6969
"""
7070
Converts the (already preprocessed) inputted @command into deployable (non-clipped!) gripper
7171
joint control signal. Since this is a null controller, command should be an empty numpy array

igibson/external/pybullet_tools/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ def set_joint_position(body, joint, value):
14411441

14421442

14431443
def set_joint_positions(body, joints, values):
1444+
print(len(values), '+++++++++++++')
14441445
assert len(joints) == len(values)
14451446
for joint, value in zip(joints, values):
14461447
set_joint_position(body, joint, value)

igibson/robots/four_wheel_robot.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FourWheelRobot(LocomotionRobot):
2323

2424
def _validate_configuration(self):
2525
# Make sure base only has two indices (i.e.: two wheels for differential drive)
26-
assert len(self.base_control_idx) == 4, "Differential drive can only be used with robot with two base joints!"
26+
assert len(self.base_control_idx) == 4, "Differential drive can only be used with robot with four base joints!"
2727

2828
# run super
2929
super()._validate_configuration()
@@ -34,27 +34,27 @@ def _create_discrete_action_space(self):
3434
# We set straight velocity to be 50% of max velocity for the wheels
3535
max_wheel_joint_vels = self.control_limits["velocity"][1][self.base_control_idx]
3636
assert len(max_wheel_joint_vels) == 4, "FourWheelRobot must only have two base (wheel) joints!"
37-
assert max_wheel_joint_vels[0] == max_wheel_joint_vels[1], "All wheels must have the same max speed!"
37+
assert max_wheel_joint_vels[0] == max_wheel_joint_vels[1] == max_wheel_joint_vels[2] == max_wheel_joint_vels[3], "All wheels must have the same max speed!"
3838
wheel_straight_vel = 0.5 * max_wheel_joint_vels[0]
3939
wheel_rotate_vel = 0.5
4040
if self.controller_config["base"]["name"] == "JointController":
4141
action_list = [
42-
[wheel_straight_vel, wheel_straight_vel],
43-
[-wheel_straight_vel, -wheel_straight_vel],
44-
[wheel_rotate_vel, -wheel_rotate_vel],
45-
[-wheel_rotate_vel, wheel_rotate_vel],
46-
[0, 0],
42+
[wheel_straight_vel, wheel_straight_vel, wheel_straight_vel, wheel_straight_vel],
43+
[-wheel_straight_vel, -wheel_straight_vel, -wheel_straight_vel, -wheel_straight_vel],
44+
[wheel_rotate_vel, -wheel_rotate_vel, wheel_rotate_vel, -wheel_rotate_vel],
45+
[-wheel_rotate_vel, wheel_rotate_vel, -wheel_rotate_vel, wheel_rotate_vel],
46+
[0, 0, 0, 0],
4747
]
4848
else:
4949
# DifferentialDriveController
5050
lin_vel = wheel_straight_vel * self.wheel_radius
5151
ang_vel = wheel_rotate_vel * self.wheel_radius * 2.0 / self.wheel_axle_length
5252
action_list = [
53-
[lin_vel, 0],
54-
[-lin_vel, 0],
55-
[0, ang_vel],
56-
[0, -ang_vel],
57-
[0, 0],
53+
[lin_vel, 0, lin_vel, 0],
54+
[-lin_vel, 0, -lin_vel, 0],
55+
[0, ang_vel, 0, ang_vel],
56+
[0, -ang_vel, 0, -ang_vel],
57+
[0, 0, 0, 0],
5858
]
5959

6060
self.action_list = action_list

igibson/robots/jackal_jaco.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import igibson
66
from igibson.external.pybullet_tools.utils import set_joint_positions
77
from igibson.robots.manipulation_robot import ManipulationRobot
8-
from from igibson.robots.four_wheel_robot import FourWheelRobot
8+
from igibson.robots.four_wheel_robot import FourWheelRobot
99
from igibson.utils.constants import SemanticClass
1010

1111
RESET_JOINT_OPTIONS = {
@@ -153,7 +153,6 @@ def wheel_radius(self):
153153
def wheel_axle_length(self):
154154
return 0.6
155155

156-
157156
@property
158157
def base_control_idx(self):
159158
return np.array([0, 1, 2, 3])

igibson/robots/robot_base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def update_state(self):
308308
for this robot
309309
"""
310310
# Grab raw values
311+
311312
joint_states = np.array([j.get_state() for j in self._joints.values()]).astype(np.float32).flatten()
312313
joint_states_normalized = (
313314
np.array([j.get_relative_state() for j in self._joints.values()]).astype(np.float32).flatten()
@@ -428,20 +429,22 @@ def apply_action(self, action):
428429
429430
:param action: Array[float], n-DOF length array of actions to convert and deploy on the robot
430431
"""
432+
print("**********************")
433+
print(action)
434+
print("**********************")
431435
assert len(action) == self.action_dim, "Action does not match robot's action dimension."
432436

433437
self._last_action = action
434438

435439
# Update state
436440
self.update_state()
437-
441+
print("************++++++++++++++**************")
438442
# If we're using discrete action space, we grab the specific action and use that to convert to control
439443
if self.action_type == "discrete":
440444
action = np.array(self.action_list[action])
441-
445+
442446
# Run convert actions to controls
443447
control, control_type = self._actions_to_control(action=action)
444-
445448
# Deploy control signals
446449
self._deploy_control(control=control, control_type=control_type)
447450

@@ -459,8 +462,10 @@ def _actions_to_control(self, action):
459462
control = OrderedDict()
460463
idx = 0
461464
for name, controller in self._controllers.items():
465+
print("*******", name, controller.command_dim)
462466
# Compose control_dict
463467
control_dict = self.get_control_dict()
468+
print('+++++++++++++', control_dict)
464469
# Set command, then take a controller step
465470
controller.update_command(command=action[idx : idx + controller.command_dim])
466471
control[name] = {

0 commit comments

Comments
 (0)