Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Kapazitives Raumtracking

28. September 2012

Unsere ursprüngliche Idee, ein grossflächiges Raumtracking zu erstellen, ohne optische Sensoren, wollten wir mit diesem kleineren Raumtracking technisch überprüfen. Kapazitive Sensoren aus Aluminium und Kupfer haben aber eine physikalisch max. Reichweite von 15cm. Unsere selbstgemachten Sensoren erreichten eine Weite von 10cm. In der Grösse der Fläche konnten wir bisher keine Limitierung der Sensorkapazität feststellen. Um die elektromagnetischen Felder zu begrenzen und auszurichten, haben wir die Sensorflächen mit einem geerdeten Leiter eingerahmt. Für Kurzdistanz-Tracking haben sich die kapazitiven Sensoren hervorragend bewährt. Einen Unterschied in der Sensorausgabe zwischen Aluminium und Kupfer als Sensorflächen, konnten wir nicht feststellen. Für grössere Distanzen sollte man beispielsweise auf optische Sensoren umsteigen. Arduino Code:
#include <CapacitiveSensor.h>

/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10M between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 */
float finalValue1;
float finalValue2;
float finalValue3;
float finalValue4;

CapacitiveSensor   cs_2_3 = CapacitiveSensor(3,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_4_5 = CapacitiveSensor(5,4);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_6_7 = CapacitiveSensor(7,6);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_8_9 = CapacitiveSensor(9,8);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired

float lasttotal1, lasttotal2, lasttotal3, lasttotal4;
float lasttotal1b, lasttotal2b, lasttotal3b, lasttotal4b;
float lasttotal1c, lasttotal2c, lasttotal3c, lasttotal4c;
float lasttotal1d, lasttotal2d, lasttotal3d, lasttotal4d;
float lasttotal1e, lasttotal2e, lasttotal3e, lasttotal4e;
int i=0;

void setup()                   
{
   cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   cs_4_5.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   cs_6_7.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   cs_8_9.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()                   
{
    long start = millis();
    long total1 =  cs_2_3.capacitiveSensor(100);
    long total2 =  cs_4_5.capacitiveSensor(100);
    long total3 =  cs_6_7.capacitiveSensor(100);
    long total4 =  cs_8_9.capacitiveSensor(100);

float finalValue1 = sqrt((total1+lasttotal1+lasttotal1b+lasttotal1c+lasttotal1d+lasttotal1e)/6);
float finalValue2 = sqrt((total2+lasttotal2+lasttotal2b+lasttotal2c+lasttotal2d+lasttotal2e)/6);
float finalValue3 = sqrt((total3+lasttotal3+lasttotal3b+lasttotal3c+lasttotal3d+lasttotal3e)/6);
float finalValue4 = sqrt((total4+lasttotal4+lasttotal4b+lasttotal4c+lasttotal4d+lasttotal4e)/6);

finalValue1= constrain(finalValue1, 2, 8);
finalValue2= constrain(finalValue2, 2, 8);
finalValue3= constrain(finalValue3, 2, 8);
finalValue4= constrain(finalValue4, 2, 8);


    Serial.print(finalValue1);
    Serial.print(",");
    Serial.print(finalValue2);                  // print sensor output 1
    Serial.print(",");
    Serial.print(finalValue3);                  // print sensor output 1
    Serial.print(",");
    Serial.print(finalValue4);                  // print sensor output 1
    Serial.print(",");
    Serial.println(); // Send a carriage-return
   
    delay(10);                             // arbitrary delay to limit data to serial port
    
    
    if( i==0)
   {
    total1 = lasttotal1;
    total2 = lasttotal2;
    total3 = lasttotal3;
    total4 = lasttotal4;
   }
   else if( i==1)
   {
    total1 = lasttotal1b;
    total2 = lasttotal2b;
    total3 = lasttotal3b;
    total4 = lasttotal4b;
   }
      else if( i==2)
   {
       total1 = lasttotal1c;
    total2 = lasttotal2c;
    total3 = lasttotal3c;
    total4 = lasttotal4c;
   }
      else if( i==3)
   {
       total1 = lasttotal1d;
    total2 = lasttotal2d;
    total3 = lasttotal3d;
    total4 = lasttotal4d;
   }
      else if( i==4)
   {
       total1 = lasttotal1e;
    total2 = lasttotal2e;
    total3 = lasttotal3e;
    total4 = lasttotal4e;
   }

i++;
if (i>4)
{
i==0;
}

}
Processing Code:
import processing.serial.*;  // Import the Processing Serial Library for communicating with arduino
import processing.opengl.*;
Serial myPort;               // The used Serial Port

float firstValue, secondValue, thirdValue, fourthValue; // fourthValue, fifthValue, ... // add more if needed

void setup() {
  size(1920, 1080, OPENGL);
  smooth();
  //println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
  myPort = new Serial(this, Serial.list()[1], 9600); // Open a new port and connect with Arduino at 9600 baud
}

void draw() {
  background(100);

  noStroke();
  lights();
  translate(960, 540,+200);
  translate(((secondValue+thirdValue)-(firstValue+fourthValue))*200,((thirdValue+fourthValue)-(firstValue+secondValue))*200,(thirdValue+fourthValue+firstValue+secondValue)*-100);
  //translate((firstValue*-0.1)+800, secondValue*01, thirdValue*-1);
  sphere(200);
}

void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
  if (myPort.available() > 0)
  {
    String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
    if (completeString != null) // If there is valid data insode the String
    {
      trim(completeString); // Remove whitespace characters at the beginning and end of the string
      String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
      firstValue = float(seperateValues[0]);
      secondValue = float(seperateValues[1]);
      thirdValue = float(seperateValues[2]);
      fourthValue = float(seperateValues[3]);
    }
  }
  
}