Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: faster & standardised object construction #81

Merged
merged 10 commits into from
Jan 2, 2025
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "ros/newton_ros"]
path = ros/pkgs/newton_ros
url = https://github.com/TheNewtonCapstone/newton-ros
[submodule "ros/newton_sim_ros"]
path = ros/pkgs/newton_sim_ros
url = https://github.com/TheNewtonCapstone/newton-sim-ros
7 changes: 7 additions & 0 deletions .idea/libraries/ROS.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/libraries/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/newton-isaac-sim.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Training.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified assets/newton/.thumbs/256x256/newton.usd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/newton/newton.usd
Binary file not shown.
84 changes: 63 additions & 21 deletions configs/robots/newton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,73 @@ robot_type: quadruped

# Kinematics
joints:
limits:
positions:
FR_HAA: [-45, 45]
gear_ratios:
FL_HAA: 9
FR_HAA: 9
HL_HAA: 9
HR_HAA: 9
FL_HFE: 9
FR_HFE: 9
HL_HFE: 9
HR_HFE: 9
FL_KFE: 9
FR_KFE: 9
HL_KFE: 9
HR_KFE: 9

effort_saturation: # of the input (i.e. the motor; before applying any gear ratio)
FL_HAA: 0.4
FR_HAA: 0.4
HL_HAA: 0.4
HR_HAA: 0.4
FL_HFE: 0.4
FR_HFE: 0.4
HL_HFE: 0.4
HR_HFE: 0.4
FL_KFE: 0.4
FR_KFE: 0.4
HL_KFE: 0.4
HR_KFE: 0.4

limits: # of the output (i.e. the joint itself, after applying any gear ratio)
positions: # deg
FL_HAA: [-45, 45]
HR_HAA: [-45, 45]
FR_HAA: [-45, 45]
HL_HAA: [-45, 45]
FR_HFE: [-90, 90]
HR_HFE: [-90, 90]
HR_HAA: [-45, 45]
FL_HFE: [-90, 90]
FR_HFE: [-90, 90]
HL_HFE: [-90, 90]
FR_KFE: [-175, 175]
HR_HFE: [-90, 90]
FL_KFE: [-175, 175]
HR_KFE: [-175, 175]
FR_KFE: [-175, 175]
HL_KFE: [-175, 175]
HR_KFE: [-175, 175]

velocities: # deg/s
FL_HAA: 5440
FR_HAA: 5440
HL_HAA: 5440
HR_HAA: 5440
FL_HFE: 5440
FR_HFE: 5440
HL_HFE: 5440
HR_HFE: 5440
FL_KFE: 5440
FR_KFE: 5440
HL_KFE: 5440
HR_KFE: 5440

velocities:
FR_HAA: 8000
FL_HAA: 8000
HR_HAA: 8000
HL_HAA: 8000
FR_HFE: 8000
HR_HFE: 8000
FL_HFE: 8000
HL_HFE: 8000
FR_KFE: 8000
FL_KFE: 8000
HR_KFE: 8000
HL_KFE: 8000
efforts: # Nm
FL_HAA: 6.3
FR_HAA: 6.3
HL_HAA: 6.3
HR_HAA: 6.3
FL_HFE: 6.3
FR_HFE: 6.3
HL_HFE: 6.3
HR_HFE: 6.3
FL_KFE: 6.3
FR_KFE: 6.3
HL_KFE: 6.3
HR_KFE: 6.3
42 changes: 42 additions & 0 deletions configs/ros.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
enabled: true
namespace: sim
domain_id: 25

defaults:
qos:
history: 0 # 0: system default, 1: keep last, 2: keep all, 3: unknown
depth: 5 # number of samples in history
reliability: 0 # 0: system default, 1: reliable, 2: best effort, 3: unknown
durability: 0 # 0: system default, 1: transient_local, 2: volatile, 3: unknown
lifespan:
seconds: 0
nanoseconds: 0
deadline:
seconds: 0
nanoseconds: 0
liveliness: 0 # 0: system default, 1: automatic, 2: manual_by_topic, 3: unknown
liveliness_lease_duration:
seconds: 0
nanoseconds: 0

nodes:
imu:
name: imu_node
pub_sim_topic: /sim/imu
pub_real_topic: /imu
pub_period: 5
pub_qos: None

contact:
name: contact_node
pub_sim_topic: /sim/contact
pub_real_topic: /contact
pub_period: 10
pub_qos: None

joints_controller:
name: joints_controller_node
pub_sim_topic: /sim/joints
pub_real_topic: /joints
pub_period: 5
pub_qos: None
1 change: 1 addition & 0 deletions configs/tasks/newton_idle_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ base_lr: 3e-6
episode_length: 500

newton:
# TODO: Remove inverse_control_frequency as a task parameter
inverse_control_frequency: 4 # we're aiming for a total compute budget of 2 times the physics timestep (0.005s * 4 = 0.02s)

# TODO: Add gains as a configuration parameter
Expand Down
5 changes: 4 additions & 1 deletion configs/world.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
physics_dt: 0.005000
stage_units_in_meters: 1.0
# TODO: Fully implement control_dt functionality across all systems
# The idea is to have everything inside of the Universe object, so it's more easily accessed from one place
control_dt: 0.020000
rendering_dt: 0.01667
stage_units_in_meters: 1.0
backend: torch
device: cuda

Expand Down
2 changes: 2 additions & 0 deletions core/actuators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .base_actuator import BaseActuator
from .dc_actuator import DCActuator
104 changes: 104 additions & 0 deletions core/actuators/base_actuator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from abc import abstractmethod

import torch

from ..base import BaseObject
from ..types import (
VecJointsEfforts,
VecJointsPositions,
VecJointsVelocities,
VecJointEffortLimits,
VecJointVelocityLimits,
VecJointGearRatios,
)
from ..universe import Universe


class BaseActuator(BaseObject):
def __init__(
self,
universe: Universe,
):
super().__init__(universe=universe)

self._vec_velocity_limits: VecJointVelocityLimits = torch.zeros(
(0,),
device=self._universe.device,
)
self._vec_effort_limits: VecJointEffortLimits = torch.zeros_like(
self._vec_velocity_limits,
)

self._vec_gear_ratios: VecJointGearRatios = torch.zeros_like(
self._vec_velocity_limits,
)

self._target_positions: VecJointsPositions = torch.zeros(
(0,),
device=self._universe.device,
)
self._computed_output_efforts: VecJointsEfforts = torch.zeros_like(
self._target_positions,
)
self._applied_output_efforts: VecJointsEfforts = torch.zeros_like(
self._target_positions,
)

@property
def computed_output_efforts(self) -> VecJointsEfforts:
"""Returns computed efforts, after any clamping, saturation, etc. and, most importantly, after the gear ratio."""
assert (
self.is_fully_constructed
), "Actuator not fully constructed: tried to access computed efforts!"

return self._computed_output_efforts

@property
def applied_output_efforts(self) -> VecJointsEfforts:
"""Returns applied efforts, after any clamping, saturation, etc. and, most importantly, after the gear ratio."""
assert (
self.is_fully_constructed
), "Actuator not fully constructed: tried to access applied efforts!"

return self._applied_output_efforts

@abstractmethod
def construct(
self,
input_vec_velocity_limits: VecJointVelocityLimits,
input_vec_effort_limits: VecJointEffortLimits,
vec_gear_ratios: VecJointVelocityLimits,
) -> None:
super().construct()

# limits are given of the input
self._vec_velocity_limits = input_vec_velocity_limits
self._vec_effort_limits = input_vec_effort_limits

self._vec_gear_ratios = vec_gear_ratios

@abstractmethod
def post_construct(self) -> None:
super().post_construct()

@abstractmethod
def step(
self,
output_current_positions: VecJointsPositions,
output_target_positions: VecJointsPositions,
output_current_velocities: VecJointsVelocities,
) -> VecJointsEfforts:
assert (
self.is_fully_constructed
), "Actuator not fully constructed: tried to step!"

return self._applied_output_efforts

@abstractmethod
def reset(self) -> None:
assert (
self.is_fully_constructed
), "Actuator not fully constructed: tried to reset!"

self._computed_output_efforts = torch.zeros_like(self._computed_output_efforts)
self._applied_output_efforts = torch.zeros_like(self._applied_output_efforts)
Loading
Loading