Wednesday, February 3, 2010

ScanTer Experiments 2

 
The ScanTer from Tudor Cosmatu on Vimeo.


The next step after establishing the vital "communication" with the arduino board through the arduino software was to manage to get processing to work with the arduino board.

After numerous failed attempts to do so, we finally came across some very usefull sites and informations (with a little help from our friends).

Therefore here they are:
http://www.arduino.cc/playground/Interfacing/Processing
http://robot-overlord.blogspot.com/2009/04/arduinoprocessing-tutorial.html
http://itp.nyu.edu/physcomp/Tutorials/Tutorials
http://www.dannyg.com/examples/res2/resistor.htm

There were also some failed attempts in trying to communicate with the arduino through the messenger library from the arduino.cc site.

And here a small abstract of what it actually exists for:
Messenger is a "toolkit" that facilitates the parsing of ASCII messages. Messenger processes characters until it receives a carriage return (CR). It then considers the message complete and available. The message is split into many elements as defined by a separator. The default separator is the space character, but can be any character other than NULL, LF or CR. 

In order to make processing work with the arduino board all you need to do is load the firmata example, from arduino, to the arduino board, and then write this code in processing:



/*
  Dessau Institute of Architecture - WS09
 

The ScanTer
 This script is ment to control/link processing with the arduino board in order to control the motion of a RCTank
 The user gets to choose between a square and a circle. once he made his choice, the tank starts performing that particular shape.

 Created 27 January 2010
 By Pula_Team; Tudor Cosmatu & Grygorii Zotov

 based, more or less, on the arduino "Blink" example
 */



//import the serial function
import processing.serial.*;

//import the arduino library
import cc.arduino.*;

Arduino arduino;

//declare the pin number
int LFPin = 5;
int RFPin = 4;
int var = 0;

//declare the PImage
PImage b;

void setup() {
  size(1000, 1000);

  //load the PImage
  b = loadImage("PulaTank.jpg");


  //Set the arduino
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);

  //declare the pinMode for the pins that are going to be used
  arduino.pinMode(LFPin, Arduino.OUTPUT);
  arduino.pinMode(RFPin, Arduino.OUTPUT);
}

void draw() {

  background(0);

  stroke(155);
  noFill(); 

  rectMode(CENTER);
  rect(width/4, height/2,width/3, width/3);

  ellipseMode(CENTER);
  ellipse((width*3)/4, height/2, width/3, width/3);
}

void mousePressed()


  if (mouseX
    //insert this image when mouse is pressed
    image(b,width/4-100, height/2-85);

    // and move the tank in a square
    while (var<3){
      //set both motors on
      arduino.digitalWrite(LFPin, Arduino.HIGH);
      arduino.digitalWrite(RFPin, Arduino.HIGH);   // set the LED off
      //unfortunately since the delay gets called within the draw function, the whole application has quite a lag
      delay(700);
      //turn off one of the motors so that the tank turns slightly
      arduino.digitalWrite(LFPin, Arduino.LOW);
      delay(350);
      var++;
    } 
    //turn off the right motor
    arduino.digitalWrite(RFPin, Arduino.LOW);

    //var gets reset to 0 so that the whole operation can be re-done
    var = 0;
  }


  else{
    //insert this image when mouse is pressed
    image(b,(width*3)/4-100, height/2-60);

    // and move the tank in a square
    while (var<28){
      //set both motors on
      arduino.digitalWrite(LFPin, Arduino.HIGH);
      arduino.digitalWrite(RFPin, Arduino.HIGH);   // set the LED off
      //unfortunately since the delay gets called within the draw function, the whole application has quite a lag
      delay(100);
      //turn off one of the motors so that the tank turns slightly
      arduino.digitalWrite(RFPin, Arduino.LOW);
      arduino.digitalWrite(LFPin, Arduino.HIGH);
      delay(50);
      var++;
    } 
    //turn off the left motor
    arduino.digitalWrite(LFPin, Arduino.LOW);

    //var gets reset to 0 so that the whole operation can be re-done
    var = 0;
  }
}


We took the time to comment everything (so that it's all clear)

By having done this step we're slowly but surely moving towards coding the last bits and pieces for the whole process to become (more or less) real-time.

The hardware problem we have is already visible. As we were mentioning in previous posts the motors of the tank don t have the same speed...


To be continued....

No comments:

Post a Comment