Asked — Edited
Resolved Resolved by DJ Sures!

Ar Drone Does Not Find Object Location

I am trying to create an application that will track a green tennis ball but I am having problems with finding the location the ball. Here's the code that I think is incorrect, how can I change it find the location of the ball?

Thank you!

private void timer_Tick(object sender, EventArgs e) { camera = new Camera(ezB_Connect1.EZB); ezB_Connect1.EZB.Movement.MovementType = EZ_B.Movement.MovementTypeEnum.ARDrone; ObjectLocation objectLocation = camera.CameraBasicColorDetection.GetObjectLocationByColor(true, ColorDetection.ColorEnum.Green, 10, 100);

    //camera.UpdatePreview();
    if (!objectLocation.isFound)
        tbLog.Text = "found not object";
    if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Left)
        ezB_Connect1.EZB.Movement.GoLeft();
    else if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Right)
        ezB_Connect1.EZB.Movement.GoRight();
    else if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Middle)
        ezB_Connect1.EZB.Movement.GoForward();
}


ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

PRO
Synthiam
#1  

download the EZ-SDK and take a look at the tracking examples.

  1. All detection needs to be done in the OnNewFrame event. For example, take a look at the code for Tutorial 11

  2. Only set the MovementType once. Set it in the Form Load event


using System;
using System.Diagnostics;
using System.Windows.Forms;
using EZ_B;
using EZ_B.CameraDetection;
using System.Drawing;

namespace Tutorial_11___Follow_Red_Object {

  public partial class Form1 : Form {

    Stopwatch _stopWatch = new Stopwatch();
    Camera    _camera;

    public Form1() {

      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e) {

      _camera = new Camera(ezB_Connect1.EZB);
      _camera.OnNewFrame += new Camera.OnNewFrameHandler(_camera_OnNewFrame);

      comboBox1.Items.Clear();
      comboBox1.Items.AddRange(Camera.GetVideoCaptureDevices());

      scLumMax.Value = 1f;
      scSatMax.Value = 1f;
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

      ValuePair videoCaptureDeviceName = (ValuePair) comboBox1.SelectedItem;

      _camera.StartCamera(videoCaptureDeviceName, panel1, panel2, 320, 240);

      Log("Video started: {0}", videoCaptureDeviceName.Text);
    }

    private void Log(object txt, params object[] values) {

      Invokers.SetAppendText(tbLog, true, txt.ToString(), values);
    }

    void _camera_OnNewFrame() {

      try {

        ObjectLocation objectLocation = _camera.CameraCustomColorDetection.GetObjectLocationByColor(
          Invokers.GetCheckedValue(cbPreviewDetect),
          Invokers.GetTrackBarValue(tbMinObjectSize),
          huePicker1.Min,
          huePicker1.Max,
          scSatMin.Value,
          scSatMax.Value,
          scLumMin.Value,
          scLumMax.Value);

        _camera.UpdatePreview();

        if (objectLocation.IsObjectFound) {

          Log("Object found at {0} {1}", objectLocation.HorizontalLocation, objectLocation.VerticalLocation);

          if (ezB_Connect1.EZB.IsConnected) {

            int position = ezB_Connect1.EZB.Servo.GetServoPosition(Servo.ServoPortEnum.D12);

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

            ezB_Connect1.EZB.Servo.SetServoPosition(Servo.ServoPortEnum.D12, position);
          }
        }
      } catch (Exception ex) {

        Log(ex);
      }
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) {

      _camera.StopCamera();
    }
  }
}

#2  

Thank your for your reply DJ! I looked at the code to for the movement of various robots. I am still not able to get the AR Drone off the ground. I received following error when I tried to start my camera using the code.


4/30/2014 10:58:20 PM - 4/30/2014 10:58 PM - Error Initializing Camera: System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 192.168.1.1:24
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
   at EZ_B.EZBv4Video.Start(EZB ezb, String ipAddress, Int32 port)
   at EZ_B.Camera.StartCamera(ValuePair videoCaptureDevice, Control processedPreviewControl, Control realtimePreviewControl, Int32 captureWidth, Int32 captureHeight). Resolution: 320x240

Also, I am not able to use

camera_OnNewFrame

with AR Drone. My Visual Studio would not find the method. The only method that would work was

ARDroneControl_OnImagecomplete(Image image)

and this method would not work when dealing with following colored objects.

PRO
Synthiam
#3  

What version of the AR Parrot Drone do you have? Our SDK currently only works with v1. I have time allocated in the future this summer to add support for v2... but our priorities currently are getting the product out the door :)

#4  

I am on AR Drone V1.0 and the firmware is 1.7.10

I believe this is not the current firmware. Do I need to upgrade to the latest firmware version for the SDK to work?

#5  

Good to hear V2 support is coming. My wife just bought me one for my birthday.

You should be aware that with the latest firmware, the Drone can connect to an infrastructure network and no longer needs to create its own ad-hoc network, so being able to specify the IP address of the drone to the EZ-B controls would be a great addition (as well as the long awaited support for the V2 camera).

Alan

#6  

I think I figured out answer to this question. Thanks!