https://github.com/iandanforth/muscledagents
Models rigged with muscles and environments which incorporate PyMuscle fatigable muscle models
https://github.com/iandanforth/muscledagents
Last synced: 8 months ago
JSON representation
Models rigged with muscles and environments which incorporate PyMuscle fatigable muscle models
- Host: GitHub
- URL: https://github.com/iandanforth/muscledagents
- Owner: iandanforth
- License: mit
- Created: 2018-05-09T22:18:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-06T22:05:32.000Z (about 7 years ago)
- Last Synced: 2024-11-07T20:13:48.035Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 12.4 MB
- Stars: 17
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MuscledAgents
OpenAI Gym compatible MuJoCo environments rigged with muscles which use
[PyMuscle](http://github.com/iandanforth/pymuscle) fatigable muscle models.

## Prerequisites
- MuJoCo==1.5
- mujoco-py
- gym
## Setup
```
python setup.py develop
```
## Usage
```python
import gym
import muscledagents
import math
def main():
# Load a muscled ant
env = gym.make("MuscledAnt-v0")
env.reset()
print("Observation Space Dims", env.observation_space.shape)
print("Action Space Dims", env.action_space.shape)
action_size = env.action_space.shape[0]
action = [0.0] * action_size
total_steps = 60 * 10
for i in range(total_steps):
action[1] = ((math.sin(i / 25) + 1) / 2)
action[5] = ((math.sin(i / 35) + 1) / 2)
action[9] = ((math.sin(i / 45) + 1) / 2)
action[13] = ((math.sin(i / 55) + 1) / 2)
env.step(action)
env.render()
if __name__ == '__main__':
main()
```
To explore these environments and models further you will need to understand
how input values get translated into final simulated movements.
### Control Signals
The action space for an ant is continuous control over 16 muscles. For
each of four legs there are four muscles. One leg extensor, one leg flexor,
and two hip muscles which move the leg left and right (or forward and back
depending on your perspective.)
### Gym Environment
The `step` method takes an array of 16 values which represent the input to
the fatigable muscle model for each muscle. Inputs should be in the range [0-1].
### PyMuscle Fatigue
After use muscles produce less force for the same level of input. So if you
were to send an input signal which recruited all motor units in a muscle
constantly for several seconds the output the model will return will rapidly
decrease. A period of light or no use is required for the muscle to recover.
### MuJoCo Model
Each tendon actuator is control limited to the range [-1.0, 0.0]. When a
General actuator is tied to a Tendon in MuJoCo negative values are the
equivalent of contractions. Muscles cannot produce force in extension so no
positive non-zero values are allowed.
Actuators have a `gainprm` which scales this input value. This is tuned to
a value of 100 to work with the mass of the ant and the resistances of opposing
tendons.
## Altering the Models
Due to frustration editing XML files the `ant` model is generated by a python
script that uses the [mjcf](http://github.com/iandanforth/mjcf) library which
I wrote to wrap MuJoCo xml elements in python classes. Note: This may
be replaced with the mjcf library from [dm_control](https://github.com/deepmind/dm_control/tree/master/dm_control/mjcf) in the future.
You can view and modify that script in `scripts/gen_ant.py`.