A dual-constraint code generation method and system for automated port operations

By constructing an architecture knowledge base for port business and heavy-load dynamic perception, and a structured, globally shared two-layer blackboard, the problems of heavy-load safety, business protocols, and automotive-grade real-time performance in code generation for large language models in port autonomous driving scenarios are solved, and compilable automotive-grade engineering code is automatically generated.

CN123114444APending Publication Date: 2026-11-17SHANGHAI ZHENHUA HEAVY IND
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611585176.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-14
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing large language model code generation methods are difficult to adapt to the special engineering constraints of port autonomous driving scenarios, such as heavy-load safety, business protocols, dual-end adaptation and automotive-grade real-time requirements, and cannot generate compilable automotive-grade engineering code in one go.

Method used

An architecture knowledge base for port operations and heavy-load dynamics perception is constructed. The architecture is layered and recursively decomposed through a master control agent. Multi-agent collaboration is carried out using a structured global shared double-layer blackboard to generate code for each subtask. A closed loop is formed through interface consistency verification and dual-track verification to ensure that the code conforms to the port heavy-load business scenario and autonomous driving architecture constraints.

Benefits of technology

It achieves one-time automatic generation of system-level requirements from port operations to compileable automotive-grade engineering code, ensuring heavy-load safety, consistent architecture interfaces, dual-end adaptation to real vehicle simulation, and closed-loop compilation and verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114444A_ABST
    Figure CN123114444A_ABST
Patent Text Reader

Abstract

This invention relates to the field of port automation technology, and more specifically, to a dual-constraint code generation method and system for port autonomous driving. The method includes: constructing an architecture knowledge base for port business and heavy-load dynamics perception; performing architecture-layered perception of port equipment system-level code requirements, recursively decomposing them into a list of sub-tasks with execution dependencies, constructing and initializing a structured globally shared two-layer blackboard; loading corresponding dual-constraint parameters according to sub-tasks, retrieving framework-adaptive code fragments from the architecture knowledge base, generating code for each sub-task, and writing the code back to the structured globally shared two-layer blackboard; assembling the sub-task code into a complete project according to architecture layers, performing interface consistency checks and dual-track checks; and outputting a compilable automotive-grade port autonomous driving engineering code package. This invention enables one-time automatic generation from port business requirements to compilable automotive-grade engineering code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of port automation and artificial intelligence, and more specifically, to a dual-constraint code generation method and system for port autonomous driving. Background Technology

[0002] In port automated transportation systems, the development of control systems for heavy equipment such as unmanned intelligent guided vehicles and straddle carriers faces extremely stringent engineering requirements. Port equipment has enormous weight and load capacity, reaching hundreds of tons when fully loaded. Its control code has strict limitations on acceleration and steering angular velocity. If conventional passenger car-level deceleration parameters are incorrectly applied to equipment weighing hundreds of tons, it can easily lead to heavy-load instability, container overturning, or even tire blowouts. Simultaneously, port vehicles need to engage in complex vehicle-road cooperative communication and alignment handshakes with the terminal operating system, quay cranes, and yard cranes. Without knowledge of industrial protocols, it is impossible to generate state machine code that conforms to port operation procedures. Furthermore, traditional development requires manually maintaining two sets of code: one for the actual vehicle hardware driver interface and the other for the simulation environment adaptation interface, which are prone to interface discrepancies. Moreover, autonomous driving systems have extremely high real-time requirements, such as prohibiting dynamic memory allocation within callbacks, mandating the configuration of communication service quality strategies, and prohibiting blocking calls within the control cycle. Code generated from general-purpose large models often violates automotive-grade specifications.

[0003] In recent years, the industry has attempted to use large language models to assist code generation, resulting in several representative technical approaches. For example, a multi-agent software code generation framework based on role division breaks down tasks according to software engineering roles and allows agents to collaboratively generate general application code; an autonomous driving code generation method based on single-agent iterative optimization uses input-output pairs as evaluation datasets in a simulation environment, allowing a single large model to repeatedly rewrite driving decision code and iterate using simulation scores as feedback signals; a multi-agent large model collaboration framework based on a shared blackboard uses a single-layer blackboard for information sharing; a multi-agent generation method based on cloud infrastructure as code is geared towards declarative cloud resource configuration generation; a structured artifact generation method based on meta-models and hierarchical constraints uses grammatical patterns as structural constraints during the decoding stage and performs post-validation using a semantic logic checker after decoding; and a code completion method based on code library context retrieval allows the large model to retrieve code fragments as context during generation.

[0004] However, the above-mentioned technical approaches all have fundamental flaws when applied to port autonomous driving code generation scenarios.

[0005] The multi-agent framework based on role division of labor is constrained by standard software engineering operating procedures. It does not involve data flow constraints and dynamic limitations of physical systems, and cannot guarantee the consistency of message types, communication topic names and state transition logic between upstream and downstream nodes. It also cannot inject heavy-load dynamic limiting or port business protocols.

[0006] The method based on single-agent iterative optimization generates end-to-end driving decision code rather than engineering framework code. It lacks multi-agent division of labor and cross-module interface contract management, and does not involve automotive coding constraints or port industry protocol constraints.

[0007] The multi-agent collaboration framework based on shared blackboards uses a single-layer blackboard to simultaneously carry task messages, intermediate results, and shared context. It lacks hierarchical management of global interface contracts and domain constraint parameters, and does not provide a mechanism for precisely injecting constraints at the architectural level or independently instantiating constraint containers by subtask.

[0008] The cloud infrastructure-as-code approach addresses the syntax and policy compliance of cloud resources, which is entirely separate from the physical and dynamic constraints, automotive-grade real-time constraints, message interface contracts, and compilation verification of autonomous driving systems.

[0009] The method based on meta-models and hierarchical constraints deals with structured artifacts rather than compilable node engineering code. Its hierarchical structure refers to the decoding time layer and the decoding post-layer, not the global interface contract layer and the constraint container layer instantiated by subtask.

[0010] In codebase context retrieval methods, the large model context window is limited, making it impossible to fully load the source code of a large-scale autonomous driving framework. Only fragmented understanding is possible, resulting in a lack of global consistency in the generated code. Reading the code only provides information on the coding pattern, not on architectural rules and domain constraints. The autonomous driving framework source code does not include port business protocols. After code generation, there is a lack of automated compilation verification and port business compliance checks.

[0011] The common shortcomings of the above technical routes are: the lack of a structured development system that enables large models to understand autonomous driving architecture and port heavy load scenarios. It is impossible to enable large models to perform architecture perception and subtask decomposition according to the autonomous driving data flow topology, nor can it force the constraints of port heavy load scenarios into the code skeleton of the corresponding architecture level. Furthermore, it lacks a closed loop formed by interface contract alignment, static scanning, sandbox compilation verification and error circuit breaking mechanism.

[0012] Therefore, there is an urgent need for a new code generation solution for autonomous driving in ports. Summary of the Invention

[0013] The purpose of this invention is to provide a dual-constraint code generation method and system for port autonomous driving, which solves the problem that existing large language model code generation methods are difficult to adapt to the special engineering constraints of port autonomous driving scenarios such as heavy-load safety, business protocols, dual-end adaptation and automotive-grade real-time performance, and cannot generate compilable automotive-grade engineering code in one go.

[0014] To achieve the above objectives, this invention provides a dual-constraint code generation method for automated port operations, comprising the following steps: Step S1: Construct an architecture knowledge base for port operations and heavy load dynamics perception, wherein the architecture knowledge base is stored in a retrieval-enhanced generation manner; Step S2: Based on the main control agent, the system-level code requirements of the port equipment system input by the user are perceived in an architecture layer. The system-level code requirements are recursively decomposed into a list of sub-tasks with execution dependencies according to the data flow dependency of the autonomous driving system. A structured global shared double-layer blackboard is constructed and initialized. Step S3: Based on the structured global shared double-layer blackboard, the sub-agents corresponding to each sub-task load the corresponding dual constraint parameters according to the sub-task, retrieve the framework adaptation code snippets from the architecture knowledge base, generate the code for each sub-task, and write the generated code back to the structured global shared double-layer blackboard. The dual constraint parameters include port heavy-load business scenario constraint parameters and autonomous driving architecture constraint parameters. Step S4: The assembly agent assembles the code of each subtask into a complete project according to the architecture layer, performs interface consistency verification and dual-track verification, and provides error feedback and regenerates the code when the verification fails. Step S5: After successful verification, output a compilable automotive-grade port autonomous driving engineering code package.

[0015] In some embodiments, the architecture knowledge base constructed in step S1 includes: We collect the source code, interface definition files, communication mechanism documents, automotive-grade coding standards, port operation communication protocols, and dynamic constraint parameters of heavy-duty vehicles in ports for specific versions of autonomous driving frameworks, store them in vector form, and label them with version tags.

[0016] In some embodiments, the retrieval enhancement generation construction method of the architecture knowledge base includes: The framework source code is divided into blocks according to the granularity of function, class and interface definitions. A text embedding model is used to convert the block text into vector representations and store them in a vector database. A filtering strategy combining sorting by similarity and selecting the top K items with a similarity threshold is used for retrieval.

[0017] In some embodiments, step S2 includes: Receive user input of port equipment system-level code requirements and framework version number; The main control agent retrieves the architecture knowledge base and, based on the node topology and data flow dependencies of the autonomous driving framework, identifies the architecture layers involved in the requirements and the data flow dependencies of port business. System-level requirements are recursively decomposed according to the architecture of autonomous driving nodes, generating a list of subtasks with execution dependencies, and a structured, globally shared, two-layer blackboard is constructed and initialized. The termination condition for recursive decomposition is that the subtask can be implemented by a single function logic and no longer contains cross-module communication and data dependencies.

[0018] In some embodiments, the architecture layering includes a data interface layer, a core algorithm layer, and a system configuration layer: The data interface layer is used for sensor driving, communication adaptation, and data format conversion; The core algorithm layer is used for perception and localization, planning and decision-making, and motion control according to the autonomous driving data stream. The system configuration layer is used for script building, startup configuration, and parameter file management.

[0019] In some embodiments, the data interface layer includes a controller local area network bus driver node, a lidar point cloud subscription node, a satellite navigation system positioning data subscription node on the vehicle side, and a user datagram protocol data adaptation node and a simulation clock synchronization node on the simulation side. The core algorithm layer is further divided into a perception and localization sublayer, a planning and decision-making sublayer, and a motion control sublayer according to the autonomous driving data flow. There are strict upstream and downstream data dependencies between each sublayer. The system configuration layer includes build files, dependency declaration files, startup files, and parameter configuration files.

[0020] In some embodiments, the structured globally shared two-layer blackboard includes a contract layer and a constraint container layer: The contract layer is a globally shared read-only layer that stores global interface definitions, legal state machine transition matrices, dual-end adaptation identifiers, and subtask dependency graphs for all sub-agents to read-only align. The constraint container layer is instantiated independently for each subtask, storing the port heavy-load business scenario constraints and autonomous driving architecture constraint parameters corresponding to that subtask.

[0021] In some embodiments, the initialization of the structured globally shared two-layer blackboard includes the initialization of the contract layer: The master control agent predetermines and writes global interface definitions, legal state machine transition matrices, dual-end adaptation identifiers, and subtask dependency graphs based on the subtask list and its data flow dependencies. This ensures that the contract layer has a globally unique and consistent interface and state machine benchmark before the sub-agents generate code, allowing all sub-agents to read-only align. The global interface definition includes the variable names, message types, communication topic names, and service interface signatures transmitted between nodes.

[0022] In some embodiments, the initialization of the structured globally shared two-layer blackboard further includes the instantiation of a constraint container layer: The main control agent creates independent constraint container instances for each subtask, and retrieves the port heavy-load business scenario constraints and autonomous driving architecture constraint parameters corresponding to the subtask from the architecture knowledge base, and fills them into the constraint containers of the corresponding subtasks. This ensures that each subtask only loads constraint parameters related to itself when generating code, thereby achieving hierarchical and subtask-based isolation and injection of constraints.

[0023] In some embodiments, step S3 includes: Each sub-agent reads the global interface definition from the contract layer of the structured global shared double-layer blackboard to align variable naming with the state machine definition, extracts the constraint parameters corresponding to the sub-task from the constraint container layer, and retrieves the architecture knowledge base to obtain the framework adaptation code snippet. Subtask code is generated by parameter interpolation based on the clipping code template, and overloaded clipping logic and double-ended conditional compilation flags are injected into the subtask code. Once generated, the code is written back to the structured globally shared double-layer blackboard and the contract layer state is updated.

[0024] In some embodiments, step S4 includes: The assembly agent assembles the code of each subtask into a complete project according to the architecture layering; Perform interface consistency verification by comparing the global interfaces referenced in each subtask code with the global interface definitions of the contract layer. Perform dual-track verification to check the code compliance and compilability of the complete project; If all checks pass, proceed to step S5; if checks fail, distinguish the error level and report back to the corresponding agent for correction.

[0025] In some embodiments, the interface consistency check includes: Compare whether the global variable names, message types, and communication topic names referenced in each subtask code match the contract layer definition; If there is a mismatch, a structured error feedback package is generated and the corresponding sub-agent is triggered to correct it; The structured error feedback package includes error type labels, error location information, and correct reference values ​​from the contract layer.

[0026] In some embodiments, the first track in the dual-track verification is an abstract syntax tree static scan and port business compliance verification, including: Scan function call nodes to detect dynamic memory allocation operations, scan assignment statement nodes to detect missing communication service quality configurations, and scan conditional expression nodes to detect the existence of clipping logic. By using in-process forward data flow propagation, the range of values ​​of acceleration and steering angle variables from calculation to output is tracked to determine whether the control command calculation logic exceeds the heavy load dynamic boundary.

[0027] In some embodiments, the second track in the dual-track verification is sandbox compilation verification, including: Execute the project compilation command in the containerized build environment to detect syntax errors, missing dependencies, linking errors, and symbol conflicts. If the compilation is successful, the complete project meets the buildability requirements.

[0028] In some embodiments, the process of differentiating error levels and feeding them back to the corresponding agents for correction includes subtask-level error feedback and architecture-level error feedback: The subtask-level error feedback includes parsing the error log and feeding it back to the corresponding sub-agent when the error belongs to an internal problem of the subtask and the cumulative number of automatic repairs is less than a preset threshold, and the sub-agent regenerates the code of the subtask. The architecture-level error feedback includes, when the cumulative number of automatic repairs reaches or exceeds the preset threshold, feeding back to the main control agent to re-disassemble the task or modify the contract layer definition; Each subtask maintains an independent repair counter, and the preset threshold is a configurable parameter.

[0029] In some embodiments, the compilable automotive-grade port autonomous driving engineering code package output in step S5 includes: Source code for the data interface layer nodes, source code for the core algorithm layer nodes, and system configuration layer build and startup files.

[0030] To achieve the above objectives, the present invention provides a dual-constraint code generation system for automated port operations, comprising a processor and a memory: The memory stores computer programs; The processor is used to execute the computer program stored in the memory to implement the dual-constraint code generation method for port autonomous driving as described above.

[0031] The present invention provides a dual-constraint code generation method and system for port autonomous driving. Through the construction of an architecture knowledge base, architecture layered perception and recursive decomposition, structured global shared dual-layer blackboard multi-agent collaboration, precise injection of dual-constraint parameters by sub-task, interface consistency verification and dual-track verification closed loop, and policy circuit breaking, it achieves one-time automatic generation from system-level requirements at the port business level to compileable automotive-grade engineering code. It achieves the technical effects of ensuring heavy-load safety, consistent architecture interfaces, dual-end adaptation to real vehicle simulation, and closed-loop compilation and verification. Attached Figure Description

[0032] The above and other features, properties and advantages of the present invention will become more apparent from the following description taken in conjunction with the accompanying drawings and embodiments, in which the same reference numerals always denote the same features, wherein: Figure 1 A step diagram of a dual-constraint code generation method for port autonomous driving according to an embodiment of the present invention is disclosed. Figure 2 A schematic diagram illustrating the mapping between a structured globally shared two-layer blackboard and an architecture layering according to an embodiment of the present invention is disclosed; Figure 3 A flowchart of constraint injection (S3) and compliance verification (S4) according to an embodiment of the present invention is disclosed; Figure 4 A schematic diagram of the closed-loop logic of sandbox compilation and port business compliance dual-track verification according to an embodiment of the present invention is disclosed. Detailed Implementation

[0033] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the invention.

[0034] This invention provides a dual-constraint code generation method and system for port autonomous driving based on Large Language Model (LLM) and multi-agent collaboration.

[0035] This invention can perceive the layered architecture of an autonomous driving system (data interface layer, core algorithm layer, and system configuration layer), and accurately inject port heavy-load business scenario constraints and autonomous driving architecture constraints according to the architecture layer. This enables a one-time automatic generation of code from port business requirements to compilable automotive-grade engineering code. Users do not need low-level development knowledge of autonomous driving frameworks, nor do they need to repeatedly interact with the code generation tool for multiple rounds of correction. The term "dual-constraint" refers to a code generation paradigm driven by both port heavy-load business scenario constraints and autonomous driving architecture constraints.

[0036] Figure 1 A step diagram of a dual-constraint code generation method for port autonomous driving according to an embodiment of the present invention is disclosed, as follows: Figure 1 As shown, the present invention proposes a dual-constraint code generation method for port autonomous driving, comprising the following steps: Step S1: Construct an architecture knowledge base for port operations and heavy-load dynamics perception, wherein the architecture knowledge base is stored in the manner of Retrieval-Augmented Generation (RAG). Step S2: Based on the main control agent, the system-level code requirements of the port equipment system input by the user are perceived in an architecture layer. The system-level code requirements are recursively decomposed into a list of sub-tasks with execution dependencies according to the data flow dependency of the autonomous driving system. A structured global shared double-layer blackboard is constructed and initialized. Step S3: Based on the structured global shared double-layer blackboard, the sub-agents corresponding to each sub-task load the corresponding dual constraint parameters according to the sub-task, retrieve the framework adaptation code snippets from the architecture knowledge base, generate the code for each sub-task, and write the generated code back to the structured global shared double-layer blackboard. The dual constraint parameters include port heavy-load business scenario constraints and autonomous driving architecture constraint parameters. Step S4: The assembly agent assembles the code of each subtask into a complete project according to the architecture layer, performs interface consistency verification and dual-track verification, and provides error feedback and regenerates the code when the verification fails. Step S5: After successful verification, output a compilable automotive-grade port autonomous driving engineering code package.

[0037] Of the five steps described above, step S1 is the knowledge preparation stage, step S2 is the task decomposition and collaboration carrier initialization stage, step S3 is the constraint-driven code generation stage, step S4 is the assembly verification and closed-loop correction stage, and step S5 is the result output stage. The structured globally shared double-layer blackboard runs through steps S2 to S4 and serves as the globally shared data carrier for multi-agent collaboration.

[0038] This invention proposes a dual-constraint code generation method for port autonomous driving, which integrates port heavy-load scenario constraints and autonomous driving architecture constraints. It uses a structured globally shared two-layer blackboard as the core collaborative carrier, where the contract layer guarantees architectural constraints and the constraint container layer carries scenario constraints. Through architecture layer perception, precise injection of dual constraints, dual-track verification closed loop, and policy circuit breaker mechanism, it realizes the automated generation of system-level requirements from port business level to compilable automotive-grade engineering code.

[0039] The above steps will be explained in more detail below with reference to the accompanying drawings.

[0040] In step S1, an architectural knowledge base for port operations and heavy load dynamics perception is constructed.

[0041] In some embodiments, the construction of the architecture knowledge base includes: collecting source code, interface definition files, communication mechanism documents, automotive-grade coding specifications, port operation communication protocols, and port heavy-duty vehicle dynamic constraint parameters of a specific version of the autonomous driving framework, storing them in vector form, constructing a Retrieval-Augmented Generation (RAG) knowledge base, and labeling it with version tags.

[0042] The specific version of the autonomous driving framework includes, but is not limited to, open-source autonomous driving frameworks such as Autoware and Apollo. The interface definition files include Interface Definition Language (IDL) files, message (Msg) definition files, and service (Srv) definition files. The communication mechanism documentation includes the Data Distribution Service (DDS) communication mechanism documentation for Robot Operating System 2 (ROS2).

[0043] The automotive-grade coding specifications include, but are not limited to, real-time coding rules such as prohibiting dynamic memory allocation within callback functions, mandating the configuration of Quality of Service (QoS) policies, and prohibiting blocking calls within the control cycle. In some embodiments, the automotive-grade coding specifications may refer to some rules of MISRA C++ and ROS2 real-time best practices.

[0044] The port operation communication protocols include: interaction protocols with the Terminal Operating System (TOS) (such as task assignment, status reporting, heartbeat keep-alive, etc.), and vehicle-to-everything (V2X) handshake protocols with Quay Cranes (QC) or Rail-Mounted Gantry Cranes (RC).

[0045] The dynamic constraints parameters for heavy-duty vehicles in ports include, but are not limited to: maximum deceleration limit under full load, minimum turning radius compensation value under full load, and center of gravity offset compensation parameters under heavy load. For example, straddle carriers can be up to 100 tons under full load, and their typical maximum deceleration limit is about 1.5 m / s², which is much lower than the deceleration parameters of conventional passenger cars (3-5 m / s²).

[0046] In some embodiments, the retrieval enhancement generation construction method of the architecture knowledge base includes: The framework source code is divided into blocks at the granularity of function, class, and interface definitions. A text embedding model is used to convert the block text into vector representations and store them in a vector database. A filtering strategy combining the top K items sorted by similarity and a similarity threshold is used for retrieval.

[0047] Optionally, the text embedding model can be a Chinese text embedding model such as bge-large-zh. The similarity threshold can be set to greater than 0.85 to ensure the relevance of the search results. The version tag has the structure "frame name + major version number + minor version number", which is used for precise filtering by frame version during retrieval.

[0048] It's important to note that dividing the framework source code into chunks based on function / class / interface definitions, rather than by a fixed number of characters, ensures that each chunk contains complete semantic units, thereby improving retrieval accuracy. Version tagging allows the same knowledge base to support code generation for multiple framework versions, avoiding interface incompatibility issues caused by framework version upgrades.

[0049] In step S2, the host intelligent agent performs architecture layering perception and recursive decomposition on the port equipment system-level code requirements input by the user.

[0050] In some embodiments, step S2 includes: Receive user input of port equipment system-level code requirements and framework version number; The main control agent retrieves the architecture knowledge base and, based on the node topology and data flow dependencies of the autonomous driving framework, identifies the architecture layers involved in the requirements and the data flow dependencies of port business. System-level requirements are recursively decomposed according to the architecture of autonomous driving nodes, generating a list of subtasks with execution dependencies, and a structured, globally shared, two-layer blackboard is constructed and initialized. The termination condition for recursive decomposition is that the subtask can be implemented by a single function logic and no longer contains cross-module communication and data dependencies.

[0051] The aforementioned architecture-layered perception refers to the main control agent identifying the architecture layers involved in user requirements based on the autonomous driving framework node topology and data flow dependencies stored in the architecture knowledge base, and recursively decomposing them according to the autonomous driving data flow dependencies.

[0052] Unlike general software engineering, which breaks down tasks according to roles such as product manager, architect, and programmer, the recursive decomposition of this invention is based on the "sensor → perception → planning → control → execution" data flow topology of an autonomous driving system. The decomposition result must ensure the consistency of message type, communication topic name, and state transition logic between upstream and downstream nodes.

[0053] Figure 2 A schematic diagram illustrating the mapping between a structured globally shared two-layer blackboard and a layered architecture, according to an embodiment of the present invention, is shown, such as... Figure 2 As shown, the architecture layered by this invention includes a data interface layer, a core algorithm layer, and a system configuration layer: The data interface layer is used for sensor driving, communication adaptation, and data format conversion; The core algorithm layer is used for perception and localization, planning and decision-making, and motion control according to the autonomous driving data stream. The system configuration layer is used for script building, startup configuration, and parameter file management.

[0054] It is important to note that the "architectural layering" here refers to the hierarchical organization of the autonomous driving system's code architecture, not the hierarchical architecture knowledge base: the architecture knowledge base is the RAG vector library built in step S1, used for storing and retrieving knowledge; architectural layering is the division of the organization method of the autonomous driving code project in step S2.

[0055] The data interface layer is the data entry point for the autonomous driving system, and its code quality directly affects the input reliability of the upstream algorithm layer.

[0056] In some embodiments, the data interface layer includes a Controller Area Network (CAN) bus driver node, a LiDAR point cloud subscription node, a Global Navigation Satellite System (GNSS) positioning data subscription node on the vehicle side, and a User Datagram Protocol (UDP) data adaptation node and a simulation clock synchronization node on the simulation side.

[0057] The functions of each node in the data interface layer are as follows: Vehicle-side CAN bus driver node: Used to realize CAN bus communication adaptation between port heavy-duty vehicles and on-board controllers, steering / braking / drive actuators and other hardware, and to complete bidirectional message packaging, parsing and format conversion of low-level control command issuance and hardware feedback signal reporting; LiDAR point cloud subscription node: used to subscribe to the raw point cloud data stream output by the vehicle-mounted LiDAR, complete timestamp synchronization, coordinate system calibration transformation and data format standardization, and provide reliable 3D environment point cloud input to the upstream perception algorithm layer; Satellite navigation and positioning data subscription node: used to subscribe to latitude, longitude, heading and speed information output by GNSS / Real-Time Kinematic (RTK) high-precision positioning module, complete coordinate projection transformation and positioning quality marking, and provide absolute position reference for high-precision positioning and path tracking; Simulation-side UDP data adapter node: Used to receive virtual sensor data and vehicle status issued by the digital twin simulation platform via UDP protocol, and convert them into an internal message format that is completely consistent with that of the real vehicle, so as to realize the interface alignment between simulation data and real vehicle data.

[0058] The core algorithm layer is further divided into a perception and localization sublayer, a planning and decision-making sublayer, and a motion control sublayer according to the autonomous driving data flow: The perception and localization sublayer is used for obstacle detection and tracking, lane line / container corner component recognition, high-precision positioning, etc. The planning and decision-making sublayer is used for global path planning, behavioral decisions, port business state machines, etc. The motion control sublayer is used for path tracking, speed planning, control command output, etc.

[0059] There are strict upstream and downstream data dependencies between the sub-layers, that is, the output of the perception and positioning sub-layer serves as the input of the planning and decision-making sub-layer, and the output of the planning and decision-making sub-layer serves as the input of the motion control sub-layer.

[0060] The system configuration layer includes build files, dependency declaration files, startup files, and parameter configuration files.

[0061] In a ROS2 project, the build file is the CMakeLists.txt file, which defines the project's compilation rules, source file organization, dependency library linking, and executable target generation method. It is the core build script for ROS2 projects to complete compilation via colcon.

[0062] The dependency declaration file is a package.xml file, which is used to declare the name, version, maintainer information, and compile-time and runtime dependencies of the package on other ROS2 packages and system libraries, so that the build system can perform dependency resolution.

[0063] The startup file is a launch file, which is used to define the startup order, running parameters, namespace and topic remapping relationship of each node, so as to realize one-click orchestration and startup of multi-node system.

[0064] The parameter configuration file is a YAML file used to centrally store the adjustable parameters of the node (such as heavy load dynamic limits, control cycles, QoS policies, etc.) in key-value form, thereby decoupling the parameters from the code and facilitating rapid adaptation to different vehicle models and scenarios.

[0065] It should be noted that the autonomous driving function data flow "sensor → perception → planning → control → execution" has a many-to-many mapping relationship with the three architectural layers mentioned above, rather than a one-to-one correspondence: the sensor stage corresponds to the data interface layer (sensor driver, communication adapter); the perception, planning, and control stages correspond to the three sub-layers of the core algorithm layer; the execution stage returns to the data interface layer (control commands are sent to the actuator via the CAN bus driver node); the system configuration layer is not on the functional data flow link, but is a horizontal support layer that supports the compilation, startup, and parameter management of the entire project.

[0066] In short, data flow is the "functional dimension," architectural layering is the "code organization dimension," sensors and execution belong to the data interface layer (one in and one out), perception / planning / control belong to the core algorithm layer, and the system configuration layer is the global support layer.

[0067] The controlling agent recursively decomposes system-level requirements according to the above architecture. The termination condition for recursive decomposition is: the subtask can be implemented by a single function logic and no longer contains cross-module communication and data dependencies.

[0068] For the data interface layer, the actual vehicle end and the simulation end are automatically separated into independent subtasks during decomposition, and a dual-end switching identifier (SIMULATION macro definition) is injected into the blackboard to ensure that the actual vehicle and simulation codes are automatically generated from the same requirements and that the interfaces are consistent.

[0069] The core collaborative carrier of this invention is a structured, globally shared, two-layer blackboard. For example... Figure 2 As shown, the structured globally shared two-layer blackboard includes a Contract Layer and a Constraint Container Layer: The contract layer is a globally shared read-only layer that stores global interface definitions, valid state machine transition matrices, dual-end adaptation identifiers (real vehicle / simulation environment switching markers), and subtask dependency graphs for all sub-agents to align in read-only mode. All sub-agents must read the contract layer to align variable naming with state machine definitions, ensuring that the generated code is consistent at the interface level.

[0070] The constraint container layer is instantiated independently for each subtask, storing the port heavy-load business scenario constraints and autonomous driving architecture constraint parameters corresponding to that subtask.

[0071] The contract layer and the constraint container layer have different functions: the contract layer ensures the global consistency of architectural constraints, that is, the code generated by all sub-agents must be consistent with the contract layer in terms of interface definition, state machine transition, and dual-end adaptation; the constraint container layer carries out the precise injection of scenario constraints by sub-task, that is, each sub-task only loads the constraint parameters related to itself, avoiding irrelevant constraints from interfering with code generation.

[0072] The initialization of the double-layer blackboard refers to the process by which the master control agent establishes and fills the two layers of the double-layer blackboard according to the decomposition results after completing the hierarchical perception and recursive decomposition of system-level requirements and before the sub-agents start generating code. Specifically, it includes the initialization of the contract layer and the instantiation of the constraint container layer.

[0073] In some embodiments, the initialization of the structured globally shared two-layer blackboard includes the initialization of the contract layer: The master control agent predetermines and writes global interface definitions, legal state machine transition matrices, dual-end adaptation identifiers, and subtask dependency graphs based on the subtask list and its data flow dependencies. This ensures that the contract layer has a globally unique and consistent interface and state machine benchmark before the sub-agents generate code, allowing all sub-agents to read-only align. The global interface definition includes the variable names, message types, communication topic names, and service interface signatures transmitted between nodes.

[0074] A subtask dependency graph is a directed graph consisting of subtasks as nodes and directed edges representing data flow dependencies or execution order constraints between subtasks. This graph describes the dependencies and execution order between subtasks after recursive decomposition. For example, perception subtasks depend on the output of data interface subtasks, and motion control subtasks depend on the output of planning and decision subtasks. This ensures that code generation and assembly follow the upstream and downstream constraints of the autonomous driving data flow, avoiding circular dependencies or incorrect execution order.

[0075] The legal state machine transition matrix refers to a global rule table that defines the allowed transitions and triggering conditions between discrete states in the port operation process in matrix form. This matrix is ​​stored in the contract layer and is used to constrain the state machine code generated by the sub-agent to only contain legal transitions, prohibiting illegal transitions or omissions of necessary transitions. It also ensures that multiple state machines across subtasks reference a unified state definition, thereby guaranteeing the continuity and consistency of the assembled state flow. Unlike the overloaded dynamic parameters stored in the constraint container layer (used locally by subtask), the state machine transition matrix is ​​global and shared across subtasks: multiple subtasks related to the port business state machine (such as the TOS task interaction state machine, QC alignment handshake state machine, speed planning and limiting) all need to reference the same set of state definitions and the same combination of transition rules, therefore, it must be enforced at the contract layer.

[0076] The closed-loop function of the legal state machine transition matrix in this invention includes three aspects: Firstly, in the writing phase (step S2 initialization stage), when the main control agent initializes the double-layer blackboard, it constructs the matrix based on the port operation process knowledge in the architecture knowledge base and writes it into the contract layer. Secondly, in the reading phase (step S3 generation stage), each state machine subtask of the planning decision sublayer reads the matrix from the contract layer and generates state transition codes only for the legal jumps marked in the matrix, referencing a unified state name and state number. Third, the verification process (step S4 verification stage) involves static scanning of the abstract syntax tree in the first track to compare the state transition statements in the generated code with the matrix definition. If a transition marked as illegal by the matrix is ​​found in the code, or a necessary legal transition in the matrix is ​​missing, the port business compliance verification is deemed to have failed, and the corresponding sub-agent is regenerated according to the policy circuit breaker mechanism.

[0077] Therefore, the legal state machine transition matrix, as one of the core contents of the contract layer, together with the limit code template (constraint container layer), constitutes the two pillars of the dual-constraint forced injection of this invention: the former ensures the correctness of state transition (business logic), and the latter ensures the correctness of numerical limit (physical security).

[0078] The core significance of contract layer initialization is that before any sub-agent starts generating code, the global interface and the baseline of the state machine have been determined and written into the contract layer. All sub-agents must align with this baseline in a read-only manner, thereby avoiding problems such as inconsistent interface naming, mismatched message types, and state machine transition conflicts when multiple agents generate code in parallel from the root. This is fundamentally different from the traditional multi-agent framework where each agent freely defines its interface and then aligns it afterward.

[0079] In some embodiments, the initialization of the structured globally shared two-layer blackboard further includes the instantiation of a constraint container layer: The main control agent creates independent constraint container instances for each subtask, and retrieves the port heavy-load business scenario constraints and autonomous driving architecture constraint parameters corresponding to the subtask from the architecture knowledge base, and fills them into the constraint containers of the corresponding subtasks. This ensures that each subtask only loads constraint parameters related to itself when generating code, thereby achieving hierarchical and subtask-based isolation and injection of constraints.

[0080] The design of the constraint container layer being instantiated independently by subtask allows different subtasks to load different combinations of constraint parameters.

[0081] For example, subtasks in the motion control sublayer need to load heavy-load dynamic parameters (such as deceleration limits and turning radius compensation values), while subtasks in the planning and decision-making sublayer need to load port business protocol parameters (such as TOS interaction protocol fields and QC / RC alignment handshake protocol fields), and subtasks in the data interface layer need to load dual-end adaptation constraint parameters. This constraint injection method, which isolates constraints by subtask, avoids the context redundancy and interference caused by injecting all constraint parameters into all subtasks at once.

[0082] After the above initialization, the double-layer blackboard forms a complete data structure of "globally shared read-only contract layer + constraint container layer that is independently instantiated by subtask", providing a unified interface benchmark and isolated constraint parameter source for the generation of constraint code for each sub-agent in the subsequent step S3.

[0083] Step S3 is the core step in generating constraint code for sub-agents based on the structured double-layer blackboard. In step S3, based on the structured globally shared double-layer blackboard, the sub-agents corresponding to each sub-task generate the code for each sub-task.

[0084] In some embodiments, step S3 includes: Each sub-agent reads the global interface definition from the contract layer of the structured global shared double-layer blackboard to align variable naming with the state machine definition, extracts the constraint parameters corresponding to the sub-task from the constraint container layer, and retrieves the architecture knowledge base to obtain the framework adaptation code snippet. Subtask code is generated by parameter interpolation based on the clipping code template, and overloaded clipping logic and double-ended conditional compilation flags are injected into the subtask code. Once generated, the code is written back to the structured globally shared double-layer blackboard and the contract layer state is updated.

[0085] In the above process, the code generation of the sub-agent is subject to three constraints: First, the global interface definition is read from the contract layer to ensure that the generated code is consistent with the global benchmark in terms of variable naming, message type, communication topic name, service interface signature, state machine transition, etc.; Second, the constraint parameters corresponding to the sub-task are extracted from the constraint container layer to ensure that the constraints of the port heavy load business scenario and the autonomous driving architecture constraints are accurately injected; Third, the framework adaptation code snippets are retrieved from the architecture knowledge base to ensure that the generated code conforms to the interface specifications and coding patterns of the specific version of the autonomous driving framework.

[0086] In some embodiments, the parameter interpolation based on the clipping code template refers to using a clipping code skeleton with parameter slots to fill the heavy-load dynamic parameters in the constraint container layer into the parameter slots, thereby forcibly including clipping protection logic in the generated code. The clipping code skeleton can be represented as follows: when the controlled parameter is greater than the threshold, the controlled parameter is assigned the threshold value (if({param} > {threshold}) {param} = {threshold}).

[0087] For example, in the velocity planning subtask, the maximum deceleration limit stored in the constraint container layer is 1.5 m / s². The code generated after parameter interpolation includes the following limiting logic: when the deceleration command is greater than 1.5, the deceleration command is assigned a value of 1.5. This ensures that the generated control code necessarily includes heavy-load limiting protection logic, preventing the hundred-ton heavy-load equipment from becoming unstable, container overturning, or tire blowouts due to excessive deceleration.

[0088] Similarly, other dynamic parameters such as steering angular velocity and acceleration can be injected through corresponding limiting code templates for parameter interpolation. Dual-ended conditional compilation flags (such as the SIMULATION macro definition) are injected into the code branches of the real vehicle and simulation ends through conditional compilation statements, ensuring that the same subtask can generate two sets of consistent code for the real vehicle and simulation ends.

[0089] The core innovation of this invention lies in its dual-constraint driving mechanism. The dual constraints refer to two types of domain constraints in the port autonomous driving scenario, which jointly drive the code generation process: The first category is constraints imposed by port heavy-load business scenarios, specifically including: (1) Heavy load dynamic constraints: maximum deceleration limit under full load, minimum turning radius compensation value, center of gravity offset compensation parameters, etc. These constraints are forcibly injected into the motion control sub-layer code through parameter interpolation using a limiting code template, ensuring that the generated control code necessarily contains limiting protection logic.

[0090] (2) Port business agreement constraints: interaction protocols with TOS (task issuance, status reporting, heartbeat keep-alive), V2X handshake protocols with QC / RC, etc. These constraints are forcibly injected into the planning and decision sub-layer code through the state machine transition matrix to ensure that the generated state machine code contains the complete port operation process.

[0091] (3) Automotive-grade coding constraints: prohibiting dynamic memory allocation within callbacks, mandating the configuration of communication QoS policies, and prohibiting blocking calls within the control cycle. These constraints are enforced through static scanning of the Abstract Syntax Tree (AST) to ensure that the generated code meets real-time requirements.

[0092] The second category is autonomous driving architecture constraints, specifically including: (1) Architecture layering constraints: The code must be organized according to the layered structure of data interface layer, core algorithm layer and system configuration layer, and there is a strict data flow dependency between each layer: "sensor → perception → planning → control → execution".

[0093] (2) Data flow dependency constraints: The message type, communication topic name, and state transition logic between upstream and downstream nodes must be consistent, which is enforced by the contract layer of the structured global shared double-layer blackboard.

[0094] (3) Dual-end adaptation constraint: The interface signatures of the real vehicle end and the simulation end must be consistent. This is ensured by conditional compilation identifier and contract layer to ensure that the real vehicle code can be used directly after the simulation verification is passed.

[0095] It's important to note that while the domain parameters (dynamic, protocol, and automotive-grade parameters) in the dual-constraint framework are stored in the constraint container layer, the enforced effectiveness of the dual constraints relies on three interconnected mechanisms: first, the constraint container layer stores the parameters; second, the clipping code template forces the parameters into the code through parameter slot interpolation; and third, static AST scanning and data flow value range tracing enforce the verification that the constraints are indeed in effect during the validation phase. Meanwhile, architectural constraints (data flow dependencies, interface consistency) are guaranteed by the contract layer, which has a different function from the constraint container layer.

[0096] Therefore, this invention uses a structured double-layer blackboard as the core carrier, in which the contract layer guarantees architectural constraints, the constraint container layer carries scenario constraints, and a constraint-forced closed loop is formed through amplitude-limiting template interpolation and dual-track verification.

[0097] The aforementioned dual constraints are fundamentally different from those in general code generation methods: the constraints of general methods (such as multi-agent code generation frameworks based on role division of labor) come from the role division of software engineering and do not involve the data flow and dynamics constraints of physical systems; while the dual constraints of this invention come from the physical and protocol constraints of port heavy-load business scenarios and the structural requirements of autonomous driving architecture. The two together drive the code generation process, ensuring that the generated code meets the heavy-load safety requirements in terms of physical behavior and meets the data flow consistency requirements of autonomous driving in terms of code structure.

[0098] Step S4 is the assembly and dual-track verification closed-loop process. In step S4, the assembly agent assembles the code of each subtask into a complete project according to the architecture and performs verification. In some embodiments, step S4 includes: The assembly agent assembles the code of each subtask into a complete project according to the architecture layering; Perform interface consistency verification by comparing the global interfaces referenced in each subtask code with the global interface definitions of the contract layer. Perform dual-track verification to check the code compliance and compilability of the complete project; If all checks pass, proceed to step S5; if checks fail, distinguish the error level and report back to the corresponding agent for correction.

[0099] In some embodiments, the interface consistency check includes: The global variable names, message types, and communication topic names referenced in each subtask code are compared with the contract layer definition to see if they match. If they do not match, a structured error feedback package is generated and the corresponding sub-agent is triggered to correct it. The structured error feedback package includes an error type label, error location information, and a correct reference value from the contract layer.

[0100] The error type label includes, for example, variable name mismatch, message type inconsistency, missing QoS, compilation error, etc.; the error location information includes the file, line number, variable name or function name of the error; the correct reference value from the contract layer includes, for example, the standard name and standard message type of the variable registered in the contract layer.

[0101] The structured error feedback package, along with the original subtask description, is re-input into the corresponding sub-agent. The sub-agent then regenerates only the code for that subtask (not the entire code), and during regeneration, forces alignment between the contract layer definition and constraint container layer parameters. The corrected code is then written back to the blackboard and participates in assembly and verification again, forming a local closed loop.

[0102] Figure 3 A flowchart of constraint injection (S3) and compliance verification (S4) according to an embodiment of the present invention is disclosed, as follows: Figure 3 As shown, the constraint injection (occurring in step S3, the sub-agent code generation stage) and the port business compliance verification (occurring in step S4, the first track of the dual-track verification) are linked together into a process: the amplitude limiting logic injection and protocol logic injection belong to step S3; the dynamic constraint verification and protocol compliance verification belong to the first track of step S4.

[0103] Figure 4 A schematic diagram of the closed-loop logic for sandbox compilation and port business compliance dual-track verification according to an embodiment of the present invention is disclosed, such as... Figure 4 As shown, the first track in the dual-track verification is a static scan of the Abstract Syntax Tree (AST) and a port business compliance verification. In some embodiments, the first track includes: Scan function call nodes to detect dynamic memory allocation operations (new / malloc), scan assignment statement nodes to detect missing Quality of Service (QoS) configurations, and scan conditional expression nodes to detect the existence of clipping logic. By using in-process forward data flow propagation, the range of values ​​of acceleration and steering angle variables from calculation to output is tracked to determine whether the control command calculation logic exceeds the heavy load dynamic boundary.

[0104] Specifically, AST static scanning includes the following detection items: (1) Dynamic memory allocation detection: Scan function call nodes to detect whether there are dynamic memory allocation operations such as new or malloc in the callback function. Automotive-grade real-time systems require that dynamic memory allocation be prohibited in the callback function to avoid control cycle jitter caused by the uncertainty of memory allocation.

[0105] (2) QoS Configuration Missing Detection: Scan assignment statement nodes to detect whether the communication subscriber or publisher has configured a QoS policy. The port autonomous driving system has strict requirements for communication reliability and must enforce the configuration of a QoS policy (such as the reliability policy RELIABILITY).

[0106] (3) Existence detection of limiting logic: Scan the condition expression node to check whether the motion control code contains heavy load dynamics limiting logic. If no limiting logic is detected, it means that the heavy load dynamics constraint has not been effectively injected.

[0107] In addition to the static scanning described above, the first track also employs in-process forward data flow propagation technology to track the complete value range of control variables such as acceleration and steering angle from calculation to output, and to determine whether the calculation logic of the control command may exceed the heavy-load dynamic boundary. For example, if the upper limit of the calculated value range of the deceleration variable in the velocity planning code exceeds the maximum deceleration limit of 1.5 m / s² stored in the constraint container layer, then the code is determined to have a heavy-load safety hazard.

[0108] The second track in the dual-track verification is sandbox compilation verification.

[0109] In some embodiments, the second track includes: executing a project compilation command (colcon build) in a containerized build environment, detecting syntax errors, missing dependencies, linking errors and symbol conflicts, and if the compilation is successful, the complete project meets the buildability requirements.

[0110] Optionally, the containerized build environment can use Docker containers, and the project compilation command in a ROS2 project is the `colcon build` command. Sandbox compilation verification ensures that the generated code is not only syntactically and compliant with specifications, but also can actually be compiled to generate an executable file. This is fundamentally different from verification methods that only perform static analysis without actual compilation.

[0111] If both checks pass, the system proceeds to the S5 output stage; if the checks fail, a policy-based circuit breaker mechanism is used to differentiate the error level and provide feedback to the corresponding agent for correction. This includes subtask-level error feedback and architecture-level error feedback. The subtask-level error feedback includes parsing the error log and feeding it back to the corresponding sub-agent when the error belongs to an internal problem of the subtask and the cumulative number of automatic repairs is less than a preset threshold, and the sub-agent regenerates the code of the subtask. The architecture-level error feedback includes, when the cumulative number of automatic repairs reaches or exceeds the preset threshold, feeding back to the main control agent to re-disassemble the task or modify the contract layer definition; Each subtask maintains an independent repair counter, and the preset threshold is a configurable parameter.

[0112] like Figure 4 As shown, the policy-based circuit breaker mechanism has two paths: subtask-level feedback and architecture-level feedback. Subtask-level error feedback is applicable to internal subtask problems such as syntax errors and single-module compilation failures, which can be resolved by local correction by the corresponding sub-agent. Architecture-level error feedback is applicable when the cumulative number of repairs reaches a threshold. At this point, the error may involve architectural design flaws (such as incorrect interface definitions or unreasonable task decomposition), requiring the task to be re-decomposed by the master agent or the contract layer definition to be modified.

[0113] The preset threshold N is a configurable parameter, and the default value can be set based on empirical statistics. For example, 3 fixes can cover more than 90% of automatically fixable compilation errors. Exceeding the threshold indicates that the error may involve architectural design flaws, and further fixes at the subtask level are unlikely to be effective. Therefore, a circuit breaker escalation is triggered, and the case is handed over to the main control agent for processing.

[0114] Each subtask maintains an independent repair counter to prevent multiple repairs in one subtask from affecting the repair strategies of other subtasks. This circuit breaker mechanism ensures both rapid repair of local errors and avoids ineffective iterations of sub-agents on architectural errors.

[0115] In step S5, after the dual-track verification passes, a compilable automotive-grade port autonomous driving engineering code package is output.

[0116] The compilable automotive-grade port autonomous driving engineering code package output in step S5 includes: data interface layer node source code, core algorithm layer node source code, and system configuration layer build and startup files.

[0117] The data interface layer node source code includes sensor driver, communication adaptation, and data format conversion node code for both the real vehicle and simulation ends; the core algorithm layer node source code includes algorithm node code for the perception and localization sublayer, planning and decision-making sublayer, and motion control sublayer; the system configuration layer build and startup files include build files, dependency declaration files, startup files, and parameter configuration files. The real vehicle and simulation end code is automatically generated from the same system-level requirements, and interface signatures are ensured to be consistent through a contract layer and conditional compilation identifiers.

[0118] The output project code is automotive-grade code that can be directly compiled, meeting automotive-grade requirements such as prohibiting dynamic memory allocation within callbacks, configuring QoS policies, and injecting amplitude limiting protection logic.

[0119] This invention proposes a dual-constraint code generation method for port autonomous driving. It uses a structured, globally shared, two-layer blackboard as its core carrier. The contract layer guarantees architectural constraints, while the constraint container layer carries scenario constraints. Dual-constraint parameters are forcibly written into the code through parameter slot interpolation of the limited code template, and dual-track verification loops enforce the effectiveness of the dual constraints. Thus, a complete mechanism is formed by the collaborative efforts of "structured two-layer blackboard + precise dual-constraint injection + dual-track verification loop + policy circuit breaker". This method ensures that port heavy-load business scenario constraints and autonomous driving architecture constraints are precisely injected and enforced, enabling the generated engineering code to meet the physical behavior requirements of heavy-load dynamics, port business protocols, and automotive-grade real-time requirements, and to meet data flow consistency and dual-end adaptation requirements in terms of code structure. This achieves one-time automatic generation from port business requirements to compilable automotive-grade engineering code, effectively improving the security, consistency, and reliability of code generation.

[0120] Although the methods described above are illustrated and described as a series of actions for the sake of simplicity, it should be understood and appreciated that these methods are not limited by the order of the actions, as some actions may occur in a different order and / or concurrently with other actions from the illustrations and descriptions herein or not illustrated and described herein but which may be understood by those skilled in the art, according to one or more embodiments.

[0121] This invention also provides a dual-constraint code generation system for port autonomous driving. In some embodiments, the system includes a processor and a memory. The memory stores a computer program; the processor executes the computer program stored in the memory to implement the dual-constraint code generation method for port autonomous driving as described in any of the preceding embodiments. The specific workflow of this system can be referred to steps S1 to S5 of the aforementioned method, and will not be repeated here.

[0122] It should be noted that the master intelligent agent, sub-intelligent agents, and assembly intelligent agents described in this invention are all intelligent agents based on Large Language Models (LLM). They achieve task decomposition, code generation, and code assembly functions by utilizing the reasoning capabilities of the LLM. Multiple intelligent agents share information and collaborate through a structured, globally shared, double-layered blackboard.

[0123] The following examples, exemplified by Example 1 and Example 2, further illustrate the dual-constraint code generation method for port autonomous driving proposed in this invention.

[0124] Example 1: Automatic alignment node code generation for port straddle carrier quay cranes.

[0125] The following example, using the automatic alignment scenario of a straddle carrier in the quay crane area at a port, further illustrates the specific implementation of the present invention.

[0126] Step S1: Collect the source code of the Autoware.universe version, interface definition files (including message definitions such as autoware_auto_msgs and sensor_msgs), ROS2 DDS communication mechanism documents, automotive-grade coding specifications (MISRA C++ rules, ROS2 real-time best practices), port operation communication protocols (TOS task issuance protocol JSON Schema, QC quay crane positioning handshake protocol V2X message format), and straddle carrier heavy-load dynamic parameters (maximum deceleration at full load 1.5 m / s², minimum turning radius compensation coefficient 1.2, center of gravity offset compensation parameter 0.15 m), build an architecture knowledge base (i.e., RAG knowledge base) and label it with version tags.

[0127] Step S2: The user input requirement is "Generate automatic alignment nodes for straddle carriers in the quay crane area, framework version Autoware.universe v0.38". The main control agent retrieves the architecture knowledge base and identifies the requirements involving the data interface layer (LiDAR point cloud subscription, GNSS positioning subscription, CAN bus driver, simulated UDP adaptation), the core algorithm layer (quay crane container corner component detection, TOS task interaction state machine, QC alignment handshake state machine, path tracking control, speed planning and limiting), and the system configuration layer (CMakeLists.txt, launch file). These are recursively broken down into 8 sub-tasks according to data flow dependencies, and a double-layer blackboard is initialized.

[0128] The eight subtasks can be summarized by architecture as follows: The data interface layer consists of three subtasks: a LiDAR point cloud subscription node, a GNSS positioning data subscription node, and a CAN bus driver node (on the actual vehicle) and a UDP simulation adaptation node (on the simulation end, both serving as dual-end instances of the same subtask); the core algorithm layer consists of five subtasks: the perception sublayer is the quay crane container corner fitting detection node; the planning sublayer consists of the TOS task interaction state machine node and the QC alignment handshake state machine node; and the control sublayer consists of the path tracking control node and the speed planning and amplitude limiting node. Additionally, the system configuration layer includes CMakeLists.txt and launch files, which are generated along with the project as system configuration layer artifacts.

[0129] When initializing the double-layer blackboard, the legal state machine transition matrix written in the contract layer takes the automatic alignment scenario of straddle carrier quay crane as an example. Its state definition includes 8 discrete states: A0 (Idle, vehicle on standby, waiting for task to be issued), A1 (receive TOS task, receive alignment task issued by the terminal operating system), A2 (go to quay crane, complete path planning and drive to quay crane operation area), A3 (coarse alignment, initial position alignment after entering the quay crane area), A4 (fine alignment handshake, perform V2X handshake with quay crane QC and complete centimeter-level alignment), A5 (wait for lifting / unloading container, alignment completed, wait for quay crane to complete lifting or unloading container), A6 (task completion report, operation completed, report task results to TOS), A7 (abnormal stop, detect fatal abnormality, stop safely).

[0130] The legal state machine transition matrix defines the legal transitions between the nine states in matrix form, with rows representing the current state and columns representing the target state. Cells marked as legal transitions in the matrix are allowed only when the corresponding triggering condition is met, while cells marked as illegal transitions are prohibited from appearing in the state machine code. Diagonal and meaningless transitions are marked as meaningless. The legal transitions for each state are as follows: A0 can only transition to A1 (triggered by receiving a TOS task) or A7 (triggered by a fatal exception); A1 can only transition to A2 (triggered by successful verification and a ready path) or A7; A2 can only transition to A3 (triggered by reaching the quay crane area) or A7; A3 can only transition to A4 (triggered by coarse alignment error less than the threshold) or A7; A4 can transition to A3 (triggered by handshake failure or timeout rollback), A5 (triggered by successful handshake and accuracy met) or A7; A5 can only transition to A6 (triggered by receiving a hoisting or container unloading completed) or A7; A6 can transition to A0 (triggered by completing TOS reporting) or A7; A7 can transition to A0 (triggered by exception resolution and reset). Any state can transition to A7 (abnormal stop) when a fatal exception is detected. This global exception transition is not expanded grid-by-grid in the main matrix.

[0131] Step S3: Each sub-agent reads the interface definition from the blackboard contract layer (e.g., the alignment status message type is autoware_auto_msgs / msg / AlignmentStatus, and the Topic name is / alignment / status), extracts constraint parameters from the constraint container layer (e.g., deceleration limit of 1.5 m / s²), retrieves the Autoware interface adaptation code snippet from the RAG knowledge base, and generates sub-task code based on the limiting code template through interpolation. For example, the following limiting logic is generated in the velocity planning sub-task: when the deceleration command is greater than 1.5, the deceleration command is assigned the value 1.5.

[0132] Step S4: Assemble the intelligent agent by assembling the code for 8 subtasks and performing interface consistency checks. Static AST scan confirms: no new / malloc calls within the callback function, QoS policy configured as RELIABILITY, and speed planning code includes deceleration limiting logic. Sandbox compilation verification: `colcon build` is executed in a Docker container; compilation succeeds.

[0133] Step S5: Output a compilable code package for the automatic alignment of the straddle carrier quay crane, including source code for the data interface layer nodes, source code for the core algorithm layer nodes, and system configuration layer build and startup files.

[0134] Example 2: Code generation for autonomous handling perception and decision-making nodes between port AGV yards; This embodiment uses the perception and decision-making scenario of an Automated Guided Vehicle (AGV, also known as an Intelligent Guided Vehicle) autonomously handling containers between yards as an example to further illustrate the universality of the present invention.

[0135] The specific differences between Example 2 and Example 1 are as follows: The business agreement constraints are different: Implementation 1 involves alignment handshake with the QC of the quay crane (QC alignment handshake V2X protocol); Implementation 2 involves alignment with the RC of the yard crane (RC alignment handshake protocol), and requires docking with yard operation instructions rather than shore loading and unloading instructions.

[0136] The dynamic parameters are different: the straddle carrier has a full load of about 60-80 tons, a maximum deceleration limit of 1.5 m / s², a minimum turning radius compensation coefficient of 1.2, and a center of gravity offset compensation of 0.15 m; the AGV / IGV has a full load of about 60-70 tons but a lower chassis and a more stable center of gravity, and the maximum deceleration limit can be relaxed to 2.0 m / s², the minimum turning radius compensation coefficient is about 1.1, and the center of gravity offset compensation is about 0.08 m.

[0137] The sensing requirements are different: Implementation 1 requires identifying the corner lock holes of containers under the quay crane to achieve centimeter-level alignment; Implementation 2 requires identifying the number of stacking layers and the edge of the stacking position of containers in the yard to achieve stacking positioning.

[0138] By injecting the different parameters mentioned above into the constraint container layer, the same method can generate engineering code that is compatible with two vehicle models, demonstrating the versatility of the method.

[0139] Step S1: Collect the source code and interface definition of the corresponding version of Autoware.universe, ROS2 DDS communication documents, automotive-grade coding specifications, and yard operation communication protocols (RC yard bridge alignment handshake protocol, TOS stacking task issuance protocol) and AGV / IGV heavy-load dynamic parameters (maximum deceleration 2.0 m / s², minimum turning radius compensation coefficient 1.1, center of gravity offset compensation 0.08 m), and build and label the RAG knowledge base with version tags.

[0140] Step S2: The user input requirement is "to generate a perception and decision-making node for AGVs to autonomously move containers between yards". The main control agent searches the knowledge base and identifies the data interface layer (LiDAR / GNSS / CAN / simulated UDP), core algorithm layer (yard container palletizing recognition, RC alignment handshake state machine, TOS stacking task state machine, path tracking, speed planning and limiting), and system configuration layer involved in the requirement. It recursively decomposes the requirement into several sub-tasks according to data flow dependencies and initializes the double-layer blackboard.

[0141] Step S3: Each sub-agent reads the interface definition from the contract layer, extracts AGV-specific constraint parameters (deceleration limit of 2.0 m / s², etc.) from the constraint container layer, retrieves the framework adaptation fragment from the RAG, and generates code based on the limiting template interpolation. For example, the speed planning subtask generates the following limiting logic: when the deceleration command is greater than 2.0, the deceleration command is assigned the value 2.0 (if(decel_cmd > 2.0) decel_cmd = 2.0).

[0142] Step S4: Assemble the agent to assemble the subtask code and perform interface consistency verification; AST static scan confirms no dynamic memory allocation within callbacks, QoS is configured, and the limiting logic exists with a value range not exceeding 2.0 m / s²; colconbuild compiles successfully within the sandbox.

[0143] Step S5: Output a compilable AGV yard handling perception and decision-making engineering code package, including the source code of the data interface layer, the core algorithm layer nodes, and the system configuration layer build and startup files.

[0144] This demonstrates that by simply injecting parameters and protocols for different vehicle models / scenarios into the constraint container layer, adaptation code can be generated without modifying the method framework itself, thus verifying the universality of this method in the field of port autonomous driving.

[0145] Compared with existing technologies, the dual-constraint code generation method and system for port autonomous driving proposed in this invention have the following advantages: 1) One-time generation, ready to use. Users only need to provide a description of their port business requirements, and the system automatically detects the architectural layers, injects double constraints, and generates compilable code, eliminating the pain points of repeated communication and multiple rounds of modification in traditional development. Users do not need to have low-level development knowledge of autonomous driving frameworks, nor do they need to repeatedly interact with the code generation tool for multiple rounds of correction.

[0146] 2) Heavy-load safety assurance. Heavy-load dynamic constraints are forcibly injected through a limiting code template, ensuring that the generated control code necessarily includes limiting protection logic, thus preventing safety accidents caused by excessive deceleration in hundred-ton-class heavy-load equipment. Data flow value range tracking in AST static scanning further verifies that the value range of control commands does not exceed the heavy-load dynamic boundary, forming a double guarantee.

[0147] 3) Architectural Consistency Guarantee. A structured, two-layered blackboard contract layer enforces alignment of interface definitions for each sub-agent, ensuring consistent data flow and coherent state machines after assembling multi-module code. The contract layer determines the global interface and state machine baseline before the sub-agents generate code, fundamentally preventing interface discrepancies when multiple agents generate code in parallel.

[0148] 4) Consistent code between the two ends. The actual vehicle code and the simulation code are automatically generated from the same requirements. The consistency of the interface is jointly guaranteed by the contract layer and the conditional compilation flag, which eliminates the interface divergence problem caused by maintaining two sets of code for the actual vehicle hardware driver interface and the simulation environment adaptation interface in traditional development. This ensures that the actual vehicle code can be used directly after the simulation verification is passed.

[0149] 5) Compilation and Verification Closed Loop. A dual-track verification process, combining static AST scanning and sandbox compilation with a policy-based circuit breaker mechanism, ensures that the generated code passes both compilation verification and business compliance checks, eliminating the need for manual checking of syntax and dependency errors. The policy-based circuit breaker mechanism distinguishes between task-level and architecture-level errors, guaranteeing efficient repair of localized errors while promptly escalating to architecture-level feedback when cumulative repairs exceed a threshold, thus avoiding ineffective loops.

[0150] It should be noted that the method described in this invention is a technical solution closely integrated with the engineering of port heavy-duty autonomous vehicle control systems and robot operating systems. By constructing a retrieval-enhanced generative architecture knowledge base, using a structured globally shared double-layer blackboard as a multi-agent collaboration carrier, employing amplitude-limited code template parameter interpolation, and combining abstract syntax tree static scanning with sandbox compilation for dual-track verification, it solves technical problems in port autonomous driving code development, such as difficulty in ensuring heavy-duty dynamic constraints, error-prone business protocol state machines, divergent interfaces, and easy violations of automotive regulations. This generates compilable engineering code that meets the requirements of heavy-duty safety and automotive-grade real-time performance. The aforementioned technical problems, methods, and effects are all closely integrated with the specific technical field of port autonomous driving systems.

[0151] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "an," and / or "the" are not specifically singular and may include plural forms. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of explicitly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.

[0152] Those skilled in the art will understand that information, signals, and data can be represented using any of a variety of different techniques and skills. For example, the data, instructions, commands, information, signals, bits, symbols, and chips described throughout the above description can be represented by voltage, current, electromagnetic waves, magnetic fields or magnetic particles, light fields or optical particles, or any combination thereof.

[0153] Those skilled in the art will further appreciate that the various illustrative logic blocks, modules, circuits, and algorithm steps described in conjunction with the embodiments disclosed herein can be implemented as electronic hardware, computer software, or a combination of both. To clearly illustrate this hardware-software interchangeability, the various illustrative components, blocks, modules, circuits, and steps are described above in a generalized manner in terms of their functionality. Whether such functionality is implemented as hardware or software depends on the specific application and the design constraints imposed on the overall system. Those skilled in the art may implement the described functionality in different ways for each specific application, but such implementation decisions should not be construed as departing from the scope of this application.

[0154] The various illustrative logic modules and circuits described in conjunction with the embodiments disclosed herein may be implemented or performed using a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. The general-purpose processor may be a microprocessor, but in alternatives, it may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors cooperating with a DSP core, or any other such configuration.

[0155] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of both. The software module may reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor such that the processor can read and write information to / from the storage medium. In an alternative, the storage medium may be integrated into the processor. The processor and storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In an alternative, the processor and storage medium may reside as discrete components in the user terminal.

[0156] The above embodiments are provided for those skilled in the art to implement or use the present invention. Those skilled in the art can make various modifications or changes to the above embodiments without departing from the inventive concept of the present invention. Therefore, the protection scope of the present invention is not limited to the above embodiments, but should be the maximum scope that conforms to the innovative features mentioned in the claims.

Claims

1. A dual-constraint code generation method for automated port operations, characterized in that, Includes the following steps: Step S1: Construct an architecture knowledge base for port operations and heavy load dynamics perception, wherein the architecture knowledge base is stored in a retrieval-enhanced generation manner; Step S2: Based on the main control agent, the system-level code requirements of the port equipment system input by the user are perceived in an architecture layer. The system-level code requirements are recursively decomposed into a list of sub-tasks with execution dependencies according to the data flow dependency of the autonomous driving system. A structured global shared double-layer blackboard is constructed and initialized. Step S3: Based on the structured global shared double-layer blackboard, the sub-agents corresponding to each sub-task load the corresponding dual constraint parameters according to the sub-task, retrieve the framework adaptation code snippets from the architecture knowledge base, generate the code for each sub-task, and write the generated code back to the structured global shared double-layer blackboard. The dual constraint parameters include port heavy-load business scenario constraint parameters and autonomous driving architecture constraint parameters. Step S4: The assembly agent assembles the code of each subtask into a complete project according to the architecture layer, performs interface consistency verification and dual-track verification, and provides error feedback and regenerates the code when the verification fails. Step S5: After successful verification, output a compilable automotive-grade port autonomous driving engineering code package.

2. The dual-constraint code generation method for port autonomous driving according to claim 1, characterized in that, The architecture knowledge base constructed in step S1 includes: We collect the source code, interface definition files, communication mechanism documents, automotive-grade coding standards, port operation communication protocols, and dynamic constraint parameters of heavy-duty vehicles in ports for specific versions of autonomous driving frameworks, store them in vector form, and label them with version tags.

3. The dual-constraint code generation method for port autonomous driving according to claim 1, characterized in that, The retrieval enhancement generation construction method of the architecture knowledge base includes: The framework source code is divided into blocks according to the granularity of function, class and interface definitions. A text embedding model is used to convert the block text into vector representations and store them in a vector database. A filtering strategy combining sorting by similarity and selecting the top K items with a similarity threshold is used for retrieval.

4. The dual-constraint code generation method for port automated driving according to claim 1, characterized in that, Step S2 includes: Receive user input of port equipment system-level code requirements and framework version number; The main control agent retrieves the architecture knowledge base and, based on the node topology and data flow dependencies of the autonomous driving framework, identifies the architecture layers involved in the requirements and the data flow dependencies of port business. System-level requirements are recursively decomposed according to the architecture of autonomous driving nodes, generating a list of subtasks with execution dependencies, and a structured, globally shared, two-layer blackboard is constructed and initialized. The termination condition for the recursive decomposition is that the subtask can be implemented by a single function logic and no longer contains cross-module communication and data dependencies.

5. The dual-constraint code generation method for port automated driving according to claim 1, characterized in that, The architecture is layered into a data interface layer, a core algorithm layer, and a system configuration layer. The data interface layer is used for sensor driving, communication adaptation, and data format conversion; The core algorithm layer is used for perception and localization, planning and decision-making, and motion control according to the autonomous driving data stream. The system configuration layer is used for script building, startup configuration, and parameter file management.

6. The dual-constraint code generation method for port automated driving according to claim 5, characterized in that, The data interface layer includes a controller local area network bus driver node, a lidar point cloud subscription node, a satellite navigation system positioning data subscription node on the actual vehicle side, and a user datagram protocol data adaptation node and a simulation clock synchronization node on the simulation side. The core algorithm layer is further divided into a perception and localization sublayer, a planning and decision-making sublayer, and a motion control sublayer according to the autonomous driving data flow. There are strict upstream and downstream data dependencies between each sublayer. The system configuration layer includes build files, dependency declaration files, startup files, and parameter configuration files.

7. The dual-constraint code generation method for port automated driving according to claim 1, characterized in that, The structured globally shared two-layer blackboard includes a contract layer and a constraint container layer: The contract layer is a globally shared read-only layer that stores global interface definitions, legal state machine transition matrices, dual-end adaptation identifiers, and subtask dependency graphs for all sub-agents to read-only align. The constraint container layer is instantiated independently for each subtask, storing the port heavy-load business scenario constraints and autonomous driving architecture constraint parameters corresponding to that subtask.

8. The dual-constraint code generation method for port automated driving according to claim 7, characterized in that, The initialization of the structured globally shared two-layer blackboard includes the initialization of the contract layer: The master control agent predetermines and writes global interface definitions, legal state machine transition matrices, dual-end adaptation identifiers, and subtask dependency graphs based on the subtask list and its data flow dependencies. This ensures that the contract layer has a globally unique and consistent interface and state machine benchmark before the sub-agents generate code, allowing all sub-agents to read-only align. The global interface definition includes the variable names, message types, communication topic names, and service interface signatures transmitted between nodes.

9. The dual-constraint code generation method for port automated driving according to claim 7, characterized in that, The initialization of the structured globally shared two-layer blackboard also includes the instantiation of the constraint container layer: The main control agent creates independent constraint container instances for each subtask, and retrieves the port heavy-load business scenario constraints and autonomous driving architecture constraint parameters corresponding to the subtask from the architecture knowledge base, and fills them into the constraint containers of the corresponding subtasks. This ensures that each subtask only loads constraint parameters related to itself when generating code, thereby achieving hierarchical and subtask-based isolation and injection of constraints.

10. The dual-constraint code generation method for port automated driving according to claim 1, characterized in that, Step S3 includes: Each sub-agent reads the global interface definition from the contract layer of the structured global shared double-layer blackboard to align variable naming with the state machine definition, extracts the constraint parameters corresponding to the sub-task from the constraint container layer, and retrieves the architecture knowledge base to obtain the framework adaptation code snippet. Subtask code is generated by parameter interpolation based on the clipping code template, and overloaded clipping logic and double-ended conditional compilation flags are injected into the subtask code. Once generated, the code is written back to the structured globally shared double-layer blackboard and the contract layer state is updated.

11. The dual-constraint code generation method for port automated driving according to claim 7, characterized in that, Step S4 includes: The assembly agent assembles the code of each subtask into a complete project according to the architecture layering; Perform interface consistency verification by comparing the global interfaces referenced in each subtask code with the global interface definitions of the contract layer. Perform dual-track verification to check the code compliance and compilability of the complete project; If all checks pass, proceed to step S5; if checks fail, distinguish the error level and report back to the corresponding agent for correction.

12. The dual-constraint code generation method for port automated driving according to claim 11, characterized in that, The interface consistency check includes: Compare whether the global variable names, message types, and communication topic names referenced in each subtask code match the contract layer definition; If there is a mismatch, a structured error feedback package is generated and the corresponding sub-agent is triggered to correct it; The structured error feedback package includes error type labels, error location information, and correct reference values ​​from the contract layer.

13. The dual-constraint code generation method for port automated driving according to claim 11, characterized in that, The first track in the dual-track verification is the static scanning of the abstract syntax tree and the port business compliance verification, including: Scan function call nodes to detect dynamic memory allocation operations, scan assignment statement nodes to detect missing communication service quality configurations, and scan conditional expression nodes to detect the existence of clipping logic. By using in-process forward data flow propagation, the range of values ​​of acceleration and steering angle variables from calculation to output is tracked to determine whether the control command calculation logic exceeds the heavy load dynamic boundary.

14. The dual-constraint code generation method for port automated driving according to claim 11, characterized in that, The second track in the dual-track verification is sandbox compilation verification, which includes: Execute the project compilation command in the containerized build environment to detect syntax errors, missing dependencies, linking errors, and symbol conflicts. If the compilation is successful, the complete project meets the buildability requirements.

15. The dual-constraint code generation method for port automated driving according to claim 11, characterized in that, The process of differentiating error levels and feeding them back to the corresponding agents for correction includes subtask-level error feedback and architecture-level error feedback: The subtask-level error feedback includes parsing the error log and feeding it back to the corresponding sub-agent when the error belongs to an internal problem of the subtask and the cumulative number of automatic repairs is less than a preset threshold, and the sub-agent regenerates the code of the subtask. The architecture-level error feedback includes, when the cumulative number of automatic repairs reaches or exceeds the preset threshold, feeding back to the main control agent to re-disassemble the task or modify the contract layer definition; Each subtask maintains an independent repair counter, and the preset threshold is a configurable parameter.

16. The dual-constraint code generation method for port automated driving according to claim 1, characterized in that, The compilable automotive-grade port autonomous driving engineering code package output in step S5 includes: Source code for the data interface layer nodes, source code for the core algorithm layer nodes, and system configuration layer build and startup files.

17. A dual-constraint code generation system for automated port operations, characterized in that, Including processor and memory: The memory stores computer programs; The processor is used to execute the computer program stored in the memory to implement the dual-constraint code generation method for port autonomous driving as described in any one of claims 1 to 16.