-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Genesis-Embodied-AI:main' into main
- Loading branch information
Showing
12 changed files
with
296 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import argparse | ||
import numpy as np | ||
import genesis as gs | ||
|
||
from genesis.engine.solvers.rigid.rigid_solver_decomp import RigidSolver | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-v", "--vis", action="store_true", default=False) | ||
args = parser.parse_args() | ||
|
||
########################## init ########################## | ||
gs.init(backend=gs.gpu) | ||
|
||
########################## create a scene ########################## | ||
viewer_options = gs.options.ViewerOptions( | ||
camera_pos=(0, -3.5, 2.5), | ||
camera_lookat=(0.0, 0.0, 1.0), | ||
camera_fov=40, | ||
max_FPS=60, | ||
) | ||
|
||
scene = gs.Scene( | ||
viewer_options=viewer_options, | ||
sim_options=gs.options.SimOptions( | ||
dt=0.01, | ||
), | ||
show_viewer=args.vis, | ||
) | ||
|
||
########################## entities ########################## | ||
plane = scene.add_entity( | ||
gs.morphs.Plane(), | ||
) | ||
cube = scene.add_entity( | ||
gs.morphs.Box( | ||
pos=(0, 0, 1.0), | ||
size=(0.2, 0.2, 0.2), | ||
), | ||
) | ||
########################## build ########################## | ||
scene.build() | ||
|
||
for solver in scene.sim.solvers: | ||
if not isinstance(solver, RigidSolver): | ||
continue | ||
rigid_solver = solver | ||
|
||
link_idx = [ | ||
1, | ||
] | ||
rotation_direction = 1 | ||
for i in range(1000): | ||
cube_pos = rigid_solver.get_links_pos(link_idx) | ||
cube_pos[:, 2] -= 1 | ||
force = -100 * cube_pos | ||
rigid_solver.apply_links_external_force( | ||
force=force, | ||
links_idx=link_idx, | ||
) | ||
|
||
torque = [ | ||
[0, 0, rotation_direction * 5], | ||
] | ||
rigid_solver.apply_links_external_torque( | ||
torque=torque, | ||
links_idx=link_idx, | ||
) | ||
|
||
scene.step() | ||
|
||
if (i + 50) % 100 == 0: | ||
rotation_direction *= -1 | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import argparse | ||
|
||
import numpy as np | ||
import torch | ||
|
||
import genesis as gs | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-v", "--vis", action="store_true", default=False) | ||
args = parser.parse_args() | ||
|
||
########################## init ########################## | ||
gs.init(seed=0, precision="32", logging_level="debug") | ||
|
||
########################## create a scene ########################## | ||
scene = gs.Scene( | ||
viewer_options=gs.options.ViewerOptions( | ||
camera_pos=(0.0, -2, 1.5), | ||
camera_lookat=(0.0, 0.0, 0.5), | ||
camera_fov=40, | ||
max_FPS=200, | ||
), | ||
show_viewer=args.vis, | ||
rigid_options=gs.options.RigidOptions( | ||
dt=0.01, | ||
constraint_solver=gs.constraint_solver.Newton, | ||
), | ||
) | ||
|
||
########################## entities ########################## | ||
scene.add_entity( | ||
gs.morphs.Plane(), | ||
) | ||
robot = scene.add_entity( | ||
gs.morphs.URDF( | ||
file="urdf/go2/urdf/go2.urdf", | ||
pos=(0, 0, 0.4), | ||
), | ||
) | ||
########################## build ########################## | ||
n_envs = 8 | ||
scene.build(n_envs=n_envs) | ||
|
||
########################## domain randomization ########################## | ||
robot.set_friction_ratio( | ||
friction_ratio=0.5 + torch.rand(scene.n_envs, robot.n_links), | ||
link_indices=np.arange(0, robot.n_links), | ||
) | ||
robot.set_mass_shift( | ||
mass_shift=-0.5 + torch.rand(scene.n_envs, robot.n_links), | ||
link_indices=np.arange(0, robot.n_links), | ||
) | ||
robot.set_COM_shift( | ||
com_shift=-0.05 + 0.1 * torch.rand(scene.n_envs, robot.n_links, 3), | ||
link_indices=np.arange(0, robot.n_links), | ||
) | ||
|
||
joint_names = [ | ||
"FR_hip_joint", | ||
"FR_thigh_joint", | ||
"FR_calf_joint", | ||
"FL_hip_joint", | ||
"FL_thigh_joint", | ||
"FL_calf_joint", | ||
"RR_hip_joint", | ||
"RR_thigh_joint", | ||
"RR_calf_joint", | ||
"RL_hip_joint", | ||
"RL_thigh_joint", | ||
"RL_calf_joint", | ||
] | ||
motor_dofs = [robot.get_joint(name).dof_idx_local for name in joint_names] | ||
|
||
robot.set_dofs_kp(np.full(12, 20), motor_dofs) | ||
robot.set_dofs_kv(np.full(12, 1), motor_dofs) | ||
default_dof_pos = np.array( | ||
[ | ||
0.0, | ||
0.8, | ||
-1.5, | ||
0.0, | ||
0.8, | ||
-1.5, | ||
0.0, | ||
1.0, | ||
-1.5, | ||
0.0, | ||
1.0, | ||
-1.5, | ||
] | ||
) | ||
robot.control_dofs_position(default_dof_pos, motor_dofs) | ||
|
||
for i in range(1000): | ||
scene.step() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.