Bašić Nedim - Bakalović Jasmin
PID myPID(&Input, &Output, &Setpoint,4.9,1.81,0.24, REVERSE);
#include <PID_v1.h>
if (Serial.available()>0)
{
int data = Serial.parseInt();
if (newSetpoint==true&&data!=888)
{
Setpoint=data;
Setpoint = map(data, 0, 640, 0, 255);//test
Serial.print("Setpoint:");
Serial.println(Setpoint);
Serial.print("Pixel position");
newSetpoint=false;
}
if (data==888)
{
Serial.println(data);
newSetpoint=true;
}
if (data==0)
{myservoX.write(85);}
else{
// map the X pixel data (0-640) to 0 - 255
Input = map(data, 0, 640, 0, 255);
myPID.Compute();//podesi izlaz PID kontrolera
int OutputX = map(Output, 0, 255, 85, 110);
//Write servo position
myservoX.write(OutputX);
}
}
else if((Serial.available()==0))
{
myservoX.write(85);
}
void setup(){
MySerialport = new Serial(this,"COM11",57600);//serial port setup
size(640,480);//screnn size in pixels
MyWebCam = new JMyron();//call JM
MyWebCam.start(640,480);//
MyWebCam.findGlobs(1); // 1 is on, 0 is off
PFont font; //create font
font = loadFont("Arial-BoldMT-16.vlw");
textFont(font);
}
//=============================================================//
void mousePressed()
{
//Set new Setpoint
Xtarget = mouseX;
MySerialport.write(888+"\n\r");//send command int for arduino
MySerialport.write(Xtarget+"\n\r");//send new setpoint value
//MyWebCam.settings();
}