Using a tablet to control grasshopper

Smartphones and tablets become more and more integrated into our way of living. For this tutorial I will explain how to take this one step further and use your smartphone and/or tablet as an input device for grasshopper. In the earlier versions of grasshopper (< 0.6.XXXX) we had the control panel, now we can use an external device as controller.  An example of this is the dancing towers workshop done in collaboration with TheWhyFactory (TUDelft). In this tutorial I will explain how to set up an iPad to control a set of 9 towers.

One of the nice capabilites of grasshopper is the ability to extend its use with plugins. For this tutorial we will combine several plugins: Firefly (for oscRead), DataRecorders and an OSCReader. Make sure you have all three plugins installed and working in Grasshopper (version 0.9.0010 or later). Furthermore you will need TouchOSC installed on your device. This works on both iOS and Android phones. For this tutorial I will use an iPad as example.

You can download the definition that I have setup. In this tutorial I will explain how this is set up and how to get it working.

1. Setting up the iPad interface

Once touchOSC is installed on your device you can start building your own interfaces using the touchOSCEditor (available @ download section). For this tutorial I have prepared an interface (included in the ZIP file). Load this into the editor and take a look at the various tools. You will see that I have set names and ranges for the controls that we will use later to link them in grasshopper. Press the “Sync” button and open touchOSC on your device. In the settings select the layouts and add a new one. If both devices are on the same network you should see your computer popup as device. Select this and the sync will proceed.

When the interface is loaded onto your device select it and it should look like the above setup. The next step is to let the tablet know where to send the data. This communication is done via Wifi using the IP address of the target machine and a designated port. Check your computers IP address and add this to the settings on your device.

2. Grasshopper

The next step is to open grasshopper and load the definition from the tutorial files. In this definition you will see a number of grouped areas which I will explain in the next sections of this tutorials. The general idea of the grasshopper definition is to load the data from the iPad, sort this based on the control names, records this, transform the towers and display them.

Set Base

The first step in the model is setting the geometric base. This consists of 9 squares on the XY plane (the grid). The squares are ordered in 3 set of each 3 squares to match the output of TouchOSC. This might require some experimentation to get it right since you want the order of the 9 squares the be the same as it is on your interface.

Read Data

Now we can start reading the data from our TouchOSC controls. If all previous steps are working the iPad should be transmitting information to our computer. Now it is a matter of setting up the receiving end.

For this we use the OSCListener component from firefly. We use the same port as defined as”Outgoing” port on our iPad. Usually this is port 8000. We also add a button to be able to reset the input. A very important component is the Timer. The timer is set to an interval at which the attached component, in this case the OSC Listener, is updated. Without this component is will only read the start values from the iPad and not update on change. You can set the interval, usually a interval of 50ms works fine for updating the definition. Be careful not to set this to rediculous low values (< 40ms) since this will also trigger a recompute of all attached components which in this case is almost our whole definition. You can check the workings by attaching a panel to the D output and change the sliders on your iPad. The values should be visible in grasshopper.

Selecting Data

Now that we have established the link we can start selecting the right controls. Every control outputs data in the same structured way: a list with the tab and name of the control and the value. Note that the will only be visible once the value is changed.

To make selecting the right data easier use the TouchOSCReader component. Specify the right tab (1 in this case) and the name of the control. The component will output the data if any found.

Record Data

In this particular example we want to be able to control each of the 9 towers by selecting it and modify its height and rotation. This results in a model where data “disappears” when deselecting the tower on the iPad. There we want to record the last value of the controls so the tower is still make correctly.

Both the Height and the Rotation controls are recorded with the recorder set to “Last” value.

Set Default Values

As mentioned in the “Read Data” the data only shows when the control is used. This results in errors when starting the setup. Therefor we setup a default set of values for the towers: All deselected, 0 height and 0 rotation. The script will always select the latest value (those which come from the iPad) if any available, if not it used the default values allowing from the definition to be resolved.

Apply Transformations

Now that all data is available we can start transforming our towers. For this we use some basic grasshopper components as show in the image above. The result is a nicely capped cubic shape.

Display active towers

Finally we want to change to color of the active towers (the ones you select on the ipad) green for active and white for non-active.

The Result

download the definition

1 Comment

  1. by Sander Mulders on June 1, 2013  07:32

    Yes, the wifi network is an important factor in this chain.

Leave a reply