<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><title>Genson</title><link>http://localhost:7090/</link><description>Genson's Blog</description><item><title><![CDATA[Win11右键菜单修改]]></title><link>http://localhost:7090/archives/wei-ming-ming-wen-zhang</link><description><![CDATA[<p style="">经测试有效：</p><p style="">1、在windows11上按Win+R调处CMD命令行窗口，然后直接复制下方命令执行：</p><pre><code class="language-undefined">reg.exe add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f

</code></pre><p style="">1<br>2、打开任务管理器，找到Windows资源管理器右击重新启动，右键菜单就会改回老版。</p><p style="">3、如果要恢复右键菜单为win11样式，只要复制输入以下命令，再回车即可。</p><pre><code>reg.exe delete "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}" /f
</code></pre><p style=""></p>]]></description><guid>/archives/wei-ming-ming-wen-zhang</guid><pubDate>Fri, 18 Oct 2024 03:07:33 GMT</pubDate></item><item><title><![CDATA[Follow认证]]></title><link>http://localhost:7090/archives/followren-zheng</link><description><![CDATA[<p style=""></p><p style="">This message is used to verify that this feed (feedId:69567090760705024) belongs to me (userId:69209574504684544). Join me in enjoying the next generation information browser <a href="https://follow.is">https://follow.is</a>.</p>]]></description><guid>/archives/followren-zheng</guid><pubDate>Thu, 17 Oct 2024 02:41:00 GMT</pubDate></item><item><title><![CDATA[Doxgen的安装与使用！]]></title><link>http://localhost:7090/archives/doxgen-s-installation-and-use-z1xr8mu</link><description><![CDATA[<h1 style="">Doxgen的安装与使用</h1><p style="">背景：使用CCS开发DSP工程时，当随着工程逐渐增大，代码的可读性时逐渐下降的。此时如何能够快速的了解代码工程就显得尤为重要。如果能够解决这个问题，或许也能够约束代码编写时的格式不统一的问题。提升代码的编写质量和可读性。</p><p style="">参考：</p><ol><li><p style=""><a href="https://coder-tronics.com/eclipse-doxygen-installation/">Eclipse Doxygen Installation also Code Composer Studio v5.x (coder-tronics.com)</a></p></li><li><p style=""><a href="https://www.cnblogs.com/viiv/p/15736106.html">callgraph工具, 函数调用关系 | cflow, egypt 和 doxygen 使用 - whilewell - 博客园 (cnblogs.com)</a></p></li><li><p style="">相关插件工具：</p><ol><li><p style=""><a href="https://www.doxygen.nl/download.html">Doxygen download</a></p></li><li><p style=""><a href="https://github.com/anb0s/eclox/releases">Releases · anb0s/eclox (github.com)</a></p></li><li><p style=""><a href="https://www.graphviz.org/download/">Download | Graphviz</a></p></li></ol></li></ol><h1 style="">实现：</h1><ul><li><p style="">首先参考了第一条的安装过程，先下载并安装了doxygen（1.12.0）软件，并且在CCS的市场中安装了插件eclox（0.13.0）</p></li><li><p style="">然后使用对应插件，并配置对应的doxygen工具的安装目录，使用插件建立得到一份doxygen.file文件</p></li><li><p style="">编译boxygen文件得到对应的html文件</p></li><li><p style="">安装Graphviz工具，手动配置对应工具的bin文件夹路径，然后指定生成图片的格式，深度等细节，再次编译doxygen文件。</p></li><li><p style="">重新查看对应的html文件，可以看到对应的说明文件已经更新了插图。（SVG格式比PNG格式要清晰）</p></li></ul><p style="">​​</p><h1 style="">参考</h1><ul><li><p style="">能根据代码给出函数调用关系的工具</p><ul><li><p style="">有一些工具可以分析代码并生成函数调用关系图，帮助你理解代码的结构和函数之间的依赖关系。以下是几种常用的工具：</p><h3 style="">1. <strong>Doxygen</strong></h3><ul><li><p style=""><strong>支持语言</strong>：C/C++、Java、Python 等多种语言。</p></li><li><p style=""><strong>功能</strong>：Doxygen 是一个自动生成文档的工具，可以分析代码并生成函数调用关系图。它可以输出多种格式，包括 HTML、LaTeX 和 XML。如果你启用 <code>CALL_GRAPH</code>​ 和 <code>CALLER_GRAPH</code>​ 选项，它还能为每个函数生成调用者和被调用者的图。</p></li><li><p style=""><strong>使用方法</strong>：</p><ol><li><p style="">编写配置文件 <code>Doxyfile</code>​。</p></li><li><p style="">在 <code>Doxyfile</code>​ 中启用 <code>CALL_GRAPH = YES</code>​ 和 <code>CALLER_GRAPH = YES</code>​。</p></li><li><p style="">运行 Doxygen，它会生成包含函数调用关系的文档。</p></li></ol></li></ul><h3 style="">2. <strong>Gprof</strong></h3><ul><li><p style=""><strong>支持语言</strong>：C/C++。</p></li><li><p style=""><strong>功能</strong>：Gprof 是一个性能分析工具，能生成程序的函数调用图。它主要用于检测程序的性能瓶颈，但也能展示函数之间的调用关系。</p></li><li><p style=""><strong>使用方法</strong>：</p><ol><li><p style="">编译程序时加上 <code>-pg</code>​ 选项生成可执行文件。</p></li><li><p style="">运行程序，生成 <code>gmon.out</code>​ 文件。</p></li><li><p style="">使用 <code>gprof</code>​ 分析 <code>gmon.out</code>​ 文件，查看函数调用关系。</p></li></ol></li></ul><h3 style="">3. <strong>Cscope</strong></h3><ul><li><p style=""><strong>支持语言</strong>：C/C++。</p></li><li><p style=""><strong>功能</strong>：Cscope 是一个交互式的代码浏览工具，可以查找函数的定义、调用、全局变量等信息，适合分析大规模的 C/C++ 项目。</p></li><li><p style=""><strong>使用方法</strong>：</p><ol><li><p style="">生成索引文件：<code>cscope -R</code>​。</p></li><li><p style="">在 Cscope 的交互界面中查找函数调用关系。</p></li></ol></li></ul><h3 style="">4. <strong>Code2flow</strong></h3><ul><li><p style=""><strong>支持语言</strong>：Python、JavaScript、Ruby、PHP 等。</p></li><li><p style=""><strong>功能</strong>：Code2flow 是一个简单的工具，可以从代码中生成流程图和调用图，适用于不需要深度分析的小项目。</p></li><li><p style=""><strong>使用方法</strong>：</p><ol><li><p style="">安装 <code>code2flow</code>​。</p></li><li><p style="">运行 <code>code2flow your_file.py</code>​，工具会生成相应的调用图。</p></li></ol></li></ul><h3 style="">5. <strong>Callgrind (结合 KCachegrind 使用)</strong></h3><ul><li><p style=""><strong>支持语言</strong>：C/C++。</p></li><li><p style=""><strong>功能</strong>：Callgrind 是 Valgrind 的一个工具，专门用于分析函数调用关系和性能。生成的报告可以用 KCachegrind 可视化，展示函数调用的详细图谱。</p></li><li><p style=""><strong>使用方法</strong>：</p><ol><li><p style="">使用 <code>valgrind --tool=callgrind ./your_program</code>​ 运行程序。</p></li><li><p style="">生成的 <code>callgrind.out</code>​ 文件可以使用 <code>kcachegrind</code>​ 查看调用关系。</p></li></ol></li></ul><p style="">这些工具各有特点，适合不同语言和场景的需求。如果你是在做 C/C++ 项目，可以考虑 Doxygen 和 Gprof。如果是其他语言，Code2flow 和 Cscope 也是不错的选择。你可以根据具体情况选择合适的工具。</p></li></ul></li><li><p style="">Doxygen生成函数调用图</p><ul><li><p style="">Doxygen 是一个非常强大的文档生成工具，它不仅可以为代码生成文档，还可以生成函数调用图。要生成函数调用图，必须正确配置 Doxygen。以下是如何使用 Doxygen 生成函数调用图的详细步骤：</p><h3 style="">1. 安装 Doxygen</h3><p style="">首先，你需要确保 Doxygen 已安装在你的系统中。你可以通过以下方式进行安装：</p><ul><li><p style=""><strong>Windows</strong>：可以从 <a href="https://www.doxygen.nl/">Doxygen官网</a> 下载可执行安装文件。</p></li><li><p style=""><strong>Linux</strong>：通过包管理器安装，例如：</p><pre><code class="language-bash">sudo apt-get install doxygen graphviz
</code></pre></li><li><p style=""><strong>macOS</strong>：使用 Homebrew 安装：</p><pre><code class="language-bash">brew install doxygen graphviz
</code></pre><p style=""><strong>Graphviz</strong> 是一个用于生成图的工具，Doxygen 生成调用图时依赖于它。因此，你还需要安装 Graphviz。</p></li></ul><h3 style="">2. 配置 Doxygen</h3><p style="">Doxygen 通过配置文件 <code>Doxyfile</code>​ 来控制生成文档的行为。你可以通过以下方式生成该文件：</p><pre><code class="language-bash">   doxygen -g
</code></pre><p style="">这将创建一个名为 <code>Doxyfile</code>​ 的默认配置文件。</p><h3 style="">3. 修改 <code>Doxyfile</code>​ 配置文件</h3><p style="">打开 <code>Doxyfile</code>​，并根据需要修改以下选项以启用函数调用图的生成：</p><ul><li><p style=""><strong>启用调用图和调用者图</strong>：</p><pre><code class="language-ini">CALL_GRAPH = YES          # 生成函数的调用图（显示被哪些函数调用）
CALLER_GRAPH = YES        # 生成函数的调用者图（显示调用了哪些函数）
</code></pre></li><li><p style=""><strong>启用图形输出格式</strong>：</p><pre><code class="language-ini">HAVE_DOT = YES            # 确保 Graphviz 的 dot 工具可用
</code></pre><p style="">如果 <code>HAVE_DOT</code>​ 被设置为 <code>NO</code>​，则需要将其更改为 <code>YES</code>​ 以支持图形生成。</p></li><li><p style=""><strong>图形显示样式（可选）</strong>：</p><pre><code class="language-ini">DOT_IMAGE_FORMAT = svg    # 可以选择生成的图形格式，如 png 或 svg
</code></pre><p style="">SVG 格式通常质量更好并支持放大缩小操作。</p></li><li><p style=""><strong>限制图的深度（可选）</strong>：<br> 如果你的项目很大，可以设置调用图的最大深度以避免生成过于复杂的图：</p><pre><code class="language-ini">MAX_DOT_GRAPH_DEPTH = 2   # 控制生成图的最大深度
</code></pre></li></ul><h3 style="">4. 生成文档</h3><p style="">配置好 <code>Doxyfile</code>​ 后，在项目根目录下运行以下命令生成文档：</p><pre><code class="language-bash">   doxygen Doxyfile
</code></pre><p style="">Doxygen 将自动分析你的源代码，并生成包含函数调用图的 HTML 文档。</p><h3 style="">5. 查看生成的函数调用图</h3><p style="">在 Doxygen 生成的文档目录中，打开 <code>index.html</code>​ 文件，通过浏览器访问。如果正确配置，点击某个函数时，它的调用图和调用者图将会显示在页面上。</p><ul><li><p style=""><strong>调用图 (Call Graph)</strong>：显示当前函数调用了哪些其他函数。</p></li><li><p style=""><strong>调用者图 (Caller Graph)</strong>：显示哪些函数调用了当前函数。</p></li></ul><h3 style="">6. 优化图形显示（可选）</h3><ul><li><p style=""><strong>调整图的布局</strong>：</p><pre><code class="language-ini">DOT_GRAPH_MAX_NODES = 50  # 控制图形中的最大节点数，防止图形过于复杂
DOT_TRANSPARENT = YES     # 使图形背景透明（更易嵌入到网页）
</code></pre></li><li><p style=""><strong>函数聚类</strong>：<br> 如果你想让相关函数聚集在一起，可以启用函数聚类选项：</p><pre><code class="language-ini">DOT_CLUSTERING = YES
</code></pre></li></ul><h3 style="">7. 示例调用图</h3><p style="">如果配置成功，生成的调用图可能看起来像这样：</p><pre><code class="language-plaintext">   +--------+    +----------+    +---------+
   | func A | --&gt;| func B    | --&gt;| func C  |
   +--------+    +----------+    +---------+
</code></pre><h3 style="">8. 调试常见问题</h3><ul><li><p style=""><strong>调用图未生成</strong>：确保 <code>HAVE_DOT</code>​ 设置为 <code>YES</code>​ 并且系统中安装了 Graphviz。</p></li><li><p style=""><strong>生成的图为空或不完整</strong>：检查 <code>MAX_DOT_GRAPH_DEPTH</code>​ 设置，增加图的深度。</p></li><li><p style=""><strong>图形显示不清晰</strong>：尝试将 <code>DOT_IMAGE_FORMAT</code>​ 设置为 <code>svg</code>​ 或其他矢量图格式。</p></li></ul><p style="">通过以上步骤，你可以生成函数的调用关系图，帮助你更好地理解项目中的函数调用逻辑。</p></li></ul></li></ul><h1 style="">实例</h1><pre><code class="language-c">

enum Colors {
    RED = 1,    /**&lt; Represents the color red */
    GREEN = 2,  /**&lt; Represents the color green */
    BLUE = 3    /**&lt; Represents the color blue */
};


/**
 * @brief Adds two integers.
 *
 * @details This function uses simple addition and assumes the input integers are valid.
 * Special care is taken to avoid overflow by ensuring the sum stays within a valid range.
 *
 * @note This function does not check for integer overflow.
 *
 * @param a First integer
 * @param b Second integer
 * @return The sum of a and b
 */
int add1(int a, int b) {
    //! This variable stores the sum of a and b
    int result = 0; /**&lt; The accumulated sum */

    // Add integers with overflow check
    if ((a &gt; 0 &amp;&amp; b &gt; 0 &amp;&amp; a &gt; INT_MAX - b) || (a &lt; 0 &amp;&amp; b &lt; 0 &amp;&amp; a &lt; INT_MIN - b)) {
        // Handle overflow case
        return -1; //!&lt; Return error code if overflow occurs
    }

    result = a + b; //!&lt; Perform the addition

    return result; //!&lt; Return the result
}

int add2(int a, int b) {
    int result = 0; /**&lt; The variable that stores the sum of a and b */

    result += a; /**&lt; Add the value of a to the result */
    result += b; /**&lt; Add the value of b to the result */

    return result; /**&lt; Return the calculated sum */
}

/**
 * @brief Adds two integers.
 *
 * This function takes two integers and returns their sum.
 *
 * @param a First integer
 * @param b Second integer
 * @return The sum of a and b
 */
int add3(int a, int b) {
    //! Initialize the result variable to zero.
    int result = 0;

    //! Add the first integer to the result.
    result += a;

    //! Add the second integer to the result.
    result += b;

    //! Return the final result.
    return result;
}


/**
 * @brief Adds two integers.
 *
 * @details
 * This function uses the following local variables:
 * - `result`: Stores the sum of the two input integers.
 *
 * @param a First integer
 * @param b Second integer
 * @return The sum of a and b
 */
int add4(int a, int b) {
    int result = 0; // Local variable to store the sum

    result += a;
    result += b;

    return result;
}


/**
 * @brief Computes the average of an integer array.
 *
 * This function takes an array of integers and its size as input, and returns
 * the average of the array elements. It handles cases where the array is empty.
 *
 * @details
 * The function iterates over the array to compute the sum of its elements.
 * If the array is empty, it returns 0 to avoid division by zero.
 * 
 * Local variables used in this function:
 * - `sum`: Accumulates the sum of array elements.
 * - `i`: Loop counter for iterating through the array.
 *
 * Example usage:
 * @code
 * int arr[] = {1, 2, 3, 4, 5};
 * double avg = compute_average(arr, 5);
 * printf("Average: %f\n", avg);
 * @endcode
 *
 * @param arr The input array of integers.
 * @param size The number of elements in the array.
 * @return The average of the array elements. If the array is empty, returns 0.
 * 
 * @note The return value is of type `double` to allow for decimal averages.
 */
double compute_average(const int* arr, size_t size) {
    //! Sum of the array elements
    int sum = 0;

    //! Loop counter to iterate through the array
    size_t i;

    // If the array is empty, return 0 to avoid division by zero
    if (size == 0) {
        return 0.0;
    }

    // Sum all elements in the array
    for (i = 0; i &lt; size; ++i) {
        sum += arr[i];
    }

    //! Return the computed average as a double
    return (double)sum / size;
}



/**
 * @brief Adds two integers.
 *
 * @details This function uses simple addition and assumes the input integers are valid.
 * Special care is taken to avoid overflow by ensuring the sum stays within a valid range.
 *
 * @note This function does not check for integer overflow.
 *
 * @param a First integer
 * @param b Second integer
 * @return The sum of a and b
 */
int add6(int a, int b) {
    int result = 0; /**&lt; The accumulated sum */

    // Add integers with overflow check
    if ((a &gt; 0 &amp;&amp; b &gt; 0 &amp;&amp; a &gt; INT_MAX - b) || (a &lt; 0 &amp;&amp; b &lt; 0 &amp;&amp; a &lt; INT_MIN - b)) {
        // Handle overflow case
        return -1; //!&lt; Return error code if overflow occurs
    }

    result = a + b; //!&lt; Perform the addition

    return result; //!&lt; Return the result
}



int add7(int a, int b) {
    int result = 0; /**&lt; The variable that stores the sum of a and b */

    result += a; /**&lt; Add the value of a to the result */
    result += b; /**&lt; Add the value of b to the result */

    return result; /**&lt; Return the calculated sum */
}


/**
 * @defgroup GeometricShapes Geometric Shape Calculations
 * @brief This module handles the calculations of areas for geometric shapes like circles, squares, and triangles.
 *
 * The functions in this module compute the areas of various geometric shapes by using their respective formulas.
 * @{
 */

/**
 * @brief Initializes the system to compute geometric areas.
 *
 * This function can be used to set up any necessary initial values before computing the areas of shapes.
 */
void init_area_computation(void) {
    shape_count = 0;  // Initialize shape counter
}

/** @} */  // End of GeometricShapes group



/**
 * @brief Computes the area of a circle.
 *
 * This function takes a pointer to a `Circle` structure and calculates its area using the formula:
 * @f$ Area = \pi \times radius^2 @f$.
 * 
 * @f[
 * Area = \pi \times radius^2
 * @f]
 *
 * @param[in] circle A pointer to the `Circle` structure containing the radius.
 * @return The area of the circle.
 */
double compute_circle_area(const Circle* circle) {
    return PI * circle-&gt;radius * circle-&gt;radius;
}







/**
 * @file example.h
 * @brief This file contains definitions, function prototypes, and data structures
 *        for a simple system that computes geometric shapes' areas.
 * 
 * This file demonstrates how to use Doxygen to document a C header file.
 * It includes macros, structures, function prototypes, and enumeration types.
 * 
 * @author John Doe
 * @date 2024-10-11
 */


/**
 * @def PI
 * @brief The mathematical constant Pi (3.14159...).
 *
 * This macro defines the value of Pi, which is used in geometric calculations.
 */
#define PI 3.141592653589793


/**
 * @enum ShapeType
 * @brief Defines the types of geometric shapes.
 *
 * This enumeration is used to specify the type of shape, 
 * such as a circle, square, or triangle.
 */
typedef enum {
    SHAPE_CIRCLE,   /**&lt; Circle shape */
    SHAPE_SQUARE,   /**&lt; Square shape */
    SHAPE_TRIANGLE  /**&lt; Triangle shape */
} ShapeType;

/**
 * @struct Triangle
 * @brief Represents a triangle with a base and height.
 *
 * This structure stores the base and height of a triangle for area calculations.
 */
typedef struct {
    double base;   /**&lt; The base length of the triangle */
    double height; /**&lt; The height of the triangle */
} Triangle;




/**
 * @struct Circle
 * @brief Represents a circle with a radius.
 *
 * This structure is used to store the radius of a circle for area calculations.
 */
typedef struct {
    double radius; /**&lt; The radius of the circle */
} Circle;

/**
 * @struct Square
 * @brief Represents a square with a side length.
 *
 * This structure stores the side length of a square for area calculations.
 */
typedef struct {
    double side_length; /**&lt; The length of one side of the square */
} Square;



/**
 * @var shape_count
 * @brief Keeps track of the number of shapes processed.
 *
 * This global variable is incremented every time a new shape's area is computed.
 */
int shape_count = 0;


/**
 * @brief Computes the area of a square.
 *
 * This function calculates the area of a square based on its side length.
 *
 * @param[in] square A pointer to the `Square` structure containing the side length.
 * @return The area of the square.
 */
double compute_square_area(const Square* square) {
    return square-&gt;side_length * square-&gt;side_length;
}

/**
 * @brief Computes the area of a triangle.
 *
 * This function computes the area of a triangle using the formula:
 * @f$ Area = \frac{1}{2} \times base \times height @f$.
 *
 * @param[in] triangle A pointer to the `Triangle` structure containing the base and height.
 * @return The area of the triangle.
 */
double compute_triangle_area(const Triangle* triangle) {
    return 0.5 * triangle-&gt;base * triangle-&gt;height;
}

</code></pre><p style="">在使用 Doxygen 生成文档时，函数内的注释可以通过特定的标记来实现。Doxygen 支持在函数内部添加详细的说明，解释代码逻辑、变量用途或步骤等。这些注释将显示在生成的文档中，帮助开发者理解函数的实现细节。</p><p style="">以下是几种常见的函数内注释方式：</p><h3 style="">1. 使用 <code>//!</code>​ 或 <code>///</code>​</h3><p style="">可以在函数体内直接使用 <code>//!</code>​ 或 <code>///</code>​ 注释每个逻辑部分。例如：</p><pre><code>好的，下面是一个全面的 C 语言项目注释示例，包含了常见的 Doxygen 注释用法，涵盖文件、函数、变量、结构体、枚举、宏定义、以及组（modules）等内容。这样你可以在实际项目中参考使用，确保所有重要元素都得到充分注释和文档化。

### 文件注释

‍‍```c
/**
 * @file example.h
 * @brief This file contains definitions, function prototypes, and data structures
 *        for a simple system that computes geometric shapes' areas.
 * 
 * This file demonstrates how to use Doxygen to document a C header file.
 * It includes macros, structures, function prototypes, and enumeration types.
 * 
 * @author John Doe
 * @date 2024-10-11
 */
</code></pre><p style="">‍</p><h3 style="">宏定义注释</h3><p style="">‍</p><pre><code class="language-c">/**
 * @def PI
 * @brief The mathematical constant Pi (3.14159...).
 *
 * This macro defines the value of Pi, which is used in geometric calculations.
 */
#define PI 3.141592653589793
</code></pre><p style="">‍</p><h3 style="">枚举类型注释</h3><p style="">‍</p><pre><code class="language-c">/**
 * @enum ShapeType
 * @brief Defines the types of geometric shapes.
 *
 * This enumeration is used to specify the type of shape, 
 * such as a circle, square, or triangle.
 */
typedef enum {
    SHAPE_CIRCLE,   /**&lt; Circle shape */
    SHAPE_SQUARE,   /**&lt; Square shape */
    SHAPE_TRIANGLE  /**&lt; Triangle shape */
} ShapeType;
</code></pre><p style="">‍</p><h3 style="">结构体注释</h3><p style="">‍</p><pre><code class="language-c">/**
 * @struct Circle
 * @brief Represents a circle with a radius.
 *
 * This structure is used to store the radius of a circle for area calculations.
 */
typedef struct {
    double radius; /**&lt; The radius of the circle */
} Circle;

/**
 * @struct Square
 * @brief Represents a square with a side length.
 *
 * This structure stores the side length of a square for area calculations.
 */
typedef struct {
    double side_length; /**&lt; The length of one side of the square */
} Square;

/**
 * @struct Triangle
 * @brief Represents a triangle with a base and height.
 *
 * This structure stores the base and height of a triangle for area calculations.
 */
typedef struct {
    double base;   /**&lt; The base length of the triangle */
    double height; /**&lt; The height of the triangle */
} Triangle;
</code></pre><p style="">‍</p><h3 style="">全局变量注释</h3><p style="">‍</p><pre><code class="language-c">/**
 * @var shape_count
 * @brief Keeps track of the number of shapes processed.
 *
 * This global variable is incremented every time a new shape's area is computed.
 */
int shape_count = 0;
</code></pre><p style="">‍</p><h3 style="">函数注释</h3><p style="">‍</p><pre><code class="language-c">/**
 * @brief Computes the area of a circle.
 *
 * This function takes a pointer to a `Circle` structure and calculates its area using the formula:
 * @f$ Area = \pi \times radius^2 @f$.
 *
 * @param[in] circle A pointer to the `Circle` structure containing the radius.
 * @return The area of the circle.
 */
double compute_circle_area(const Circle* circle) {
    return PI * circle-&gt;radius * circle-&gt;radius;
}

/**
 * @brief Computes the area of a square.
 *
 * This function calculates the area of a square based on its side length.
 *
 * @param[in] square A pointer to the `Square` structure containing the side length.
 * @return The area of the square.
 */
double compute_square_area(const Square* square) {
    return square-&gt;side_length * square-&gt;side_length;
}

/**
 * @brief Computes the area of a triangle.
 *
 * This function computes the area of a triangle using the formula:
 * @f$ Area = \frac{1}{2} \times base \times height @f$.
 *
 * @param[in] triangle A pointer to the `Triangle` structure containing the base and height.
 * @return The area of the triangle.
 */
double compute_triangle_area(const Triangle* triangle) {
    return 0.5 * triangle-&gt;base * triangle-&gt;height;
}
</code></pre><p style="">‍</p><h3 style="">组（Modules）注释</h3><p style="">为了组织代码，你可以使用 Doxygen 的 <code>@defgroup</code>​ 和 <code>@addtogroup</code>​ 标签将相关函数、结构体等归为一组，便于文档阅读。</p><pre><code class="language-c">/**
 * @defgroup GeometricShapes Geometric Shape Calculations
 * @brief This module handles the calculations of areas for geometric shapes like circles, squares, and triangles.
 *
 * The functions in this module compute the areas of various geometric shapes by using their respective formulas.
 * @{
 */

/**
 * @brief Initializes the system to compute geometric areas.
 *
 * This function can be used to set up any necessary initial values before computing the areas of shapes.
 */
void init_area_computation(void) {
    shape_count = 0;  // Initialize shape counter
}

/** @} */  // End of GeometricShapes group
</code></pre><p style="">‍</p><h3 style="">main.c 中的代码示例</h3><p style="">为了结合所有的注释，以下是一个主程序文件中使用这些函数的示例。</p><pre><code class="language-c">#include "example.h"

int main(void) {
    Circle circle = {5.0};       // Circle with radius 5.0
    Square square = {4.0};       // Square with side length 4.0
    Triangle triangle = {3.0, 6.0}; // Triangle with base 3.0 and height 6.0

    init_area_computation();

    double circle_area = compute_circle_area(&amp;circle);
    double square_area = compute_square_area(&amp;square);
    double triangle_area = compute_triangle_area(&amp;triangle);

    printf("Circle Area: %f\n", circle_area);
    printf("Square Area: %f\n", square_area);
    printf("Triangle Area: %f\n", triangle_area);

    return 0;
}
</code></pre><p style="">‍</p><h3 style="">其他注释标签</h3><p style="">‍</p><ol><li><p style=""><code>@param</code>​ 和 <code>@return</code>​：用于注释函数参数和返回值。</p></li><li><p style=""><code>@file</code>​：用于文件级别的注释。</p></li><li><p style=""><code>@struct</code>​ 和 <code>@typedef</code>​：用于结构体和类型定义。</p></li><li><p style=""><code>@brief</code>​：简要描述。</p></li><li><p style=""><code>@details</code>​：详细描述。</p></li><li><p style=""><code>@note</code>​：给出提示或注意事项。</p></li><li><p style=""><code>@code</code>​ 和 <code>@endcode</code>​：用于嵌入代码示例。</p></li><li><p style=""><code>@ingroup</code>​：将元素添加到组中。</p></li></ol><h3 style="">总结</h3><p style="">这是一套完整的 Doxygen 注释示例，展示了如何为 C 语言中常见的元素（如文件、函数、变量、结构体、枚举、宏和组）进行注释。使用这些注释方式，可以确保生成的文档清晰、全面，方便团队协作和代码维护。</p><pre><code>
### 2. 使用 `/**&lt;` 在变量声明中注释

如果想对函数内部局部变量进行注释的话应该怎么办

最后得到的只是写的注释，并没有给出局部变量的名字

对于函数内的变量，您可以使用 `/**&lt;` 来直接注释变量的声明，帮助读者了解每个变量的作用：

</code></pre><p style="">int add(int a, int b) {<br> int result = 0; /**&lt; The variable that stores the sum of a and b */</p><pre><code>result += a; /**&lt; Add the value of a to the result */  
result += b; /**&lt; Add the value of b to the result */

return result; /**&lt; Return the calculated sum */  
</code></pre><p style="">}</p><pre><code>
### 3. 使用 `@details` 和 `@note`

对于较为复杂的函数，可以使用 `@details` 和 `@note` 来解释函数中的特定细节或提醒：

</code></pre><p style="">/**</p><ul><li><p style="">@brief Adds two integers.</p></li><li><p style="">‍</p></li><li><p style="">@details This function uses simple addition and assumes the input integers are valid.</p></li><li><p style="">Special care is taken to avoid overflow by ensuring the sum stays within a valid range.</p></li><li><p style="">‍</p></li><li><p style="">@note This function does not check for integer overflow.</p></li><li><p style="">‍</p></li><li><p style="">@param a First integer</p></li><li><p style="">@param b Second integer</p></li><li><p style="">@return The sum of a and b<br> */<br> int add(int a, int b) {<br> int result = 0; /**&lt; The accumulated sum */</p><p style="">// Add integers with overflow check<br> if ((a &gt; 0 &amp;&amp; b &gt; 0 &amp;&amp; a &gt; INT_MAX - b) || (a &lt; 0 &amp;&amp; b &lt; 0 &amp;&amp; a &lt; INT_MIN - b)) {<br> // Handle overflow case<br> return -1; //!&lt; Return error code if overflow occurs<br> }</p><p style="">result = a + b; //!&lt; Perform the addition</p><p style="">return result; //!&lt; Return the result<br> }</p></li></ul><pre><code>
### 小结

在函数内部添加详细的注释有助于提升代码的可读性和维护性，Doxygen 支持多种注释格式，可以根据项目需求灵活选择。

如果最后生成的文档显示的公式是 `$ Area = \pi \times radius^2 $` 而不是公式的数学格式，可能是 Doxygen 没有正确识别 LaTeX 公式的标记。为了让 Doxygen 正确地显示数学公式，可以尝试以下几种解决方案：

### 1. 确保使用正确的 `@f$` 标签

Doxygen 支持 LaTeX 公式，但它需要你使用正确的标签格式。如果你想让公式显示为数学格式，应该用 `@f$` 来标记公式的开始和结束。例如：

</code></pre><p style="">/**</p><ul><li><p style="">@brief Computes the area of a circle.</p></li><li><p style="">‍</p></li><li><p style="">The area of a circle is given by the formula:</p></li><li><p style="">@f$Area = \pi \times radius^2 @f$.</p></li><li><p style="">‍</p></li><li><p style="">@param[in] radius The radius of the circle.</p></li><li><p style="">@return The area of the circle.<br> */<br> double compute_circle_area(double radius) {<br> return PI * radius * radius;<br> }</p></li></ul><pre><code>
在生成文档时，Doxygen 会识别 `@f$` 标签并将其转换为 LaTeX 格式，显示为：

[\\text{Area} \= \\pi \\times \\text{radius}\^2]

### 2. 使用 `@f[` 和 `@f]` 包围公式

如果公式较长或你想换行，可以使用 `@f[` 和 `@f]` 标签将整个公式包围起来，生成更加清晰的数学公式表示。例如：

</code></pre><p style="">/**</p><ul><li><p style="">@brief Computes the area of a circle.</p></li><li><p style="">‍</p></li><li><p style="">The area of a circle is calculated as:</p></li><li><p style="">@f[</p></li><li><p style="">Area = \pi \times radius^2</p></li><li><p style="">@f]</p></li><li><p style="">‍</p></li><li><p style="">@param[in] radius The radius of the circle.</p></li><li><p style="">@return The area of the circle.<br> */<br> double compute_circle_area(double radius) {<br> return PI * radius * radius;<br> }</p></li></ul><pre><code>
这样，公式将会被识别为块状公式，并正确渲染。

### 3. 确保 Doxygen 配置支持 LaTeX

Doxygen 需要特定的配置才能正确处理 LaTeX 公式：

* 打开 `Doxyfile`，确保以下设置启用：
  * `USE_MATHJAX = YES` 让 Doxygen 使用 MathJax 来渲染数学公式。
  * 如果没有 MathJax，你可以设置 `LATEX_OUTPUT = YES`，以确保 LaTeX 能被正确编译成 PDF 或 HTML 格式。

</code></pre><p style="">USE_MATHJAX   = YES<br> MATHJAX_FORMAT = HTML</p><pre><code>
### 4. 确保 MathJax 或 LaTeX 环境可用

* 如果生成 HTML 文档并希望公式正确显示，你需要确保 MathJax 脚本能够正常加载。如果是生成 PDF，你需要 LaTeX 环境来正确编译数学公式。

### 结论

总结来说，确保使用 `@f$` 标签正确标记公式，并且检查 Doxygen 的配置文件是否启用了 MathJax 或 LaTeX 支持。
</code></pre><h2 style="">效果图</h2><p style="">​<img src="https://blog.genson.fun/upload/image-20241011110820-nr6opkr.png" alt="image" width="100%" height="100%" style="display: inline-block">​</p><p style="">‍</p>]]></description><guid>/archives/doxgen-s-installation-and-use-z1xr8mu</guid><pubDate>Tue, 8 Oct 2024 05:58:00 GMT</pubDate></item><item><title><![CDATA[MATLAB 图中放大图]]></title><link>http://localhost:7090/archives/matlab-map-amplified-map-1icqhx</link><description><![CDATA[<h1>MATLAB 图中放大图</h1>
<p>magnifyOnFigure是一个工具箱，下载链接为：<a href="https://download.csdn.net/download/miao0967020148/15154799?spm=1001.2014.3001.5501">https://download.csdn.net/download/miao0967020148/15154799?spm=1001.2014.3001.5501</a></p>
<pre><code class="language-matlab">clc;
clear all
close all
disp( sprintf('The figure handle is here passed as an input argument.') ) 
fig = figure;
hold on;
plot(rand(100,1), 'b'); plot(rand(300, 1), 'r'); 
grid on;
hold off;
magnifyOnFigure(fig);
disp('Press a key...')
pause;
</code></pre>
<p>​<img src="https://blog.genson.fun/upload/2021020915263254-blre.jpg" alt="img" />​</p>
<pre><code class="language-matlab"> magnifyOnFigure(fig,'displayLinkStyle', 'straight',...
                    'EdgeColor', 'black',...
                    'magnifierShape', 'rectangle',...
                    'initialPositionSecondaryAxes', [80 150 96 56],...
                    'initialPositionMagnifier',     [150 100 24 16],...    
                    'frozenZoomAspectratio', 'on',...
                    'edgeWidth',1); 
</code></pre>
<p>'initialPositionSecondaryAxes', [80 150 96 56] 设置放大图的位置</p>
<p>'initialPositionMagnifier',   [150 100 24 16]设置放大的区域</p>
<p><img src="https://blog.genson.fun/upload/20210209153045345-wxil.png" alt="img" /></p>
]]></description><guid>/archives/matlab-map-amplified-map-1icqhx</guid><pubDate>Sun, 14 Apr 2024 05:05:00 GMT</pubDate></item><item><title><![CDATA[在线服务]]></title><link>http://localhost:7090/archives/zai-xian-fu-wu</link><description><![CDATA[<div class="html-edited"><hao-flink name="自建服务" desc="博主名下的个别服务" style="beautify">
                    <div class="flink" id="article-container">
                       <div class="flink-name">自建服务</div>
                     <div class="flink-desc">博主名下的个别服务</div>
                        <div class="site-card-group">

                                <div class="site-card">
                                    <a class="img" target="_blank" href="https://gitea.genson.fun" title="Gitea">
                                        <img class="flink-avatar entered loaded" style="pointer-events: none;" alt="Gitea" data-lazy-src="https://redirect.cnkj.site:8099/b/2023/656d3eb8c5077.webp?type=blog" data-ll-status="loaded" src="https://redirect.cnkj.site:8099/b/2023/656d3eb8c5077.webp?type=blog">
                                    </a>

                                    <a class="info cf-friends-link" target="_blank" href="https://gitea.genson.fun" title="Gitea">
                                        <div class="site-card-avatar no-lightbox">
                                            <img class="flink-avatar cf-friends-avatar entered loaded" alt="Gitea" data-lazy-src=" https://redirect.cnkj.site:18092/assets/img/logo.svg" data-ll-status="loaded" src=" https://redirect.cnkj.site:18092/assets/img/logo.svg">
                                        </div>
                                        <div class="site-card-text">
                                            <span class="title cf-friends-name">Gitea</span>
                                            <span class="desc" title="一款极易搭建的自助 Git 服务">一款极易搭建的自助 Git 服务</span>
                                        </div>
                                    </a>
                                </div>
                            
                                <div class="site-card">
                                    <a class="img" target="_blank" href="https://minio.cnkj.site" title="对象云存储">
                                        <img class="flink-avatar entered loaded" style="pointer-events: none;" alt="对象云存储" data-lazy-src="https://redirect.cnkj.site:8099/b/2023/656dea9920eb0.webp?type=blog" data-ll-status="loaded" src="https://redirect.cnkj.site:8099/b/2023/656dea9920eb0.webp?type=blog">
                                    </a>

                                    <a class="info cf-friends-link" target="_blank" href="https://minio.cnkj.site" title="对象云存储">
                                        <div class="site-card-avatar no-lightbox">
                                            <img class="flink-avatar cf-friends-avatar entered loaded" alt="对象云存储" data-lazy-src="https://redirect.cnkj.site:8099/b/2023/656dea9920eb0.webp?type=blog" data-ll-status="loaded" src="https://redirect.cnkj.site:8099/b/2023/656dea9920eb0.webp?type=blog">
                                        </div>
                                        <div class="site-card-text">
                                            <span class="title cf-friends-name">对象云存储</span>
                                            <span class="desc" title="High-Performance Object Store">High-Performance Object Store</span>
                                        </div>
                                    </a>
                                </div>
                        </div>
					</div>
</hao-flink>
<div class="flink" id="article-container">
                       <div class="flink-name">工具箱</div>
					   
                     <div class="flink-desc">一些实用的在线工具</div>
                    
                       
                        <div class="flink-list">
                           
                                <div class="flink-list-item">
                                    <a class="cf-friends-link" rel="external nofollow" target="_blank" href="https://xbeibeix.com/api/bilibili/" title="贝贝BiliBili">
                                        <img class="flink-avatar cf-friends-avatar entered loaded" alt="贝贝BiliBili" data-lazy-src="https://xbeibeix.com/wp-content/uploads/2019/07/cropped-%E6%9C%AA%E5%91%BD%E5%90%8D_%E5%89%AF%E6%9C%AC-32x32.jpg" data-ll-status="loaded" src="https://xbeibeix.com/wp-content/uploads/2019/07/cropped-%E6%9C%AA%E5%91%BD%E5%90%8D_%E5%89%AF%E6%9C%AC-32x32.jpg">
                                        <div class="flink-item-info no-lightbox">
                                            <span class="flink-item-name cf-friends-name">贝贝BiliBili</span>
                                            <span class="flink-item-desc" title="B站视频下载">B站视频下载</span>
                                            <img data-lazy-src="https://xbeibeix.com/wp-content/uploads/2019/07/cropped-%E6%9C%AA%E5%91%BD%E5%90%8D_%E5%89%AF%E6%9C%AC-32x32.jpg" data-ll-status="loaded" class="entered loaded" src="https://xbeibeix.com/wp-content/uploads/2019/07/cropped-%E6%9C%AA%E5%91%BD%E5%90%8D_%E5%89%AF%E6%9C%AC-32x32.jpg">
                                        </div>
                                    </a>
                                </div>
                            
                                <div class="flink-list-item">
                                    <a class="cf-friends-link" rel="external nofollow" target="_blank" href="https://online-video-cutter.com/cn/" title="123APPS">
                                        <img class="flink-avatar cf-friends-avatar entered loaded" alt="123APPS" data-lazy-src="https://online-video-cutter.com/static/i/v3/apple-touch-icon.png" data-ll-status="loaded" src="https://online-video-cutter.com/static/i/v3/apple-touch-icon.png">
                                        <div class="flink-item-info no-lightbox">
                                            <span class="flink-item-name cf-friends-name">123APPS</span>
                                            <span class="flink-item-desc" title="在线裁剪视频 - 裁剪 MP4、AVI、MPG、3GP">在线裁剪视频 - 裁剪 MP4、AVI、MPG、3GP</span>
                                            <img data-lazy-src="https://online-video-cutter.com/static/i/v3/apple-touch-icon.png" data-ll-status="loaded" class="entered loaded" src="https://online-video-cutter.com/static/i/v3/apple-touch-icon.png">
                                        </div>
                                    </a>
                                </div>
                            
                                <div class="flink-list-item">
                                    <a class="cf-friends-link" rel="external nofollow" target="_blank" href="https://tableconvert.com/" title="tableconvert">
                                        <img class="flink-avatar cf-friends-avatar entered loaded" alt="tableconvert" data-lazy-src="https://lsky.genson.fun/blog/2024/01/16/65a5e5f46d865.webp" data-ll-status="loaded" src="https://lsky.genson.fun/blog/2024/01/16/65a5e5f46d865.webp">
                                        <div class="flink-item-info no-lightbox">
                                            <span class="flink-item-name cf-friends-name">tableconvert</span>
                                            <span class="flink-item-desc" title="在线表格转换">在线表格转换</span>
                                            <img data-lazy-src="https://lsky.genson.fun/blog/2024/01/16/65a5e5f46d865.webp" data-ll-status="loaded" class="entered loaded" src="https://lsky.genson.fun/blog/2024/01/16/65a5e5f46d865.webp">
                                        </div>
                                    </a>
                                </div>		
								
                                <div class="flink-list-item">
                                    <a class="cf-friends-link" rel="external nofollow" target="_blank" href="https://www.lddgo.net/" title="Online tools">
                                        <img class="flink-avatar cf-friends-avatar entered loaded" alt="Online tools" data-lazy-src="https://lsky.genson.fun/blog/2024/03/15/65f3eac660f70.webp" data-ll-status="loaded" src="https://lsky.genson.fun/blog/2024/03/15/65f3eac660f70.webp">
                                        <div class="flink-item-info no-lightbox">
                                            <span class="flink-item-name cf-friends-name">Online tools</span>
                                            <span class="flink-item-desc" title="320个在线工具">320个在线工具</span>
                                            <img data-lazy-src="https://lsky.genson.fun/blog/2024/03/15/65f3eac660f70.webp" data-ll-status="loaded" class="entered loaded" src="https://lsky.genson.fun/blog/2024/03/15/65f3eac660f70.webp">
                                        </div>
                                    </a>
                                </div>									
                        </div>
                    
					</div></div><p style=""></p>]]></description><guid>/archives/zai-xian-fu-wu</guid><pubDate>Tue, 16 Jan 2024 02:50:00 GMT</pubDate></item><item><title><![CDATA[ASCII对照表]]></title><link>http://localhost:7090/archives/asciidui-zhao-biao</link><description><![CDATA[<div class="html-edited"><table class="toolTable table" width="100%" cellspacing="0" cellpadding="0">
				<tbody><tr>
					<th class="separateColor">ASCII值</th>
					<th>控制字符</th>
					<th class="separateColor">ASCII值</th>
					<th>控制字符</th>
					<th class="separateColor">ASCII值</th>
					<th>控制字符</th>
					<th class="separateColor">ASCII值</th>
					<th>控制字符</th>
				</tr>
				<tr>
					<td class="separateColor">0</td>
					<td>NUT</td>
					<td class="separateColor">32</td>
					<td>(space)</td>
					<td class="separateColor">64</td>
					<td>@</td>
					<td class="separateColor">96</td>
					<td>、</td>
				</tr>
				<tr>
					<td class="separateColor">1</td>
					<td>SOH</td>
					<td class="separateColor">33</td>
					<td>!</td>
					<td class="separateColor">65</td>
					<td>A</td>
					<td class="separateColor">97</td>
					<td>a</td>
				</tr>
				<tr>
					<td class="separateColor">2</td>
					<td>STX</td>
					<td class="separateColor">34</td>
					<td>"</td>
					<td class="separateColor">66</td>
					<td>B</td>
					<td class="separateColor">98</td>
					<td>b</td>
				</tr>
				<tr>
					<td class="separateColor">3</td>
					<td>ETX</td>
					<td class="separateColor">35</td>
					<td>#</td>
					<td class="separateColor">67</td>
					<td>C</td>
					<td class="separateColor">99</td>
					<td>c</td>
				</tr>
				<tr>
					<td class="separateColor">4</td>
					<td>EOT</td>
					<td class="separateColor">36</td>
					<td>$</td>
					<td class="separateColor">68</td>
					<td>D</td>
					<td class="separateColor">100</td>
					<td>d</td>
				</tr>
				<tr>
					<td class="separateColor">5</td>
					<td>ENQ</td>
					<td class="separateColor">37</td>
					<td>%</td>
					<td class="separateColor">69</td>
					<td>E</td>
					<td class="separateColor">101</td>
					<td>e</td>
				</tr>
				<tr>
					<td class="separateColor">6</td>
					<td>ACK</td>
					<td class="separateColor">38</td>
					<td>&amp;</td>
					<td class="separateColor">70</td>
					<td>F</td>
					<td class="separateColor">102</td>
					<td>f</td>
				</tr>
				<tr>
					<td class="separateColor">7</td>
					<td>BEL</td>
					<td class="separateColor">39</td>
					<td>,</td>
					<td class="separateColor">71</td>
					<td>G</td>
					<td class="separateColor">103</td>
					<td>g</td>
				</tr>
				<tr>
					<td class="separateColor">8</td>
					<td>BS</td>
					<td class="separateColor">40</td>
					<td>(</td>
					<td class="separateColor">72</td>
					<td>H</td>
					<td class="separateColor">104</td>
					<td>h</td>
				</tr>
				<tr>
					<td class="separateColor">9</td>
					<td>HT</td>
					<td class="separateColor">41</td>
					<td>)</td>
					<td class="separateColor">73</td>
					<td>I</td>
					<td class="separateColor">105</td>
					<td>i</td>
				</tr>
				<tr>
					<td class="separateColor">10</td>
					<td>LF</td>
					<td class="separateColor">42</td>
					<td>*</td>
					<td class="separateColor">74</td>
					<td>J</td>
					<td class="separateColor">106</td>
					<td>j</td>
				</tr>
				<tr>
					<td class="separateColor">11</td>
					<td>VT</td>
					<td class="separateColor">43</td>
					<td>+</td>
					<td class="separateColor">75</td>
					<td>K</td>
					<td class="separateColor">107</td>
					<td>k</td>
				</tr>
				<tr>
					<td class="separateColor">12</td>
					<td>FF</td>
					<td class="separateColor">44</td>
					<td>,</td>
					<td class="separateColor">76</td>
					<td>L</td>
					<td class="separateColor">108</td>
					<td>l</td>
				</tr>
				<tr>
					<td class="separateColor">13</td>
					<td>CR</td>
					<td class="separateColor">45</td>
					<td>-</td>
					<td class="separateColor">77</td>
					<td>M</td>
					<td class="separateColor">109</td>
					<td>m</td>
				</tr>
				<tr>
					<td class="separateColor">14</td>
					<td>SO</td>
					<td class="separateColor">46</td>
					<td>.</td>
					<td class="separateColor">78</td>
					<td>N</td>
					<td class="separateColor">110</td>
					<td>n</td>
				</tr>
				<tr>
					<td class="separateColor">15</td>
					<td>SI</td>
					<td class="separateColor">47</td>
					<td>/</td>
					<td class="separateColor">79</td>
					<td>O</td>
					<td class="separateColor">111</td>
					<td>o</td>
				</tr>
				<tr>
					<td class="separateColor">16</td>
					<td>DLE</td>
					<td class="separateColor">48</td>
					<td>0</td>
					<td class="separateColor">80</td>
					<td>P</td>
					<td class="separateColor">112</td>
					<td>p</td>
				</tr>
				<tr>
					<td class="separateColor">17</td>
					<td>DCI</td>
					<td class="separateColor">49</td>
					<td>1</td>
					<td class="separateColor">81</td>
					<td>Q</td>
					<td class="separateColor">113</td>
					<td>q</td>
				</tr>
				<tr>
					<td class="separateColor">18</td>
					<td>DC2</td>
					<td class="separateColor">50</td>
					<td>2</td>
					<td class="separateColor">82</td>
					<td>R</td>
					<td class="separateColor">114</td>
					<td>r</td>
				</tr>
				<tr>
					<td class="separateColor">19</td>
					<td>DC3</td>
					<td class="separateColor">51</td>
					<td>3</td>
					<td class="separateColor">83</td>
					<td>S</td>
					<td class="separateColor">115</td>
					<td>s</td>
				</tr>
				<tr>
					<td class="separateColor">20</td>
					<td>DC4</td>
					<td class="separateColor">52</td>
					<td>4</td>
					<td class="separateColor">84</td>
					<td>T</td>
					<td class="separateColor">116</td>
					<td>t</td>
				</tr>
				<tr>
					<td class="separateColor">21</td>
					<td>NAK</td>
					<td class="separateColor">53</td>
					<td>5</td>
					<td class="separateColor">85</td>
					<td>U</td>
					<td class="separateColor">117</td>
					<td>u</td>
				</tr>
				<tr>
					<td class="separateColor">22</td>
					<td>SYN</td>
					<td class="separateColor">54</td>
					<td>6</td>
					<td class="separateColor">86</td>
					<td>V</td>
					<td class="separateColor">118</td>
					<td>v</td>
				</tr>
				<tr>
					<td class="separateColor">23</td>
					<td>TB</td>
					<td class="separateColor">55</td>
					<td>7</td>
					<td class="separateColor">87</td>
					<td>W</td>
					<td class="separateColor">119</td>
					<td>w</td>
				</tr>
				<tr>
					<td class="separateColor">24</td>
					<td>CAN</td>
					<td class="separateColor">56</td>
					<td>8</td>
					<td class="separateColor">88</td>
					<td>X</td>
					<td class="separateColor">120</td>
					<td>x</td>
				</tr>
				<tr>
					<td class="separateColor">25</td>
					<td>EM</td>
					<td class="separateColor">57</td>
					<td>9</td>
					<td class="separateColor">89</td>
					<td>Y</td>
					<td class="separateColor">121</td>
					<td>y</td>
				</tr>
				<tr>
					<td class="separateColor">26</td>
					<td>SUB</td>
					<td class="separateColor">58</td>
					<td>:</td>
					<td class="separateColor">90</td>
					<td>Z</td>
					<td class="separateColor">122</td>
					<td>z</td>
				</tr>
				<tr>
					<td class="separateColor">27</td>
					<td>ESC</td>
					<td class="separateColor">59</td>
					<td>;</td>
					<td class="separateColor">91</td>
					<td>[</td>	
					<td class="separateColor">123</td>
					<td>{</td>
				</tr>
				<tr>
					<td class="separateColor">28</td>
					<td>FS</td>
					<td class="separateColor">60</td>
					<td>&lt;</td>
					<td class="separateColor">92</td>
					<td>\</td>
					<td class="separateColor">124</td>
					<td>|</td>
				</tr>
				<tr>
					<td class="separateColor">29</td>
					<td>GS</td>
					<td class="separateColor">61</td>
					<td>=</td>
					<td class="separateColor">93</td>
					<td>]</td>
					<td class="separateColor">125</td>
					<td>}</td>
				</tr>
				<tr>
					<td class="separateColor">30</td>
					<td>RS</td>
					<td class="separateColor">62</td>
					<td>&gt;</td>
					<td class="separateColor">94</td>
					<td>^</td>
					<td class="separateColor">126</td>
					<td>`</td>
				</tr>
				<tr>
					<td class="separateColor">31</td>
					<td>US</td>
					<td class="separateColor">63</td>
					<td>?</td>
					<td class="separateColor">95</td>
					<td>_</td>
					<td class="separateColor">127</td>
					<td>DEL</td>
				</tr>
			</tbody></table></div><p style=""></p>]]></description><guid>/archives/asciidui-zhao-biao</guid><pubDate>Tue, 16 Jan 2024 02:04:35 GMT</pubDate></item><item><title><![CDATA[scanf遇到空格结束的问题]]></title><link>http://localhost:7090/archives/scanfyu-dao-kong-ge-jie-shu-de-wen-ti</link><description><![CDATA[<h1 style="" id="%E8%A7%A3%E5%86%B3scanf%E8%8E%B7%E5%8F%96%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E6%97%B6%EF%BC%8C%E9%81%87%E5%88%B0%E7%A9%BA%E6%A0%BC%E7%BB%93%E6%9D%9F%E7%9A%84%E9%97%AE%E9%A2%98">解决scanf获取输入数据时，遇到空格结束的问题</h1><p style="">先简单了解一下scanf函数：</p><pre><code class="language-c">函数原型：int scanf(const char *format, ...);
</code></pre><p style="">参数：要注意的是变量前面的取地址符&amp;不要忘记<br>返回值 ：返回的是正确按指定格式输入变量的个数，也就是能正确接收到值的变量个数</p><pre><code class="language-c">#include &lt;stdio.h&gt;

int main(int argc, const char **argv)
{
	int a=0,b=0,i=0;
	
	i = scanf("%d %d",&amp;a,&amp;b);
	printf("i = %d\n",i);
	
	return 0;
}
</code></pre><p style="">以上代码<br>如果输入：4 5，则输出结果为：i = 2<br>如果输入：4 k，则输出结果为：i = 1<br>因为a和b都是整型数据，输入的k为字符，故正确接收到的变量就只有a，所有才输出 i = 1</p><p style="">回归正题，请看以下代码</p><pre><code class="language-c">#include &lt;stdio.h&gt;

int main(int argc, const char **argv)
{
	char buf[20]={0};
	
	printf("输入一串字符:");
	scanf("%s",buf);
	
	printf("buf = %s\n",buf);	
}
</code></pre><p style="">如果输入字符串为：abcd ，返回的结果无疑是：buf = abcd<br>那如果输入字符串：a b c d 呢，返回的结果则为：buf = a</p><p style="">这是因为：<br><strong>scanf的读取原理是匹配字符，当scanf从缓冲区读取数据时遇到空格和回车键则会认为读取完毕</strong></p><p style="">因此有以下几种方式解决<br>（1）使用gets(buf); 替换scanf("%s",buf);即可，但是编译时系统会报警告，说它不安全，因为gets()不能指定获取数据的长度，故可使用fgets()</p><p style="">（2）使用fgets(buf,20,stdin); 替换scanf("%s",buf);即可</p><pre><code class="language-c">函数原型：char *fgets(char *s, int size, FILE *stream);
参数说明：
	char *s	:存储读到的数据的首地址，这里是buf
	int size:存储空间的大小,这里是20
	FILE *stream:读的目标文件的文件流，这里是stdin
返回值：
	成功返回一个指针，指向字符串中第一个字符的地址
	失败/读到末尾，返回NULL
</code></pre><p style="">（3）使用scanf("%[^\n]",buf); 替换scanf("%s",buf);即可<br>这是从一些大牛们的博客找到的方法，一开始并不理解为什么这样就可以，后来找到在这篇博客有说到<a target="_blank" rel="noopener noreferrer nofollow" href="https://blog.csdn.net/qq_30007603/article/details/81164232"><u>https://blog.csdn.net/qq_30007603/article/details/81164232</u></a></p><p style="">总结为：[^\n]的意思是scanf遇到\n才停止读取，需<strong>注意</strong>的是,使用<br>scanf("%[^\n]",buf)后，buf中存放的字符串末尾是没有‘\n’的。</p><p style="">要想知道更多关于scanf的用法和注意事项可以看看：<br><a target="_blank" rel="noopener noreferrer nofollow" href="https://blog.csdn.net/qq_30007603/article/details/81164232"><u>http://c.biancheng.net/view/160.html</u></a></p><p style=""><a target="_blank" rel="noopener noreferrer nofollow" href="https://blog.csdn.net/qq_30007603/article/details/81164232"><u>https://www.cnblogs.com/windpiaoxue/p/9184194.html</u></a></p>]]></description><guid>/archives/scanfyu-dao-kong-ge-jie-shu-de-wen-ti</guid><pubDate>Mon, 15 Jan 2024 03:03:25 GMT</pubDate></item><item><title><![CDATA[CMD空间分配]]></title><link>http://localhost:7090/archives/cmdkong-jian-fen-pei</link><description><![CDATA[<h1 style="" id="dsp%E4%B8%ADcmd%E7%A9%BA%E9%97%B4%E5%88%86%E9%85%8D">DSP中CMD空间分配</h1><p style=""></p><p style="">在DSP的CMD文件中，分配的空间大小计算：如RAMGS2: origin = 0x00E000, length = 0x000E00；他对应的函数意义是，初始地址为0x00E000，大小为0x000E00=14*16*16=3,584，这么大空间。如果长度为0x001000=1*16*16*16=4K。</p><p style=""></p><p style="">此外，对于PAGE 0，和PAGE 1中如果有同样名称的变量，不使用的要注释掉，不然CSS Memory allocation的显示会异常，内存不够用报错了，CSS上显示的是使用空间占比为0%</p><p style=""></p><p style="">在CMD文件中，PAGE0代表程序空间，PAGE1代表数据空间</p><pre><code>PAGE 0 :  /* Program Memory */
          /* Memory (RAM/FLASH) blocks can be moved to PAGE1 for data allocation */
          /* BEGIN is used for the "boot to Flash" bootloader mode   */
    RAMGS2           : origin = 0x00E000, length = 0x000E00           /* reserved for C28 flash to GSRAM*/
    FLASHD           : origin = 0x086000, length = 0x000800	/* on-chip Flash */
PAGE 1 : /* Data Memory */
         /* Memory (RAM/FLASH) blocks can be moved to PAGE0 for program allocation */</code></pre><p style="">在开发DSP时，平时都是在调试程序，是把程序下载到RAM中，而当开发完成后，需要烧写到flash中，但是当程序烧写到flash中后，运行速度要慢，大概降到原来的RAM中的70%~80%。如果对时间敏感的可以复制到RAM中运行，程序如下：</p><pre><code>SECTIONS
{
    ramfuncs          : LOAD = FLASHD,

                        RUN = RAMGS2,
                        LOAD_START(_RamfuncsLoadStart),
                        LOAD_SIZE(_RamfuncsLoadSize),
                        LOAD_END(_RamfuncsLoadEnd),
                        RUN_START(_RamfuncsRunStart),
                        RUN_SIZE(_RamfuncsRunSize),
                        RUN_END(_RamfuncsRunEnd),
                        PAGE = 0, ALIGN(4)
}</code></pre><p style="">在其他C文件中，定义函数时，能够声明该函数运行的位置</p><pre><code class="language-c">#pragma CODE_SECTION(DABCtrlFun_PI, "ramfuncs");
void DABCtrlFun_PI(DAB_PI_CTRL_COEFFS *coeffs,DAB_PI_CTRL_VARS *vars)
{
    vars-&gt;Err = vars-&gt;Ref - vars-&gt;Fdb;
    vars-&gt;Out0 = vars-&gt;Out1 + vars-&gt;Err * coeffs-&gt;Ki * vars-&gt;AntiSat;
    vars-&gt;Out1 = vars-&gt;Out0;
    vars-&gt;Out0 = vars-&gt;Out0 + vars-&gt;Err * coeffs-&gt;Kp;
    if(vars-&gt;Out0 &gt; coeffs-&gt;OutMax)
    {
        vars-&gt;Out0 = coeffs-&gt;OutMax;
        if(vars-&gt;Err &gt; 0)
        {
            vars-&gt;AntiSat = 0;
        }
        else
        {
            vars-&gt;AntiSat = 1;
        }
    }
    else if(vars-&gt;Out0 &lt;= coeffs-&gt;OutMin)  //todo
    {
        vars-&gt;Out0 = coeffs-&gt;OutMin;
        if(vars-&gt;Err &lt; 0)
        {
            vars-&gt;AntiSat = 0;
        }
        else
        {
            vars-&gt;AntiSat = 1;
        }
    }
    else
    {
        vars-&gt;AntiSat = 1;
    }
}</code></pre><p style=""></p>]]></description><guid>/archives/cmdkong-jian-fen-pei</guid><pubDate>Wed, 10 Jan 2024 11:29:08 GMT</pubDate></item><item><title><![CDATA[网站导航]]></title><link>http://localhost:7090/archives/wang-zhan-dao-hang</link><description><![CDATA[<p style=""><iframe src="https://bewildcard.com/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe><iframe src="https://www.logosc.cn/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""><iframe src="https://shields.io/badges" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""><iframe src="https://convertio.co/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe><iframe src="https://icones.js.org/collection/all" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""><iframe src="https://search.censys.io/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe><iframe src="https://cdkm.com/cn/epub-to-pdf" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""><iframe src="https://www.iconfont.cn/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe><iframe src="https://plantuml.com/zh/state-diagram" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""><iframe src="https://imnks.com/8302.html" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe><iframe src="https://tableconvert.com/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""></p><p style=""><iframe src="https://zhile.io/" width="100%" height="300px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p><p style=""></p>]]></description><guid>/archives/wang-zhan-dao-hang</guid><pubDate>Thu, 21 Dec 2023 01:52:00 GMT</pubDate></item><item><title><![CDATA[120秒看世界]]></title><link>http://localhost:7090/archives/120miao-kan-shi-jie</link><description><![CDATA[<p style=""></p><p style=""><iframe src="https://www.dhkk.cn/today/" width="100%" height="2100px" frameborder="0" allowfullscreen="true" framespacing="0" style="display: inline-block"></iframe></p>]]></description><guid>/archives/120miao-kan-shi-jie</guid><pubDate>Wed, 20 Dec 2023 07:04:22 GMT</pubDate></item><item><title><![CDATA[基于PID的Simulink控制系统仿真]]></title><link>http://localhost:7090/archives/ji-yu-pidde-simulinkkong-zhi-xi-tong-fang-zhen</link><description><![CDATA[<h1 id="基于pid的simulink控制系统仿真">基于PID的Simulink控制系统仿真</h1>
<p><em>在工程实际中，应用最为广泛的调节器控制规律为比例、积分、微分控制，简称PID控制，又称PID调节。</em></p>
<h1 id="pid控制原理">PID控制原理</h1>
<p>在模拟控制系统中，控制器最常用的控制规律是PID控制。模拟PID控制系统原理框图如图7-1所示。系统由模拟PID控制器和被控对象组成。</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019174019421.png" alt="image-20231019174019421"></p>
<p>PID控制器是一种线性控制器，它根据给定值<span class="math math-inline">y_d\left(t\right)</span>与实际输出值<span class="math math-inline">y\left(t\right)</span>构成控制偏差：</p>
<div class="math math-display">error(t)=y_d(t)-y(t)</div>
<p>PID的控制规律为：</p>
<div class="math math-display">u\left(t\right)=k_p\left[error\left(t\right)+\frac1{T_1}\int_0^terror\left(t\right)dt+\frac{T_Dderror(t)}{dt}\right]</div>
<p>或可以写成传递函数的形式，</p>
<div class="math math-display">G(s)=\frac{U(s)}{E\left(s\right)}=k_{p}\left(1+\frac1{T_{s}s}+T_{D}s\right)</div>
<p>式中，<span class="math math-inline">k_p</span>为比例系数，<span class="math math-inline">T_1</span>积分时间常数，<span class="math math-inline">T_D</span>为微分时间常数。</p>
<h1 id="基于pid的控制仿真">基于PID的控制仿真</h1>
<h2 id="程序进行仿真">程序进行仿真</h2>
<p>根据PID控制算法，对下列对象进行控制：</p>
<div class="math math-display">G\left(s\right)=\frac{400}{s^2+50s}</div>
<p>PID控制参数为：<span class="math math-inline">k_p = 8, k_i = 0.10, k_d = 10</span></p>
<p>MATLAB程序如下：</p>
<pre><code class="language-matlab">%%
%增量式PID Increment PID Controller
clc% 清屏
clear all;%删除workplace变量
close all;%关掉显示图形窗口

ts=0.001; % 采样时间
sys=tf(400,[1,50,0]); % 传递函数
dsys=c2d(sys,ts,'z');% 连续模型离散化
[num,den]=tfdata(dsys,'v');% 获得分子分母
%PID控制量
u_1=0.0;u_2=0.0;u_3=0.0;
y_1=0;y_2=0;y_3=0;

x=[0,0,0]';
% 误差
error_1=0;
error_2=0;
for k=1:1:1000
    time(k)=k*ts;
    yd(k)=1.0;
    % PID参数
    kp=8; %比例系数
    ki=0.10;%积分系数
    kd=10;%微分系数

    du(k)=kp*x(1)+kd*x(2)+ki*x(3); 
    u(k)=u_1+du(k);

    if u(k)>=10
      u(k)=10;
    end
    if u(k)&#x3C;=-10
      u(k)=-10;
    end   
    y(k)=-den(2)*y_1-den(3)*y_2+num(2)*u_1+num(3)*u_2;

    error=yd(k)-y(k);
    u_3=u_2;u_2=u_1;u_1=u(k);
    y_3=y_2;y_2=y_1;y_1=y(k);
    x(1)=error-error_1;             %Calculating P
    x(2)=error-2*error_1+error_2;   %Calculating D
    x(3)=error;                     %Calculating I

    error_2=error_1;
    error_1=error;
end
figure(1);
plot(time,yd,'r',time,y,'b','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
grid on
title('增量式PID跟踪响应曲线')
legend('Ideal position signal','Position tracking');
figure(2);
plot(time,yd-y,'r','linewidth',2);
xlabel('time(s)');ylabel('error');
grid on
title('增量式PID跟踪误差');
</code></pre>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019175606806.png" alt="image-20231019175606806"></p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019175633296.png" alt="image-20231019175633296"></p>
<h2 id="使用simulink进行仿真">使用Simulink进行仿真</h2>
<p>采用MATLAB/Simulink中PID控制器进行模型控制，搭建相应的PID控制仿真文件如图7-4所示:</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019180158337.png" alt="image-20231019180158337"></p>
<p>PID控制器参数设置如图7-5所示:<br>
<img src="http://picgo.genson.fun/img/uploads/2023/10/image-20231019180233177.png" alt="image-20231019180233177"></p>
<p>PID控制参数为：<span class="math math-inline">k_p = 8, k_i = 0.10, k_d = 10</span>,对其进行仿真输出图形如图所示:</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019180421707.png" alt="image-20231019180421707"></p>
<h2 id="自己搭建pid控制器进行仿真">自己搭建PID控制器进行仿真</h2>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019180651710.png" alt="image-20231019180651710"></p>
<p>对应的控制输出如图所示：</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019180822768.png" alt="image-20231019180822768"></p>
<h1 id="基于s函数的pid控制系统仿真">基于S函数的PID控制系统仿真</h1>
<h2 id="考虑一电动机被控对象传递函数">考虑一电动机被控对象传递函数：</h2>
<div class="math math-display">G\left(s\right)=\frac1{0.0067s^2+0.1s}</div>
<p>采用MATLAB脚本文件，利用ode45的方法求解该连续对象方程，输入指令方程为一正弦函数：</p>
<div class="math math-display">y_d(k)=0.5\sin(2\pi t)</div>
<p>采用PID控制方法设计控制器，其中采用PID参数为：<span class="math math-inline">k_p = 20, k_d = 0.5</span></p>
<p>编写MATLAB PID控制程序如下：</p>
<pre><code class="language-matlab">clear all;
close all;
 
ts=0.001;  %Sampling time
xk=zeros(2,1);
e_1=0;
u_1=0;
 
for k=1:1:2000
time(k) = k*ts;
 
yd(k)=0.50*sin(1*2*pi*k*ts);
  
para=u_1;
tSpan=[0 ts];
[tt,xx]=ode45('ysw13_3plant',tSpan,xk,[],para);
xk = xx(length(xx),:);
y(k)=xk(1); 
e(k)=yd(k)-y(k);
de(k)=(e(k)-e_1)/ts; 
 
u(k)=20.0*e(k)+0.50*de(k);
%Control limit
if u(k)>10.0
   u(k)=10.0;
end
if u(k)&#x3C;-10.0
   u(k)=-10.0;
end
 
u_1=u(k);
e_1=e(k);
end
figure(1);
plot(time,yd,'r',time,y,'k:','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
legend('实际信号','仿真结果'); 
figure(2);
plot(time,yd-y,'r','linewidth',2);
xlabel('time(s)'),ylabel('误差');
title('误差')


</code></pre>
<pre><code class="language-matlab">function dy = PlantModel(t,y,flag,para)
u=para;
J=0.0067;B=0.1;
 
dy=zeros(2,1);
dy(1) = y(2);
dy(2) = -(B/J)*y(2) + (1/J)*u;
end
</code></pre>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019181817063.png" alt="image-20231019181817063"></p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019181828917.png" alt="image-20231019181828917"></p>
<h2 id="考虑被控对象为三阶传递函数">考虑被控对象为三阶传递函数</h2>
<div class="math math-display">G(\mathrm{s})=\frac{523.5}{s^3+87.35s^2+10.47s}</div>
<h3 id="采用simulink模块与interpreted-matlab-fcn函数相结合的形式利用ode45的方法求解">采用Simulink模块与Interpreted MATLAB Fcn函数相结合的形式，利用ode45的方法求解。</h3>
<p>输入指令方程为一正弦函数</p>
<div class="math math-display">y_d\left(k\right)=0.05\sin(2\pi t)</div>
<p>采用PID控制方法设计控制器，其中采用PID参数为:<span class="math math-inline">k_p = 2.5, k_i = 0.02, k_d = 0.5</span>,搭建PID控制仿真模型，如图所示：</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019192133372.png" alt="image-20231019192133372"></p>
<img src="http://picgo.genson.fun/img/uploads/2023/10/image-20231019192351325.png" alt="image-20231019192351325">
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019192406123.png" alt="image-20231019192406123"></p>
<p>其中控制器程序如下：</p>
<pre><code class="language-matlab">function [u]=pidsimf(u1,u2)
persistent pidmat errori error_1
t=u1;
if t==0
   errori=0;
   error_1=0;
end   
 
kp=2.5;
ki=0.020;
kd=0.50;
 
error=u2;
errord=error-error_1;
errori=errori+error;
 
u=kp*error+kd*errord+ki*errori;
error_1=error;
end
</code></pre>
<p>​	运行仿真程序，仿真数据自动保存到工作区中，采用如下画图程序进行数据显示。</p>
<pre><code class="language-matlab">close all;
figure(1);
plot(t,y(:,1),'r',t,y(:,2),'k:','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
legend('实际信号','仿真结果');
figure(2);
plot(t,y(:,1)-y(:,2),'r','linewidth',2);
xlabel('time(s)'),ylabel('误差');
title('误差')
</code></pre>
<p>​	运行画图程序输出图形如图所示。</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019192609778.png" alt="image-20231019192609778"></p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019193030018.png" alt="image-20231019193030018"></p>
<h3 id="采用simulink模块与s函数的方法进行对象建模求解">采用Simulink模块与S函数的方法进行对象建模求解</h3>
<p>输入指令方程为一正弦函数</p>
<div class="math math-display">y_d\left(k\right)=0.05\sin(2\pi t)</div>
<p>采用PID控制方法设计控制器，其中采用PID参数为:<span class="math math-inline">k_p = 1.5, k_i = 2.0, k_d = 0.05</span>,搭建PID控制仿真模型，如图所示：</p>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019193841026.png" alt="image-20231019193841026"></p>
<pre><code class="language-matlab">function [sys,x0,str,ts]=exp_pidf(t,x,u,flag)
switch flag,
case 0           % initializations
    [sys,x0,str,ts] = mdlInitializeSizes;
case 2           % discrete states updates
    sys = mdlUpdates(x,u);
case 3           % computation of control signal
%    sys = mdlOutputs(t,x,u,kp,ki,kd,MTab);
    sys=mdlOutputs(t,x,u);
case {1, 4, 9}   % unused flag values
    sys = [];
otherwise        % error handling
    error(['Unhandled flag = ',num2str(flag)]);
end;

%==============================================================
% when flag=0, perform system initialization
%==============================================================
function [sys,x0,str,ts] = mdlInitializeSizes
sizes = simsizes;        % read default control variables
sizes.NumContStates = 0; % no continuous states
sizes.NumDiscStates = 3; % 3 states and assume they are the P/I/D components
sizes.NumOutputs = 1;    % 2 output variables: control u(t) and state x(3)
sizes.NumInputs = 2;     % 4 input signals
sizes.DirFeedthrough = 1;% input reflected directly in output
sizes.NumSampleTimes = 1;% single sampling period
sys = simsizes(sizes);   % 
x0 = [0; 0; 0];          % zero initial states
str = []; 
ts = [-1 0];             % sampling period
%==============================================================
% when flag=2, updates the discrete states
%==============================================================
function sys = mdlUpdates(x,u)
T=0.001;
sys=[ u(1); 
      x(2)+u(1)*T;
      (u(1)-u(2))/T];

%==============================================================
% when flag=3, computates the output signals
%==============================================================
function sys = mdlOutputs(t,x,u,kp,ki,kd,MTab)

kp=1.5;
ki=2.0;
kd=0.05;

%sys=[kp,ki,kd]*x;
sys=kp*x(1)+ki*x(2)+kd*x(3);
</code></pre>
<p>运行仿真程序，仿真数据自动保存到工作区中，采用如下画图程序进行数据显示。</p>
<pre><code class="language-matlab">close all;
figure(1);
plot(t,y(:,1),'r',t,y(:,2),'k:','linewidth',2);
xlabel('time(s)');ylabel('yd,y');
legend('实际信号','仿真结果');
figure(2);
plot(t,y(:,1)-y(:,2),'r','linewidth',2);
xlabel('time(s)'),ylabel('误差');
title('误差')
</code></pre>
<p><img src="https://lsky.genson.fun/picgo/2024/04/09/image-20231019193958369.png" alt="image-20231019193958369"></p>
<h1 id="基于pid的倒立摆小车控制仿真">基于PID的倒立摆小车控制仿真</h1>
<p>暂时省略，参考意义不大：</p>
<p><em>直线式倒立摆中，小车只有水平方向的直线运动，模型的非线性因素比较少，有利于倒立摆的控制；而在直线式倒立摆中，旋臂处在绕轴转动的状态，同时具有水平和垂直两个方向的运动，模型中非线性因素较多，对倒立摆的控制算法较高。</em></p>]]></description><guid>/archives/ji-yu-pidde-simulinkkong-zhi-xi-tong-fang-zhen</guid><pubDate>Fri, 20 Oct 2023 00:54:23 GMT</pubDate></item></channel></rss>