Request for help with Joint Control for Unitree Go2 in Genesis #1250
-
Hello , import genesis as gs
gs.init(backend=gs.cpu)
scene = gs.Scene(show_viewer=True)
plane = scene.add_entity(gs.morphs.Plane())
robot = gs.morphs.MJCF(file="xml/Unitree_Go2/go2.xml")
Go2 = scene.add_entity(robot)
scene.build()
jnt_names = [
'FL_hip_joint', 'FL_thigh_joint', 'FL_calf_joint',
'FR_hip_joint', 'FR_thigh_joint', 'FR_calf_joint',
'RL_hip_joint', 'RL_thigh_joint', 'RL_calf_joint',
'RR_hip_joint', 'RR_thigh_joint', 'RR_calf_joint',
]
dofs_idx = [Go2.get_joint(name).dof_idx_local for name in jnt_names]
print(dofs_idx) The output is:
Then I try to set joint positions like this:
But I keep getting this error:
I’ve tried many variations, but nothing works. I will be grateful if you kindly help me. Thanks in advance Here I am giving the detailed output of the code: Cell 2: Getting the joint dof info# Getting the joint Info Go2
jnt_names = [
'FL_hip_joint',
'FL_thigh_joint',
'FL_calf_joint',
'FR_hip_joint',
'FR_thigh_joint',
'FR_calf_joint',
'RL_hip_joint',
'RL_thigh_joint',
'RL_calf_joint',
'RR_hip_joint',
'RR_thigh_joint',
'RR_calf_joint',
]
dofs_idx = [Go2.get_joint(name).dof_idx_local for name in jnt_names]
print(dofs_idx) Output:[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[Genesis] [10:18:29] [WARNING] This property is deprecated and will be removed in future release. Please use 'dof_idx_local' instead.
[[0, 1, 2, 3, 4, 5], 10, 14, 7, 11, 15, 8, 12, 16, 9, 13, 17] Cell 3: Try 1 to apply action# Hard reset
import numpy as np
for i in range(150):
if i < 50:
Go2.set_dofs_position(np.array([[0, 0, 0, 0, 0, 0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), dofs_idx)
elif i < 100:
Go2.set_dofs_position(np.array([[1, 1, 1, 1, 1, 1], 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), dofs_idx)
else:
Go2.set_dofs_position(np.array([[2, 2, 2, 2, 2, 2], 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), dofs_idx)
scene.step() Output:ValueError Traceback (most recent call last) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (12,) + inhomogeneous part. Cell 3: I tried to change the input by making it flattened (one dimension)# Hard reset
import numpy as np
for i in range(150):
if i < 50:
Go2.set_dofs_position(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), dofs_idx)
elif i < 100:
Go2.set_dofs_position(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), dofs_idx)
else:
Go2.set_dofs_position(np.array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), dofs_idx)
scene.step() Output:TypeError Traceback (most recent call last)
Cell In[4], line 5
3 for i in range(150):
4 if i < 50:
----> 5 Go2.set_dofs_position(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), dofs_idx)
6 elif i < 100:
7 Go2.set_dofs_position(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), dofs_idx)
File ~\Genesis\genesis\utils\misc.py:72, in assert_built.<locals>.wrapper(self, *args, **kwargs)
70 if not self.is_built:
71 gs.raise_exception("Scene is not built yet.")
---> 72 return method(self, *args, **kwargs)
File ~\Genesis\genesis\engine\entities\rigid_entity\rigid_entity.py:2144, in RigidEntity.set_dofs_position(self, position, dofs_idx_local, envs_idx, zero_velocity, unsafe)
2128 @gs.assert_built
2129 def set_dofs_position(self, position, dofs_idx_local=None, envs_idx=None, *, zero_velocity=True, unsafe=False):
2130 """
2131 Set the entity's dofs' position.
2132
(...)
2142 Whether to zero the velocity of all the entity's dofs. Defaults to True. This is a safety measure after a sudden change in entity pose.
2143 """
-> 2144 dofs_idx = self._get_idx(dofs_idx_local, self.n_dofs, self._dof_start, unsafe=True)
2145 self._solver.set_dofs_position(position, dofs_idx, envs_idx, unsafe=unsafe, skip_forward=zero_velocity)
2146 if zero_velocity:
File ~\Genesis\genesis\engine\entities\rigid_entity\rigid_entity.py:1992, in RigidEntity._get_idx(self, idx_local, idx_local_max, idx_global_start, unsafe)
1990 idx_global = idx_local + idx_global_start
1991 elif isinstance(idx_local, (list, tuple)):
-> 1992 idx_global = [i + idx_global_start for i in idx_local]
1993 else:
1994 # Increment may be slow when dealing with heterogenuous data, so it must be avoided if possible
1995 if idx_global_start > 0:
File ~\Genesis\genesis\engine\entities\rigid_entity\rigid_entity.py:1992, in <listcomp>(.0)
1990 idx_global = idx_local + idx_global_start
1991 elif isinstance(idx_local, (list, tuple)):
-> 1992 idx_global = [i + idx_global_start for i in idx_local]
1993 else:
1994 # Increment may be slow when dealing with heterogenuous data, so it must be avoided if possible
1995 if idx_global_start > 0:
TypeError: can only concatenate list (not "int") to list Cell 3: Another try with 12 element array# Hard reset
import numpy as np
for i in range(150):
if i < 50:
Go2.set_dofs_position(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), dofs_idx)
elif i < 100:
Go2.set_dofs_position(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), dofs_idx)
else:
Go2.set_dofs_position(np.array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), dofs_idx)
scene.step() Output:TypeError Traceback (most recent call last)
Cell In[5], line 5
3 for i in range(150):
4 if i < 50:
----> 5 Go2.set_dofs_position(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), dofs_idx)
6 elif i < 100:
7 Go2.set_dofs_position(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), dofs_idx)
File ~\Genesis\genesis\utils\misc.py:72, in assert_built.<locals>.wrapper(self, *args, **kwargs)
70 if not self.is_built:
71 gs.raise_exception("Scene is not built yet.")
---> 72 return method(self, *args, **kwargs)
File ~\Genesis\genesis\engine\entities\rigid_entity\rigid_entity.py:2144, in RigidEntity.set_dofs_position(self, position, dofs_idx_local, envs_idx, zero_velocity, unsafe)
2128 @gs.assert_built
2129 def set_dofs_position(self, position, dofs_idx_local=None, envs_idx=None, *, zero_velocity=True, unsafe=False):
2130 """
2131 Set the entity's dofs' position.
2132
(...)
2142 Whether to zero the velocity of all the entity's dofs. Defaults to True. This is a safety measure after a sudden change in entity pose.
2143 """
-> 2144 dofs_idx = self._get_idx(dofs_idx_local, self.n_dofs, self._dof_start, unsafe=True)
2145 self._solver.set_dofs_position(position, dofs_idx, envs_idx, unsafe=unsafe, skip_forward=zero_velocity)
2146 if zero_velocity:
File ~\Genesis\genesis\engine\entities\rigid_entity\rigid_entity.py:1992, in RigidEntity._get_idx(self, idx_local, idx_local_max, idx_global_start, unsafe)
1990 idx_global = idx_local + idx_global_start
1991 elif isinstance(idx_local, (list, tuple)):
-> 1992 idx_global = [i + idx_global_start for i in idx_local]
1993 else:
1994 # Increment may be slow when dealing with heterogenuous data, so it must be avoided if possible
1995 if idx_global_start > 0:
File ~\Genesis\genesis\engine\entities\rigid_entity\rigid_entity.py:1992, in <listcomp>(.0)
1990 idx_global = idx_local + idx_global_start
1991 elif isinstance(idx_local, (list, tuple)):
-> 1992 idx_global = [i + idx_global_start for i in idx_local]
1993 else:
1994 # Increment may be slow when dealing with heterogenuous data, so it must be avoided if possible
1995 if idx_global_start > 0:
TypeError: can only concatenate list (not "int") to list |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Can you provide the complete traceback of the error? |
Beta Was this translation helpful? Give feedback.
-
The issue is that motor_dofs = [i for name in joint_names for i in robot.get_joint(name).dofs_idx_local] The same goes for the setters. The values must be flattened. |
Beta Was this translation helpful? Give feedback.
The issue is that
dofs_idx
must be a flat list of integers, not a nested list. Here is how to properly completedofs_idx
:The same goes for the setters. The values must be flattened.