feat: 添加配置属性
parent
d7c2582190
commit
02845303ad
|
@ -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"
|
||||
KERNEL=="ttyUSB*", SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-fc840000.usb-usb-0:1:1.0", SYMLINK+="autolabor_ld19", MODE="0777"
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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. 连接组件
|
||||
// 雷达数据流向避障检测
|
||||
|
|
|
@ -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<Worker>();
|
||||
|
||||
// 注册配置绑定到 RectRoiSettings 类
|
||||
builder.Services.Configure<RectRoiSettings>(builder.Configuration.GetSection("RectRoiSettings"));
|
||||
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
|
@ -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<Worker> _logger;
|
||||
private readonly RectRoiSettings _roiSettings;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
public Worker(ILogger<Worker> logger, IOptions<RectRoiSettings> 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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
echo "脚本当前目录:$SCRIPT_DIR"
|
||||
|
||||
mono "$SCRIPT_DIR"/bin/publish/BenzObstacleDetect.exe
|
||||
mono "$SCRIPT_DIR"/Release/BenzObstacleDetect.exe
|
Loading…
Reference in New Issue