-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_world.py
69 lines (62 loc) · 3.27 KB
/
hello_world.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.core.controllers import BaseController
from omni.isaac.core.utils.types import ArticulationAction
from omni.isaac.core.utils.nucleus import get_assets_root_path
from omni.isaac.wheeled_robots.robots import WheeledRobot
# This extension includes several generic controllers that could be used with multiple robots
from omni.isaac.wheeled_robots.controllers import WheelBasePoseController
# Robot specific controller
from omni.isaac.wheeled_robots.controllers.differential_controller import DifferentialController
import numpy as np
class CoolController(BaseController):
def __init__(self):
super().__init__(name="my_cool_controller")
# An open loop controller that uses a unicycle model
self._wheel_radius = 0.03
self._wheel_base = 0.1125
return
def forward(self, command):
# command will have two elements, first element is the forward velocity
# second element is the angular velocity (yaw only).
joint_velocities = [0.0, 0.0]
joint_velocities[0] = ((2 * command[0]) - (command[1] * self._wheel_base)) / (2 * self._wheel_radius)
joint_velocities[1] = ((2 * command[0]) + (command[1] * self._wheel_base)) / (2 * self._wheel_radius)
# A controller has to return an ArticulationAction
return ArticulationAction(joint_velocities=joint_velocities)
class HelloWorld(BaseSample):
def __init__(self) -> None:
super().__init__()
return
def setup_scene(self):
world = self.get_world()
world.scene.add_default_ground_plane()
assets_root_path = get_assets_root_path()
jetbot_asset_path = assets_root_path + "/Isaac/Robots/Jetbot/jetbot.usd"
self._jetbot = world.scene.add(
WheeledRobot(
prim_path="/World/Fancy_Robot",
name="fancy_robot",
wheel_dof_names=["left_wheel_joint", "right_wheel_joint"],
create_robot=True,
usd_path=jetbot_asset_path,
)
)
return
async def setup_post_load(self):
self._world = self.get_world()
self._jetbot = self._world.scene.get_object("fancy_robot")
self._world.add_physics_callback("sending_actions", callback_fn=self.send_robot_actions)
# Initialize our controller after load and the first reset
# Initialize our controller after load and the first reset
self._my_controller = WheelBasePoseController(name="cool_controller",
open_loop_wheel_controller=
DifferentialController(name="simple_control",
wheel_radius=0.03, wheel_base=0.1125),
is_holonomic=False)
return
def send_robot_actions(self, step_size):
position, orientation = self._jetbot.get_world_pose()
self._jetbot.apply_action(self._my_controller.forward(start_position=position,
start_orientation=orientation,
goal_position=np.array([0.8, 0.8])))
return