{'fraction_non_alphanumeric': 0.026287462466715768, 'fraction_numerical': 0.004985553226446094, 'mean_word_length': 4.533542319749216, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Automated, Credible Autocoding of An Unmanned Aggressive Maneuvering Car Controller

This article describes the application of a credible autocoding framework for control systems towards a nonlinear car controller example. The framework generates code, along with guarantees of high level functional properties about the code that can be independently verified. These high-level functional properties not only serves as a certificate of good system behvaior but also can be used to guarantee the absence of runtime errors. In one of our previous works, we have constructed a prototype autocoder with proofs that demonstrates this framework in a fully automatic fashion for linear and quasi-nonlinear controllers. With the nonlinear car example, we propose to further extend the prototype's dataflow annotation language environment with with several new annotation symbols to enable the expression of general predicates and dynamical systems. We demonstrate manually how the new extensions to the prototype autocoder work on the car controller using the output language Matlab. Finally, we discuss the requirements and scalability issues of the automatic analysis and verification of the documented output code.


Introduction
In this article, we examine the autocoding of a nonlinear car controller model along with its control semantics. The system is of interest because of the presence of fully nonlinear dynamics and a nonlinear non-quadratic invariant. We discuss the impact of these nonlinearities on the autocoding and the proof-checking. Other issues of interest include the presence of transcendental functions and their impact on the correctness of the control-theoretic proofs. This work follows [2] that first described the idea of leveraging control domain proofs for code analysis and [7] [3] [8], which are later efforts in creating an automated framework that can perform such leveraging on real case studies.
The article is organized as follows: we first give a brief summary of the automated framework in section 2; we then proceed to describe the model of the car and its control-theoretic properties in section 3. Sections 4 5 describe informally, the expression and translation of the control-theoretic properties of the nonlinear car controller from the Simulink model to Matlab code. Finally, in section 6, we describe the limitations encountered in the automatic verification of the fully-nonlinear case.

Autocoding with Control Semantics
First we give a brief summary about the automated framework that leverages control system knowledge for the formal analysis of code and the prototype that we built to demonstrate this framework in a fully automated fashion. For a good introduction on the control stability proofs and code analysis, one can refer to [?]. For more details on the automated framework and the prototype implementation, one can refer to [8].
We define, informally-speaking, control semantics as any innate properties of the control system that can be expressed either as a predicate or as a statetransition system. This can included, but is not limited to, proofs of stability or absolute stability, performance measures like margins and overshoot, and elements that are used in the construction of the proofs such as the model of the system being controlled i.e. the plant, or other dynamical systems used in the construction of the proof or the controller. The framework of autocoding with control semantics is consisted of the following: a synchronous modeling language environment extended with synchronous observers to express the control semantics on the model level; an autocoder extended with the capability of transforming the observers into useful annotations for the code output; a proof-checking analyzer that can automatically verify the annotated code. As shown in figure 1, the input language of the prototype was chosen to be Simulink, and the output language is C. These two languages were chosen due to their ubiquitous presence in the industry as we want the prototype to be a practical demonstration of the framework that we just discussed. The prototype autocoder in [8] has been built to handle linear controllers and quasi-nonlinear cases that are linear systems with bounded nonlinearities in a feedback interconnection configuration. The prototype is based on the Simulinkto-C autocoder Gene-Auto [5]. For linear or quasi-nonlinear controllers, the leveraging of the control system knowledge comes from the fact that the proof of stability for these systems forms a quadratic invariant of the following form , where x ∈ R n denotes an array of states and P is a n × n symmetric matrix. The quadratic formula in (1) can be used to show that the variables of the output code that correspond to the states in x are bounded. Furthermore, any variables in the output code that are related linearly to the states in x are also bounded. Hence the proof of stability, which results in the matrix P , can be used both as a certificate of good behavior for a control system and to show the absence of runtime errors. For nonlinear controllers, we can apply the same type of leveraging, with caveat that the proof of stability is does not usually result in a simple symmetric matrix P . In the next section, we present a car example that is fully nonlinear and its proof of stability does not yield a quadratic invariant.

Car Controller Example
We choose the running example to be the sliding mode based nonlinear car controller from [6]. Here we give a detailed overview of its specifications. For the sake of consistency and simplicity, we have chosen to reuse the notations from [6]. There are two main reasons why we picked this car controller: 1. Unlike the previous examples that we have studied in the context of autocoding with control semantics, this example is fully nonlinear. By fully nonlinear, we mean that the car controller cannot be reformulated as a linear system with bounded nonlinearities in a feedback interconnection. 2. The car controller is constructed using an non-quadratic Lyapunov function.
The non-quadratic Lyapunov function results in a non-quadratic nonlinear invariant, which our prototype autocoder could not handle.

Single Track Model
In figure 2, we have the single-track model of the car. The wheels have a radius of r and angular velocities of ω i , i = F, R, in which F, R denote respectively the front and rear locations. The controller stabilizes the single-track model of a car about a steady-state cornering equilibrium. In a steady-state cornering equilibrium, the car undergoes a constant radius turn in which its speed V , path angle β, steering angle δ, and angular velocityψ are all constant. In additions, the longitudinal slips s i , i = F, R are also constant. The longitudinal slip is a measure of the amount of "sliding" due to a difference between the tangential speed of a wheel (ωr) and the velocity V of the car projected onto the longitudinal axis of the wheel. From the model in figure (2), the longitudinal slips are .

Fig. 2. Single-track Model of the Car [6]
The car dynamics is represented by the nonlinear state-space systeṁ with the state vector x = V βψ T , the input vector u = s F s R T , and the vector field f : R 5 → R 3 . The precise structure of the function f is not necessary for the discussion in this paper hence is omitted. We assume that f does satisfy all the well-posed conditions to guarantee the existence, uniqueness and smooothness of solutions to the differential equation in (3). The linear plant model is obtained by linearizing the nonlinear model in (3) about the cornering equilibrium x ss = V ss β ssψss T and u ss = s F ss s Rss T . By definition, we have that f (x ss , u ss ) = 0. The controller model can be divided into two

Linear Subsystem
This subsystem is consisted a LQR controller that drives the trajectories of the linearized model to the equilibrium point x ss . The input to this controller is and the controller output u =ũ + u ss . The K is computed using the algebraic Riccati that is associated with the LOR problem.

Sliding Mode Subsystem
The output u from the linear subsystem, being the longitudinal slips, cannot be controlled directly. Instead, we have a sliding mode controller that controls the angular velocities of the wheels by applying torques T i , i = F, R. From (2), we have the following mappings φ i , i = F, R from given longitudinal slips u to the angular velocities of the wheels.
The goal is to drive the angular velocities ω of the wheels to mach the commanded angular velocitiesω so the longitudinal slips are equal to u. We want ω−φ(x, u) = 0, which defines the manifold Let f x i being the longitudinal frictional forces on the wheels and let I w be the moment of inertia of the wheels. The dynamics of the rotations of the wheels is With (6) and (7), ollowing auxiliary dynamic systeṁ The controller hence was picked to be The first part of the controller f xr + I w ∂φ ∂x f (x, u) ensuresż = 0 when z = 0.
The second part of the controller −sat (z) drives the system trajectories towards the manifold z = 0.

Annotating the Model with Control Semantics
We have already for linear controllers, constructed two annotation blocks tailored for linear systems. One is the plant block, which has the semantics of a linear state-space system. The other is an ellipsoid block, which is a synchronous observer with the semantics of a quadratic inequality i.e. the block takes in an input of x and returns if x T P x ≤ 1 is true or false. For fully-nonlinear controllers, we require a less restriction on the structure of the plant or the synchronous observer. Hence propose extending the current prototype's input Simulink environment with two new annotation blocks.
One is a general synchronous observer block that accepts any logic formula that can be expressed by the underlying language. The other one is a generalized plant block. Likewise, there is no restriction on the type of state-transition system that can define inside of the block. For a practical prototype demonstration, we can pick the underlying language to be that of the subset of Simulink supported by Gene-Auto.
For the example in this article, the controller model does not contain any signals with memory. For control systems without dynamics, however unrealistic that might be, a closed-loop analysis with the plant model becomes a necessary step before we can express any interesting high-level functional properties such as Lyapunov stability. Hence for the car controller, it is required to embed both the linearized plant model and the auxiliary dynamics in (8) into the model to support the eventual verification of the stability proofs on the code.
We can express the linearized model by using the existing plant block. This is an annotation block that has already been implemented in the prototype autocoder. The auxiliary dynamics requires the proposed generalized plant block. The stability proof for the linear portion of the controller can be expressed using the existing ellipsoid block. The proof of the stability of the sliding-mode portion of the controller require the new generalized synchronous observer.
For the insertion of the plant semantics and the stability proofs, we can use the same type of method as discussed in our previous work [7]. For example, to insert the linear plant block into the diagram, one can simply connect the output signal labelled utilde from the linear subsystem into the input port on the plant block that is labelled inputs or u and then connect the input signals of the linear subsystem into the input port on the plant block that is labelled outputs or y. Similarly we can connect the auxiliary dynamics with the nonlinear subsystem using the proposed generalized plant block. The annotated Simulink model is shown in figure 4. For loop #1, since it is a stable linear system, we can T z (ω, x, u) ≤ 1 and z is a nonlinear function of the states ω, x and inputs u as defined in (6). Note the annotation blocks for expressing the stability proofs are not displayed in figure 4 since it is not always required for them to be explicitly inserted into the model. For the linear cases, the prototype autocoder can analyze the model and compute a stability proof. The insertion of the stability proofs as an invariant is done internally in the autocoding process. For the fully-nonlinear case, this process cannot be fully-automated for the most part and requires the end user to manually insert the proof stability using a general synchronous observer block.
Since we have not finalized the grammar and semantics of the proposed new annotation blocks, we choose to skip those details in this article. Unlike the examples that we have looked at before, the two invariants for the two loops of the system require two completely different set of analysis and autocoding methods. One is linear with a quadratic invariant which is fully handled by the current version of the prototype autocoder. The second loop has an nonlinear non-quadratic invariant, which is currently partially supported by the prototype. We focus on the nonlinear part in the next section in a manual demonstration of the analysis and autocoding of the non-quadratic invariant.

Example of the Autocoded Output
For the reason of brevity, in this article, we choose to use Matlab to represent the generated code and a Matlab annotation language that is similar to ACSL [1] for the example annotations. We also conceal a large portion of the controller's code inside function calls and only display a few examples annotations for demonstration's purpose. Figure 5 has the code and the partial of set of the annotations. Generally speaking, the placement of the invariants from the model onto the code depends only on the type of the invariant. The assumptions are inserted at the location where the variables of the invariant are assigned to for the first time. The inductive ones e.g. all the invariants derived from the control stability proofs are inserted at the beginning and end of the code portion of their corresponding loop. By loop, we meant the loop formed by the controller subsystem (code) and its corresponding plant model (annotations) as shown in figure 4. For example, the quadratic invariant {xtilde * P * xtilde <= 1} for loop#1 is inserted into the code at line 3 and at line 10 of figure 5. They become a pre and post-condition pair for the code portion of loop#1. Likewise, the non-quadratic invariant {z * z <= 1} is inserted into the code at line 14 and line 32. The code between 14 and 32 is generated from the nonlinear controller subsystem of loop#2.
For the non-quadratic invariant {z * z <= 1}, since cannot be propagated using affine transformation rules, we must employ backward propagation using the axiomatic rules for the simple imperative language from hoare logic [4]. The same problem applies if the line of code does not represent an affine transformation. For example in figure 5, given the assumption in line 30, the pre-condition in line 27 can be generated using the assignment rule from the post-condition on line 32. This backward propagation procedure is executed until it is terminated right before the inserted pre-condition on line 14. This results in the second precondition on line 15. Since this is a weakest pre-condition, we also need to check if the inserted invariant {z * z <= 1} implies the invariant in line 15. can be simplified to another function U (X), the problem is reduced to determine if U (x) > 0. Since we already know that the function U (x) is positive i.e. U (X) > 0 is always true. We know this is a fact because the specification of the controller is extracted from the proof of good behavior i.e. the Lyapunov stability proof. Due to the limitations of the backend analyzer, it is necessary to insert the invariant U (x) > 0 as an annotation into the code to automate the proof-checking process. Note that U (X) does not necessary belong to a class of polynomials or any other smooth functions because of the saturation operator in the controller, Hence we cannot determine if U (x) is positive using a single general decision procedure. There remains a need for a theorem prover.

Non-quadratic Invariant and Runtime Errors
From the non-quadratic invariant, we can obtain bounds on many variables of the output code. Note that z = ω − φ (x, u) and φ (x, u) as defined in (5), and the steering angle δ, the radius r and l f are all fixed. We also have that x = V βψ T belongs to an ellipsoid. We can assume that the longitudinal slip belongs to the set (−1, ∞]. It is only equal to −1 in the physically impossible case where V = 0,ψ = 0, and ω > 0 i.e. the car is stationary while the tires are spinning. The auxiliary variable z is bounded by z T z ≤ 1. Hence we know that both ω and φ (x, u) will be bounded. This decision procedure used to obtain the bounds is by no mean a fully automated one since it clearly depends on certain knowledge about the physical limitations of the car. Otherwise, we can't make any conclusions about bounds on ω and φ.

Conclusion
We have presented an application of the autocoder with control semantics framework on a nonlinear car controller example. The set of improvements on our prototype autocoder resulting from the car controller can be summarized as follows: a new generalized synchronous observer block that is not restricted to any structure with the exception of the limitations presented by the subset of the Simulink blocks supported by Gene-Auto; likewise we also generalized the plant block to be able to express nonlinear state-transition functions.