-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reward functions are now split out from agents
- Loading branch information
Showing
7 changed files
with
151 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .rConstant import * | ||
from .rSpeed import * | ||
from .rHealthy import * | ||
from .rControl import * |
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,15 @@ | ||
from typing import Tuple | ||
|
||
import jax | ||
from brax import actuator, base, math | ||
from brax.envs import PipelineEnv, State | ||
from brax.io import mjcf | ||
from etils import epath | ||
from jax import numpy as jp | ||
|
||
def rConstant(sys: base.System, | ||
pipeline_state: base.State, | ||
weight=1.0, | ||
focus_idx_range=(1, -1)) -> jp.ndarray: | ||
|
||
return jp.array([weight]) |
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,18 @@ | ||
from typing import Tuple | ||
|
||
import jax | ||
from brax import actuator, base, math | ||
from brax.envs import PipelineEnv, State | ||
from brax.io import mjcf | ||
from etils import epath | ||
from jax import numpy as jp | ||
|
||
def rControl_act_ss(sys: base.System, | ||
pipeline_state: base.State, | ||
action: jp.ndarray, | ||
weight=1.0, | ||
focus_idx_range=(1, -1)) -> jp.ndarray: | ||
|
||
ctrl_cost = weight * jp.sum(jp.square(action)) | ||
|
||
return ctrl_cost |
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,31 @@ | ||
from typing import Tuple | ||
|
||
import jax | ||
from brax import actuator, base, math | ||
from brax.envs import PipelineEnv, State | ||
from brax.io import mjcf | ||
from etils import epath | ||
from jax import numpy as jp | ||
|
||
def rHealthy_simple_z(sys: base.System, | ||
pipeline_state: base.State, | ||
z_range: Tuple, | ||
early_terminate: True, | ||
weight=1.0, | ||
focus_idx_range=(1, -1)) -> jp.ndarray: | ||
|
||
min_z, max_z = z_range | ||
focus_s = focus_idx_range[0] | ||
focus_e = focus_idx_range[-1] | ||
|
||
focus_x_pos = pipeline_state.x.pos[focus_s, focus_e] | ||
|
||
is_healthy = jp.where(focus_x_pos < min_z, x=0.0, y=1.0) | ||
is_healthy = jp.where(focus_x_pos > max_z, x=0.0, y=is_healthy) | ||
|
||
if early_terminate: | ||
hr = weight | ||
else: | ||
hr = weight * is_healthy | ||
|
||
return jp.array([hr, is_healthy]) |
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,44 @@ | ||
from typing import Tuple | ||
|
||
import jax | ||
from brax import actuator, base, math | ||
from brax.envs import PipelineEnv, State | ||
from brax.io import mjcf | ||
from etils import epath | ||
from jax import numpy as jp | ||
|
||
def rSpeed_X(sys: base.System, | ||
pipeline_state: base.State, | ||
CoM_prev: jp.ndarray, | ||
CoM_now: jp.ndarray, | ||
dt, | ||
weight=1.0, | ||
focus_idx_range=(1, -1)) -> jp.ndarray: | ||
|
||
|
||
velocity = (CoM_now - CoM_prev) / dt | ||
|
||
focus_s = focus_idx_range[0] | ||
focus_e = focus_idx_range[-1] | ||
|
||
sxr = weight * velocity[0] | ||
|
||
return jp.array([sxr, velocity[0], velocity[1]]) | ||
|
||
def rSpeed_Y(sys: base.System, | ||
pipeline_state: base.State, | ||
CoM_prev: jp.ndarray, | ||
CoM_now: jp.ndarray, | ||
dt, | ||
weight=1.0, | ||
focus_idx_range=(1, -1)) -> jp.ndarray: | ||
|
||
|
||
velocity = (CoM_now - CoM_prev) / dt | ||
|
||
focus_s = focus_idx_range[0] | ||
focus_e = focus_idx_range[-1] | ||
|
||
syr = weight * velocity[1] | ||
|
||
return jp.array([syr, velocity[0], velocity[1]]) |
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