add temp1, temp2
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AGVControl.Models
|
||||
{
|
||||
public enum Direction
|
||||
{
|
||||
Forward = 0,
|
||||
Backward = 1
|
||||
}
|
||||
|
||||
public class AGV
|
||||
{
|
||||
public Point CurrentPosition { get; set; }
|
||||
@@ -19,12 +26,17 @@ namespace AGVControl.Models
|
||||
/// </summary>
|
||||
public Direction TargetDirection { get; set; }
|
||||
public bool IsMoving { get; set; }
|
||||
public List<Point> CurrentPath { get; set; }
|
||||
public List<Point> CurrentPath { get; set; } = new List<Point>();
|
||||
public List<Point> PlannedPath { get; set; }
|
||||
public List<string> PathRFIDs { get; set; }
|
||||
public Point TargetPosition { get; set; }
|
||||
public uint TargetRFID { get; set; }
|
||||
|
||||
// 이동 경로 기록을 위한 새로운 속성들
|
||||
public List<uint> MovementHistory { get; set; } = new List<uint>();
|
||||
public List<Point> PositionHistory { get; set; } = new List<Point>();
|
||||
public const int HISTORY_SIZE = 4; // 최근 4개 위치 기록
|
||||
|
||||
public AGV()
|
||||
{
|
||||
CurrentPath = new List<Point>();
|
||||
@@ -45,12 +57,179 @@ namespace AGVControl.Models
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 이동 경로에 새로운 RFID 추가
|
||||
public void AddToMovementHistory(uint rfidValue, Point position)
|
||||
{
|
||||
// 중복 RFID가 연속으로 들어오는 경우 무시
|
||||
if (MovementHistory.Count > 0 && MovementHistory[MovementHistory.Count - 1] == rfidValue)
|
||||
return;
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
Forward,
|
||||
Backward
|
||||
MovementHistory.Add(rfidValue);
|
||||
PositionHistory.Add(position);
|
||||
|
||||
// 기록 크기 제한
|
||||
if (MovementHistory.Count > HISTORY_SIZE)
|
||||
{
|
||||
MovementHistory.RemoveAt(0);
|
||||
PositionHistory.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
// 연결 정보 기반 실제 이동 방향 계산
|
||||
public Direction? CalculateActualDirectionByConnection(uint currentRFID, uint previousRFID, List<RFIDConnection> connections)
|
||||
{
|
||||
if (connections == null || connections.Count == 0)
|
||||
return null;
|
||||
|
||||
// 이전 RFID에서 현재 RFID로의 연결 확인
|
||||
var connection = connections.FirstOrDefault(c =>
|
||||
(c.StartRFID == previousRFID && c.EndRFID == currentRFID) ||
|
||||
(c.IsBidirectional && c.StartRFID == currentRFID && c.EndRFID == previousRFID));
|
||||
|
||||
if (connection == null)
|
||||
return null; // 연결되지 않은 경로
|
||||
|
||||
// 연결 방향에 따라 실제 이동 방향 결정
|
||||
if (connection.StartRFID == previousRFID && connection.EndRFID == currentRFID)
|
||||
{
|
||||
return Direction.Forward; // Start -> End 방향으로 이동
|
||||
}
|
||||
else
|
||||
{
|
||||
return Direction.Backward; // End -> Start 방향으로 이동
|
||||
}
|
||||
}
|
||||
|
||||
// 연결 정보 기반 방향 불일치 검증 및 정정
|
||||
public bool ValidateAndCorrectDirectionByConnection(Direction expectedDirection, List<RFIDConnection> connections)
|
||||
{
|
||||
if (MovementHistory.Count < 2 || connections == null)
|
||||
return true; // 검증 불가능한 경우
|
||||
|
||||
// 최근 두 RFID 값 가져오기
|
||||
var recentRFIDs = MovementHistory.Skip(Math.Max(0, MovementHistory.Count - 2)).Take(2).ToList();
|
||||
if (recentRFIDs.Count < 2)
|
||||
return true;
|
||||
|
||||
var previousRFID = recentRFIDs[0];
|
||||
var currentRFID = recentRFIDs[1];
|
||||
|
||||
var actualDirection = CalculateActualDirectionByConnection(currentRFID, previousRFID, connections);
|
||||
if (!actualDirection.HasValue)
|
||||
return true; // 연결 정보로 방향 판단 불가
|
||||
|
||||
// 방향이 일치하지 않는 경우
|
||||
if (actualDirection.Value != expectedDirection)
|
||||
{
|
||||
// AGV 방향을 실제 이동 방향으로 정정
|
||||
CurrentDirection = actualDirection.Value;
|
||||
TargetDirection = actualDirection.Value;
|
||||
return false; // 정정됨을 알림
|
||||
}
|
||||
|
||||
return true; // 방향 일치
|
||||
}
|
||||
|
||||
// RFID 순서 기반 실제 이동 방향 계산 (기존 메서드 - 호환성 유지)
|
||||
public Direction? CalculateActualDirectionByRFID()
|
||||
{
|
||||
if (MovementHistory.Count < 2)
|
||||
return null;
|
||||
|
||||
// 최근 두 RFID 값으로부터 실제 이동 방향 계산
|
||||
var recentRFIDs = MovementHistory.Skip(Math.Max(0, MovementHistory.Count - 2)).Take(2).ToList();
|
||||
if (recentRFIDs.Count < 2)
|
||||
return null;
|
||||
|
||||
var prevRFID = recentRFIDs[0];
|
||||
var currentRFID = recentRFIDs[1];
|
||||
|
||||
// RFID 값의 증가/감소로 방향 판단
|
||||
if (currentRFID > prevRFID)
|
||||
{
|
||||
return Direction.Forward; // RFID 값이 증가하면 전진
|
||||
}
|
||||
else if (currentRFID < prevRFID)
|
||||
{
|
||||
return Direction.Backward; // RFID 값이 감소하면 후진
|
||||
}
|
||||
else
|
||||
{
|
||||
return null; // 같은 RFID 값이면 방향 판단 불가
|
||||
}
|
||||
}
|
||||
|
||||
// 경로상 RFID 순서 기반 예상 방향 계산
|
||||
public Direction? CalculateExpectedDirectionByRFID()
|
||||
{
|
||||
if (CurrentPath == null || CurrentPath.Count < 2)
|
||||
return null;
|
||||
|
||||
// 현재 위치의 RFID 찾기
|
||||
var currentRFID = CurrentRFID;
|
||||
if (currentRFID == 0)
|
||||
return null;
|
||||
|
||||
// 경로상 다음 RFID 찾기
|
||||
int currentIdx = CurrentPath.FindIndex(p => p == CurrentPosition);
|
||||
if (currentIdx < 0 || currentIdx >= CurrentPath.Count - 1)
|
||||
return null;
|
||||
|
||||
// 다음 위치의 RFID 찾기 (MapControl에서 RFID 정보 필요)
|
||||
// 이 부분은 MapControl에서 처리하도록 수정 필요
|
||||
return null;
|
||||
}
|
||||
|
||||
// 실제 이동 방향 계산 (기존 메서드 - 호환성 유지)
|
||||
public Direction? CalculateActualDirection()
|
||||
{
|
||||
if (MovementHistory.Count < 2)
|
||||
return null;
|
||||
|
||||
// 최근 두 위치로부터 실제 이동 방향 계산
|
||||
var recentPositions = PositionHistory.Skip(Math.Max(0, PositionHistory.Count - 2)).Take(2).ToList();
|
||||
if (recentPositions.Count < 2)
|
||||
return null;
|
||||
|
||||
var prevPos = recentPositions[0];
|
||||
var currentPos = recentPositions[1];
|
||||
|
||||
// X축 이동이 더 큰 경우
|
||||
if (Math.Abs(currentPos.X - prevPos.X) > Math.Abs(currentPos.Y - prevPos.Y))
|
||||
{
|
||||
return currentPos.X > prevPos.X ? Direction.Forward : Direction.Backward;
|
||||
}
|
||||
// Y축 이동이 더 큰 경우
|
||||
else
|
||||
{
|
||||
return currentPos.Y > prevPos.Y ? Direction.Forward : Direction.Backward;
|
||||
}
|
||||
}
|
||||
|
||||
// 경로상 예상 방향 계산
|
||||
public Direction? CalculateExpectedDirection()
|
||||
{
|
||||
if (CurrentPath == null || CurrentPath.Count < 2)
|
||||
return null;
|
||||
|
||||
int currentIdx = CurrentPath.FindIndex(p => p == CurrentPosition);
|
||||
if (currentIdx < 0 || currentIdx >= CurrentPath.Count - 1)
|
||||
return null;
|
||||
|
||||
var currentPos = CurrentPath[currentIdx];
|
||||
var nextPos = CurrentPath[currentIdx + 1];
|
||||
|
||||
// X축 이동이 더 큰 경우
|
||||
if (Math.Abs(nextPos.X - currentPos.X) > Math.Abs(nextPos.Y - currentPos.Y))
|
||||
{
|
||||
return nextPos.X > currentPos.X ? Direction.Forward : Direction.Backward;
|
||||
}
|
||||
// Y축 이동이 더 큰 경우
|
||||
else
|
||||
{
|
||||
return nextPos.Y > currentPos.Y ? Direction.Forward : Direction.Backward;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PathNode
|
||||
|
||||
Reference in New Issue
Block a user