Order.cs 9.62 KB
using System.Numerics;
using System.Text.Json.Serialization;
using Rcs.Domain.Attributes;
using Rcs.Domain.Extensions;
using Rcs.Domain.ValueObjects;

namespace Rcs.Domain.Models.VDA5050;

/// <summary>
/// VDA 5050 Order消息 - 用于向AGV发送任务指令
/// </summary>
[ProtocolInfo("Default","2.0.0", nameof(Order))]
public class Order : VDA5050_Header
{
    public Order()
    {
            
    }
    /// <summary>
    /// 订单ID
    /// </summary>
    [JsonPropertyName("orderId")]
    public string OrderId { get; set; } = string.Empty;

    /// <summary>
    /// 订单更新ID
    /// </summary>
    [JsonPropertyName("orderUpdateId")]
    public int OrderUpdateId { get; set; }

    /// <summary>
    /// 区域编号
    /// </summary>
    [JsonPropertyName("zoneSetId")]
    public string? ZoneSetId { get; set; }

    /// <summary>
    /// 节点列表
    /// </summary>
    [JsonPropertyName("nodes")]
    public List<Node> Nodes { get; set; } = new();

    /// <summary>
    /// 边列表
    /// </summary>
    [JsonPropertyName("edges")]
    public List<Edge> Edges { get; set; } = new();
}

/// <summary>
/// 节点信息
/// </summary>
public class Node
{
    /// <summary>
    /// 节点ID
    /// </summary>
    [JsonPropertyName("nodeId")]
    public string NodeId { get; set; } = string.Empty;

    /// <summary>
    /// 序列ID
    /// </summary>
    [JsonPropertyName("sequenceId")]
    public int SequenceId { get; set; }

    /// <summary>
    /// 节点说明
    /// </summary>
    [JsonPropertyName("nodeDescription")]
    public string? NodeDescription { get; set; }

    /// <summary>
    /// 是否释放
    /// </summary>
    [JsonPropertyName("released")]
    public bool Released { get; set; } = false;

    /// <summary>
    /// 节点位置
    /// </summary>
    [JsonPropertyName("nodePosition")]
    public NodePosition? NodePosition { get; set; }

    /// <summary>
    /// 动作列表
    /// </summary>
    [JsonPropertyName("actions")]
    public List<Action>? Actions { get; set; }
}

/// <summary>
/// 节点位置
/// </summary>
public class NodePosition
{
    /// <summary>
    /// X坐标
    /// </summary>
    [JsonPropertyName("x")]
    public double X { get; set; }

    /// <summary>
    /// Y坐标
    /// </summary>
    [JsonPropertyName("y")]
    public double Y { get; set; }

    /// <summary>
    /// 角度 (弧度)
    /// </summary>
    [JsonPropertyName("theta")]
    public double? Theta { get; set; }
    /// <summary>
    /// 坐标偏差范围
    /// </summary>
    [JsonPropertyName("allowedDeviationXY")]
    public double AllowedDeviationXY { get; set; } = PositionConstants.AllowedDeviationPosition;
    /// <summary>
    /// 角度 (弧度)偏差范围 // 默认15度
    /// </summary>
    [JsonPropertyName("allowedDeviationTheta")]
    public double AllowedDeviationTheta { get; set; } = AngleConstants.AllowedDeviationTheta;

    /// <summary>
    /// 地图ID
    /// </summary>
    [JsonPropertyName("mapId")]
    public string MapId { get; set; } = string.Empty;
    /// <summary>
    /// 地图描述
    /// </summary>
    [JsonPropertyName("mapDescription")]
    public string? MapDesription { get; set; }
}

/// <summary>
/// 边信息
/// </summary>
public class Edge
{
    /// <summary>
    /// 边ID
    /// </summary>
    [JsonPropertyName("edgeId")]
    public string EdgeId { get; set; } = string.Empty;

    /// <summary>
    /// 序列ID
    /// </summary>
    [JsonPropertyName("sequenceId")]
    public int SequenceId { get; set; }

    /// <summary>
    /// 边描述
    /// </summary>
    [JsonPropertyName("edgeDescription")]
    public string? EdgeDescription { get; set; }

    /// <summary>
    /// 是否释放
    /// </summary>
    [JsonPropertyName("released")]
    public bool Released { get; set; } = false;
    /// <summary>
    /// 起始节点ID
    /// </summary>
    [JsonPropertyName("startNodeId")]
    public string StartNodeId { get; set; } = string.Empty;

    /// <summary>
    /// 结束节点ID
    /// </summary>
    [JsonPropertyName("endNodeId")]
    public string EndNodeId { get; set; } = string.Empty;

    /// <summary>
    /// 最大速度 m/s
    /// </summary>
    [JsonPropertyName("maxSpeed")]
    public double? MaxSpeed { get; set; }

    /// <summary>
    /// 最大高度 m
    /// </summary>
    [JsonPropertyName("maxHeight")]
    public double? MaxHeight { get; set; }

    /// <summary>
    /// 最小高度 m
    /// </summary>
    [JsonPropertyName("minHeight")]
    public double? MinHeight { get; set; }

    /// <summary>
    /// 方向
    /// </summary>
    [JsonPropertyName("orientation")]
    public double? Orientation { get; set; }

    /// <summary>
    /// 方向类型
    /// GLOBAL-允许全局方向
    /// TANGENTIAL-与边相切
    /// </summary>
    [JsonPropertyName("orientationType")]
    public string OrientationType { get; set; } = "TANGENTIAL";
        
    /// <summary>
    /// 为线导或线缆引导车辆设定交叉路口方向
    /// </summary>
    [JsonPropertyName("direction")]
    public string? Direction { get; set; }

    /// <summary>
    /// 是否允许旋转
    /// </summary>
    [JsonPropertyName("rotationAllowed")]
    public bool RotationAllowed { get; set; }

    /// <summary>
    /// 最大转速
    /// </summary>
    [JsonPropertyName("maxRotationSpeed")]
    public double? MaxRotationSpeed { get; set; }

    /// <summary>
    /// 轨迹
    /// </summary>
    [JsonPropertyName("trajectory")]
    public Trajectory? Trajectory { get; set; }

    /// <summary>
    /// 起点到终点的长度
    /// </summary>
    [JsonPropertyName("length")]
    public double? Length { get; set; }

    /// <summary>
    /// 通道参数
    /// </summary>
    [JsonPropertyName("corridor")]
    public Corridor? Corridor { get; set; }

    /// <summary>
    /// 动作列表
    /// </summary>
    [JsonPropertyName("actions")]
    public List<Action>? Actions { get; set; }
}

/// <summary>
/// 动作信息
/// </summary>
public class Action
{
    public Action() { }
        
    public Action(string actionType, List<(string, string?, bool?, object)> par, out string actionId, string blockingType = "HARD")
    {
        actionId = Guid.NewGuid().ToString();
        ActionId = actionId;
        ActionType = actionType;
        BlockingType = blockingType;
        if (par != null && par.Count > 0)
        {
            var actions = new List<ActionParameter>();
            //循环par添加到actions
            foreach (var kvp in par)
            {
                actions.Add(new ActionParameter
                {
                    Key = kvp.Item1,
                    ValueDataType = kvp.Item2,
                    IsOptional = kvp.Item3,
                    Value = kvp.Item4
                });
            }
            ActionParameters = actions;
        }
            
    }
    /// <summary>
    /// 动作ID
    /// </summary>
    [JsonPropertyName("actionId")]
    public string ActionId { get; set; } = System.Guid.NewGuid().ToString();

    /// <summary>
    /// 动作类型
    /// </summary>
    [JsonPropertyName("actionType")]
    public string ActionType { get; set; } = string.Empty;

    /// <summary>
    /// 动作描述
    /// </summary>
    [JsonPropertyName("actionDescription")]
    public string ActionDescription { get; set; } = string.Empty;

    /// <summary>
    /// 动作参数
    /// </summary>
    [JsonPropertyName("actionParameters")]
    public List<ActionParameter> ActionParameters { get; set; } = new();

    /// <summary>
    /// 是否阻塞
    /// NONE-允许移动和其他动作
    /// SOFT-不允许移动,允许其他动作
    /// HARD-不允许移动和其他动作
    /// </summary>
    [JsonPropertyName("blockingType")]
    public string BlockingType { get; set; } = "HARD";
}
public class ActionParameter
{
    public ActionParameter() { }
        
    public ActionParameter(string key, object value)
    {
        Key = key;
        Value = value;
    }
        
    [JsonPropertyName("key")]
    public string Key { get; set; } = string.Empty;
    [JsonPropertyName("value")]
    public object Value { get; set; }
    [JsonPropertyName("valueDataType")]
    public string? ValueDataType { get; set; }
    [JsonPropertyName("isOptional")]
    public bool? IsOptional { get; set; }
}
public class Trajectory {
    /// <summary>
    /// 曲线的度数
    /// </summary>
    [JsonPropertyName("degree")]
    public double Degree { get; set; }
    /// <summary>
    /// 曲线的节点向量数组 范围0.0-1.0
    /// </summary>
    [JsonPropertyName("knotVector")]
    public List<double> KnotVector { get; set; } = new();
    /// <summary>
    /// 定义NURBS控制点的控点对象阵列,包括起始点和终点。
    /// </summary>
    [JsonPropertyName("controlPoints")]
    public List<ControlPoint> ControlPoints { get; set; } = new();
}

public class ControlPoint {
    /// <summary>
    /// X坐标
    /// </summary>
    [JsonPropertyName("x")]
    public double X { get; set; }
    /// <summary>
    /// Y坐标
    /// </summary>
    [JsonPropertyName("y")]
    public double Y { get; set; }
    /// <summary>
    /// 权重
    /// </summary>
    [JsonPropertyName("weight")]
    public double? Weight { get; set; }
}

public class Corridor
{
    /// <summary>
    /// 左侧走廊宽度
    /// </summary>
    [JsonPropertyName("leftWidth")]
    public double LeftWidth { get; set; }
    /// <summary>
    /// 右侧走廊宽度
    /// </summary>
    [JsonPropertyName("rightWidth")]
    public double RightWidth { get; set; }

    /// <summary>
    /// 边界定义
    /// KINEMATICCENTER-车体轮廓
    /// CONTOUR-运动学中心
    /// </summary>
    [JsonPropertyName("corridorRefPoint")]
    public string? CorridorRefPoint { get; set; }
}