User Tools

Site Tools


darwin_color_detection

This is an old revision of the document!


How to Use Darwin OP 2's Computer Vision

Author: Yu Hang He Email: hey6@unlv.nevada.edu
Date: Last modified on <11/19/17>
Keywords: Darwin OP 2, C++/C Programming, Robotis OP 2, Computer Vision


This tutorial will demonstrate how to use vision processing capability on Darwin OP 2 to detect and track color. Darwin OP 2 have computer vision that can detect multiple colors and return x and y center position of those colors. A second class will move camera to keep track of color based on x and y position. It takes approximately 2 hours to complete.

Motivation and Audience

This tutorial's motivation is to demonstrate how to use computer vision on Darwin OP 2. This tutorial assumes the reader has the following background and interests:

  • Familiar with handling Darwin OP 2
  • Familiar with C++/C programming language
  • Familiar with C++/C codes on Darwin OP 2
  • Interested in computer vision

The rest of this tutorial is presented as follows:

Color Detection

The core of image processing on Darwin OP 2 is ColorFinder class. ColorFinder can find the center of mass of detected color and return its location. There is a tutorial on Robotis' online manual that can provide more insights.

ColorFinder class requires 5 input color parameters: hue, tolerance, minimum saturation, minimum value, gain, and exposure. To find the most accurate set of values for the color you want to detect, use the color_filtering program on Darwin OP 2.

Use terminal and go to directory /robotisop2/Linux/project/tutorial/color_filtering

Type in make and execute the program ./color_filtering.


Once the program is running, open web browser and type in the address http://192.168.123.1:8080


Now you can adjust the values until Darwin OP 2 properly detect your color.

In this example, I am trying to detect a blue color.

Before adjustments


Afterward


The adjusted values are:

  • Hue: 225
  • Tolerance: 15
  • Minimum Saturation: 45
  • Minimum Value: 0
  • Gain: 0.3
  • Exposure: 50.0

Programming

This tutorial will demonstrate how to create a new ColorFinder object and how to implement it in demo program.

main.cpp can be found under directory /robotisop2/Linux/project/demo

| main.cpp
//declare a new object of class ColorFinder
ColorFinder* finder = new ColorFinder();
//you can initiate the object with 5 input color parameters
//Example 
ColorFinder* green_finder = new ColorFinder(120, 45, 35, 0, 0.3, 40.0);
//There are default values of color you can load from ini file. Example
finder->LoadINISettings(ini, "RED"); 
//To get the position of center of mass of filtered pixels
Point2D pos;
pos = finder->GetPosition(LinuxCamera::GetInstance()->fbuffer->m_HSVFrame);
//first declare an object of class Point2D
//then set it equal to GetPosition function of ColorFinder object
| StatusCheck.cpp
//At the end of if statement Line 141
if(m_old_btn & BTN_MODE)
        ///////////////////////////
        //////////////////////////
        //////////////////////////
        else if(m_cur_mode == SPRINT) //adding LED and play mp3 for new mode
        {
            cm730.WriteByte(CM730::P_LED_PANNEL, 0x01|0x04, NULL);
            //Signaling Darwin OP 2 which LED to turn on
            LinuxActionScript::PlayMP3("../../../Data/mp3/New_Mode mode.mp3");
            //play an mp3 file (you can use any mp3 file but make sure file name matches)
        }
    }
 
// Line 267 Add
  else if(m_cur_mode == NEW_MODE)
  {
      MotionManager::GetInstance()->Reinitialize();
      MotionManager::GetInstance()->SetEnable(true);
      //initialize and enable MotionManager class
      m_is_started = 1;
      LinuxActionScript::PlayMP3("../../../Data/mp3/Start New_Mode demonstration.mp3");
      //play an mp3 file (you can use any mp3 file but make sure file name matches)
 
      // Joint Enable...
      Action::GetInstance()->m_Joint.SetEnableBody(true, true);
 
      Action::GetInstance()->Start(9);
      while(Action::GetInstance()->IsRunning() == true) usleep(8000);
 
      Head::GetInstance()->m_Joint.SetEnableHeadOnly(true, true);
      Walking::GetInstance()->m_Joint.SetEnableBodyWithoutHead(true, true);
      //Reset Gyro sensor
      MotionManager::GetInstance()->ResetGyroCalibration();
      while(1)
      {
          if(MotionManager::GetInstance()->GetCalibrationStatus() == 1)
          {
              LinuxActionScript::PlayMP3("../../../Data/mp3/Sensor calibration complete.mp3");
              break;
          }
          else if(MotionManager::GetInstance()->GetCalibrationStatus() == -1)
          {
              LinuxActionScript::PlayMP3Wait("../../../Data/mp3/Sensor calibration fail.mp3");
              MotionManager::GetInstance()->ResetGyroCalibration();
          }
          usleep(8000);
      }
  //copied status check condition from soccer mode to new mode
  //These codes initialize Darwin OP 2 for movement and walking
| main.cpp
//L317 Add
  case New_Mode:
  //implement new codes here to execute after pressing start button

Camera Tracking

Programming

Demonstration

In this demonstration, I created a new mode called Sprint mode following the previous step and successfully execute it on Darwin OP 2.

Final Words

This tutorial's objective was to demonstrate how to add a new mode to Darwin OP 2's demo program. Follow this tutorial to quickly implement and test new codes on Darwin OP 2.

For questions, clarifications, etc, Email: hey6@unlv.nevada.edu

darwin_color_detection.1511134858.txt.gz · Last modified: by yuhanghe