diff --git a/Components/Layout/NavMenu.razor b/Components/Layout/NavMenu.razor index 91b07fe..234a450 100644 --- a/Components/Layout/NavMenu.razor +++ b/Components/Layout/NavMenu.razor @@ -1,6 +1,6 @@  @@ -10,7 +10,7 @@ diff --git a/Components/Pages/Control.razor b/Components/Pages/Control.razor new file mode 100644 index 0000000..6776c80 --- /dev/null +++ b/Components/Pages/Control.razor @@ -0,0 +1,365 @@ +@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(); + } +} + + \ No newline at end of file diff --git a/Components/Pages/Home.razor b/Components/Pages/Home.razor index 9001e0b..e1cdc45 100644 --- a/Components/Pages/Home.razor +++ b/Components/Pages/Home.razor @@ -1,7 +1,82 @@ @page "/" -Home +博裕空轨管理平台 -

Hello, world!

+
+
+
+
+

欢迎使用

+

博裕空轨设备管理系统

+

高效、精准的空轨设备控制与监控解决方案

+
+
+
-Welcome to your new app. +
+
+
+
+

系统功能简介

+
+
+

博裕空轨设备管理系统是一款先进的自动化控制解决方案,专为工业空轨设备设计。系统提供精确的位置控制、靶机角度调节、运动参数配置和实时状态监控功能。

+ +
+
+
位置控制功能
+

系统可以精确控制空轨设备前进和后退到指定位置,实现毫米级精确定位,满足各种工业场景的定位需求。

+
+
+
靶机测转功能
+

空轨下方的靶机可以进行0-90度的精确测转,用户可通过系统界面直观地设置和监控靶机角度。

+
+
+
运动参数配置
+

系统提供完善的运动参数配置功能,包括速度、加速度、减速度等参数设置,用户可根据实际需求灵活调整。

+
+
+
色标传感器监控
+

实时查看空轨当前色标传感器的颜色状态,系统提供直观的颜色显示和状态提示功能。

+
+
+
+
+
+
+ +
+
+
+
立即开始使用系统
+

请使用右侧导航菜单访问各个功能模块,或联系山东博裕获取相关帮助。

+
+
+
+
+ + diff --git a/Components/Pages/ParamSetting.razor b/Components/Pages/ParamSetting.razor new file mode 100644 index 0000000..10e5615 --- /dev/null +++ b/Components/Pages/ParamSetting.razor @@ -0,0 +1,386 @@ +@page "/paramSetting" +@using EGFramework +@using Pages +@using System.Numerics +@implements IEGFramework +@rendermode InteractiveServer + +参数设置 +

参数设置

+ + + + + +
+ +

基本设置

+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+

颜色映射设置

+ +
+ + @foreach (var color in DataSettings.ColorMapping) + { +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ } +
+ + +
+ + +
+
+ +

动作状态

+ +
+ + + +
+ +
+ + + +
+ +
+ + +
+
+
+ +@code { + private DataSetting DataSettings { get; set; } + private DataActionStatus DataActionStatus { get; set; } + public int newColorKey { set; get; } + private EditContext? EditContext; + + protected override void OnInitialized() + { + // 这里应该从数据存储加载设置 + LoadSettings(); + EditContext = new EditContext(DataSettings); + } + + private void LoadSettings() + { + // 模拟加载设置数据 + DataSettings = this.GetModule().Setting; + DataActionStatus = this.GetModule().Status; + } + + private void HandleValidSubmit() + { + // 这里应该保存设置到数据存储 + this.GetModule().Save(DataSettings); + Console.WriteLine("设置已保存"); + // 显示成功消息或导航到其他页面 + } + + private void ResetToDefaults() + { + DataSettings = this.GetModule().CreateDefault(); + EditContext = new EditContext(DataSettings); + } + + private void AddColorMapping() + { + if (!DataSettings.ColorMapping.ContainsKey(newColorKey)) + { + DataSettings.ColorMapping[newColorKey] = new Vector3(0, 0, 0); + StateHasChanged(); + } + } + + private void RemoveColorMapping(int key) + { + if (DataSettings.ColorMapping.ContainsKey(key)) + { + DataSettings.ColorMapping.Remove(key); + StateHasChanged(); + } + } +} + + \ No newline at end of file diff --git a/Program.cs b/Program.cs index bd92a0f..d6821d1 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,10 @@ using TargetService.Components; +using EGFramework; + +EGBlazorController MainApp = new EGBlazorController(); +MainApp.Init(); +MainApp.Start(); + var builder = WebApplication.CreateBuilder(args); @@ -12,12 +18,17 @@ var app = builder.Build(); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error", createScopeForErrors: true); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } +app.UseHttpsRedirection(); + app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); -app.Run(); +app.Run("http://0.0.0.0:6556"); + diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 1534944..b9545c6 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -13,7 +13,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "http://localhost:5257", + "applicationUrl": "http://localhost:6556", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/wwwroot/favicon.png b/wwwroot/favicon.png index 8422b59..41ac9b8 100644 Binary files a/wwwroot/favicon.png and b/wwwroot/favicon.png differ