private void GetMeasures()
{
// Getting AGV's position
pbTerrain.Image = CopyImage(OriginalMap);
Bitmap b = pbTerrain.Image as Bitmap;
Point pPos = new Point(pbRobot.Left - pbTerrain.Left + 5, pbRobot.Top - pbTerrain.Top + 5);
// AGV on the wall
if ((b.GetPixel(pPos.X, pPos.Y).R == 0) && (b.GetPixel(pPos.X, pPos.Y).G == 0) && (b.GetPixel(pPos.X, pPos.Y).B == 0))
{
if (btnRun.Text != RunLabel)
{
btnRun_Click(btnRun, null);
}
string Msg = "The vehicle is on the solid area!";
MessageBox.Show(Msg, "Error!");
throw new Exception(Msg);
}
// Getting distances
Point pFrontObstacle = GetObstacle(pPos, b, -1, 0);
Point pLeftObstacle = GetObstacle(pPos, b, 1, 90);
Point pRightObstacle = GetObstacle(pPos, b, 1, -90);
// Showing beams
Graphics g = Graphics.FromImage(b);
if (cbLasers.Checked)
{
g.DrawLine(new Pen(Color.Green, 1), pFrontObstacle, pPos);
g.DrawLine(new Pen(Color.Red, 1), pLeftObstacle, pPos);
g.DrawLine(new Pen(Color.Red, 1), pRightObstacle, pPos);
}
// Drawing AGV
if (btnRun.Text != RunLabel)
{
g.FillEllipse(new SolidBrush(Color.Navy), pPos.X - 5, pPos.Y - 5, 10, 10);
}
g.DrawImage(b, 0, 0);
g.Dispose();
pbTerrain.Refresh();
// Updating distances texts
txtFront.Text = GetDistance(pPos, pFrontObstacle).ToString();
txtLeft.Text = GetDistance(pPos, pLeftObstacle).ToString();
txtRight.Text = GetDistance(pPos, pRightObstacle).ToString();
}