You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AnyLogic中如何依据运载Motor参数设置AGV节点行驶速度?

AnyLogic中获取AGV运载的Motor智能体解决速度调整问题

问题根源

你代码里的motor变量未指向当前AGV(unit)上运载的具体Motor智能体实例,所以AnyLogic无法识别这个变量。

解决方案

1. 获取当前AGV上的Motor智能体

在Transporter Fleet的On enter node事件中,通过Transporter类的getCargo()方法获取运载对象,再强制转换为你的Motor智能体类型。同时建议添加非空判断,避免AGV空载时触发空指针错误。

2. 修改后的工序1示例代码

if (node == locationCycle1) {
    // 获取当前AGV运载的Motor智能体
    Motor currentMotor = (Motor) unit.getCargo();
    // 非空校验,防止空载报错
    if(currentMotor != null){
        double targetSpeed = selectFrom(speeds_axel)
            .where(speeds_axel.axel_type.eq(currentMotor.axelType))
            .firstResult(false, speeds_axel.cycle1)/60.0;
        unit.setMaximumSpeed(targetSpeed, MPS);
    }
}

3. 27个工序的批量优化

如果逐个写27个if判断过于繁琐,可以用映射关系简化代码:

  • 先在Main页面的On startup事件中初始化节点与数据库列的映射:
// 建立工序节点和对应速度列的映射
Map<Node, String> nodeCycleMap = new HashMap<>();
nodeCycleMap.put(locationCycle1, "cycle1");
nodeCycleMap.put(locationCycle2, "cycle2");
// ... 依次添加到locationCycle27
  • 然后在On enter node事件中统一处理所有工序:
String cycleColumn = nodeCycleMap.get(node);
if(cycleColumn != null){
    Motor currentMotor = (Motor) unit.getCargo();
    if(currentMotor != null){
        double targetSpeed = selectFrom(speeds_axel)
            .where(speeds_axel.axel_type.eq(currentMotor.axelType))
            .firstResult(false, speeds_axel.getColumn(cycleColumn))/60.0;
        unit.setMaximumSpeed(targetSpeed, MPS);
    }
}

内容的提问来源于stack exchange,提问作者SimulationNewBe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 12:10:34