|
|
|
@ -5,93 +5,13 @@ |
|
|
|
@implements IEGFramework |
|
|
|
@implements IEGFramework |
|
|
|
@rendermode InteractiveServer |
|
|
|
@rendermode InteractiveServer |
|
|
|
|
|
|
|
|
|
|
|
<PageTitle>空轨控制</PageTitle> |
|
|
|
<PageTitle>靶机控制</PageTitle> |
|
|
|
|
|
|
|
|
|
|
|
<h1>空轨控制</h1> |
|
|
|
<h1>靶机控制</h1> |
|
|
|
|
|
|
|
|
|
|
|
<div class="control-panel"> |
|
|
|
<div class="control-panel"> |
|
|
|
<div class="status-display"> |
|
|
|
|
|
|
|
<p>当前位置: <strong>@dataActionStatus.Position</strong> / 25</p> |
|
|
|
|
|
|
|
<p>旋转角度: <strong>@dataActionStatus.Rotate</strong>°</p> |
|
|
|
|
|
|
|
<p>当前定位点: <strong>@(currentLocationName ?? "无")</strong></p> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="control-section"> |
|
|
|
<div class="control-section"> |
|
|
|
<h3>位置控制</h3> |
|
|
|
|
|
|
|
<div class="slider-container"> |
|
|
|
|
|
|
|
<div class="position-markers"> |
|
|
|
|
|
|
|
@foreach (var marker in locationMarkers) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
<div class="position-marker" |
|
|
|
|
|
|
|
style="left: @((marker.Key / 25.0) * 100)%; |
|
|
|
|
|
|
|
background-color: @GetMarkerColor(marker.Value)" |
|
|
|
|
|
|
|
title="@marker.Key - @GetLocationName(marker.Key)"> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<input type="range" |
|
|
|
|
|
|
|
class="form-range location-slider" |
|
|
|
|
|
|
|
min="0" |
|
|
|
|
|
|
|
max="25" |
|
|
|
|
|
|
|
step="1" |
|
|
|
|
|
|
|
value="@dataActionStatus.Position" |
|
|
|
|
|
|
|
@oninput="OnPositionSliderInput" |
|
|
|
|
|
|
|
disabled="@isMoving" /> |
|
|
|
|
|
|
|
<span class="slider-value">@dataActionStatus.Position</span> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="MoveToPosition" disabled="@isMoving"> |
|
|
|
|
|
|
|
@(isMoving ? "移动中..." : "开始移动") |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.EnableTrack" >启用通讯 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.StartTrack" >前进 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.BackTrack" >后退 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.StartSlowTrack" >缓速前进 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.BackSlowTrack" >缓速后退 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.StopTrack" >停止 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.BreakTrack" >刹车 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="StartScanColor" >开启扫描 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button class="btn btn-secondary mt-2" @onclick="@ModelTrackControl.StopScanColor" >结束扫描 |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="control-section"> |
|
|
|
|
|
|
|
<h3>快速定位</h3> |
|
|
|
|
|
|
|
<div class="location-buttons"> |
|
|
|
|
|
|
|
@foreach (var location in locationMarkers) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
<button class="btn location-btn" |
|
|
|
|
|
|
|
style="background-color: @GetMarkerColor(location.Value); color: white" |
|
|
|
|
|
|
|
@onclick="e => MoveToLocation(location.Key)" |
|
|
|
|
|
|
|
disabled="@isMoving"> |
|
|
|
|
|
|
|
@GetLocationName(location.Key) |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="control-section"> |
|
|
|
|
|
|
|
<h3>颜色显示</h3> |
|
|
|
|
|
|
|
<div class="color-display" style="background-color: @GetColorValue(CurrentColor)"> |
|
|
|
|
|
|
|
<span>RGB: @((int)(CurrentColor.X * 255)), @((int)(CurrentColor.Y * 255)), @((int)(CurrentColor.Z * 255)) |
|
|
|
|
|
|
|
HSV: @((int)(CurrentHSV.X)), @((int)(CurrentHSV.Y)), @((int)(CurrentHSV.Z)) |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="control-section"> |
|
|
|
|
|
|
|
<h3>靶机控制</h3> |
|
|
|
|
|
|
|
<button class="btn @(isTargetActive ? "btn-danger" : "btn-success")" |
|
|
|
<button class="btn @(isTargetActive ? "btn-danger" : "btn-success")" |
|
|
|
@onclick="ToggleTarget" |
|
|
|
@onclick="ToggleTarget" |
|
|
|
disabled="@isTargetOperationInProgress"> |
|
|
|
disabled="@isTargetOperationInProgress"> |
|
|
|
@ -123,92 +43,12 @@ |
|
|
|
private bool isMoving = false; |
|
|
|
private bool isMoving = false; |
|
|
|
private bool isTargetActive = false; |
|
|
|
private bool isTargetActive = false; |
|
|
|
private bool isTargetOperationInProgress = 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; } |
|
|
|
public ModelTrackControl ModelTrackControl { set; get; } |
|
|
|
|
|
|
|
|
|
|
|
// 定义定位点字典 |
|
|
|
|
|
|
|
private Dictionary<int, Vector3> locationMarkers = new Dictionary<int, Vector3> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
{ 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() |
|
|
|
protected override void OnInitialized() |
|
|
|
{ |
|
|
|
{ |
|
|
|
UpdateCurrentLocationName(); |
|
|
|
|
|
|
|
ModelTrackControl = this.GetModule<ModelTrackControl>(); |
|
|
|
ModelTrackControl = this.GetModule<ModelTrackControl>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
private async Task ToggleTarget() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (isTargetOperationInProgress) return; |
|
|
|
if (isTargetOperationInProgress) return; |
|
|
|
@ -233,39 +73,6 @@ |
|
|
|
StateHasChanged(); |
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
<style> |
|
|
|
<style> |
|
|
|
|