Sensing to shape the virtual world

This is a story about what happens when you give a Mechatronics engineer a new toy and a free Friday afternoon.

I’ve always been interested in sensors and how to use the information they collect. After we recently purchased some Arduino boards, I set about exploring different methods of manipulating the virtual world from the physical world. I was looking for an alternative input device to the keyboard and mouse.

After conquering the mandatory “Hello World” program on the Arduino, I started experimenting with some of the sensors. Simpler sensors include those that are sensitive to light, temperature, pressure, sound and movement. This project started with a thermistor (temperature sensitive) and an LDR (light sensitive).

Using the sensed data to manipulate a Rhino model. I used a piece of open source software called UbiMash produced by Flora Salim and her team at SIAL. UbiMash enables a connection between the Arduino board (physical world) and Rhino modelling package (Virtual world).

The following video shows the final product. The shape changes height as the light levels change, and the colour changes as the sensed temperature changes.

What could it be used for? Sculpting models in Rhino? Interactive public art display?

Arduino code (modified version of code supplied by UbiMash):

int ledPin=9;
int ldrPin=1;
int lightVal=0;
int tempPin=2;
int tempVal=0;
void setup()
{
Serial.begin(9600);
Serial.flush();
pinMode(ledPin,OUTPUT);
}
void loop()
{
// for (int i = 0; i < length; i++) {
lightVal=analogRead(ldrPin);
analogWrite(ledPin,lightVal);
delay(lightVal);
analogWrite(ledPin,0);
delay(lightVal);
//Serial.print(i);
Serial.print(“light:”);
Serial.println(lightVal);
//Serial.print(“1: “);
tempVal = analogRead(tempPin);
Serial.print(“temp:”);
Serial.println(tempVal);
}
Rhino Code (some code provided by UbiMash)

Option Explicit

Call Main()
Sub Main()

 
  ‘ Create a new square surface
  Dim sqSize : sqSize = 200
  Dim ptOrigin : ptOrigin = Array(-sqSize,-sqSize,0)
  Dim ptX : ptX = Array(sqSize,-sqSize,0)
  Dim ptY : ptY = Array(-sqSize,sqSize,0)
  Dim dX : dX = Rhino.Distance(ptOrigin, ptX)
  Dim dY : dY = Rhino.Distance(ptOrigin, ptY)
  Dim arrPlane : arrPlane = Rhino.PlaneFromPoints(ptOrigin, ptX, ptY)
  Dim plane : plane = Rhino.AddPlaneSurface(arrPlane, dX, dY)
 
  ‘ Add (and get) more control points to the plane
  Rhino.RebuildSurface plane, Array(2,2), Array(5,5)
  ‘Dim points : points = Rhino.SurfaceEditPoints(plane,False,True)
  Dim j
  Dim sLight, sTemp, resLight, resTemp
  For j=0 To 250 Step 1
    ‘Retrieve ARDUINO Light and Temperature Sensor data
    sLight = “ARD|LIGHT”
    sTemp = “ARD|temp”   
    resLight = getSensorData(sLIGHT)
    resTemp  = getSensorData(sTemp) 
 
    ‘ Print out all control points
    Dim points : points = Rhino.SurfaceEditPoints(plane,False,True)
    Dim i
    For i=0 To UBound(points)
      points(i)(2) = 500 – resLight
    Next  
 
    points(0)(2) = 0
    points(4)(2) = 0   
    points(12)(2) = (500 – resLight) \ 2
    points(20)(2) = 0   
    points(24)(2) = 0
 
    ‘ Move the surface points
    Rhino.DeleteObject(plane)   
    plane = Rhino.AddSrfPtGrid(Array(5,5), points)

    ‘ Change the colour of the object  
    Dim blueCalc, redCalc
    blueCalc = 255 – (255\30) * (resTemp-490)
    If (blueCalc > 255) Then
      bluecalc = 255
    End If
    If (blueCalc < 0) Then
      bluecalc = 0
    End If
   
    redCalc  = (255/30)*(resTemp-490)
    If (redCalc < 0) Then
      redCalc = 0
    End If
    If (redCalc > 255) Then
      redCalc = 255
    End If     
    Call Rhino.Print( “blue: ” & blueCalc & ” red: ” & redCalc)
    Rhino.ObjectColor plane, RGB(redCalc, 0, blueCalc) 

    sleep(125)

  Next 
 
  Rhino.DeleteObject(plane)   
 
 
End Sub

Function getSensorData(varName)

  Dim objPlugIn, objTest
 
  ‘Rhino.Print “Attempting to get ResponsiveRhino”

  ‘ Get the TestRhinoScript plugin’s
  ‘ primary COM visible object
  On Error Resume Next
  Set objPlugIn = Rhino.GetPlugInObject(“ResponsiveRhino”)
  If Err Then
    MsgBox Err.Description
    Exit Function
  Else
    ‘Rhino.Print “Successfully get ResponsiveRhino”   
 
    ‘Get the current light sensor value
    getSensorData = objPlugIn.GetTopicValue(varName)
         
  End If

End Function

Details

About the Author: Andrew Tsakmakis

I am a mechanical engineer involved with the design of buildings and their surrounding environments. I'm interested in the way people interact, respond and attempt to change the environment around them.

Click to read articles by Andrew Tsakmakis (1 articles)

3 Comments

Flora Salim Jul 14, 2010, 8:39

Thanks for posting this, Andrew! Great to see that UbiMash is working for you. I’m in the process of updating UbiMash to a newer version. Check http://ubimash.com or follow our twitter feed (ubimash) to receive updates.

Matt Willcox Jul 27, 2010, 17:22

Anyone know of any Melbourne based groups that might be able to teach a noob like me a thing or two about Arduino? Keen to start tinkering with some of these things but would love some sort of crash course to cover the basics.

Andrew Tsakmakis Jul 30, 2010, 12:29

Matt – There is a great online community of people using the Arduino. The best way to get started is to purchase an “Arduino starter kit” and visit the website (http://arduino.cc/en/Tutorial/HomePage) where you will find lots of useful tutorials and information. Have fun!

Leave a Reply



*

What we're reading

  • No bookmarks avaliable.

Archives

  • [+]2012
  • [+]2011
  • [+]2010
  • [+]2009

Subscribe + Follow