lengan buatan rasa stik es krim :D

ini nih salah satu tugas di semester yg luarrrr biasa. tugas besar mata kuliah akuisis data dan pengolahan sinyal. awalnya sih bikin sensor kemiringan, dan akhirnya jadi lengan buata gitu. pake 3 axis accelerometer MMA 7361, Arduino, I/O Expansion Shield for Arduino, Arduino UNO dan tidak lupa software Arduino juga Processing.
nih source Arduino nya :
#include <Servo.h>

Servo myservo1;  // menciptakan objek servo untuk mengontrol servo
Servo myservo2;
Servo myservo3;

int val1,val2,val3;    // variabel untuk membaca nilai input analog
float volt1, volt2, volt3; //variabel untuk konversi val menjadi tegangan
float deg1, deg2, deg3; //variabel untuk
float tambah1, tambah2, tambah3;
float g1, g2, g3;
int x, y, z;

void setup()
{
  Serial.begin(9600);
  myservo1.attach(9);  // pin output untuk servo x
  myservo2.attach(11); // pin output untuk servo y
  myservo3.attach(13); // pin output untuk servo z
}

void loop()
{
  val1 = analogRead(0);            // reads the value of the potentiometer (value between 0 and 1023)
  volt1=val1*5.0/1024;
  tambah1=volt1-1.62;
  g1=tambah1/0.8;

 
  val2 = analogRead(2);            // reads the value of the potentiometer (value between 0 and 1023)
  volt2=val2*5.0/1024;
  tambah2=volt2-1.74;
  g2=tambah2/0.8;

 
  val3 = analogRead(4);            // reads the value of the potentiometer (value between 0 and 1023)
  volt3=val3*5.0/1024;
  tambah3=volt3-1.48;
  g3=tambah3/0.8;
  

  if(g1<=1&&g1>=-1) //We use this condition to prevent the overflow of asin(x).( If x>1 or x<-1, asin(x)=0)
  {
  deg1=asin(g1)*180.0/PI;//calculate the degree value
  deg2=asin(g2)*180.0/PI;
  deg3=asin(g3)*180.0/PI;
  }
  //fix the overflow condition
    if(g1>1)
  deg1=90;
    if(g1<-1)
  deg1=-90;
    if(g2>1)
  deg2=90;
    if(g2<-1)
  deg2=-90;
    if(g3>1)
  deg3=90;
    if(g3<-1)
  deg3=-90;
 
    if(deg1>=0) 
  x=deg1+90;
    if(deg1<0)
  x=90+deg1;
    if(deg2>=0)
  y=deg2+90;
    if(deg2<0)
  y=90+deg2;
    if(deg3>=0)
  z=deg3+90;
    if(deg3<0)
  z=90+deg3;
  myservo1.write(180-x);
  myservo2.write(y);
  myservo3.write(z);
 
 //#########################
 //print
  Serial.print(180-x);
  Serial.print(“,”);
  Serial.print(y);
  Serial.print(“,”);
  Serial.print(z);
  Serial.println(“,”);
  delay(200);
}

yang ini source code processing:
import processing.serial.*;

Serial myPort;

float angle1 = 0.0;
float angle2 = 0.0;
float angle3 = 0.0;
float segLength = 100;
PImage a;

  void setup () { println(Serial.list());
  size(487,487);
  a = loadImage(“oke.jpg”);
   myPort = new Serial(this, Serial.list()[1], 9600);
   myPort.bufferUntil(‘\n’);
 
  strokeWeight(10.0);
  stroke(255);
  rectMode(CENTER);
}

void draw(){}

void serialEvent (Serial myPort) {

      float inByte,inByte1,inByte2;
   String inString = myPort.readStringUntil(‘\n’);
   if (inString != null) {
     String[] tokens = inString.split(“,”);
  
     if (tokens.length == 4) {
       background(a);
fill(226);
image(a,0,0);inString = trim(inString);
    
       // rouge
       inByte = int(tokens[0]);
     
       float x1= inByte;
       float x2 = x1/180;
    
       // vert
       inByte1 = int(tokens[1]);
     
       angle1 = radians(inByte1%360);
             inByte2 = int(tokens[2]);
     
       angle2 = radians((180-inByte2)%360);
     
  pushMatrix();
  segment(218, , radians(330%360)); //perlu diedit disini
  segment(x2*segLength, 0, angle1);
  segment(segLength,0,angle2);
  popMatrix();
     }
   }

}

void segment(float x, float y, float a) {
  translate(x, y);
  rotate(a);
  line(0, 0, segLength, 0);}

ini videonya
http://www.youtube.com/watch?v=d5T8JBOT6XU&feature=share

ini oke.jpg nya

semoga bermanfaat.
source codenya dapet dari berbagai sumber terus diedit  Devic Octora+Monica Sari. terimakasih ya teman 🙂
ini lucu-lucuannya
http://www.youtube.com/watch?v=t93VqGhB5eQ&feature=youtu.be

Advertisements

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