Vision Tracking Robot

Description: This robot uses the EZ-B Vision Color Tracking module. I wanted a robot that would fit a camera in it's head, so this is what I came up with.

Originally, the shell was a toy remote control robot. I emptied the guts, removed the motor mechanism and attached my own servos. The shell had to be modified quite a bit to fit the servos. I used a lot of my hot glue gun to hold the servos in place.

This is a test robot I created to trial a new module that I have been working on. It tracks and follows objects by their color.

The module has the ability to look up and down also, but this hardware platform that I created doesn't have a vertical head servo.

My next robot will look up, down, left and right. But I'm waiting on some parts that I ordered before I can build it.


Video:


Peripherals: 1 x Customized Robot Toy
1 x EZ-Robot Complete Kit [Buy]


Connections:
Servo Head ServoPortEnum.RB4
Left Arm ServoPortEnum.RB2
Right Arm ServoPortEnum.RB1


Development Enviroment: EZ-B Bluetooth Controller Board
C# .Net EZ-B SDK (Version 2010.11.05.01)


Tools: Dremel or Equivalent Tool
Hot Glue Gun


Code: The code for this project is included in the EZ-B SDK. It was written in C# and is a Windows Form application. It also contains the web server for remote control.

The Project is titled Robot Vision Tracking in the EZ-B SDK Sample.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EZ_B;

namespace Tutorial_11___Follow_Red_Object {

  public partial class Form1 : Form {

    EZCommunicator _ezb = new EZCommunicator();

    public Form1() {

      InitializeComponent();

      comboBox1.Items.Clear();
      foreach (DirectX.Capture.VideoCaptureDevice videoCaptureDevice in _ezb.Camera.GetVideoCaptureDeviceList())
        comboBox1.Items.Add(videoCaptureDevice.Name);

      comboBox2.Items.Clear();
      comboBox2.Items.AddRange(_ezb.GetAvailableCommunicationPorts().ToArray());

      comboBox3.Items.Clear();
      foreach (Camera.ColorEnum item in Enum.GetValues(typeof(Camera.ColorEnum)))
        comboBox3.Items.Add(item);

      comboBox3.SelectedIndex = 0;

      timer1.Interval = 200;
      timer1.Enabled = true;
    }

    private void button1_Click(object sender, EventArgs e) {

      if (_ezb.IsConnected) {

        _ezb.Disconnect();
      } else {

        if (comboBox2.SelectedItem == null)
          _ezb.AutoConnect();
        else
          _ezb.Connect(comboBox2.SelectedItem.ToString());
      }

      if (_ezb.IsConnected) {

        button1.Text = "Disconnect";

        _ezb.Servo.SetServoPosition(Servo.ServoPortEnum.RB3, Servo.SERVO_CENTER);
      } else {

        button1.Text = "Connect";
      }
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

      string videoCaptureDeviceName = comboBox1.SelectedItem.ToString();

      _ezb.Camera.StartCamera(_ezb.Camera.GetVideoCaptureDevicebyName(videoCaptureDeviceName), panel1, panel2);
    }

    private void button2_Click(object sender, EventArgs e) {

      _ezb.ShowDebugWindow();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) {

      if (_ezb.IsConnected)
        _ezb.Servo.ReleaseAllServos();

      _ezb.Camera.StopCamera();
    }

    private void timer1_Tick(object sender, EventArgs e) {

      if (!_ezb.Camera.IsActive)
        return;

      Camera.ColorEnum color          = (Camera.ColorEnum)comboBox3.SelectedItem;
      ObjectLocation   objectLocation = _ezb.Camera.GetObjectLocation(
                                          color, 
                                          Camera.SearchObjectSize.Med, 
                                          (byte)trackBar1.Value);

      if (!objectLocation.isFound)
        return;

      if (_ezb.IsConnected) {

        int position = _ezb.Servo.GetServoPosition(Servo.ServoPortEnum.RB3);

        if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Left)
          position++;
        else if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Right)
          position--;

        _ezb.Servo.SetServoPosition(Servo.ServoPortEnum.RB3, position);
      }

      string logMsg = string.Format("Object found at {0} {1} ({2}x{3})", 
        objectLocation.horizontalLocation, 
        objectLocation.verticalLocation, 
        objectLocation.FoundX, 
        objectLocation.FoundY);

      tbLog.AppendText(logMsg);
      tbLog.AppendText(Environment.NewLine);
    }
  }
}