Ecuador
Asked — Edited

Ez-B Is Crazy! When A Color Is Following.. Help :(

Hi!... I have been developing my own application for Ez-B.. my robot is following a color, it is fine, but when I remove the color, the robot is moving in the direction where he saw last color I am using an Hbridge... here is the code...


private void timer1_Tick(object sender, EventArgs e)
    {

        if (!_camera.IsActive)
            return;
        {
            ColorDetection.ColorEnum color = (ColorDetection.ColorEnum)comboBox3.SelectedItem;
            ObjectLocation objectLocation = _camera.CameraBasicColorDetection.GetObjectLocationByColor(color, 10, (byte)trackBar1.Value);

            _camera.UpdatePreview();
            {
                if (!objectLocation.isFound)
                    return;
                {

                    if (checkservo.Checked)
                    {

                        int position = _ezb.Servo.GetServoPosition(Servo.ServoPortEnum.D12);
                        int positiony = _ezb.Servo.GetServoPosition(Servo.ServoPortEnum.D13);

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

                        _ezb.Servo.SetServoPosition(Servo.ServoPortEnum.D12, position);

                        if (objectLocation.verticalLocation == ObjectLocation.VerticalLocationEnum.Top)
                            positiony++;
                        else if (objectLocation.verticalLocation == ObjectLocation.VerticalLocationEnum.Bottom)
                            positiony--;

                        _ezb.Servo.SetServoPosition(Servo.ServoPortEnum.D13, positiony);
                    }

                    else if (checkmovimiento.Checked)
                    {
                        if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Left)
                        {
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D1, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D2, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D3, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D4, false);
                        }
                        else if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Right)
                        {
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D1, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D2, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D3, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D4, true);
                        }
                        else if (objectLocation.verticalLocation == ObjectLocation.VerticalLocationEnum.Middle)
                        {
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D1, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D2, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D3, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D4, false);
                        }
                        else if (objectLocation.verticalLocation == ObjectLocation.VerticalLocationEnum.Top)
                        {
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D1, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D2, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D3, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D4, false);
                        }
                        else if (objectLocation.verticalLocation == ObjectLocation.VerticalLocationEnum.Bottom)
                        {
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D1, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D2, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D3, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D4, false);
                        }
                        else if (objectLocation.horizontalLocation == ObjectLocation.HorizontalLocationEnum.Middle)
                        {
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D1, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D2, false);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D3, true);
                            _ezb.Digital.SetDigitalPort(Digital.DigitalPortEnum.D4, false);
                        }
                    }




                    string logMsg = string.Format("Objeto encontrado: {0} {1}", objectLocation.horizontalLocation, objectLocation.verticalLocation);

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

            }
        }

    }

how do I get the robot when it detects anything stand still?

User-inserted image


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.

#1  

This may or may not be related to your problem but sometime when i start color/face/motion tracking, my robot just turn itself all the way to one side until i put something in front of him, then he will work as normal. Very strange! Hope DJ has some pointers at this.

#2  

reason for the brackets for _camera.UpdatePreview(); this should just be calling for and update on the camera console not a routine to be run within. Though I doubt this would be the solution. Secondly after the returns; there is no reason for the brackets as well.

Ecuador
#3  

... i am a beginner:) .. and _camera.UpdatePreview() DJ gave me this code.. someone can help me with a little example?

#4  

most of which you can grab from the example program he released just with modifications. He uses the D12 where your using D1-D4

PRO
Synthiam
#5  

the answer to this is within your question ...:)

*hint: Where is your code to tell the robot to stop when an object is not found?

Ecuador
#6  

all the night I have been writing the code... but.. I can not find the form to stop my robot... can you help me with a little example?? in my code ?? thank you very much:(

PRO
Synthiam
#7  


                if (!objectLocation.isFound) {
                  
                  // STOP CODE HERE

                  return;
                }