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: https://github.com/nengo/nengo and the GUI code here: https://github.com/nengo/nengo_gui, 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>nengo_arm.py</code> file.

As it’s set up right now, it uses a 2-link arm, but you can simply swap out the Arm.py 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!):

nengoarm

Tagged , , , , ,

8 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: Arm.py, nengo_arm.py, nengo_arm.py,cfg, and ran nengo_arm.py. 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/nengo_arm.py”, line 80, in
    nengo_gui.GUI(model=model, filename=__file__, locals=locals(),
    AttributeError: ‘module’ object has no attribute ‘GUI’

    Did I miss anything? .

    Sincerely,

    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!
      Cheers,

      • 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 nengo_arm.py.cfg 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: https://pypi.python.org/pypi/nengo_gui/0.1.5
        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!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: