New Project

CONNECT

Arduino Matlab Object Tracking Robot Making

  • Page Views 1362
  • Spread the love
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  

    Make your own robot by image processing with MATLAB in this part of our project, I’ll tell the robots made following the red object.Our project consists of two phases.MATLAB first phase will handle that part of the image.The second stage, according to information coming from MATLAB with Arduino section we manage our robot.In general, our project lines in this way.Now we can begin the construction of our object tracking robot project.

    Materials:

    1. Arduino (model does not matter)
    2. Webcams
    3. L293d or b-series, or if you want you can also use shield.
    4. Motor, wheels and chassis ready whether you want to do it yourself kits can be used in cars or toys.
    5. Battery (LiPo 7.2v or 6V NiMH)

    Electronic Section:

    Circuit connections are as shown.Right engine 10 and 11 digital pins.Left engine digital pins 8 and 95.dijital pin to the speed control pin.pin eNB speed control pin 4.dijital.Let’s consider the Arduino and MATLAB software.

    Software Part:
    Arduino Software:

    // Robimek Robotik Sistemler
    // Yazılım Lisvalns by Robimek
    //www.robimek.com
     
    //motor pinleri
    const int sag_ileri=11;
    const int sag_geri=10;
    const int sol_ileri=9;
    const int sol_geri=8;
    //hız kontrol pin
    const int ena=5;
    const int enb=4;
    //motorların hızı
    const int motor_hiz = 200; // motor hızı
    int led = 13;
    void setup()
    {
    Serial.begin(9600);
    pinMode(led,OUTPUT);
    pinMode(sag_ileri,OUTPUT);
    pinMode(sag_geri,OUTPUT);
    pinMode(sol_ileri,OUTPUT);
    pinMode(sol_geri,OUTPUT);
    pinMode(ena, OUTPUT);
    pinMode(enb, OUTPUT);
    }
     
    void loop()
    {
    int val;
    if (Serial.available())
    {
     
    val=Serial.read();
    if(val=='L')
    {
    analogWrite(ena,motor_hiz);
    analogWrite(enb,motor_hiz);
    digitalWrite(sag_ileri,HIGH);
    digitalWrite(sag_geri,LOW);
    digitalWrite(sol_ileri,LOW);
    digitalWrite(sol_geri,HIGH);
    digitalWrite(led,LOW);
    }
    else if(val=='R')
    {
    analogWrite(ena,motor_hiz);
    analogWrite(enb,motor_hiz);
    digitalWrite(sag_ileri,LOW);
    digitalWrite(sag_geri,HIGH);
    digitalWrite(sol_ileri,HIGH);
    digitalWrite(sol_geri,LOW);
    digitalWrite(led,LOW);
     
    }
    else if(val=='C')
    {
     
    digitalWrite(sag_ileri,LOW);
    digitalWrite(sag_geri,LOW);
    digitalWrite(sol_ileri,LOW);
    digitalWrite(sol_geri,LOW);
    digitalWrite(led,HIGH);
    }
    else if(val=='F')
    {
    analogWrite(ena,motor_hiz);
    analogWrite(enb,motor_hiz);
    digitalWrite(sag_ileri,HIGH);
    digitalWrite(sag_geri,LOW);
    digitalWrite(sol_ileri,HIGH);
    digitalWrite(sol_geri,LOW);
    digitalWrite(led,HIGH);
     
    }
    else if(val=='B')
    {
    analogWrite(ena,motor_hiz);
    analogWrite(enb,motor_hiz);
    digitalWrite(sag_ileri,LOW);
    digitalWrite(sag_geri,HIGH);
    digitalWrite(sol_ileri,LOW);
    digitalWrite(sol_geri,HIGH);
    digitalWrite(led,HIGH);
     
    }
    else
    digitalWrite(led,LOW);
    }
    }

    I’m uploading the Arduino software.
    MATLAB now also open a new page with the following code Let’s just put the script.
    Matlab Software:

    vid = videoinput('winvideo',1);
    set(vid, 'FramesPerTrigger', Inf);
    set(vid, 'ReturnedColorspace', 'rgb')
    vid.FrameGrabInterval = 3;
    s = serial('COM5','BaudRate',9600);
    fopen(s);
    start(vid)
    i=1;
    q=1;
    c='A';
    min=5500;
    max=10500;
    while(i<=300)
    i=i+1;
    obj_found=0;
    data = getsnapshot(vid);
    [y x c]=size(data);
    x1=x/2;
    x2=x1-40;
    x3=x1+40;
    % IMAGE SEPERATION BLOCK ---------------------
     
    diff_im = imsubtract(data(:,:,1), rgb2gray(data));
    diff_im = medfilt2(diff_im, [3 3]);
    diff_im = im2bw(diff_im,0.18);
    diff_im = bwareaopen(diff_im,300);
    bw = bwlabel(diff_im, 8);
    stats = regionprops(bw, 'all');
    imshow(data)
    hold on
     
    for object = 1:length(stats)
    obj_found=1;
    bb = stats(object).BoundingBox;
    bc = stats(object).Centroid;
    ar=stats(object).Area;
    rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
    plot(bc(1),bc(2), '-m+')
     
    pix=((((ar<=max)&(ar>=min))*2)+((ar>max)*4)+((ar<min)*5)); if (bc(1)>x2)&(bc(1)<x3)
    disp('merkez')
    switch (pix)
    case 2
    r=1;
    case 4
    r=4;
    case 5
    r=5;
    end
     
    else if bc(1)<x2 r=2; disp('sol') else if bc(1)>x3
    r=3;
    disp('sag')
    else
    end
    end
    end
     
    y1=1:y;
    plot(x2,y1);
    plot(x3,y1);
    switch(r)
    case 1
    fwrite(s,'C');
    case 2
    fwrite(s,'L');
    case 3
    fwrite(s,'R');
    case 4
    fwrite(s,'B');
    case 5
    fwrite(s,'F');
    otherwise
    fwrite(s,'N');
    end
    end
    if obj_found == 0
    fwrite(s,'C');
    disp('resim yok')
    end
     
     
    hold off
    end
    fwrite(s,'C');
    stop(vid);
    flushdata(vid);
    fclose(s);
    clear all

    That part of the port address in Matlab n = serial (‘COM5 “,” baudrate “, 9600);Change the port number that is attached Arduino COM5 written statement in this section.Webcams camera into the computer.Vid = videoinput in the software part (‘winvideo’, 1); in line “1” shall indicate the number of cameras installed in the computer.So now if you run the computer will open its camera.A second camera installed, this value must be changed.So “2” Run the yapılmalıdır.matlab programs.If your robot is ready for all transactions take place successfully.Now that you show a red object location of the object and the camera will move the robot will be to follow the subject.

    You can download all software files here. >> MATLAB object tracking robot

    Make your own robot following our project we had our robot Arduino-based object with Matlab in this section.

    Share

    What did they say ?

    First Comment About You!!

    avatar
    wpDiscuz

    BE A FACEBOOK FAN

    Instagram