A simple rat simulation with whiskers using gym environment and pybox2d as the physics engine and matplotlib for graphics.
-
Download the RatSim repo:
git clone https://github.com/francesco-mannella/RatSim.git
-
Install the RatSim package:
cd ratsim pip install -e .
import gym
import RatSim
env = gym.make('RatSim-v0')
for t in range(10):
env.render()
observation = env.step(env.action_space.sample())
The two possible values of the argument to be passed to env.render() are:
- "human": open a matplotlib figure and update it at each call.
- "offline": save a frame into a png file at each call. Files are saved into the local folder 'frames'. This folder is created if it does not exist.
Example in test.py |
The action attribute of env.step must be a vector of 15 float elements. Elements in the first 6 indices give the current amplitude of oscillation for each of the 6 whiskers. Indices from the 7th to the 12th define the central points of oscillations. the 13th index defines the current joint angle of the body-to-head joint. the 14th index defines the angular velocity of the rat. The 15th index defines the speed in the current straight direction.
|
The observation object returned by env.step is a dictionary:
- observation["JOINT_POSITIONS"] is a vector containing the current angles of the 7 joints
- observation["TOUCH_SENSORS"] is a vector containing the current touch intensity at the six touch sensors (see figure below)
- observation["OBJ_POSITION"] coordinates of the center of mass of the external object
The reward value returned by env.step is always put to 0.
The done value returned by env.step is always set to False.
The info value returned by env.step is always set to an empy set {}. .