diff --git a/99-benz-serial.rules b/99-benz-serial.rules index d9c0cda..7b2feb5 100644 --- a/99-benz-serial.rules +++ b/99-benz-serial.rules @@ -1,4 +1,4 @@ # 串口继电器 -KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-xhci-hcd.4.auto-usb-0:1:1.0-port0", SYMLINK+="autolabor_relay", MODE="0777" +KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-xhci-hcd.4.auto-usb-0:1:1.0", SYMLINK+="autolabor_relay", MODE="0777" # 雷达 -KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-fc840000.usb-usb-0:1:1.0-port0", SYMLINK+="autolabor_ld19", MODE="0777" \ No newline at end of file +KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-fc840000.usb-usb-0:1:1.0", SYMLINK+="autolabor_ld19", MODE="0777" \ No newline at end of file diff --git a/BenzObstacleDetect/DataType/RectRoi.cs b/BenzObstacleDetect/DataType/RectRoi.cs new file mode 100644 index 0000000..76bba96 --- /dev/null +++ b/BenzObstacleDetect/DataType/RectRoi.cs @@ -0,0 +1,16 @@ +namespace Autolabor.Benz.ObstacleDetection.DataType +{ + + public class RectRoiSettings + { + public RectRoi[] RectRois { get; set; } + } + + public struct RectRoi + { + public double LeftUpX { get; set; } + public double LeftUpY { get; set; } + public double RightDownX { get; set; } + public double RightDownY { get; set; } + } +} \ No newline at end of file diff --git a/BenzObstacleDetect/Detection.cs b/BenzObstacleDetect/Detection.cs index 0f97de6..f6da589 100644 --- a/BenzObstacleDetect/Detection.cs +++ b/BenzObstacleDetect/Detection.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Net; +using Autolabor.Benz.ObstacleDetection.DataType; using Autolabor.Robobase; using Autolabor.Robobase.Component.Algorithm.LidarDetection; using Autolabor.Robobase.Component.Algorithm.LidarDetection.DataType; @@ -36,8 +39,12 @@ namespace Autolabor.Benz.ObstacleDetection // 配置过滤区域 private LidarRoi[] _lidarRois; - public Detection() + public Detection(RectRoiSettings roiSettings) { + // 1. 获取感兴趣区域 + var rois = roiSettings.RectRois.Select(roi => LidarRoiFactory.Make(roi.LeftUpX, roi.LeftUpY, roi.RightDownX, roi.RightDownY)).ToList(); + _lidarRois = rois.ToArray(); + // 2. 创建各个功能组件 // 驱动组件 _lidarDriver = new Ld19DriverNew(); @@ -79,11 +86,6 @@ namespace Autolabor.Benz.ObstacleDetection // 串口继电器配置 _serialRelay.SetProperty("serial.relay.port", "/dev/autolabor_relay"); - // 创建感兴趣区 - _lidarRois = new[] - { - LidarRoiFactory.Make(0.6, 0.5, 0.1, -0.5), - }; // 配置过滤器 _lidarRoiFilter.SetProperty("roiArray", _lidarRois); // 障碍物检测器配置 @@ -92,8 +94,8 @@ namespace Autolabor.Benz.ObstacleDetection _obstacleDetector.SetProperty("MaxPrjDistance", 0.05); _obstacleDetector.SetProperty("GuessDistance", 1.0); // 配置发现和丢失次数 - _benzObstacleController.SetProperty("FoundObstacleThreshold", 3); - _benzObstacleController.SetProperty("LostObstacleThreshold", 5); + _benzObstacleController.SetProperty("FoundObstacleThreshold", 2); + _benzObstacleController.SetProperty("LostObstacleThreshold", 3); // 5. 连接组件 // 雷达数据流向避障检测 diff --git a/BenzObstacleDetect/Program.cs b/BenzObstacleDetect/Program.cs index 466e3f2..c21e313 100644 --- a/BenzObstacleDetect/Program.cs +++ b/BenzObstacleDetect/Program.cs @@ -1,9 +1,15 @@ using Autolabor.Benz.ObstacleDetection; +using Autolabor.Benz.ObstacleDetection.DataType; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; + var builder = Host.CreateApplicationBuilder(args); builder.Services.AddHostedService(); +// 注册配置绑定到 RectRoiSettings 类 +builder.Services.Configure(builder.Configuration.GetSection("RectRoiSettings")); + + var host = builder.Build(); host.Run(); \ No newline at end of file diff --git a/BenzObstacleDetect/Worker.cs b/BenzObstacleDetect/Worker.cs index d7a7f68..277da2a 100644 --- a/BenzObstacleDetect/Worker.cs +++ b/BenzObstacleDetect/Worker.cs @@ -1,23 +1,32 @@ using System; using System.Threading; using System.Threading.Tasks; +using Autolabor.Benz.ObstacleDetection.DataType; using Autolabor.Robobase; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Autolabor.Benz.ObstacleDetection { public class Worker : BackgroundService { private readonly ILogger _logger; + private readonly RectRoiSettings _roiSettings; - public Worker(ILogger logger) + public Worker(ILogger logger, IOptions roiSettings) { _logger = logger; + _roiSettings = roiSettings.Value; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + foreach (var roi in _roiSettings.RectRois) + { + _logger.LogInformation("RectRoi: leftUp({0},{1}) - rightDown({2},{3})", + roi.LeftUpX, roi.LeftUpY, roi.RightDownX, roi.RightDownY); + } // 创建用户配置文件 var app = Kits.GetAutolaborDataPath(); @@ -26,18 +35,10 @@ namespace Autolabor.Benz.ObstacleDetection // 输出日志 TestKit.Logger.Trace("BenzObstacleDetection start"); + // 启动顶层组件 - var detection = new Detection(); + var detection = new Detection(_roiSettings); detection.Enable = true; - // while (!stoppingToken.IsCancellationRequested) - // { - // if (_logger.IsEnabled(LogLevel.Information)) - // { - // _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); - // } - // - // await Task.Delay(1000, stoppingToken); - // } } } } \ No newline at end of file diff --git a/BenzObstacleDetect/appsettings.json b/BenzObstacleDetect/appsettings.json index b2dcdb6..8b78f12 100644 --- a/BenzObstacleDetect/appsettings.json +++ b/BenzObstacleDetect/appsettings.json @@ -4,5 +4,23 @@ "Default": "Information", "Microsoft.Hosting.Lifetime": "Information" } + }, + + "RectRoiSettings": { + "RectRois": [ + { + "leftUpX": 1.5, + "leftUpY": 0.3, + "rightDownX": 0.55, + "rightDownY": -0.3 + }, + { + "leftUpX": -0.55, + "leftUpY": 0.3, + "rightDownX": -1.5, + "rightDownY": -0.3 + } + ] } + } diff --git a/Release/BenzObstacleDetect.exe b/Release/BenzObstacleDetect.exe index 65438f4..d7d2da1 100644 Binary files a/Release/BenzObstacleDetect.exe and b/Release/BenzObstacleDetect.exe differ diff --git a/Release/BenzObstacleDetect.pdb b/Release/BenzObstacleDetect.pdb index b59790f..07dea61 100644 Binary files a/Release/BenzObstacleDetect.pdb and b/Release/BenzObstacleDetect.pdb differ diff --git a/Release/appsettings.json b/Release/appsettings.json index b2dcdb6..8b78f12 100644 --- a/Release/appsettings.json +++ b/Release/appsettings.json @@ -4,5 +4,23 @@ "Default": "Information", "Microsoft.Hosting.Lifetime": "Information" } + }, + + "RectRoiSettings": { + "RectRois": [ + { + "leftUpX": 1.5, + "leftUpY": 0.3, + "rightDownX": 0.55, + "rightDownY": -0.3 + }, + { + "leftUpX": -0.55, + "leftUpY": 0.3, + "rightDownX": -1.5, + "rightDownY": -0.3 + } + ] } + } diff --git a/detection.sh b/detection.sh index dcaeae0..115cd02 100644 --- a/detection.sh +++ b/detection.sh @@ -4,4 +4,4 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" echo "脚本当前目录:$SCRIPT_DIR" -mono "$SCRIPT_DIR"/bin/publish/BenzObstacleDetect.exe \ No newline at end of file +mono "$SCRIPT_DIR"/Release/BenzObstacleDetect.exe \ No newline at end of file