Setting up an arm simulation interface in Nengo 2

I got an email the other day asking about how to set up an arm controller in Nengo, where they had been working from the Spaun code to strip away things until they had just the motor portion left they could play with. I ended up putting together a quick script to get them started and thought I would share it here in case anyone else was interested. It’s kind of fun because it shows off some of the new GUI and node interfacing. Note that you’ll need nengo_gui version .15+ for this to work. In general I recommend getting the dev version installed, as it’s stable and updates are made all the time improving functionality.

Nengo 1.4 core was all written in Java, with Jython and Python scripting thrown in on top, and since then a lot of work has gone into the re-write of the entire code base for Nengo 2. Nengo 2 is now written in Python, all the scripting is in Python, and we have a kickass GUI and support for running neural simulations on CPUs, GPUs, and specialized neuromorphic hardware like SpiNNaKer. I super recommend checking it out if you’re at all interested in neural modelling, we’ve got a bunch of tutorials up and a very active support board to help with any questions or problems. You can find the simulator code for installation here: and the GUI code here:, where you can also find installation instructions.

And once you have that up and running, to run an arm simulation you can download and run the following code I have up on my GitHub. When you pop it open at the top is a run_in_GUI boolean, which you can use to open the sim up in the GUI, if you set it to False then it will run in the Nengo simulator and once finished will pop up with some basic graphs. Shout out to Terry Stewart for putting together the arm-visualization. It’s a pretty slick little demo of the extensibility of the Nengo GUI, you can see the code for it all in the <code>arm_func</code> in the <code></code> file.

As it’s set up right now, it uses a 2-link arm, but you can simply swap out the file with whatever plant you want to control. And as for the neural model, there isn’t one implemented in here, it’s just a simple input node that runs through a neural population to apply torque to the two joints of the arm. But! It should be a good start for anyone looking to experiment with arm control in Nengo. Here’s what it looks like when you pull it up in the GUI (also note that the arm visualization only appears once you hit the play button!):


Tagged , , , , ,

12 thoughts on “Setting up an arm simulation interface in Nengo 2

  1. Hi,

    Thank you very much for this series of blog post. They are very helpful to me to understand how a robot arm is controlled and to include them into a brief introduction to motor controls in my course, Computational Cognitive Neuroscience, where nengo is the major tool we use.

    I downloaded the three files:,,,cfg, and ran The result is the error message as the following

    Traceback (most recent call last):
    File “C:/Users/User/Anaconda/blog-master/Nengo scripting/arm_control/”, line 80, in
    nengo_gui.GUI(model=model, filename=__file__, locals=locals(),
    AttributeError: ‘module’ object has no attribute ‘GUI’

    Did I miss anything? .


    Shyh-Kang Jeng

    • travisdewolf says:

      Hi Shyh-Kang,

      awesome! So this error actually comes from me writing the script for the latest version of nengo_gui, where we changed the call from nengo_gui.Viz (i think) to nengo_gui.GUI. Three possible solutions! 1) Changing GUI to Viz, should hopefully work, I don’t think any parameters changed just the object name. 2) You can download and install the development version of nengo_gui (up on the github page with instructions there), or 3) there should be another release of nengo_gui with the keyword update that you can pip install this week.

      If any of those options don’t work let me know and we’ll figure something out! Getting the dev version is probably the safest way to go, since there might have been other updates that I’m using in the script, but it’s possible that just the quick change to Viz will work too.
      And if there’s anything else that I can help with in getting some simple examples set up just let me know!

      • Hello, Travis,

        Thank you very much for your help. I tried option 1, changing GUI to Viz, I got a simple interactive plot with only input_node, ens, and arm_node. The sliders and the “robot arm” as well as the diagram in your post did not show up. I can add the sliders and other diagrams in the interactive plot, but not the “arm” animation. I noticed that arm_func.nengo_html is assigned to a HTML-like string enclosed by comment symbols ” ” “, where the motion of arms and joints in the plot seems to be
        described. Thus, is it the problem that the script just ignored it? Or the is not used? Does cfg file better not generated manually, and should be generated on the interactive plot, just like the layout file in nengo 1.4? Where can I get some examples or user guide to better understand it?

        As to the nengo code of development version, I am not familiar with the process, and pass this time. I shall begin to follow the development code in the winter vacation.

      • travisdewolf says:

        The new version of nengo_gui has been released! You can find it here:
        So, hopefully it will just be a matter of installing the update and running the original scripts and it should run.

  2. Hi,
    Thank you very much for the new version of nengo_gui. After installing nengo_gui 0.1.5, I can run the script well, except that the animation of the arm motion is not easy to show up. In fact, that animation is blank in the beginning, and I cannot see the motion of the 2-arm system. How should we tune the input sliders to get the motion of two arms? Is it normal that the robot arm motion animation to be blank?

  3. Dear Travis,

    I am sorry. It works perfectly now. I think I was not patient enough to see the arm_node works. Thanks again for the help.

    • travisdewolf says:

      Great! Really glad to hear, thank you for testing it out for me! Sorry that it didn’t work off the bat, I’ll make sure to add notes about that. Hope that you find it useful!

  4. Zard Liu says:

    Hi Travis,

    Thank you for your post.

    I’m a Master Degree Candidate and my tutor asked me to learn Spaun. I firstly went through the documentations of Spaun on Then I found the Spaun code on and I tried to run the code as what the README says. However, it has errors and cannot run properly.

    I asked many acquaintances who are familiar with python and C++(where I think the error may happen), and searched for solutions on Google but finally failed.

    When I run the Spaun code(python2 -d 512 –ocl –ocl_platform=0 –ocl_device=0), it finally shows the error like

    ImportError: dlopen(/Users/zard/Downloads/spaun2.0-master/_spaun/arms/three_link/, 2): no suitable image found. Did find:
    /Users/liudong/Downloads/spaun2.0-master/_spaun/arms/three_link/ unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00

    when I want to import py3LinkArm.

    The environment of my laptop is ‘OSX El Captian’, do you think this error occurs because of the the OSX environment. And, could you please tell me how to solve this question or give me some advice on how to handle this or do i miss something on this?

    Thank you for taking your time to read my long questions and forgive me for my poor English. I am looking forward to your reply.


    Zard Liu.

    • travisdewolf says:

      Hi Zard,

      Thanks for writing (your english is great!) I’ve run into this problem before, and unfortunately, it’s because of Mac OS. I’ve seen it before, but I’m not sure how to resolve it. It might be possible for you to delete the file, and then run python build_ext -i on the setup file inside the three_link arm file.

      Basically I think the immediate problem is that the .so file was generated for ubuntu systems, and OSX doesn’t know how to read it. So it’s a problem of regenerating the shared object file using cython for a Mac. I’m afraid I don’t have any insight into problems that might come up during this process (and I believe some do crop up). We could explore a few options if you’re not having luck compiling. First I’d ask you to try recompiling the .so file and seeing if that works. If it’s not working then, if you repost here we’ll start trying some more options and figure it out 🙂

      • Zard Liu says:

        Hi Travis,

        I am so happy. After following your advice, I successfully run the code!

        Actually I read the README in the folder where is in and run ‘python build_ext -i ‘ , but nothing happened because I didn’t delete the old file. So the error occurs.

        Thank you very much for your help. I was so touched when i saw your reply, even before I solve my problem, of course I’m very happy for solving my problem with your help. I do not know how to express my gratitude, I can only wish you a happy day!


        Zard Liu.

      • travisdewolf says:

        Ahah excelent! Very glad to hear that it’s working! 😀 You’re very welcome, best of luck exploring the model!

        If you run into any more problems please feel free to send me an email, or post on, or on the Nengo forum I mentioned above.

        We are definitely interested in you being able to run the model!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: