edison2
Ecuador
Asked
— Edited
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?
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.
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.
... i am a beginner .. and _camera.UpdatePreview() DJ gave me this code.. someone can help me with a little example?
most of which you can grab from the example program he released just with modifications. He uses the D12 where your using D1-D4
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?
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