@page "/control" @using Pages @using System.Numerics @using EGFramework @implements IEGFramework @rendermode InteractiveServer 空轨控制

空轨控制

当前位置: @dataActionStatus.Position / 25

旋转角度: @dataActionStatus.Rotate°

当前定位点: @(currentLocationName ?? "无")

位置控制

@foreach (var marker in locationMarkers) {
}
@dataActionStatus.Position


快速定位

@foreach (var location in locationMarkers) { }

颜色显示

RGB: @((int)(CurrentColor.X * 255)), @((int)(CurrentColor.Y * 255)), @((int)(CurrentColor.Z * 255)) HSV: @((int)(CurrentHSV.X)), @((int)(CurrentHSV.Y)), @((int)(CurrentHSV.Z))

靶机控制

@if (isMoving) {
移动中...

空轨移动中,请等待...

}
@code { private DataActionStatus dataActionStatus = new DataActionStatus { Position = 0, Rotate = 0 }; private bool isMoving = false; private bool isTargetActive = false; private bool isTargetOperationInProgress = false; private int targetPosition; private string? currentLocationName; private Vector3 CurrentColor = new Vector3(0.5f, 0.5f, 0.5f); // 默认灰色 private Vector3 CurrentHSV = new Vector3(); public ModelTrackControl ModelTrackControl { set; get; } // 定义定位点字典 private Dictionary locationMarkers = new Dictionary { { 0, new Vector3(0.3f, 0.8f, 0.12f) }, // 浅绿 - 起点 { 7, new Vector3(0.1f, 0.5f, 0.2f) }, // 深绿色 - 中间点1 { 10, new Vector3(0.0f, 0.5f, 1.0f) }, // 蓝色 - 中间点2 { 15, new Vector3(0.5f, 0.2f, 0.75f) }, // 紫色 - 中间点3 { 25, new Vector3(0.8f, 0.2f, 0.5f) } // 洋红色 - 终点 }; protected override void OnInitialized() { UpdateCurrentLocationName(); ModelTrackControl = this.GetModule(); } private void OnPositionSliderInput(ChangeEventArgs e) { if (int.TryParse(e.Value?.ToString(), out int value)) { // 寻找最近的定位点 var nearestLocation = locationMarkers.Keys .OrderBy(x => Math.Abs(x - value)) .First(); targetPosition = nearestLocation; UpdateCurrentLocationName(targetPosition); } } private async Task StartScanColor(){ if(ModelTrackControl.IsScanning) return; ModelTrackControl.StartScanColor(); StateHasChanged(); while(ModelTrackControl.IsScanning){ // 更新颜色显示 UpdateCurrentColor(); StateHasChanged(); await Task.Delay(50); } } private async Task MoveToPosition() { if (isMoving) return; isMoving = true; StateHasChanged(); // 模拟移动过程 int steps = Math.Abs(targetPosition - dataActionStatus.Position); int direction = targetPosition > dataActionStatus.Position ? 1 : -1; while(ModelTrackControl.MoveStatus != StatusTrack.Stop) { if(targetPosition!=dataActionStatus.Position){ dataActionStatus.Position += direction; } // 更新颜色显示 UpdateCurrentColor(); StateHasChanged(); await Task.Delay(50); } UpdateCurrentLocationName(); isMoving = false; } private async Task MoveToLocation(int position) { targetPosition = position; this.ModelTrackControl.MoveToPosition(position); await MoveToPosition(); } private async Task ToggleTarget() { if (isTargetOperationInProgress) return; isTargetOperationInProgress = true; StateHasChanged(); isTargetActive = !isTargetActive; if(isTargetActive){ this.ModelTrackControl.StartTarget(); }else{ this.ModelTrackControl.RevertTarget(); } // 模拟靶机操作延迟 await Task.Delay(2000); dataActionStatus.Rotate = isTargetActive ? 90 : 0; isTargetOperationInProgress = false; StateHasChanged(); } private string GetMarkerColor(Vector3 colorVector) { // 将Vector3转换为CSS颜色值 return $"rgb({(int)(colorVector.X * 255)}, {(int)(colorVector.Y * 255)}, {(int)(colorVector.Z * 255)})"; } private string GetColorValue(Vector3 colorVector) { // 将Vector3转换为CSS颜色值 return $"rgb({(int)(colorVector.X * 255)}, {(int)(colorVector.Y * 255)}, {(int)(colorVector.Z * 255)})"; } private string GetLocationName(int position) { return locationMarkers.ContainsKey(position) ? $"定位点 {position}" : position.ToString(); } private void UpdateCurrentLocationName(int? position = null) { int pos = position ?? dataActionStatus.Position; currentLocationName = locationMarkers.ContainsKey(pos) ? $"定位点 {pos}" : null; } private void UpdateCurrentColor() { // 根据传感器检测到的颜色进行更新 CurrentColor = this.ModelTrackControl.GetColor(); CurrentHSV = this.ModelTrackControl.GetColorHSV(); } }