-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fast Foward Gym Solo #55
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a87084c
Comitting for push
goobta 2cb8ac6
TorsoIMU should be normalized?
goobta e13091e
Write tests for motor encoder observation space
goobta c7f9d3f
Normalize MotorEncoders
goobta 2c8c407
Updates rewards tests to account for tolerance change
goobta a8cda83
Add more cases for normalized actions
goobta dbcbcec
Remove useless impots
goobta 9cd677c
Create runner for functional testing the normalization
goobta bfda81d
Currently satisfied with how observations/actions/rewardswork
goobta 57dacb7
Merge branch 'master' into goobta-normalized-obs
goobta 9159d67
Merge branch 'master' into goobta-normalized-obs
goobta a728e4a
Remove hardcoded assets folder
goobta c73f0cf
Make assets a submodule
goobta 2812a8d
Update assets submodule to have v3 models
goobta 43f4f30
Try to get CI working?
goobta df0085a
Try to use public endpoint instead
goobta 2617705
Try to use git ssh keys instead
goobta 18abda1
Update realtime script
goobta 2815217
Change bounds on normalization script
goobta b79bb26
Revert back to normal
goobta 486d1f0
Add interactive pos control for solo8mmr
goobta b7de171
Add realtime script for MMR model
goobta 38f3402
Fully reset the simulation cause of memory leaks
goobta 57abd87
Merge all conflicts
goobta 5714b51
Clean up realtime file
goobta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 @@ | ||
[submodule "gym_solo/assets"] | ||
path = gym_solo/assets | ||
url = git@github.com:WPI-MMR/assets.git |
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,88 @@ | ||
"""A demo for the Solo8 MMR with configurable position control on the | ||
the joints. | ||
""" | ||
|
||
import gym | ||
import numpy as np | ||
|
||
from gym_solo.envs import solo8v2vanilla | ||
from gym_solo.core import obs | ||
from gym_solo.core import rewards | ||
from gym_solo.core import termination as terms | ||
|
||
|
||
if __name__ == '__main__': | ||
config = solo8v2vanilla.Solo8VanillaConfig() | ||
config.urdf_path = 'assets/solo8_URDF_v3/solo8_URDF_v3.urdf' | ||
env: solo8v2vanilla.Solo8VanillaEnv = gym.make('solo8vanilla-v0', use_gui=True, | ||
realtime=True, config=config) | ||
|
||
env.obs_factory.register_observation(obs.TorsoIMU(env.robot)) | ||
env.termination_factory.register_termination(terms.PerpetualTermination()) | ||
|
||
flat = rewards.FlatTorsoReward(env.robot, hard_margin=.1, soft_margin=np.pi) | ||
height = rewards.TorsoHeightReward(env.robot, 0.33698, 0.025, 0.15) | ||
|
||
small_control = rewards.SmallControlReward(env.robot, margin=10) | ||
no_move = rewards.HorizontalMoveSpeedReward(env.robot, 0, hard_margin=.5, | ||
soft_margin=3) | ||
|
||
stand = rewards.AdditiveReward() | ||
stand.client = env.client | ||
stand.add_term(0.5, flat) | ||
stand.add_term(0.5, height) | ||
|
||
home_pos = rewards.MultiplicitiveReward(1, stand, small_control, no_move) | ||
env.reward_factory.register_reward(1, home_pos) | ||
|
||
joint_params = [] | ||
num_joints = env.client.getNumJoints(env.robot) | ||
|
||
for joint in range(num_joints): | ||
joint_params.append(env.client.addUserDebugParameter( | ||
'Joint {}'.format( | ||
env.client.getJointInfo(env.robot, joint)[1].decode('UTF-8')), | ||
-2 * np.pi, 2 * np.pi, 0)) | ||
|
||
camera_params = { | ||
'fov': env.client.addUserDebugParameter('fov', 30, 150, 80), | ||
'distance': env.client.addUserDebugParameter('distance', .1, 5, 1.5), | ||
'yaw': env.client.addUserDebugParameter('yaw', -90, 90, 0), | ||
'pitch': env.client.addUserDebugParameter('pitch', -90, 90, -10), | ||
'roll': env.client.addUserDebugParameter('roll', -90, 90, 0), | ||
} | ||
|
||
|
||
try: | ||
print("""\n | ||
============================================= | ||
Solo 8 MMR Position Control | ||
|
||
Simulation Active. | ||
|
||
Exit with ^C. | ||
============================================= | ||
""") | ||
|
||
done = False | ||
cnt = 0 | ||
while not done: | ||
user_joints = [env.client.readUserDebugParameter(param) | ||
for param in joint_params] | ||
obs, reward, done, info = env.step(user_joints) | ||
|
||
if cnt % 100 == 0: | ||
config.render_fov = env.client.readUserDebugParameter( | ||
camera_params['fov']) | ||
config.render_cam_distance = env.client.readUserDebugParameter( | ||
camera_params['distance']) | ||
config.render_yaw = env.client.readUserDebugParameter( | ||
camera_params['yaw']) | ||
config.render_pitch = env.client.readUserDebugParameter( | ||
camera_params['pitch']) | ||
config.render_roll = env.client.readUserDebugParameter( | ||
camera_params['roll']) | ||
env.render() | ||
cnt += 1 | ||
except KeyboardInterrupt: | ||
pass |
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,42 @@ | ||
""" A demo for the Solo MMR with realtime control. | ||
|
||
This environment is designed to act like a real robot would. There is no concept | ||
of a "timestep"; rather the step command should be interprated as sending | ||
position values to the robot's PID controllers. | ||
""" | ||
import gym | ||
import numpy as np | ||
|
||
import gym_solo | ||
from gym_solo.envs import solo8v2vanilla_realtime | ||
from gym_solo.core import obs | ||
|
||
|
||
if __name__ == '__main__': | ||
config = solo8v2vanilla_realtime.RealtimeSolo8VanillaConfig() | ||
config.urdf_path = 'assets/solo8_URDF_v3/solo8_URDF_v3.urdf' | ||
|
||
env = gym.make('solo8vanilla-realtime-v0', config=config) | ||
env.obs_factory.register_observation(obs.TorsoIMU(env.robot)) | ||
|
||
try: | ||
print("""\n | ||
============================================= | ||
Solo 8 v2 Vanilla Realtime Simulation | ||
|
||
Simulation Active. | ||
|
||
Exit with ^C. | ||
============================================= | ||
""") | ||
|
||
while True: | ||
pos = float(input('Which position do you want to set all the joints to?: ')) | ||
if pos == 69.: | ||
num_bodies = env.client.getNumBodies() | ||
else: | ||
action = np.full(env.action_space.shape, pos) | ||
env.step(action) | ||
|
||
except KeyboardInterrupt: | ||
pass |
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,114 @@ | ||
"""A demo for the Solo8 v2 Vanilla to mess around with normalized vs | ||
unnormalized actions and observations. | ||
""" | ||
|
||
import gym | ||
import numpy as np | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from gym_solo.envs import solo8v2vanilla | ||
from gym_solo.core import obs as solo_obs | ||
from gym_solo.core import rewards | ||
from gym_solo.core import termination as terms | ||
|
||
|
||
fig = plt.figure() | ||
obs_ax = fig.add_subplot(1, 2, 1) | ||
rewards_ax = fig.add_subplot(1, 2, 2) | ||
|
||
|
||
if __name__ == '__main__': | ||
config = solo8v2vanilla.Solo8VanillaConfig() | ||
config.max_motor_rotation = np.pi / 2 | ||
|
||
env: solo8v2vanilla.Solo8VanillaEnv = gym.make('solo8vanilla-v0', use_gui=True, | ||
config=config, | ||
normalize_observations=True) | ||
|
||
env.obs_factory.register_observation(solo_obs.TorsoIMU(env.robot)) | ||
env.obs_factory.register_observation(solo_obs.MotorEncoder( | ||
env.robot, max_rotation=config.max_motor_rotation)) | ||
env.termination_factory.register_termination(terms.PerpetualTermination()) | ||
|
||
flat = rewards.FlatTorsoReward(env.robot, hard_margin=.05, soft_margin=np.pi) | ||
height = rewards.TorsoHeightReward(env.robot, 0.33698, 0.01, 0.15) | ||
|
||
small_control = rewards.SmallControlReward(env.robot, margin=10) | ||
no_move = rewards.HorizontalMoveSpeedReward(env.robot, 0, hard_margin=.5, | ||
soft_margin=3) | ||
|
||
stand = rewards.AdditiveReward() | ||
stand.client = env.client | ||
stand.add_term(0.5, flat) | ||
stand.add_term(0.5, height) | ||
|
||
home_pos = rewards.MultiplicitiveReward(1, stand, small_control, no_move) | ||
env.reward_factory.register_reward(1, home_pos) | ||
|
||
joint_params = [] | ||
num_joints = env.client.getNumJoints(env.robot) | ||
|
||
for joint in range(num_joints): | ||
joint_params.append(env.client.addUserDebugParameter( | ||
'Joint {}'.format( | ||
env.client.getJointInfo(env.robot, joint)[1].decode('UTF-8')), | ||
-config.max_motor_rotation, config.max_motor_rotation, 0)) | ||
|
||
camera_params = { | ||
'fov': env.client.addUserDebugParameter('fov', 30, 150, 80), | ||
'distance': env.client.addUserDebugParameter('distance', .1, 5, 1.5), | ||
'yaw': env.client.addUserDebugParameter('yaw', -90, 90, 0), | ||
'pitch': env.client.addUserDebugParameter('pitch', -90, 90, -10), | ||
'roll': env.client.addUserDebugParameter('roll', -90, 90, 0), | ||
} | ||
|
||
try: | ||
print("""\n | ||
============================================= | ||
Solo 8 v2 Vanilla Normalization Debugging | ||
|
||
Simulation Active. | ||
|
||
Exit with ^C. | ||
============================================= | ||
""") | ||
|
||
done = False | ||
cnt = 0 | ||
while not done: | ||
user_joints = [env.client.readUserDebugParameter(param) | ||
for param in joint_params] | ||
obs, reward, done, info = env.step(user_joints) | ||
|
||
if cnt % 100 == 0: | ||
config.render_fov = env.client.readUserDebugParameter( | ||
camera_params['fov']) | ||
config.render_cam_distance = env.client.readUserDebugParameter( | ||
camera_params['distance']) | ||
config.render_yaw = env.client.readUserDebugParameter( | ||
camera_params['yaw']) | ||
config.render_pitch = env.client.readUserDebugParameter( | ||
camera_params['pitch']) | ||
config.render_roll = env.client.readUserDebugParameter( | ||
camera_params['roll']) | ||
env.render() | ||
|
||
obs_ax.cla() | ||
obs_ax.set_title('Observations') | ||
obs_ax.bar(np.arange(len(obs)), obs, tick_label=info['labels']) | ||
|
||
rewards_ax.cla() | ||
rewards_ax.set_title('Rewards') | ||
rewards_ax.bar(np.arange(5), [flat.compute(), | ||
height.compute(), | ||
small_control.compute(), | ||
no_move.compute(), | ||
reward], | ||
tick_label=('flat', 'height', 'small control', 'no move', | ||
'overall')) | ||
|
||
plt.pause(1e-8) | ||
cnt += 1 | ||
except KeyboardInterrupt: | ||
pass |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is up with this xD?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's the value to reset the robot lol. I'll open up another PR and get rid of it lmfao