# 脚本生成特性汇总表

> 本文档汇总了工程中所有的 `TemplateTrackCoderSettings`、`TemplateSiteCoderSettings` 和 `ProgramTrackCoderSettings` 特性配置。

---

## 关键参数说明

| 参数 | 说明 |
|------|------|
| **priority** | 优先级，数值越大则脚本生成顺序越靠前 |
| **useVerb** | 判断条件，为 true 时生成 templateString |
| **blockVerb** | 如果为 true，且 useVerb 通过，则低于此 priority 的脚本不再继续判断 |
| **templateString** | 生成的脚本模板，支持 `${变量}` 语法 |
| **siteFields** | 站点字段类型定义 |
| **trackFields** | 路径字段类型定义 |
| **planFields** | 计划字段类型定义 |

---

## 执行流程说明

1. 按 **priority 从大到小** 依次检查每个 CoderSettings
2. 如果 **useVerb** 条件为 true，则生成 **templateString** 脚本
3. 如果 **blockVerb** 为 true 且 useVerb 通过，则 **阻止低优先级脚本继续执行**
4. ProgramTrackCoderSettings 使用自定义的 `ITrackCoder` 程序来生成脚本

---

## 一、TemplateTrackCoderSettings（路径脚本）

### 1. MultiWheelLifterCar.cs - 多舵轮顶升车

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 30 | `track.SleepTime!=0` | false | `agv.Wait();agv.Sleep(${track.SleepTime});agv.Wait();` | 路径上休眠 |
| 30 | `track.TrayTarget!=0` | false | `agv.Wait();agv.TrayControl(${track.TrayTarget});agv.Wait();` | 托盘控制 |
| 27 | `track.LidarArea != -2` | - | `agv.Queue(()=>{},()=>{ agv.SwitchLidarArea(${track.LidarArea}); });` | 切换激光避障区域 |
| 20 | (无条件) | - | `agv.Queue(()=>{},()=>{ agv.ChangeAvoidanceDistance(${track.StopDistance},${track.SlowDistance}); });` | 更改避障距离 |
| 20 | `track.IOArea != -1` | - | `agv.Queue(()=>{},()=>{ agv.SwitchIoArea(${track.IOArea}); });` | 切换IO区域 |
| 20 | `dst.ChangeAvoidanceParam==true` | - | `agv.Queue(()=>{},()=>{ agv.ChangeAvoidanceParam(${dst.CarLength},${dst.CarWidth},${dst.CarCenterX},${dst.CarCenterY}); });` | 切换避障尺寸 |
| 20 | `track.BiasAlarmThresh >0 \|\| track.DthAlarmThresh > 0` | - | `agv.Queue(()=>{},()=>{ agv.ChangeTrackingErrThresh(${track.BiasAlarmThresh},${track.DthAlarmThresh}); });` | 更改跟踪误差阈值 |
| 19 | `dst.tag>0 && src.tag>0` | true | `agv.QrGo(${src.x},${src.y},${src.id},${src.tag},${dst.x},${dst.y},${dst.id},${dst.tag},${track.id},...);` | 二维码导航 |

---

### 2. Kiva.cs - Kiva车

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 30 | `dst.tag>0 && src.tag>0` | true | `agv.QrGo(...);` | 二维码导航 |
| 22 | `src.Shelf && plan.curSeg==1` | true | `agv.LeaveShelf(...);` | 离开货架 |
| 20 | `plan.action=='fetch' && dst.Shelf && plan.curSeg==plan.segN-2` | true | `agv.Fetch(...);` | 取货 |
| 20 | `plan.action=='put' && dst.Shelf && plan.curSeg==plan.segN-2` | true | `agv.Put(...);` | 放货 |
| 20 | (无条件) | - | `agv.Queue(()=>{},()=>{ agv.ChangeAvoidanceDistance(...); });` | 更改避障距离 |
| 20 | (无条件) | - | `agv.Queue(()=>{},()=>{ agv.ChangeAvoidanceParam(${dst.CarLength},${dst.CarWidth}); });` | 切换避障尺寸 |
| 20 | `track.IOArea != -1` | - | `agv.Queue(()=>{},()=>{ agv.SwitchIoArea(${track.IOArea}); });` | 切换IO区域 |
| 20 | `track.BiasAlarmThresh >0 \|\| track.DthAlarmThresh > 0` | - | `agv.Queue(()=>{},()=>{ agv.ChangeTrackingErrThresh(...); });` | 更改跟踪误差阈值 |
| 17 | `track.LidarArea != -2` | - | `agv.Queue(()=>{},()=>{ agv.SwitchLidarArea(${track.LidarArea}); });` | 切换激光避障区域 |
| 10 | `track.CalibrateWheelEncoder && track.ReverseDst != dst.id` | true | `agv.CalibrateWheelEncoder(...);` | 标定轮里程计 |

---

### 3. Forklift.cs - 叉车

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 22 | `src.Shelf` | true | `agv.LeaveShelf(...);agv.Wait();` | 离开货架 |
| 20 | `track.LidarArea != -2` | - | `agv.Queue(()=>{},()=>{ agv.SwitchLidarArea(${track.LidarArea}); });` | 切换激光避障区域 |
| 20 | `track.IOArea != -1` | - | `agv.Queue(()=>{},()=>{ agv.SwitchIoArea(${track.IOArea}); });` | 切换IO区域 |
| 20 | `dst.CarLength != -1 && dst.CarWidth != -1` | - | `agv.Queue(()=>{},()=>{ agv.ChangeAvoidanceParam(${dst.CarLength},${dst.CarWidth}); });` | 切换避障尺寸 |
| 20 | `plan.action=='fetch' && dst.Shelf` | true | `agv.Wait();agv.Fetch(...);agv.Wait();` | 取货 |
| 20 | `plan.action=='put' && dst.Shelf` | true | `agv.Wait();agv.Put(...);agv.Wait();` | 放货 |
| 20 | `track.BiasAlarmThresh >0 \|\| track.DthAlarmThresh > 0` | - | `agv.Queue(()=>{},()=>{ agv.ChangeTrackingErrThresh(...); });` | 更改跟踪误差阈值 |

---

### 4. MultiWheelForkLifter.cs - 多舵轮叉车

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 20 | `plan.action=='fetch' && dst.Shelf && plan.curSeg==plan.segN-2` | true | `agv.Wait();agv.Fetch(...);agv.Wait();` | 取货 |
| 20 | `plan.action=='put' && dst.Shelf && plan.curSeg==plan.segN-2` | true | `agv.Wait();agv.Put(...);agv.Wait();` | 放货 |

---

## 二、TemplateSiteCoderSettings（站点脚本）

### 1. Kiva.cs

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 25 | `plan.action=='fetch' && plan.segN == 1 && dst.Shelf` | true | `agv.FetchInPlace(...);agv.Wait();` | 原地取货 |

### 2. Forklift.cs

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 25 | `plan.action=='fetch' && plan.segN==1 && dst.Shelf` | true | `agv.FetchInPlace(...);agv.Wait();` | 原地取货 |

### 3. ArmCar.cs - 机械臂车

| Priority | useVerb | blockVerb | templateString | 说明 |
|----------|---------|-----------|----------------|------|
| 5 | `plan.action=='pickFull' && plan.curSeg==plan.segN-1` | true | `agv.Wait();agv.PickFull("${dst.name}");agv.Wait();` | 满盘取货 |
| 5 | `plan.action=='pickEmpty' && plan.curSeg==plan.segN-1` | true | `agv.Wait();agv.PickEmpty("${dst.name}");agv.Wait();` | 空盘取货 |
| 5 | `plan.action=='putFull' && plan.curSeg==plan.segN-1` | true | `agv.Wait();agv.PutFull("${dst.name}");agv.Wait();` | 满盘放货 |
| 5 | `plan.action=='putEmpty' && plan.curSeg==plan.segN-1` | true | `agv.Wait();agv.PutEmpty("${dst.name}");agv.Wait();` | 空盘放货 |
| 5 | `plan.action=='MoveArm' && plan.curSeg==plan.segN-1` | true | `agv.Wait();agv.MoveArm(${dst.MoveDirection});agv.Wait();` | 移动机械臂 |

---

## 三、ProgramTrackCoderSettings（程序化路径脚本）

| 车型 | Priority | Program | 说明 |
|------|----------|---------|------|
| MultiWheelLifterCar | 19 | `MagTrackCoder` | 磁导航路径编码 |
| Kiva | 19 | `AllCarMagTrackCoder` | 磁导航路径编码 |
| Kiva | 5 | `KivaCarTrackCoder` | Kiva旋转控制 |

---

## 四、字段类型定义

### BasicCarFields
```csharp
public float MagSlowSpeed = 0;
public float MagFullSpeed = 0;
```

### BasicSiteFields
```csharp
public bool Shelf = false;
public float CarLength = -1;
public float CarWidth = -1;
public float CarCenterX = 0;
public float CarCenterY = 0;
public int tag = -1;
public int TagValue = -1;// 磁导航，二维码值，或者rfid值
```

### BasicTrackFields
```csharp
public int IOArea = -1;
public int LidarArea = -2;
public float BiasAlarmThresh = -1;
public float DthAlarmThresh = -1;
public float Speed = 0.2f;
public bool Reverse = false;
public int ReverseDst = -1;
public bool SwitchBarrier = false;
public bool CalibrateWheelEncoder = false;
public float CarDirectionBias = 0;
public bool EnableCarAbsoluteDirection = false;
public float CarAbsoluteDirection = 0;
public float SlowDistance = -1;
public float StopDistance = -1;
```

### BasicPlanFields
```csharp
public string action = "/";
public float CarLength = -1;
public float CarWidth = -1;
```

---

## 五、扩展字段类型

### MultiWheelLifterTrackFields (继承 BasicTrackFields)
```csharp
public int SleepTime = 0;
public float TrayTarget = 0;
```

### MultiWheelLifterSiteFields (继承 BasicSiteFields)
```csharp
public bool ChangeAvoidanceParam = false;
```

### KivaSiteFields (继承 BasicSiteFields)
```csharp
public int AngleTarget = 0;
public bool Turn = false;
public float FetchSpeed = 0;
public int FetchLidarArea = -2;
public int FetchIOArea = -1;
public bool FetchReverse = false;
public float FetchBlindMoveDist = 0;
public float FetchLiftDownTarget = -1;
public float FetchLiftUpTarget = -1;
public bool FetchUseQr = false;
public int FetchQrMode = -1;
public bool FetchIsUpQr = false;
public bool FetchUseDetector = false;
public int FetchDetector = 0;
public float FetchDetectWidth = -1;
public float FetchDetectDepth = -1;
public bool FetchLeaveSrcEarly = false;
public float FetchShieldObstacleDist = -1;
// ... 以及 Put 和 LeaveShelf 相关字段
```

### KivaTrackFields (继承 BasicTrackFields)
```csharp
public int ManeuverDir = 0;
public int ForwardDst = 0;
public int ForwardObChooseDst = -2;
public float BlindMoveDist = 0;
public bool UseDetector = false;
public int DetectorMode = -1;
public float DetectWidth = -1;
public float DetectDepth = -1;
public bool LeaveSrcEarly = false;
public float ShieldObstacleDist = -1;
```

### KivaPlanFields (继承 BasicPlanFields)
```csharp
public bool reverse = false;
public int level = 0;
```

---

## 六、ITrackCoder 接口

程序化脚本生成器需要实现 `ITrackCoder` 接口：

```csharp
public interface ITrackCoder
{
    /// <summary>
    /// 生成脚本代码
    /// </summary>
    /// <param name="plan">路径计划</param>
    /// <param name="track">当前路径段</param>
    /// <param name="src">起点</param>
    /// <param name="dst">终点</param>
  /// <param name="i">段索引</param>
    /// <returns>是否成功生成</returns>
    bool Code(SegmentPlan plan, Track track, Site src, Site dst, int i);
    
    /// <summary>
    /// 是否阻止后续脚本生成
    /// </summary>
    bool toBlock();
}
```

---

*文档生成时间: 2024年*
