2013/uns13/resources: nengo_robot_example.py

File nengo_robot_example.py, 2.5 KB (added by francesco.galluppi, 5 years ago)

Nengo/SpiNNaker 2D communication channel used to control the robot example

Line 
1"""
22D communication channel, used to manually control the spiNNaker/robot system in a navigation task.
3An input + 3 population are connected in a communication channel:
4
5input (in nengo) --> source --> middle --> target --> nengo/robot
6
7./nengo-cl nengo_spinnaker_interface/viewer_2d.py -n 2d_view -b <spinnaker board address> -d 2 -s 1
8
9The input is provided by the nengo benchmark; the output is sent to both nengo (for visualisation) and to the robot (for control)
10.. moduleauthor:: Francesco Galluppi, University of Manchester, francesco.galluppi@cs.man.ac.uk
11"""
12
13import nef
14
15# importing the Nengo/SpiNNakerinterface module
16import nengo_spinnaker_interface.spinn as spinn
17
18net=nef.Network('2D Representation/Robot')
19
20# Input is used to control the first population, and it's not explicitly modelled in SpiNNaker
21input=net.make_input('input',[0,0])
22
23# source is the population which has input (a 2D vector) as the value it's representing.
24# the source population is encoded as a LIF/NEF neuron, translating a (2D) value coming from input into spiking activity
25source=net.make('source', 100, dimensions=2, quick=True, intercept=(-.9,.9),max_rate=(120,140))
26
27# middle is a LIF neuron, receiving spikes and encoding its output in another population spike train
28middle=net.make('middle', 100, dimensions=2, quick=True, intercept=(-.9,.9),max_rate=(120,140))
29
30# target is a NEF/OUT population, receiving a spike train and translating it into a value to be sent out (to nengo or robot)
31# intercept is set to .1, .9 so to not send small (~0) motor commands
32target=net.make('target', 100, dimensions=2, quick=True, intercept=(.01,.9),max_rate=(120,140))
33
34# connecting the input + 3 population in a communication channel
35# input (in nengo) --> source --> middle --> target --> nengo/robot
36net.connect(input,source)
37net.connect(source,middle)
38net.connect(middle,target)
39
40# values from the target population will be interpreted as 2D motor commands and sent to the robot and to nengo for visualisation
41
42
43# dumps the nengo network in a text file
44#spinn.dump_network(net)
45
46s=spinn.SpiNN(net.network)
47s.set_robot_output('target')
48s.print_info()
49s.write_to_file('nengo_spinnaker_interface/nengo_values.py')
50
51# at this point it is possible to execute the "compile_nengo_model" script in the nengo_spinnaker_interface directory
52# the compile_nengo_model script runs PACMAN and deploys the model on the default_board_address
53#  if run_pacman and run_simulation are set to true in pacman.cfg (nengo_interface section)
54
55# in order to visualise the results use ...