copilot file backup
This commit is contained in:
@@ -577,8 +577,7 @@ namespace AGVSimulator.Forms
|
||||
_simulatorCanvas.UpdateAGVDirection(selectedAGV.AgvId, selectedDirection);
|
||||
|
||||
// VirtualAGV 객체의 위치와 방향 업데이트
|
||||
selectedAGV.SetPosition(targetNode.Position); // 이전 위치 기억하도록
|
||||
selectedAGV.SetDirection(selectedDirection);
|
||||
selectedAGV.SetPosition(targetNode, targetNode.Position, selectedDirection); // 이전 위치 기억하도록
|
||||
|
||||
// SetPosition 호출 후 상태 확인 및 리프트 계산
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace AGVSimulator.Models
|
||||
/// <summary>
|
||||
/// 위치 변경 이벤트
|
||||
/// </summary>
|
||||
public event EventHandler<Point> PositionChanged;
|
||||
public event EventHandler<(Point, AgvDirection, MapNode)> PositionChanged;
|
||||
|
||||
/// <summary>
|
||||
/// RFID 감지 이벤트
|
||||
@@ -51,27 +51,30 @@ namespace AGVSimulator.Models
|
||||
private string _agvId;
|
||||
private Point _currentPosition;
|
||||
private Point _targetPosition;
|
||||
private string _targetId;
|
||||
private string _currentId;
|
||||
private AgvDirection _currentDirection;
|
||||
private AgvDirection _targetDirection;
|
||||
private AGVState _currentState;
|
||||
private float _currentSpeed;
|
||||
|
||||
|
||||
// 경로 관련
|
||||
private AGVPathResult _currentPath;
|
||||
private List<string> _remainingNodes;
|
||||
private int _currentNodeIndex;
|
||||
private string _currentNodeId;
|
||||
private string _targetNodeId;
|
||||
|
||||
private MapNode _currentNode;
|
||||
private MapNode _targetNode;
|
||||
|
||||
// 이동 관련
|
||||
private System.Windows.Forms.Timer _moveTimer;
|
||||
private DateTime _lastMoveTime;
|
||||
private Point _moveStartPosition;
|
||||
private Point _moveTargetPosition;
|
||||
private float _moveProgress;
|
||||
|
||||
|
||||
// 도킹 관련
|
||||
private DockingDirection _dockingDirection;
|
||||
|
||||
|
||||
// 시뮬레이션 설정
|
||||
private readonly float _moveSpeed = 50.0f; // 픽셀/초
|
||||
private readonly float _rotationSpeed = 90.0f; // 도/초
|
||||
@@ -97,6 +100,7 @@ namespace AGVSimulator.Models
|
||||
|
||||
/// <summary>
|
||||
/// 현재 방향
|
||||
/// 모터의 동작 방향
|
||||
/// </summary>
|
||||
public AgvDirection CurrentDirection
|
||||
{
|
||||
@@ -126,7 +130,7 @@ namespace AGVSimulator.Models
|
||||
/// <summary>
|
||||
/// 현재 노드 ID
|
||||
/// </summary>
|
||||
public string CurrentNodeId => _currentNodeId;
|
||||
public string CurrentNodeId => _currentNode.NodeId;
|
||||
|
||||
/// <summary>
|
||||
/// 목표 위치
|
||||
@@ -141,7 +145,7 @@ namespace AGVSimulator.Models
|
||||
/// <summary>
|
||||
/// 목표 노드 ID
|
||||
/// </summary>
|
||||
public string TargetNodeId => _targetNodeId;
|
||||
public string TargetNodeId => _targetNode.NodeId;
|
||||
|
||||
/// <summary>
|
||||
/// 도킹 방향
|
||||
@@ -166,9 +170,9 @@ namespace AGVSimulator.Models
|
||||
_currentState = AGVState.Idle;
|
||||
_currentSpeed = 0;
|
||||
_dockingDirection = DockingDirection.Forward; // 기본값: 전진 도킹
|
||||
_currentNodeId = string.Empty;
|
||||
_targetNodeId = string.Empty;
|
||||
|
||||
_currentNode = null; // = string.Empty;
|
||||
_targetNode = null;// string.Empty;
|
||||
|
||||
InitializeTimer();
|
||||
}
|
||||
|
||||
@@ -211,21 +215,21 @@ namespace AGVSimulator.Models
|
||||
var startNode = mapNodes.FirstOrDefault(n => n.NodeId == _remainingNodes[0]);
|
||||
if (startNode != null)
|
||||
{
|
||||
_currentNodeId = startNode.NodeId;
|
||||
|
||||
_currentNode = startNode;
|
||||
|
||||
// 목표 노드 설정 (경로의 마지막 노드)
|
||||
if (_remainingNodes.Count > 1)
|
||||
{
|
||||
_targetNodeId = _remainingNodes[_remainingNodes.Count - 1];
|
||||
var _targetNodeId = _remainingNodes[_remainingNodes.Count - 1];
|
||||
var targetNode = mapNodes.FirstOrDefault(n => n.NodeId == _targetNodeId);
|
||||
|
||||
|
||||
// 목표 노드의 타입에 따라 도킹 방향 결정
|
||||
if (targetNode != null)
|
||||
{
|
||||
_dockingDirection = GetDockingDirection(targetNode.Type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StartMovement();
|
||||
}
|
||||
else
|
||||
@@ -266,7 +270,7 @@ namespace AGVSimulator.Models
|
||||
_moveStartPosition = _currentPosition;
|
||||
_moveTargetPosition = targetPosition;
|
||||
_moveProgress = 0;
|
||||
|
||||
|
||||
SetState(AGVState.Moving);
|
||||
_moveTimer.Start();
|
||||
}
|
||||
@@ -281,41 +285,40 @@ namespace AGVSimulator.Models
|
||||
return;
|
||||
|
||||
SetState(AGVState.Rotating);
|
||||
|
||||
|
||||
// 시뮬레이션: 즉시 방향 변경 (실제로는 시간이 걸림)
|
||||
_currentDirection = direction;
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(500); // 회전 시간 시뮬레이션
|
||||
SetState(AGVState.Idle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 방향 직접 설정 (시뮬레이터용)
|
||||
/// </summary>
|
||||
/// <param name="direction">설정할 방향</param>
|
||||
public void SetDirection(AgvDirection direction)
|
||||
{
|
||||
_currentDirection = direction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// AGV 위치 직접 설정 (시뮬레이터용)
|
||||
/// TargetPosition을 이전 위치로 저장하여 리프트 방향 계산이 가능하도록 함
|
||||
/// </summary>
|
||||
/// <param name="newPosition">새로운 위치</param>
|
||||
public void SetPosition(Point newPosition)
|
||||
/// <param name="motorDirection">모터이동방향</param>
|
||||
public void SetPosition(MapNode node, Point newPosition, AgvDirection motorDirection)
|
||||
{
|
||||
// 현재 위치를 이전 위치로 저장 (리프트 방향 계산용)
|
||||
if (_currentPosition != Point.Empty)
|
||||
{
|
||||
_targetPosition = _currentPosition; // 이전 위치 (previousPos 역할)
|
||||
_targetDirection = _currentDirection;
|
||||
_targetNode = node;
|
||||
}
|
||||
|
||||
// 새로운 위치 설정
|
||||
_currentPosition = newPosition;
|
||||
_currentDirection = motorDirection;
|
||||
_currentNode = node;
|
||||
|
||||
// 위치 변경 이벤트 발생
|
||||
PositionChanged?.Invoke(this, _currentPosition);
|
||||
PositionChanged?.Invoke(this, (_currentPosition, _currentDirection, _currentNode));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -384,9 +387,9 @@ namespace AGVSimulator.Models
|
||||
|
||||
UpdateMovement(deltaTime);
|
||||
UpdateBattery(deltaTime);
|
||||
|
||||
|
||||
// 위치 변경 이벤트 발생
|
||||
PositionChanged?.Invoke(this, _currentPosition);
|
||||
PositionChanged?.Invoke(this, (_currentPosition, _currentDirection, _currentNode));
|
||||
}
|
||||
|
||||
private void UpdateMovement(float deltaTime)
|
||||
@@ -396,13 +399,13 @@ namespace AGVSimulator.Models
|
||||
|
||||
// 목표 위치까지의 거리 계산
|
||||
var distance = CalculateDistance(_currentPosition, _moveTargetPosition);
|
||||
|
||||
|
||||
if (distance < 5.0f) // 도달 임계값
|
||||
{
|
||||
// 목표 도달
|
||||
_currentPosition = _moveTargetPosition;
|
||||
_currentSpeed = 0;
|
||||
|
||||
|
||||
// 다음 노드로 이동
|
||||
ProcessNextNode();
|
||||
}
|
||||
@@ -414,7 +417,7 @@ namespace AGVSimulator.Models
|
||||
_moveTargetPosition.X - _currentPosition.X,
|
||||
_moveTargetPosition.Y - _currentPosition.Y
|
||||
);
|
||||
|
||||
|
||||
// 정규화
|
||||
var length = (float)Math.Sqrt(direction.X * direction.X + direction.Y * direction.Y);
|
||||
if (length > 0)
|
||||
@@ -422,13 +425,13 @@ namespace AGVSimulator.Models
|
||||
direction.X /= length;
|
||||
direction.Y /= length;
|
||||
}
|
||||
|
||||
|
||||
// 새 위치 계산
|
||||
_currentPosition = new Point(
|
||||
(int)(_currentPosition.X + direction.X * moveDistance),
|
||||
(int)(_currentPosition.Y + direction.Y * moveDistance)
|
||||
);
|
||||
|
||||
|
||||
_currentSpeed = _moveSpeed;
|
||||
}
|
||||
}
|
||||
@@ -445,9 +448,9 @@ namespace AGVSimulator.Models
|
||||
BatteryLevel += 5.0f * deltaTime; // 충전
|
||||
BatteryLevel = Math.Min(100.0f, BatteryLevel);
|
||||
}
|
||||
|
||||
|
||||
BatteryLevel = Math.Max(0, BatteryLevel);
|
||||
|
||||
|
||||
// 배터리 부족 경고
|
||||
if (BatteryLevel < 20.0f && _currentState != AGVState.Charging)
|
||||
{
|
||||
@@ -469,11 +472,11 @@ namespace AGVSimulator.Models
|
||||
// 다음 노드로 이동
|
||||
_currentNodeIndex++;
|
||||
var nextNodeId = _remainingNodes[_currentNodeIndex];
|
||||
|
||||
|
||||
// RFID 감지 시뮬레이션
|
||||
RfidDetected?.Invoke(this, $"RFID_{nextNodeId}");
|
||||
_currentNodeId = nextNodeId;
|
||||
|
||||
//_currentNodeId = nextNodeId;
|
||||
|
||||
// 다음 목표 위치 설정 (실제로는 맵에서 좌표 가져와야 함)
|
||||
// 여기서는 간단히 현재 위치에서 랜덤 오프셋으로 설정
|
||||
var random = new Random();
|
||||
|
||||
Reference in New Issue
Block a user