Design sequence diagram - take APA automatic parking system as an example

1. Timing diagram description

A sequence diagram is a UML (Unified Modeling Language) diagram that illustrates the interactions between objects in a system over time, and is often used to visualize the flow of messages and the sequence of method calls between objects in a software system.
Sequence diagrams show the sequence of interactions between objects, model interaction behavior as message passing, and dynamically display interactions between objects by describing how messages are sent and received between objects; compared to other UML diagrams, sequence diagrams emphasize more Time sequence of interactions; concurrent processes can be described intuitively.

2. Drawing principles

The drawing principle is relatively simple, but if you want to describe the real interaction situation in detail, you need to pay more attention to the details and have a clear grasp of the overall process. In the process of drawing sequence diagrams recently, I felt that my understanding of the system was much deeper and clearer, and the places that I didn't understand suddenly became clear.

2.1 Actor

System roles can be people, machines, other systems, or subsystems; they are represented by the following figure in the sequence diagram.


2.2 Object and Lifeline

Objects: The left and right order of objects is not important, but for clear and tidy drawing, the following two principles should generally be followed: put the frequently interacting objects as close as possible; 2. Place the objects that initialize the entire interactive activity at the far left.

Lifeline: Represented in a sequence diagram as a dotted line extending downward from the object icon, indicating the time the object exists.


2.3 Focus of Control

Also known as the activation period, it is a symbol representing the time period during which the object will perform the corresponding operation. It can be understood as the content in a pair of curly braces { } in C language semantics; represented by a small rectangle.

2.4 Messages

Synchronous Message (Synchronous Message) : The sender of the message passes control to the receiver of the message, then stops activity, and waits for the receiver of the message to give up or return control. Used to express the meaning of synchronization.

Asynchronous Message (Asynchronous Message) : The sender of the message passes the signal to the receiver of the message through the message, and then continues its own activities without waiting for the receiver to return the message or control. The receiver and sender of asynchronous messages work concurrently.

Return Message : Return message represents return from a procedure call.

2.5 Self-associated messages

Represents a method calling itself or a method within an object calling another method.

2.6 Combining fragments

Combining fragments are used to solve the conditions and modes of interactive execution. It allows the direct representation of logical components in sequence diagrams and is used to define special conditions and sub-processes for any part of any lifeline by specifying the application area of ​​​​the condition or sub-process. The names and meanings of the mainly used combined fragments are as follows:

3. Drawing suggestions

The most important thing about a sequence diagram is that it should clearly and accurately express the interactions and behaviors of the system. It is best to communicate and provide feedback with team members as needed to ensure that the sequence diagram accurately conveys the design intent and allows developers to have no misunderstandings.

The following are some personal experiences when drawing timing diagrams:

  1. Determine the goal : Make it clear what the purpose of drawing the sequence diagram is. Is it to understand the interaction process of the system, or to perform design and debugging work? This helps determine the level of detail and focus required.
  2. Choose the appropriate granularity : Based on the goals and requirements determined in the previous item, choose the appropriate granularity to represent objects and messages. Too fine a granularity may make the timing diagram complex and difficult to understand, while too coarse a granularity may cause some important details to be lost. Certainly, we cannot convey all the information, and we need to choose the tendency of description based on the purpose of the sequence diagram.
  3. Use clear naming : Choose clear, accurate naming for each role, object, and message to ensure readability and understandability of the sequence diagram. Avoid using vague or unclear terms and try to use terminology that is relevant to your business domain.
  4. Reasonable organization and layout : When drawing sequence diagrams, organize and lay out objects, lifelines, and messages appropriately to make them easy to understand. You can arrange objects and messages in chronological order and use alignment and spacing to improve readability.
    Use annotations and captions: Use annotations and captions in sequence diagrams to provide additional explanation and contextual information. This can help readers better understand sequence diagrams, especially for complex interactions and control flows.
  5. Simplification and abstraction : For complex systems and interactions, consider using a simplified and abstract approach to drawing sequence diagrams to highlight key points and reduce confusion. You can use layered and nested sequence diagrams, or use critical paths and key messages for highlighting.
  6. Use tool support : Consider using professional sequence diagram drawing tools, such as UML modeling tools or online drawing tools. These tools provide more functionality and automation support, making drawing and editing sequence diagrams more efficient and convenient.

3.1 Determine the goal

When clarifying the goal, first emphasize that the timing diagram has no distinction between good and bad, and its function is to help designers convey the author's design concept, so that readers can understand it more quickly and without error.

For example, as a system engineer, we are the people who know the system best and the data interaction between the modules in the ADCU domain; therefore, the timing diagram of our design tries to sort out the interaction between the modules clearly, so that The owner of the perception, fusion, positioning, planning, control and other modules can clearly know what kind of handshake the module needs to perform with other modules at what time, and the signal logic inside the module belongs to the person in charge of the module to design.
Okay, so for the automatic parking system, the overall functional process of APA is intricate. In order to avoid the decrease in readability caused by bloated and cumbersome sequence diagrams; we decompose the APA function into several functional processes, and separately analyze each process. The timing is described one by one, and a clear functional timing can be obtained after splicing each process.

3.2 Choose the appropriate particle size

As system engineers, of course we choose to draw timing diagrams separately through functional deconstruction . This article does not give a detailed introduction to the APA function logic, so students who are familiar with APA know that the APA process can be simply divided into parking space search, parking space selection, parking in and out process, interruption recovery, etc. The following figure uses this idea to make a simple sequence Graph decomposition.

So we know that we need to design "activate parking function", "exit parking function", "search parking space at the front desk", "search parking space at the background", "click to select a parking space", "automatic parking process", "parking Process interrupt" and other sequence diagrams.

3.3 Naming rules

In addition, the granularity of description should be chosen as the interaction signal between modules. If the signal is not defined in the early stage of design, you can choose to use semantic signals to describe it, which is easy to understand. It is best to clearly indicate the type of signal with a prefix, such as Ethernet, CAN, FR, or interactive signals within the domain.
For example, when the user presses the activation parking button, this is an Ethernet signal, prefixed with Eth, using big camel case naming (personal habit), described as Eth_ApaBtn (1: EnterApa), and the signal in parentheses should be sent at this time value.

3.4 Reasonable layout

In terms of the overall layout, this mainly meets the aesthetic requirements. Generally when we design the module interaction diagram, the left side is the input and the right side is the output. We can follow this principle and design.
APA system interaction is divided into out-of-domain and in-domain. Out-of-domain will interact with user input, DHU, chassis power, steering and other ECUs, while in-domain is the interaction between various modules.
We color-code objects inside and outside the domain, start with the original input from the left, arrange objects and messages in chronological order, and use alignment and spacing to improve readability .

3.5 Notes and explanations

The objects are described in the form of Diagram Conventions on the far left side of the sequence diagram. Describe each jump in detail through text after the timing diagram.

3.6 Simplification and abstraction

Avoid complexity and duplication, and cleverly use combined fragments to solve the conditions and methods of interactive execution . For example, Opt options, Alt selections, Loop cycles, etc. can help you save a lot of time, improve readability, and look very professional.
I love this lazy yet practical technique.



4. Recommended drawing tools

Sharpening a knife does not waste time cutting firewood. In the information age, good tools can exponentially improve our work efficiency. The following introduces commonly used timing diagram drawing tools.

Enterprise Architect : EA (Enterprise Architect) is a powerful modeling and design tool widely used in software development, systems engineering, and business process modeling.
Draw.io : Draw.io is an online drawing tool that provides drawing functions for various chart types, including sequence diagrams. It has an intuitive user interface and rich graphics library to easily draw and edit timing diagrams. Draw.io also supports integration with cloud storage services such as Google Drive and Dropbox to facilitate team collaboration and file sharing.
Microsoft Visio : Microsoft Visio is a popular business drawing tool with an extensive graphics library and templates for creating a variety of diagrams and graphs, including timing diagrams. Visio provides an intuitive interface and powerful drawing functions, suitable for more complex sequence diagram drawing needs.
Lucidchart : Lucidchart is another online drawing tool with an easy-to-use interface and an extensive graphics library. It supports the drawing of sequence diagrams and provides a series of interactive elements and layout options to facilitate drawing and adjusting the structure and style of sequence diagrams. Lucidchart also provides integration with tools such as Google Drive and Slack to facilitate team collaboration and sharing.
PlantUML : PlantUML is a text-based drawing tool that can generate various UML diagrams, including sequence diagrams, through simple text descriptions. It has an easy-to-use syntax and supports a variety of output formats. Sequence diagrams can be written in any text editor using PlantUML and converted to images using the command line or plugins.

Let me talk in detail about the two tools I have used, EA and Draw.io:

Needless to say, EA is famous in the automotive industry. We see a large number of design drawings from EA. The software has built-in special state machine drawing modules, software deployment, autosar, timing diagrams, etc., and can automatically generate code. , very convenient to use, beautiful and neat.

However, due to the charging of the professional version, none of the companies I worked for bought the genuine version (sweat). I could only play with it at home, or use the trial version, which has a 30-day free trial (exported pictures will have watermarks)


The biggest advantage of Draw.io is its convenience, it can be drawn online, and it has a variety of templates that are automatically updated online to facilitate team collaboration. You can download the application on Github, and the experience is exactly the same as the online version, perfectly realizing office work without environment dependence.


5. Use tools to support design

Since the author designed it at home and used the trial version of EA, the graphics are simple and beautiful. I give EA designers a thumbs up. It is also a software that took countless efforts to complete. It can be played without thinking. However, I personally feel that UML modeling is used less and less, maybe due to personal limitations. Drawing pictures is still very useful.
Now that the groundwork has been laid, let’s just describe the functional logic without thinking. Take the most basic “activate automatic parking” function sequence diagram we just decomposed as an example.

5.1 First, function description:

Activate the automatic parking function: The user turns on the automatic parking function through operations, and if the conditions for opening the function are met, the state machine jumps and notifies the downstream module to enter the automatic parking function; if the conditions for opening the function are not met, APA returns to the reason for failure to enable the DHU function. hint.

5.2 Then attach the timing diagram:

5.3 Comments:

1. The user clicks the central control soft switch or speaks to activate the automatic parking function, and the DHU sends the APA function activation signal Flexray_BtnPush == 1: EnterAPA to ADCU through Flexray;

2.ADCU MCU Flexray Transceiver receives the signal and transmits it to SOC through Ethernet;

3. The HMI Arbitration module in the SOC parses the signal and distributes it to the downstream ParkingModeManager module;

4. After receiving the Signal Service on the SOC side, it forwards APA_ActivationReq to the HMI Arbitration module;

5. The HMI Arbitration module forwards the request to the Parking Mode Manager;

6. After the Parking Mode Manager receives the activation signal, it selects the currently entered parking in and out mode according to the parking in and out policy, and sends it to the downstream module;

7. The state machine performs state jump judgment:

a) If the current Mag_APAModSts==2: APA_Standby successfully enters the Searching state, Parking Mode Manage will send the APAModSts == 3: APA_SEARCHING state to other downstream nodes.

b) If the current Mag_APAModSts == 1: APA_OFF, the APA function cannot be turned on, and Parking Mode Manage will send the APAModSts == 1: APA_OFF status to other downstream nodes.

8. Return APA status Ethernet_apa_state and classical prompt Ethernet_AlarmInfo to DHU through Ethernet for display;

Guess you like

Origin blog.csdn.net/lovely_yoshino/article/details/132618255