-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adapt code to version 2023.1.1 (#42) * Feature/go1 (#44) * feat: adapt code to version 2023.1.1 * feat: add go1 However, It doesn't have any controller yet. You can add walk these ways controller here * Bug/ros2 node duplicate (#45) * feat: adapt code to version 2023.1.1 * feat: add go1 However, It doesn't have any controller yet. You can add walk these ways controller here * bug: fix duplicated ros node problem * fix: pylint error(cyclic import) * fix2: pylint error(cyclic import) * fix3: pylint error(cyclic import)
- Loading branch information
Showing
8 changed files
with
150 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
sensor: | ||
imu: | ||
update_frequency: 250 | ||
|
||
lidar: | ||
update_frequency: 25 | ||
prim_path: /World/go1/lidar/lidar_PhysX |
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
2 changes: 2 additions & 0 deletions
2
exts/stride.simulator/stride/simulator/vehicles/quadrupedrobot/__init__.py
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .quadrupedrobot import QuadrupedRobot, QuadrupedRobotConfig | ||
from .anymalc import AnymalC, AnymalCConfig | ||
from .go1 import Go1, Go1Config |
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
111 changes: 111 additions & 0 deletions
111
exts/stride.simulator/stride/simulator/vehicles/quadrupedrobot/go1.py
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,111 @@ | ||
from stride.simulator.vehicles.quadrupedrobot.quadrupedrobot import ( | ||
QuadrupedRobot, | ||
QuadrupedRobotConfig, | ||
) | ||
|
||
# Mavlink interface | ||
# from stride.simulator.logic.backends.mavlink_backend import MavlinkBackend | ||
|
||
# Get the location of the asset | ||
# from stride.simulator.backends import LoggerBackend | ||
from stride.simulator.params import ROBOTS | ||
from stride.simulator.vehicles.sensors.imu import Imu | ||
|
||
# from stride.simulator.vehicles.sensors.lidar import Lidar | ||
|
||
from stride.simulator.vehicles.controllers.anymal_controller import AnyamlController | ||
|
||
import yaml | ||
import os | ||
|
||
|
||
class Go1Config(QuadrupedRobotConfig): | ||
""" | ||
Go1 configuration class | ||
""" | ||
|
||
def __init__(self): | ||
|
||
super().__init__() | ||
|
||
self.vehicle_name = "go1" | ||
|
||
# Get the path to the "" directory | ||
stridesim_dir = os.path.abspath(__file__) | ||
for _ in range(5): | ||
stridesim_dir = os.path.dirname(stridesim_dir) | ||
|
||
# Stage prefix of the vehicle when spawning in the world | ||
self.stage_prefix = "/World/Go1" | ||
|
||
# The USD file that describes the visual aspect of the vehicle | ||
self.usd_file = ROBOTS["go1"] | ||
|
||
# read config file | ||
with open( | ||
stridesim_dir + "/config/go1_cfg.yaml", "r", encoding="utf-8" | ||
) as file: | ||
self.config = yaml.safe_load(file) | ||
|
||
# The default sensors for a Go1 | ||
self.sensors = [ | ||
Imu(self.config["sensor"]["imu"]), | ||
# Lidar(self.config["sensor"]["lidar"]), | ||
] # pylint: disable=use-list-literal FIXME | ||
|
||
# The backends for actually sending commands to the vehicle. | ||
# It can also be a ROS2 backend or your own custom Backend implementation! | ||
self.backends = [] # pylint: disable=use-list-literal | ||
|
||
|
||
class Go1(QuadrupedRobot): | ||
"""Go1 class - It is a child class of QuadrupedRobot class to implement a Go1 robot in the simulator.""" | ||
|
||
def __init__(self, id: int, init_pos, init_orientation, config=Go1Config()): | ||
|
||
if init_pos is None: | ||
init_pos = [0.0, 0.0, 0.5] | ||
if init_orientation is None: | ||
init_orientation = [0.0, 0.0, 0.0, 1.0] | ||
|
||
super().__init__( | ||
config.stage_prefix, | ||
config.usd_file, | ||
id, | ||
init_pos, | ||
init_orientation, | ||
config=config, | ||
) | ||
|
||
self.controller = AnyamlController() | ||
|
||
def update_sensors(self, dt: float): | ||
"""Callback that is called at every physics steps and will call the sensor.update method to generate new | ||
sensor data. For each data that the sensor generates, the backend.update_sensor method will also be called for | ||
every backend. For example, if new data is generated for an IMU and we have a MavlinkBackend, then the | ||
update_sensor method will be called for that backend so that this data can latter be sent thorugh mavlink. | ||
Args: | ||
dt (float): The time elapsed between the previous and current function calls (s). | ||
""" | ||
|
||
# Call the update method for the sensor to update its values internally (if applicable) | ||
for sensor in self._sensors: | ||
try: | ||
sensor_data = sensor.update(self._state, dt) | ||
except Exception as e: # pylint: disable=broad-except | ||
print(f"Error updating sensor: {e}") | ||
continue | ||
|
||
if sensor_data is not None: | ||
for backend in self._backends: | ||
backend.update_sensor(sensor.sensor_type, sensor_data) | ||
|
||
def initialize(self, physics_sim_view=None) -> None: | ||
"""[summary] | ||
initialize the dc interface, set up drive mode | ||
""" | ||
super().initialize(physics_sim_view=physics_sim_view) | ||
self.get_articulation_controller().set_effort_modes("force") | ||
self.get_articulation_controller().switch_control_mode("effort") |
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