Skip to content

Commit

Permalink
Revamp and check examples; Remove unfinished prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
iandanforth committed Feb 12, 2019
1 parent f22dafa commit a4f83a0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 99 deletions.
3 changes: 1 addition & 2 deletions examples/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .arm import PymunkArmEnv # noqa
from .muscled_hopper import MuscledHopperEnv # noqa
from .pymunk_arm import PymunkArmEnv # noqa
23 changes: 14 additions & 9 deletions examples/envs/arm.py → examples/envs/pymunk_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pymunk.pygame_util
import numpy as np
from pygame.locals import (QUIT, KEYDOWN, K_ESCAPE)
from pymuscle import PotvinFuglevandMuscle as Muscle
from pymuscle import StandardMuscle as Muscle


class PymunkArmEnv(gym.Env):
Expand All @@ -24,10 +24,12 @@ def __init__(self, apply_fatigue=False):
self.brach, self.tricep = self._add_arm()

# Instantiate the PyMuscles
brach_motor_unit_count = 100
self.brach_muscle = Muscle(brach_motor_unit_count, apply_fatigue)
tricep_motor_unit_count = 100
self.tricep_muscle = Muscle(tricep_motor_unit_count, apply_fatigue)
self.brach_muscle = Muscle(
apply_peripheral_fatigue=apply_fatigue
)
self.tricep_muscle = Muscle(
apply_peripheral_fatigue=False # Tricep never gets tired in this env
)

self.frames = 0

Expand Down Expand Up @@ -150,7 +152,7 @@ def step(self, input_array, step_size, debug=True):
self._handle_keys()

# Scale input to match the expected range of the muscle sim
input_array = np.array(input_array) * 67.0
input_array = np.array(input_array)

if debug:
print(input_array)
Expand All @@ -163,12 +165,15 @@ def step(self, input_array, step_size, debug=True):
brach_output = self.brach_muscle.step(input_array[0], step_size)
tricep_output = self.tricep_muscle.step(input_array[1], step_size)

gain = 500
self.brach.stiffness = brach_output * gain
self.tricep.stiffness = tricep_output * gain

if debug:
print("Brach Total Output: ", brach_output)
print("Tricep Total Output: ", tricep_output)

self.tricep.stiffness = tricep_output
self.brach.stiffness = brach_output
print("Brach Stiffness: ", self.brach.stiffness)
print("Tricep Stiffness: ", self.tricep.stiffness)

hand_location = self.hand_shape.body.local_to_world((170, 0))
return hand_location
Expand Down
29 changes: 0 additions & 29 deletions examples/gym-example-hopper.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
muscle = Muscle(motor_unit_count)

# Set up the simulation parameters
sim_duration = 60 # seconds
sim_duration = 200 # seconds
frames_per_second = 50
step_size = 1 / frames_per_second
total_steps = int(sim_duration / step_size)
Expand Down
9 changes: 6 additions & 3 deletions examples/gym-example.py → examples/pymunk-gym-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@

import sys
import os
from pymuscle.envs import PymunkArmEnv
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from envs import PymunkArmEnv


def main():
env = PymunkArmEnv(apply_fatigue=True)

# Set up the simulation parameters
sim_duration = 60 # seconds
sim_duration = 120 # seconds
frames_per_second = 50
step_size = 1 / frames_per_second
total_steps = int(sim_duration / step_size)

# Here we are going to send a constant excitation to the tricep and
# vary the excitation of the bicep as we try to hit a target location.
brachialis_input = 0.4 # Percent of max input
tricep_input = 0.6
tricep_input = 0.2
hand_target_y = 360
target_delta = 10
# Hand tuned PID params.
Expand Down Expand Up @@ -58,6 +59,8 @@ def main():

if brachialis_input > 1.0:
brachialis_input = 1.0
if brachialis_input < 0.0:
brachialis_input = 0.0

# Vary our set point and display the excitation required
if i % frames_per_second == 0:
Expand Down
55 changes: 0 additions & 55 deletions examples/random_agent.py

This file was deleted.

0 comments on commit a4f83a0

Please sign in to comment.