In Explauto, an environment implements the physical properties of the interaction between the robot body and the environment in which it evolves. Explauto come with several sensorimotor systems available from the environment package. To learn how to set an environment, look at the notebook Setting Environments.
In [7]:
from explauto.environment import environments
print 'Available environments: {}'.format(environments.keys())
We will use the npendulum environment for this tutorial. It consists in the simulation of a multiple pendulum with $n+1$ nodes, aiming to model a string. The first node is the one which undergoes the input force.
This environment comes with a predefined configuration, named default.
In [8]:
env_cls, env_configs, _ = environments['npendulum']
print 'Available configurations for the simple arm environment: {}'.format(env_configs.keys())
In the case of the npendulum environment, a configuration must defines the following values:
For more advanced settings, please look at the npendulum environment documentation.
Then we create the Environment instance.
In [18]:
config = env_configs['default']
print 'Default configuration for the npendulum:'
for config_key, value in config.items():
print '\t{}: {}'.format(config_key, value)
environment = env_cls(**config)
Each environment has an update method, we take as argument a motor command vector $m$. It computes $m\_bounds$, the command $m$ bounded according to the configuration used (m_mins, m_maxs values), then computes the corresponding sensory effect vector $s$ and returns the position and velocity of the last effector.
$m$ is a list of ten elements that are the amplitude of each step function.
In [21]:
from math import pi
m = [0.01,0.06,-0.05,0.01,0.,0.,0.,0.,-0.1,0.01]
print environment.update(m)
Then, we add the noise :
In [23]:
s = environment.compute_sensori_effect(m)
print s
The simple arm environment also comes with few methods to visualize the arm shape for a given motor configuration.
The first one plot the position of the end effector at the end of the movement.
In [13]:
%pylab inline
ax = axes()
environment.plot_s(ax, s)
The second one computes and plots the position of the end effector from $m$. In this example, we generate goals and plot them.
In [14]:
%pylab inline
motor_configurations = environment.random_motors(n=5)
ax = axes()
for m in motor_configurations:
environment.plot_and_compute(ax, m)
The third one plots the whole npendulum. The squared point is the end effector.
In [25]:
%pylab inline
motor_configurations = environment.random_motors(n=1)
ax = axes()
for m in motor_configurations:
environment.plot_npendulum(ax, m)
The last one generates .png files that contains the whole pendulum image, in order to create a video. The computation may take few minutes.
In [16]:
%pylab inline
m = [0.01,0.06,-0.05,0.01,0.,0.,0.,0.,-0.1,0.01]
environment.animate_pendulum(m)