Plotting from NPendulum Environment

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())


Available environments: ['npendulum', 'pendulum', 'simple_arm']

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())


Available configurations for the simple arm environment: ['default']

In the case of the npendulum environment, a configuration must defines the following values:

  • nb_joints (number $n$ of the joints)
  • m_mins and m_maxs (bounds of the motor space)
  • s_mins ans s_maxs (bounds of the sensory space)
  • length_ratio (length ratio from one segment to the following one)
  • noise (gaussian noise added in the sensor space)

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)


Default configuration for the npendulum:
	s_mins: [-450.   -1.]
	m_mins: [-0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1]
	noise: 0.02
	s_maxs: [ 450.    1.]
	m_maxs: [ 0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1]
	n: 5

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)


[  1.00000000e-02   6.00000000e-02  -5.00000000e-02   1.00000000e-02
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
  -1.00000000e-01   1.00000000e-02   8.15708828e+01  -6.32193953e-01]

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)


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['pi']
`%matplotlib` prevents importing * from pylab and numpy

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)


Populating the interactive namespace from numpy and matplotlib

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)


Populating the interactive namespace from numpy and matplotlib

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)


Populating the interactive namespace from numpy and matplotlib
<matplotlib.figure.Figure at 0x7fb4f5fc7b50>