PID parameter synchronous switching method, device, equipment and medium
By pre-storing multiple parameter sets in the motor controller and automatically selecting the target parameter set that matches the current speed feedback source in each control cycle, the problem of parameter mismatch after the speed feedback source is switched is solved, thus achieving smooth transition and high-precision control of the system.
Patent Information
- Application Number
- CN202611410937.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-11
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, after the speed feedback source is switched, the PID parameters of the motor controller cannot automatically match the hysteresis characteristics of the current speed feedback source, resulting in system oscillation or insufficient control stiffness.
By pre-storing multiple sets of control parameters in the motor controller and automatically selecting the target parameter set that matches the current speed feedback source in each control cycle, the speed loop control gain is updated to ensure that the parameters accurately correspond to the hysteresis characteristics of the feedback source, thus avoiding self-excited oscillation and stiffness decay.
It achieves smooth transition and high-precision control of the system during the switching of speed feedback sources, avoids self-excited oscillation under high-delay sources and stiffness decay under low-delay sources, and ensures that the control gain corresponds precisely to the hysteresis characteristics of the feedback source.
Smart Images

Figure CN123113295A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of motor control technology, and in particular to a method, apparatus, device, and medium for synchronous switching of PID parameters. Background Technology
[0002] In motion control scenarios such as gimbals, stabilization platforms, and servo drives, motor controllers typically employ a dual-loop control structure with a cascaded position loop and a speed loop. The position loop generates speed commands based on angular deviations, while the speed loop generates voltage or torque commands based on speed deviations, thereby driving the motor. The closed-loop performance of the speed loop is highly dependent on the quality of the angular velocity feedback signal, where signal lag in the feedback channel, i.e., group delay, is a key factor affecting closed-loop stability.
[0003] In practical engineering, there are typically two methods for obtaining angular velocity feedback in the velocity loop. The first method involves differentially analyzing the angle sequence output from the joint angle sensor and applying a low-pass filter to calculate the angular velocity from the angle data. This method does not require an additional angular velocity sensor and is suitable for the initial power-on stage before an angle reference is established; however, the differential and filtering stages introduce a signal group delay on the order of milliseconds. The second method directly reads the angular velocity signal from a sensor capable of outputting an angular velocity signal. This method does not include a differential stage, and the group delay is typically in the sub-millisecond range. The same device may need to switch between these two angular velocity sources at different operational stages; for example, the first source might be used during power-on calibration, and then switched to the second source after calibration is complete.
[0004] However, the group delays from the two sources of angular velocity mentioned above often differ by about an order of magnitude. From a control theory perspective, the group delay of the velocity feedback channel does not change the amplitude characteristics of the loop, but it introduces an additional phase lag proportional to the frequency at the amplitude crossover frequency, thus directly reducing the phase margin of the closed-loop system. For a velocity loop using proportional-integral control, increasing the integral gain raises the amplitude crossover frequency of the loop, thereby amplifying the phase lag caused by the group delay. Therefore, given the group delay, there exists a critical integral gain: when the actual integral gain exceeds this critical value, the phase margin drops to zero or even negative, and the closed-loop system changes from a convergent response to continuous oscillation. Since the critical integral gain is approximately inversely proportional to the group delay, when the group delays from the two sources of angular velocity differ by an order of magnitude, the allowable integral gains for them also differ by about an order of magnitude.
[0005] Existing technologies typically address the above problems in two ways. The first approach is to globally retain only one set of control parameters, using the same proportional gain, integral gain, and derivative gain for the velocity loop regardless of the current angular velocity source. The second approach is to expose the control parameters to a debugging interface, allowing operators to manually modify the parameters before and after switching feedback sources.
[0006] The first approach described above has an inherent contradiction: if a high integral gain is tuned to obtain sufficient static stiffness and disturbance rejection capability based on a low group delay source, then when the feedback source is switched to a high group delay source, the integral gain will far exceed the critical value, the phase margin will be exhausted, and the motor will generate continuous self-excited oscillations. Conversely, if a low integral gain is tuned to ensure stability based on a high group delay source, then when the feedback source is switched to a low group delay source, the low-frequency loop gain will be insufficient, the static stiffness and disturbance rejection capability of the system will decrease significantly, and the stability augmentation residual and following error will increase. A single set of fixed parameters cannot simultaneously adapt to two feedback channels with drastically different group delay characteristics.
[0007] The second approach faces a fundamental timing challenge: the switching of feedback sources usually occurs within the system power-on calibration process, and the switching time is determined by the calibration completion status, which operators cannot accurately predict; manual parameter modification relies on the debugging interface, with an operation rhythm on the order of seconds, while the switching of feedback sources needs to be completed within the control cycle. The time scales of the two differ by more than three orders of magnitude, making it impossible for manual modification to be synchronized with the switching of feedback sources.
[0008] In summary, in the prior art, after the speed feedback source is switched, the PID control parameters of the speed loop of the motor controller cannot automatically match the group delay characteristics of the currently effective speed feedback source, resulting in continuous oscillation of the system under high group delay sources or insufficient control stiffness under low group delay sources. Summary of the Invention
[0009] The embodiments of the present invention provide a method, apparatus, device and medium for synchronous switching of PID parameters, which aims to solve the problem in the prior art that the PID parameters of the motor controller cannot automatically match the hysteresis characteristics of the current speed feedback source after the speed feedback source is switched, thereby causing system oscillation or insufficient control stiffness.
[0010] In a first aspect, embodiments of the present invention provide a PID parameter synchronous switching method applied to a motor controller. The motor controller is used to control at least one control axis. The motor controller has a dual-loop control structure with a position loop and a speed loop cascaded. The feedback quantity of the speed loop is configured to be selectable between a first speed feedback source and a second speed feedback source. The first speed feedback source has a first group delay, and the second speed feedback source has a second group delay. The first group delay is greater than the second group delay. The method is executed for each control axis and performs the following steps in each control cycle: Obtain the currently active speed feedback source, wherein the currently active speed feedback source is the first speed feedback source or the second speed feedback source; Based on the currently active speed feedback source, a target control parameter set is selected from multiple sets of control parameters pre-stored in the parameter storage area for the control axis. The multiple sets of control parameter sets include at least a first control parameter set corresponding to the first speed feedback source and a second control parameter set corresponding to the second speed feedback source. The integral gain of the second control parameter set is greater than the integral gain of the first control parameter set. Write the speed loop control gain of the target control parameter set into the speed loop controller instance corresponding to the control axis, and update the currently effective control parameters of the speed loop. The speed loop control gain includes speed loop proportional gain, speed loop integral gain and speed loop derivative gain. Based on the updated control parameters currently in effect for the velocity loop, control calculations are performed for the position loop and the velocity loop, and control commands are output.
[0011] Secondly, embodiments of the present invention also provide a PID parameter synchronization switching device for executing the PID parameter synchronization switching method described above.
[0012] Thirdly, embodiments of the present invention also provide a computer device, the computer device including a memory and a processor connected to the memory; the memory is used to store a computer program; the processor is used to run the computer program stored in the memory to perform the steps of the above-described PID parameter synchronization switching method.
[0013] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a processor, can implement the steps of the above-described PID parameter synchronous switching method.
[0014] Compared with the prior art, the beneficial effects of the present invention are: In the technical solution of this invention, the PID parameter synchronous switching method automatically acquires the currently effective speed feedback source in each control cycle of the motor controller and selects a matching target parameter set from the pre-stored parameter set based on its group delay characteristics. Subsequently, the speed loop control gain of the target parameter set is written to the controller instance to update the effective parameters. During the writing process, the original values in the parameter storage area remain unchanged, and the integral accumulation is not reset. Finally, dual-loop control calculations are performed based on the updated parameters, and commands are output. This solution, through a periodically driven automatic parameter matching and integral continuity mechanism, ensures that the control gain always precisely corresponds to the lag characteristics of the feedback source, effectively avoiding self-excited oscillations under high-delay sources and stiffness decay under low-delay sources, while eliminating torque steps during gear shifts, achieving smooth system transition and high-precision control. Attached Figure Description
[0015] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 A flowchart of the PID parameter synchronization switching method provided by the present invention; Figure 2 This is a first sub-flowchart of the PID parameter synchronous switching method provided by the present invention. Figure 3 This is the second sub-flowchart of the PID parameter synchronization switching method provided by the present invention; Figure 4 The third sub-flowchart of the PID parameter synchronization switching method provided by the present invention; Figure 5 This is the fourth sub-flowchart of the PID parameter synchronization switching method provided by the present invention; Figure 6 This is the fifth sub-flowchart of the PID parameter synchronization switching method provided by the present invention; Figure 7 The sixth sub-flowchart of the PID parameter synchronization switching method provided by the present invention; Figure 8 A schematic block diagram of a unit of the PID parameter synchronous switching device provided by the present invention; Figure 9 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0019] It should also be understood that the terminology used in this specification is for the purpose of describing embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0020] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0021] In order to solve the problem in the prior art that the PID parameters of the motor controller cannot automatically match the hysteresis characteristics of the current speed feedback source after the speed feedback source is switched, resulting in system oscillation or insufficient control stiffness, the present invention discloses a method for synchronous switching of PID parameters.
[0022] Reference Figures 1 to 7 The PID parameter synchronization switching method includes the following steps: S110. Obtain the currently effective speed feedback source, wherein the currently effective speed feedback source is the first speed feedback source or the second speed feedback source; S120. Based on the currently active speed feedback source, select a target control parameter set from multiple sets of control parameters pre-stored in the parameter storage area for the control axis, wherein the multiple sets of control parameter sets include at least a first control parameter set corresponding to the first speed feedback source and a second control parameter set corresponding to the second speed feedback source, and the integral gain of the second control parameter set is greater than the integral gain of the first control parameter set. S130. Write the speed loop control gain of the target control parameter set into the speed loop controller instance corresponding to the control axis, and update the currently effective control parameters of the speed loop. The speed loop control gain includes speed loop proportional gain, speed loop integral gain and speed loop differential gain. S140. Based on the updated control parameters currently in effect for the speed loop, perform control calculations for the position loop and the speed loop, and output control commands.
[0023] To facilitate understanding, we will use the motor controller of a three-axis gimbal as an application scenario to illustrate the solution of this method. The three-axis gimbal includes a pitch motor, a roll motor, and a yaw motor. All three motors are brushless DC motors, driven by the motor controller in a field-oriented manner. The motor controller internally employs a dual-loop control structure with a cascaded position loop and a speed loop. The position loop generates a speed command based on the angular deviation, and the speed loop generates a voltage command based on the speed deviation. The voltage command is applied to the motor windings via a power drive circuit, thereby driving the motor to rotate. Specifically, the motor controller is implemented by a microcontroller. The microcontroller performs control calculations at a fixed cycle, with a control frequency of 3kHz, meaning each control cycle lasts approximately 0.33ms. Each of the three control axes independently executes the method described in this embodiment. The following explanation uses one control axis as an example; the execution method for the other control axes is the same.
[0024] The feedback quantity of the speed loop is the angular velocity signal. Specifically, the motor controller is configured with two angular velocity sources, defined as the first speed feedback source and the second speed feedback source. The first speed feedback source is obtained by differentially analyzing the angle sequence output by the joint angle sensor through a sliding window and then passing it through a first-order low-pass filter. Specifically, the joint angle sensor outputs angle data at a sampling frequency of 1kHz. The angle data is sequentially written into a sliding window of length 8 points. The angle difference between the two ends of the window is divided by the time difference between the two ends to obtain the differential angular velocity. The differential angular velocity is then output after passing through a first-order low-pass filter with a time constant of 3 radians. The group delay introduced by the sliding window differential is half the window length, i.e., 3.5ms; the group delay introduced by the first-order low-pass filter is equal to its time constant, i.e., 3 radians. Adding the two together, the group delay of the first speed feedback source is approximately 7 radians. The second speed feedback source is provided by a sensor that directly outputs angular velocity. It does not go through differential calculation and low-pass filtering. The group delay is determined by the sensor's own sampling period and internal anti-aliasing filtering. Specifically, the sampling frequency of the angular velocity sensor is 2kHz, the sensor output rate is 4kHz, and the group delay of the second velocity feedback source is approximately 0.3ms. The group delay of the first velocity feedback source differs from that of the second velocity feedback source by approximately 20 times, or about one order of magnitude.
[0025] The same equipment uses different speed feedback sources at different operating stages. During the power-on calibration phase, the angle reference of the joint angle sensor has not yet been established, and the motor controller can only use the first speed feedback source. After calibration, the motor controller switches to the second speed feedback source. The switching of the speed feedback source is determined by the upper-level operating environment based on the calibration readiness status. In each control cycle, the motor controller reads the currently effective speed feedback source identifier and determines whether the currently effective speed feedback source is the first or the second speed feedback source based on the identifier.
[0026] The motor controller internally allocates two independent storage areas for each control axis. The first area is the parameter storage area, used to store multiple sets of control parameters pre-tuned for the control axis. The second area is the speed loop controller instance, used to store the actual effective gain value and the integral accumulation of the speed loop in the current control cycle. The separate storage of the parameter storage area and the speed loop controller instance forms the structural basis for subsequent idempotent reset. Specifically, the parameter storage area stores at least two sets of control parameters: a first set corresponding to the first speed feedback source, and a second set corresponding to the second speed feedback source. Both sets of control parameters contain three components: speed loop proportional gain, speed loop integral gain, and speed loop derivative gain.
[0027] The main difference between the two sets of control parameters lies in the speed loop integral gain. Since the group delay of the first speed feedback source is approximately 7ms, much larger than the group delay of the second speed feedback source (approximately 0.3ms), if the high integral gain tuned for the second speed feedback source is used for the first speed feedback source, the integral gain will far exceed the critical value, the closed-loop phase margin will be exhausted, and the motor will produce continuous self-excited oscillations. Conversely, if the low integral gain tuned for the first speed feedback source is used for the second speed feedback source, the low-frequency loop gain will be insufficient, and the system's static stiffness and disturbance rejection capability will significantly decrease. Therefore, the integral gain of the second control parameter set must be greater than that of the first control parameter set, and their ratio must match the ratio of the group delay. Furthermore, the speed loop differential gain of the first control parameter set is zero because the first speed feedback source itself already contains a differential element. If a differential action is applied to the speed loop again, the quantization noise will be amplified a second time, generating high-frequency howling.
[0028] The position loop specifically adopts a pure proportional structure. The proportional gain of the position loop maintains the same value across all control parameter sets, the integral gain of the position loop is zero, and the derivative gain of the position loop is zero. Since the pure proportional element does not introduce additional phase lag, the control parameters of the position loop do not need to change with the switching of the speed feedback source. All five parameter sets share the same proportional gain of the position loop, thus avoiding the doubling of the number of parameters with each mode.
[0029] Within each control cycle, the motor controller executes the following steps sequentially for each control axis.
[0030] The first step is for the motor controller to read the identifier of the currently active speed feedback source and determine whether the currently active speed feedback source is the first speed feedback source or the second speed feedback source.
[0031] The second step involves the motor controller selecting the target control parameter set corresponding to the currently active speed feedback source from the parameter storage area. If the currently active speed feedback source is the first speed feedback source, the first control parameter set is selected as the target control parameter set; if the currently active speed feedback source is the second speed feedback source, the second control parameter set is selected as the target control parameter set.
[0032] The third step involves the motor controller reading the speed loop proportional gain, speed loop integral gain, and speed loop derivative gain from the target control parameter set. It then writes these three gain values to the corresponding currently active gain storage location in the speed loop controller instance, thereby updating the currently active control parameters of the speed loop. This write operation only modifies the active gain value in the speed loop controller instance; it does not modify the stored values of multiple control parameter sets in the parameter storage area, nor does it reset the integral accumulation of the speed loop. The integral accumulation remains continuous before and after gain switching, ensuring that the output torque does not jump at the switching moment. Since the write operation does not change the parameter storage area, and the target value written is uniquely determined by the currently active speed feedback source, when the same set of parameters is repeatedly written in multiple consecutive control cycles, the writing result is the same as if it were written only once, without any cumulative side effects. Therefore, the motor controller unconditionally performs the write operation in each control cycle without needing to determine whether the currently active gain is correct. If the gain in the speed loop controller instance is modified by other write processes, the write operation in the next control cycle will correct the gain back to the target value matching the currently active speed feedback source, with a correction delay of no more than one control cycle, approximately 0.33 milliseconds.
[0033] Fourth, the motor controller executes control calculations for the position and speed loops based on the updated speed loop's currently effective control parameters. The position loop reads the angle values output by the joint angle sensor, calculates the angle deviation, and multiplies the angle deviation by the position loop's proportional gain to obtain the speed command. The speed loop reads the angular velocity values provided by the currently effective speed feedback source, calculates the speed deviation between the speed command and the angular velocity feedback, and calculates the voltage command according to the speed loop's proportional gain, integral gain, and derivative gain. The voltage command is applied to the motor windings via the power drive circuit, driving the motor to rotate. After the control calculations are completed, the motor controller enters the next control cycle and re-executes steps one through four.
[0034] The PID parameter synchronous switching method of this invention achieves continuous automatic matching between control parameters and the group delay characteristics of the speed feedback source by pre-storing at least two sets of control parameters corresponding to different speed feedback sources in the parameter storage area for each control axis, and automatically selecting the target control parameter set according to the currently effective speed feedback source in each control cycle. The speed loop control gain of the target control parameter set is then written into the speed loop controller instance, thus achieving continuous automatic matching between the control parameters and the group delay characteristics of the speed feedback source. The write operation only modifies the effective gain in the speed loop controller instance, without modifying the stored value in the parameter storage area or resetting the integral accumulation of the speed loop. Furthermore, it is unconditionally repeated driven by the control cycle, ensuring that any parameter mismatch caused by bypass writing is corrected in the next control cycle, with a correction delay not exceeding one control cycle. Therefore, the motor controller does not experience self-oscillation due to excessively high integral gain under high group delay speed feedback sources, and does not lose static stiffness and disturbance rejection capability due to excessively low integral gain under low group delay speed feedback sources. Simultaneously, the output torque remains continuous during gain switching without any step changes.
[0035] In one embodiment, step S110 includes: S111. Read the calibration ready status of each control axis. The calibration ready status is used to characterize whether the joint angle sensor of the corresponding control axis has completed the reference calibration. S112. If all the control axes are in the calibration ready state, then the second speed feedback source is determined as the currently effective speed feedback source. S113. If any of the control axes is not in the calibration ready state, then the first speed feedback source is determined as the currently effective speed feedback source.
[0036] The motor controller controls three control axes: pitch, roll, and yaw. Each control axis has a joint angle sensor at its rotation point, which outputs the rotation angle of the corresponding control axis relative to the previous support. Before participating in closed-loop control, the joint angle sensors need to undergo reference calibration, i.e., determining the correspondence between the sensor's zero position and the mechanical zero position. Before reference calibration is completed, the angle values output by the joint angle sensors do not contain valid absolute position information, and the motor controller cannot establish a reliable position closed loop based on these angle values.
[0037] The motor controller maintains a calibration ready state for each control axis. The calibration ready state is a Boolean value, which can be either ready or not ready. When the joint angle sensor of the corresponding control axis completes its reference calibration, the motor controller sets the calibration ready state of that control axis to ready; when the joint angle sensor of the corresponding control axis has not yet completed its reference calibration, the motor controller sets the calibration ready state of that control axis to not ready. The calibration ready state is written by the calibration process in the host operating environment; the motor controller itself does not perform calibration calculations, but only reads the calibration results.
[0038] Within each control cycle, the motor controller reads the calibration readiness status of all control axes. After reading, the motor controller performs a joint judgment on the calibration readiness status of all control axes. The joint judgment rules are as follows: if all three control axes—pitch, roll, and yaw—are in the calibration readiness status, the motor controller determines the second speed feedback source as the currently effective speed feedback source; if any one of the three control axes—pitch, roll, and yaw—is not in the calibration readiness status, the motor controller determines the first speed feedback source as the currently effective speed feedback source.
[0039] The aforementioned joint judgment rule requires all control axes to simultaneously meet the readiness condition, rather than only requiring the current control axis itself to be ready. The reason for using joint judgment for all control axes is that the second velocity feedback source in this embodiment is obtained through multi-axis projection, and the projected amount includes cross-axis coupling components. If only some control axes are calibrated while others are not, the coupling components of the uncalibrated axes in the projected amount will introduce incorrect angular velocity information, causing the velocity feedback of the calibrated axes to also be distorted. Therefore, the source identifiers of the three axes are given by the same readiness condition, and the three axes switch velocity feedback sources simultaneously, disallowing independent switching of a single axis.
[0040] The execution process of this step is illustrated using a typical process after the system is powered on. Initially, the joint angle sensors of all three control axes have not completed reference calibration, and the calibration readiness status of all three control axes is not ready. After reading the calibration readiness status in each control cycle, the motor controller determines that a control axis is not in the calibration readiness state and identifies the first speed feedback source as the currently effective speed feedback source. At this time, the motor controller uses the angular velocity obtained by differential analysis and low-pass filtering of the joint angle sensor angle sequence through a sliding window as the speed loop feedback quantity, and the speed loop selects the first control parameter set corresponding to the first speed feedback source.
[0041] As the power-on calibration process progresses, the calibration module sequentially performs reference calibration on each control axis. Assuming the pitch and roll axes are calibrated sequentially, but the yaw axis is not yet calibrated, the motor controller, after reading the calibration readiness status, determines that there are still control axes not in the calibration readiness state and continues to designate the first velocity feedback source as the currently effective velocity feedback source. Once the yaw axis is also calibrated, the calibration readiness status of all three control axes is ready, and the motor controller designates the second velocity feedback source as the currently effective velocity feedback source in the next control cycle. Subsequently, the motor controller uses the angular velocity directly output from the angular velocity sensor as the velocity loop feedback quantity, and the velocity loop selects the second control parameter set corresponding to the second velocity feedback source in the next control cycle.
[0042] This embodiment reads the calibration readiness status of each control axis and uses the condition that all control axes are in the calibration readiness state as the condition for switching to the second speed feedback source, ensuring strict synchronization between the speed feedback source switching and the calibration progress of the joint angle sensor. During the calibration incomplete phase, the motor controller always uses the first speed feedback source and its matching first control parameter set to avoid speed feedback distortion due to missing angle references. After all control axes are calibrated, the motor controller automatically switches to the second speed feedback source and its matching second control parameter set, achieving lower group delay and higher control stiffness. The rule of joint judgment for all control axes avoids local switching errors caused by cross-axis coupling, ensuring that the three axes synchronously complete the speed feedback source switching within the same control cycle, thus coordinating with the aforementioned mechanism of reselecting the target control parameter set in each control cycle.
[0043] In one embodiment, step S120 includes: S121. Determine whether the currently effective speed feedback source is the first speed feedback source; S122. If the currently effective speed feedback source is the first speed feedback source, then the first control parameter set is selected as the target control parameter set. S123. If the currently effective speed feedback source is the second speed feedback source, then the second control parameter set is selected as the target control parameter set. S124. Based on the target control parameter set, the motor controller responds to the speed-only closed-loop motion mode.
[0044] After acquiring the currently active speed feedback source in each control cycle, the motor controller enters the target control parameter set selection phase. The core logic of the selection phase is to perform a binary judgment on the currently active speed feedback source and select the corresponding control parameter set from the parameter storage area as the target control parameter set based on the judgment result.
[0045] Specifically, the motor controller first determines whether the currently active speed feedback source is the first speed feedback source. If the determination result is yes, meaning the currently active speed feedback source is the first speed feedback source, the motor controller reads the first control parameter set from the parameter storage area and selects the first control parameter set as the target control parameter set. If the determination result is no, meaning the currently active speed feedback source is the second speed feedback source, the motor controller reads the second control parameter set from the parameter storage area and selects the second control parameter set as the target control parameter set. The above binary determination is performed once in each control cycle. The determination process is a pure algebraic comparison operation, without iteration or looping, and the time consumption per cycle is fixed and extremely short.
[0046] In this embodiment, the parameter storage area stores each set of control parameters in the form of compile-time constants. Taking the yaw axis as an example, the first control parameter set stores a speed loop proportional gain of 0.8, a speed loop integral gain of 1.25, and a speed loop differential gain of 0; the second control parameter set stores a speed loop proportional gain of 0.8, a speed loop integral gain of 100, and a speed loop differential gain of 0. Taking the pitch axis as an example, the first control parameter set stores a speed loop proportional gain of 0.2, a speed loop integral gain of 2.5, and a speed loop differential gain of 0; the second control parameter set stores a speed loop proportional gain of 0.3, a speed loop integral gain of 50, and a speed loop differential gain of 0. Taking the roll axis as an example, the first control parameter set stores a speed loop proportional gain of 0.3, a speed loop integral gain of 10, and a speed loop differential gain of 0; the second control parameter set stores a speed loop proportional gain of 1, a speed loop integral gain of 300, and a speed loop differential gain of 0. Because the three axes have different mechanical inertia, their corresponding parameter set values are different, and the parameter sets are stored separately for each axis and are not shared.
[0047] The speed loop differential gain of the first control parameter set is set to zero. The reason for this zero setting is that the first speed feedback source is obtained by differentially analyzing the angle sequence from the joint angle sensor via a sliding window. The differential operation of the angle sequence itself is already a differential operation. If the speed loop controller applies a differential action, it is equivalent to performing two differential operations on the angle signal, and the quantization noise of the joint angle sensor will be amplified twice, manifesting as a high-frequency whine in the motor output. Therefore, the first control parameter set paired with the first speed feedback source does not enable differential control, and the speed loop differential gain is fixed at zero. In this embodiment, the speed loop differential gain of the second control parameter set is also set to zero to simplify parameter tuning and maintain consistency.
[0048] In addition to the binary selection logic based on the speed feedback source described above, this embodiment also provides an independent trigger condition: when the motor controller enters the speed-only closed-loop motion mode, regardless of the current effective speed feedback source, the motor controller selects the first control parameter set as the target control parameter set. The speed-only closed-loop motion mode occurs during the system calibration and homing phase. During this phase, the position loop is not yet closed; the motor controller only closes the speed loop, driving the motor to operate at a given speed to complete the reference calibration of the joint angle sensor or the mechanical homing action. Since the angle reference of the joint angle sensor has not yet been established or is in the process of being established during the calibration and homing phase, the feedback quantity of the speed loop can only come from the first speed feedback source, i.e., the angular velocity obtained by the angle sequence difference. Therefore, when entering the speed-only closed-loop motion mode, the motor controller writes the first control parameter set into the speed loop controller instance, causing the speed loop to operate with a low integral gain, suppressing oscillations that may occur during this phase due to the large delay of the feedback channel group.
[0049] The effect of the above triggering conditions is illustrated using the execution of the pitch axis during the calibration and homing phases as an example. The pitch axis only supports the camera mount, and its mechanical inertia is the smallest among the four control axes. The same gain corresponds to a higher amplitude crossover frequency on the pitch axis; therefore, the pitch axis is most sensitive to the group delay of the feedback channel. When entering the speed-only closed-loop motion mode, the motor controller selects the first set of control parameters as the target set. The speed loop uses a proportional gain of 0.2, an integral gain of 2.5, and a differential gain of 0. At this time, the corner frequency is 2.5 divided by 0.2, which equals 12.5 rad / s. Multiplying this by the approximately 7 ms group delay of the first speed feedback source yields 0.088 rad, equivalent to 5.0°. The phase margin loss is within an acceptable range, and the speed loop converges stably. If the second set of control parameters is used incorrectly in this stage, the speed loop integral gain of 50 corresponds to a cutoff frequency of approximately 166.7 rad / s when 50 is divided by 0.3. Multiplying this by 7 ms yields 1.17 rad, equivalent to 66.8°, which far exceeds the conventionally tuned phase margin of approximately 45°. This results in a negative closed-loop phase margin, leading to severe oscillations on the pitch axis. These oscillations are independent of individual motor variations, as the sign of the phase margin depends solely on the product of the group delay and the crossover frequency.
[0050] After homing is completed and the speed-only closed-loop motion mode is exited, the motor controller resumes binary judgment based on the currently effective speed feedback source in the next control cycle. If all three-axis calibrations have been completed at this time, and the currently effective speed feedback source is the second speed feedback source, the motor controller selects the second control parameter set as the target control parameter set, and writes the speed loop control gain of the second control parameter set into the speed loop controller instance in the write step.
[0051] In one embodiment, step S130 includes: S131. Read the speed loop proportional gain, speed loop integral gain and speed loop differential gain from the target control parameter set; S132. Write the speed loop proportional gain, the speed loop integral gain, and the speed loop differential gain into the corresponding currently active gain storage locations in the speed loop controller instance; S133. During the writing process, the integral accumulation of the speed loop is kept continuous and the stored values of the multiple sets of control parameters in the parameter storage area remain unchanged. S134. During multiple consecutive control cycles, when the target control parameter set remains unchanged, the speed loop proportional gain, the speed loop integral gain, and the speed loop differential gain are repeatedly written over and overwritten into the speed loop controller instance.
[0052] The motor controller maintains two independent storage areas for each control axis. The first is the parameter storage area, which stores multiple sets of control parameters pre-tuned for the control axis. Each set of control parameters is fixed in the program memory as compile-time constants. The second is the speed loop controller instance, which stores the actual effective gain value and the integral accumulation of the speed loop in the current control cycle. The values in the parameter storage area are not modified during operation, while the values in the speed loop controller instance may be updated in each control cycle. This separation of storage areas is the structural basis for write operations to be executed unconditionally and repeatedly without side effects.
[0053] Within each control cycle, after the motor controller selects the target control parameter set, it enters the writing phase. The writing phase includes the following specific operations.
[0054] The motor controller first reads three values from the parameter storage area: the speed loop proportional gain, speed loop integral gain, and speed loop derivative gain of the target control parameter set. This read operation is read-only and does not change the contents of any storage cell in the parameter storage area. Taking the yaw axis as an example, if the target control parameter set is the second control parameter set, then the speed loop proportional gain is read as 0.8, the speed loop integral gain as 100, and the speed loop derivative gain as 0; if the target control parameter set is the first control parameter set, then the speed loop proportional gain is read as 0.8, the speed loop integral gain as 1.25, and the speed loop derivative gain as 0.
[0055] After the read operation is complete, the motor controller writes the speed loop proportional gain, speed loop integral gain, and speed loop derivative gain to the corresponding currently active gain storage locations in the speed loop controller instance. The speed loop controller instance has three independent gain storage locations, corresponding to the currently active speed loop proportional gain, the currently active speed loop integral gain, and the currently active speed loop derivative gain, respectively. The write operation assigns the three read values one by one to the corresponding storage locations, overwriting the original values in those locations. After the write operation is complete, the three gain values in the speed loop controller instance are consistent with the target control parameter set, and the currently active control parameters of the speed loop are updated.
[0056] During the write operation, the motor controller maintains the integral accumulation of the speed loop continuously. The integral accumulation is the value obtained by the speed loop integrator accumulating the speed deviation in each control cycle, reflecting the compensation amount accumulated by the motor to eliminate steady-state error. The write operation only replaces the three gain values and does not perform zeroing, resetting, or scaling operations on the integral accumulation. Before and after the gain switch, the value of the integral accumulation remains continuous, and the output of the integral term is equal to the new integral gain multiplied by the current integral accumulation. Since the integral accumulation itself does not change, the change in the integral term output only comes from the change in the gain ratio, not from a sudden change in the integral state. The output torque remains continuous at the moment of switching without a step. If the write operation simultaneously zeroes the integral accumulation, the integral term output drops to zero at the moment of switching, the output torque jumps, and the motor experiences a sudden torque change, which manifests as screen flickering in gimbal applications.
[0057] During the write process, the motor controller simultaneously maintains the stored values of multiple sets of control parameters in the parameter storage area. The target address of the write operation is limited to the gain storage location in the speed loop controller instance and does not involve any address in the parameter storage area. Each set of control parameters stored in the parameter storage area retains its initial setpoint throughout the entire operation and is not modified or cumulatively offset by repeated write operations. The immutability of the parameter storage area ensures that the target control parameter set read in each control cycle is always the correct setpoint, and the write operation will not change the content read in the current operation due to the result of the previous execution.
[0058] Over multiple consecutive control cycles, when the target control parameter set remains constant, the motor controller repeatedly writes the speed loop proportional gain, speed loop integral gain, and speed loop derivative gain to the speed loop controller instance. Since the target control parameter set does not change, the three gain values read in multiple consecutive control cycles are the same, and the write operation repeatedly assigns the same value to the same storage location in the speed loop controller instance. The result of repeated writing is the same as writing only once, without producing any cumulative side effects. The write operation is idempotent, meaning that regardless of whether it is executed once or multiple times, the gain value in the speed loop controller instance converges to the value specified by the target control parameter set.
[0059] The significance of idempotent reset lies in addressing the issue of multi-entry writes. Besides the write operation of this method, the speed loop gain of the motor controller also has other write sources. Parameter configuration commands write operating parameters through the debug interface and synchronously write them to the speed loop controller instance; motion mode switching logic writes specific parameter sets in specific modes; external force dwell logic writes dwell parameters when the external force drag determination is met. These write sources are independent, and their timing depends on the order of event arrival, and there is no synchronization relationship with the periodic writes of this method. If a bypass write modifies the gain value in the speed loop controller instance between two control cycles, causing the gain value to deviate from the target value corresponding to the currently effective speed feedback source, the write operation of the next control cycle will rewrite the gain value of the target control parameter set, restoring the gain value in the speed loop controller instance to the correct value matching the currently effective speed feedback source.
[0060] The effect of the write operation is illustrated using the process of switching the yaw axis from the first speed feedback source to the second speed feedback source as an example. In the control cycle before the switch, the target control parameter set is the first control parameter set. The motor controller writes the speed loop proportional gain of 0.8, the speed loop integral gain of 1.25, and the speed loop derivative gain of 0 into the speed loop controller instance, and the speed loop operates with a low integral gain. In the next control cycle after the switch, the target control parameter set becomes the second control parameter set, and the motor controller writes the speed loop proportional gain of 0.8, the speed loop integral gain of 100, and the speed loop derivative gain of 0 into the speed loop controller instance. During the write process, the integral accumulation of the speed loop remains unchanged from before the switch. The integral term output changes from 1.25 multiplied by the integral accumulation to 100 multiplied by the integral accumulation; the change only comes from the change in the gain ratio, and the output voltage transitions continuously without any step changes. The stored values of the first and second control parameter sets in the parameter storage area remain unchanged before and after the write operation.
[0061] In subsequent control cycles after the switch is completed, the target control parameter set remains the second control parameter set. In each control cycle, the motor controller repeatedly writes the speed loop proportional gain (0.8), speed loop integral gain (100), and speed loop derivative gain (0) back to the speed loop controller instance. If the parameter configuration command modifies the speed loop integral gain to another value via the debugging interface during this period, the write operation in the next control cycle will restore the speed loop integral gain to 100, with a correction delay of approximately 0.33ms. Repeated writing does not change the contents of the parameter storage area, does not reset the integral accumulation, and does not produce any cumulative effect.
[0062] In one embodiment, step S140 includes: S141. Obtain the position deviation of the control axis and the speed feedback amount provided by the currently active speed feedback source; S142. Generate a speed command based on the position deviation and position loop control parameters; S143. Based on the speed command, the speed feedback quantity, and the updated control parameters currently in effect for the speed loop, generate the control command to drive the motor corresponding to the control axis.
[0063] The motor controller controls three control axes: pitch, roll, and yaw. Each control axis is driven by a corresponding brushless DC motor, and the motor controller applies the drive to the motor in a field-oriented manner. The following description uses one control axis as an example to illustrate the execution process of the control operation; the execution method for the other control axes is the same.
[0064] Within each control cycle, after writing the speed loop control gain, the motor controller enters the control calculation phase. The control calculation phase sequentially performs position loop calculations and speed loop calculations, ultimately outputting control commands to drive the motor. The motor controller first acquires the position deviation of the control axis and the speed feedback provided by the currently active speed feedback source. The position deviation is acquired by reading the current angle value output by the joint angle sensor, reading the target angle value sent by the host operating environment, and subtracting the current angle value from the target angle value to obtain the position deviation. The joint angle sensor outputs angle data at a sampling frequency of 1kHz, and the motor controller reads the latest sampled value in each control cycle. The speed feedback is acquired by reading the angular velocity value output by the currently active speed feedback source. If the currently active speed feedback source is the first speed feedback source, the speed feedback is the angular velocity obtained after differential analysis and low-pass filtering of the joint angle sensor angle sequence through a sliding window; if the currently active speed feedback source is the second speed feedback source, the speed feedback is the angular velocity directly output by the angular velocity sensor. The source of the speed feedback quantity is consistent with the steps described above for obtaining the currently effective speed feedback source, that is, the speed feedback quantity used by the control operation always comes from the currently effective speed feedback source.
[0065] After acquiring the position deviation and speed feedback, the motor controller performs position loop calculations, generating speed commands based on the position deviation and position loop control parameters. In this embodiment, the position loop adopts a pure proportional structure, and the position loop control parameters only include the position loop proportional gain; the position loop integral gain and the position loop derivative gain are both zero. The position loop calculation formula is as follows: in, For speed commands, For position loop proportional gain, This is the positional deviation, which is the difference between the target angle value and the current angle value.
[0066] The position loop proportional gain maintains the same value across all control parameter sets. In this embodiment, the position loop proportional gain of the three control axes... Both are set to 0.3. Since the position loop integral gain is zero and the position loop differential gain is zero, the position loop does not introduce additional phase lag, and the position loop gain does not need to change with the switching of the speed feedback source. The significance of using a pure proportional structure for the position loop is that it limits the range of parameter shifting to within the speed loop, and the position loop parameters do not participate in the shifting, thereby avoiding the number of parameters doubling with the number of speed feedback sources and simplifying parameter tuning.
[0067] After the position loop calculation is completed, the motor controller performs the speed loop calculation, generating control commands based on the speed command, speed feedback, and the updated, currently effective control parameters of the speed loop. The speed loop calculation process is as follows: the motor controller subtracts the speed feedback from the speed command to obtain the speed deviation, and then performs a proportional-integral (PI) calculation on the speed deviation according to the updated, currently effective control parameters of the speed loop to generate control commands. The speed loop uses a proportional-integral (PI) controller, and the transfer function of the speed loop controller is: in, For the velocity loop proportional gain, For velocity loop integral gain, For the Laplace operator.
[0068] In a discrete control cycle, the proportional-integral (PI) operation is implemented as follows: the proportional term equals the speed loop proportional gain multiplied by the current speed deviation; the integral term equals the speed loop integral gain multiplied by the integral accumulation, which is accumulated in each control cycle by the product of the current speed deviation and the control cycle value. The sum of the proportional and integral terms is the value of the control command. The discrete operation formula for the speed loop is: in, For the first Speed deviation per control cycle For the first Speed command per control cycle, For the first Speed feedback amount per control cycle For the first The control commands output in each control cycle For the velocity loop proportional gain, For velocity loop integral gain, For the first The integral accumulation over each control cycle For the first The integral accumulation over each control cycle To control the cycle duration, the velocity loop differential gain is zero, and the velocity loop does not perform differential operations.
[0069] The currently active control parameters for the speed loop are the speed loop proportional gain, speed loop integral gain, and speed loop derivative gain updated in the aforementioned write step. The write step is completed before the control calculation; therefore, the gain values used in the control calculation are strictly matched with the currently active speed feedback source. If the currently active speed feedback source is the first speed feedback source, the speed loop uses the low integral gain of the first control parameter set; if the currently active speed feedback source is the second speed feedback source, the speed loop uses the high integral gain of the second control parameter set.
[0070] After the control command is generated, the motor controller outputs the control command to the power drive circuit. In this embodiment, the control command is a voltage command. The power drive circuit converts the voltage command into a three-phase drive current, applies it to the motor windings, and drives the motor to rotate. The rotation of the motor changes the attitude of the control shaft through mechanical transmission, thereby reducing position deviation and forming closed-loop control.
[0071] The specific values are illustrated using the control operation of the yaw axis under the second velocity feedback source as an example. (Yaw axis position loop proportional gain) The positional deviation is 0.3. When the angle is 0.1°, the speed command is obtained from formula (1). The currently active control parameters for the speed loop are the second set of control parameters, and the speed loop proportional gain is... The velocity loop integral gain is 0.8. The value is 100, and the differential gain of the speed loop is 0. If the speed feedback quantity... The value is 0.02° / ms, then the velocity deviation is obtained from formula (3). From formula (4), the proportional term is: The integral term is The sum of the proportional and integral terms is output as a voltage command to the power drive circuit, driving the yaw motor to rotate.
[0072] Taking the control operation of the pitch axis under the first velocity feedback source as an example, another operating condition is illustrated. The pitch axis position loop proportional gain... The value is 0.3. The currently effective control parameters for the speed loop are the first set of control parameters, and the speed loop proportional gain is [value missing]. The velocity loop integral gain is 0.2. The gain is 2.5, and the differential gain of the velocity loop is 0. The velocity feedback comes from the first velocity feedback source, which is the angular velocity obtained after the joint angle sensor angle sequence is differentially processed by a sliding window and low-pass filtered, with a group delay of approximately 7ms. Due to the low integral gain of the first control parameter set, the velocity loop still maintains sufficient phase margin under the 7ms group delay, and the closed loop converges stably.
[0073] It should be noted that the motor is approximately a first-order inertial element within the small signal range, and the motor's transfer function is: in, For motor gain, The time constant of the motor. This is the Laplace operator. The velocity feedback channel has a group delay, and the transfer function of the feedback channel is: in, For the group delay of the feedback channel, This is the Laplace operator. The amplitude of the pure delay element is always 1, it does not attenuate any frequency components, but the phase lag is... The phase margin increases linearly with frequency and has no upper bound. After adding a delay, the phase margin of the closed-loop system becomes: in, To incorporate the phase margin after the delay, The phase margin without delay. For amplitude crossover frequency, For group delay. When When the phase margin drops to zero or negative, the closed-loop system changes from a convergent response to a continuous oscillation.
[0074] Proportional-integral controller at frequencies higher than It exhibits a proportional characteristic, with the amplitude crossing the frequency range. Located above this corner frequency, and increasing with integral gain It monotonically increases. Therefore, given the group delay... There exists a critical integral gain. , making Group delay As the critical integral gain increases, The gain decreases accordingly, and the two are approximately inversely proportional. This relationship explains why the speed loop control gain must match the group delay of the currently active speed feedback source: the larger the group delay, the lower the allowable integral gain; the smaller the group delay, the higher the allowable integral gain. By performing control operations in each control cycle using control parameters paired with the currently active speed feedback source, the phase margin is always positive, and the closed-loop system remains stable.
[0075] After the control calculation is completed, the motor controller enters the next control cycle and re-executes the complete process of obtaining the currently effective speed feedback source, selecting the target control parameter set, writing the speed loop controller instance, executing the control calculation and outputting the control command.
[0076] In one embodiment, the PID parameter synchronous switching method of the present invention further includes an external force dwell parameter set in the multiple control parameter sets, and the steps of the method further include: S151. In response to the external force dragging determination being established, the speed loop control gain of the external force dwell parameter set is written into the speed loop controller instance, and the effective period of the external force dwell parameter set is enabled, the effective period being identified by the external force dwell flag; S152. In each control cycle, before writing the speed loop control gain of the target control parameter set into the speed loop controller instance, it is determined whether the external force dwell parameter set is within the effective period. S153. If the external force dwell parameter set is within the effective period, skip this write and keep the currently effective control parameters of the speed loop in the speed loop controller instance. S154. If the external force dwell parameter set is not within the effective period, then execute the writing of the speed loop control gain of the target control parameter set into the speed loop controller instance. S155. After the effective period ends, clear the external force dwell flag, and reselect the target control parameter set according to the currently effective speed feedback source, and re-execute the step of writing the speed loop control gain of the target control parameter set into the speed loop controller instance.
[0077] In addition to storing the first control parameter set corresponding to the first speed feedback source and the second control parameter set corresponding to the second speed feedback source, the parameter storage area also stores the external force dwell parameter set. The external force dwell parameter set is used in external force dragging scenarios, i.e., situations where the user directly drags a control axis of the gimbal to make it rotate. In external force dragging scenarios, the motor controller needs to reduce the control stiffness of the speed loop, making the motor rotate in the direction of the external force, rather than resisting the external force with high stiffness. The speed loop integral gain of the external force dwell parameter set is lower than the speed loop integral gain of the second control parameter set, thus enabling the motor to exhibit compliant following characteristics under external force. Taking the roll axis as an example, the speed loop integral gain of the second control parameter set is 300, while the speed loop integral gain of the external force dwell parameter set is 30, reduced to one-tenth of the second control parameter set.
[0078] The motor controller maintains an external force dwell flag and an effective period start time for each control axis. The external force dwell flag is a Boolean value, which can be either valid or invalid. The effective period start time is a timestamp that records the control cycle number or system clock value at which the external force dwell parameter set begins to take effect. Both the external force dwell flag and the effective period start time are stored in the running memory of the speed loop controller instance and can be read and modified within each control cycle.
[0079] The external force drag determination is performed by the external force detection module. The external force detection module determines whether an external force is acting on the control shaft based on the motor's current estimate, speed residual, or the output of the torque observer. When the external force detection module determines that external force drag is established, the external force drag determination established signal is set. After reading the external force drag determination established signal, the motor controller performs the following actions: writes the speed loop control gain of the external force dwell parameter set into the speed loop controller instance, switching the currently effective control parameters of the speed loop to the low stiffness parameters specified by the external force dwell parameter set; simultaneously, it sets the external force dwell flag to valid and records the current time as the effective period start time. The above writing operation has the same structure as the previous writing operation, that is, it only modifies the effective gain value in the speed loop controller instance, does not modify the stored value in the parameter storage area, and does not reset the integral accumulation of the speed loop.
[0080] Within each control cycle, before executing the aforementioned step of writing the speed loop control gain of the target control parameter set into the speed loop controller instance, the motor controller first determines whether the external force dwell parameter set is within its effective period. The determination method is as follows: the motor controller reads the external force dwell flag and the effective period start time, and determines whether the external force dwell parameter set meets the preset end condition based on the external force dwell flag and the effective period start time. If the external force dwell flag is valid and the preset end condition is not met, then the external force dwell parameter set is determined to be within its effective period; if the external force dwell flag is invalid or the preset end condition has been met, then the external force dwell parameter set is determined to be outside its effective period.
[0081] The preset termination conditions include the following two items: First, the elapsed time since the start of the effective period reaches the preset time limit; second, the motor controller receives a new target position command from the upper-level operating environment. The effective period is determined to have ended when either of these two conditions is met. In this embodiment, the preset time limit is set to 3 seconds. The purpose of setting the preset time limit is to prevent the external force dwell state from continuing indefinitely: when the external force is removed, if the user does not issue a new target position command, the external force dwell parameter set will still automatically exit after the preset time limit is reached, and the motor will restore its operating stiffness. The purpose of setting early termination upon receiving a new target position command is: when the user issues a new motion command, it indicates that the user is no longer dragging the gimbal, and the motor should immediately resume normal operating parameters.
[0082] If the external force dwell parameter set is within its effective period, the motor controller skips the current write operation, maintaining the currently effective control parameters of the speed loop in the speed loop controller instance unchanged. That is, the speed loop proportional gain, speed loop integral gain, and speed loop derivative gain stored in the speed loop controller instance maintain the values specified by the external force dwell parameter set and are not overwritten by the target control parameter set corresponding to the currently effective speed feedback source. The significance of skipping the write operation is that without this judgment, the write operation performed in each control cycle mentioned above would overwrite the external force dwell parameter set back to the parameter set paired with the currently effective speed feedback source in the next control cycle. The softening effect of the external force dwell parameter set can only last for one control cycle. During the continuous external force drag, the motor will resist the external force with its operating stiffness, generating repeated torque resistance, which the user feels as a continuous pull between the motor and their hand.
[0083] If the external force dwell parameter set is not in effect, the motor controller will normally execute the step of writing the speed loop control gain of the target control parameter set into the speed loop controller instance. The selection logic of the target control parameter set is the same as described above, that is, the first control parameter set or the second control parameter set is selected according to the currently effective speed feedback source.
[0084] After the effective period ends, the motor controller clears the external force dwell flag, setting it to invalid. After clearing the external force dwell flag, the motor controller reselects the target control parameter set based on the currently effective speed feedback source and re-executes the step of writing the speed loop control gain of the target control parameter set into the speed loop controller instance. Since the external force dwell flag has been cleared, the effective period determination in subsequent control cycles will determine that the external force dwell parameter set is no longer within its effective period, the write operation resumes normal execution, and the currently effective control parameters of the speed loop are restored to the values specified by the target control parameter set paired with the currently effective speed feedback source.
[0085] The effect of this embodiment is illustrated by taking the complete execution process of the roll axis under external force dragging scenario as an example. In normal operation, the currently effective speed feedback source is the second speed feedback source. The speed loop control gain in the speed loop controller instance is the speed loop proportional gain of 1, speed loop integral gain of 300, and speed loop derivative gain of 0, as specified by the second control parameter set. When the user drags the roll axis by hand, the external force detection module determines that external force dragging has occurred. The motor controller writes the speed loop control gain of the external force dwell parameter set into the speed loop controller instance, the speed loop integral gain decreases from 300 to 30, and simultaneously sets the external force dwell flag to valid, recording the start time of the effective period.
[0086] In each subsequent control cycle, the motor controller reads the external force dwell flag, determines that the external force dwell parameter set is within its effective period, skips the write operation, and the speed loop integral gain in the speed loop controller instance remains unchanged at 30. The motor operates with low stiffness, rotating in the direction of the user's hand drag, without generating torque resistance.
[0087] If the user issues a new target position command during the dragging process, the motor controller determines that the preset termination condition has been met, and the effective period ends. The motor controller clears the external force dwell flag and reselects the target control parameter set based on the currently effective speed feedback source. Since the currently effective speed feedback source is the second speed feedback source, the target control parameter set is the second control parameter set. The motor controller writes the speed loop proportional gain of 1, the speed loop integral gain of 300, and the speed loop derivative gain of 0 into the speed loop controller instance, the roll axis restores its running stiffness, and begins tracking the new target position.
[0088] If the user does not issue a new target position command, the effective period will reach its preset maximum duration 3 seconds after activation, at which point the effective period will end. The motor controller will then perform the same clear flag, reselect, and rewrite operations as described above, and the roll shaft will regain its operating stiffness.
[0089] The external force dwell time determination for the three control axes is independent of each other. When one control axis enters the external force dwell time period, the other control axes continue to perform write operations normally according to the currently effective speed feedback source. Priority arbitration is conducted independently within each control axis, and the control axes do not interfere with each other.
[0090] By adding an external force dwell parameter set to multiple control parameter sets and adding a judgment on the effective period of external force dwell before the write operation of each control cycle, priority protection of control parameters during external force dragging is achieved. When the external force drag judgment is valid, the external force dwell parameter set is written into the speed loop controller instance, and the effective period is activated. During the effective period, the write operation performed in each of the aforementioned control cycles is skipped, and the softening effect of the external force dwell parameter set is maintained throughout the entire effective period, rather than just for one control cycle. After the effective period ends, the external force dwell flag is cleared, the motor controller reselects the target control parameter set according to the currently effective speed feedback source and resumes the write operation, and the motor automatically restores its operating stiffness. The above mechanism avoids the repeated torque resistance caused by the motor resisting the external force with its operating stiffness during external force dragging, while ensuring that the motor can automatically return to normal control state after the external force is removed, without the need for additional exit criteria or manual intervention.
[0091] In one embodiment, step S152 includes: S1521. Read the external force stay flag and the effective period start time. The external force stay flag is set when the external force drag determination is established, and the effective period start time is recorded when the external force stay flag is set. S1522. Based on the external force dwelling flag and the effective period start time, determine whether the external force dwelling parameter set meets the preset end condition; S1523. If the external force stay flag is valid and the preset end condition is not met, then it is determined that the external force stay parameter set is within the effective period. S1524. If the external force stay flag is invalid or the preset end condition has been met, then it is determined that the external force stay parameter set is not within the effective period.
[0092] The motor controller maintains two state variables related to external force dwell time for each control axis: an external force dwell time flag and an effective period start time. The external force dwell time flag is a Boolean value, taking the value of valid or invalid, and is stored in the runtime memory of the speed loop controller instance. The effective period start time is a timestamp, recording the system clock count value corresponding to when the external force dwell time flag is set, and is also stored in the runtime memory. Each of the three control axes independently maintains its own external force dwell time flag and effective period start time, ensuring no interference between the control axes.
[0093] The timing for setting the external force dwell flag is as follows: When the external force detection module determines that an external force drag is established, the motor controller responds to the external force drag determination signal by setting the external force dwell flag of the corresponding control axis from invalid to valid. The setting action and the writing action of the external force dwell parameter set are completed within the same control cycle; that is, the motor controller writes the speed loop control gain of the external force dwell parameter set to the speed loop controller instance while simultaneously setting the external force dwell flag to valid. The timing for recording the effective period start time is as follows: Within the same control cycle where the external force dwell flag changes from invalid to valid, the motor controller reads the current system clock count value and writes this count value into the effective period start time field. The system clock count value has a control cycle as the minimum resolution; therefore, the recording accuracy of the effective period start time is one control cycle.
[0094] Within each control cycle, before performing a write operation, the motor controller reads the external force dwell flag and the effective period start time for the corresponding control axis. After reading, the motor controller determines whether the external force dwell parameter set meets the preset termination conditions based on the external force dwell flag and the effective period start time.
[0095] The preset termination conditions include two items; if either one is met, the preset termination condition is determined to be valid.
[0096] The first preset end condition is a duration condition: the elapsed time since the start of the effective period reaches the preset duration limit. The motor controller reads the current system clock count value, subtracts the start time of the effective period from the current system clock count value, and obtains the elapsed time since the start of the effective period. The elapsed time is compared with the preset duration limit. If the elapsed time is greater than or equal to the preset duration limit, the duration condition is determined to be satisfied.
[0097] The second preset termination condition is the target position condition: the motor controller receives a new target position command from the host operating environment. In each control cycle, the motor controller checks the target position command receiving buffer. If there is a new target position command in the buffer that has not yet been processed, the target position condition is deemed met. The meaning of the target position condition is: the user has issued a new motion command, indicating that the user is no longer dragging the gimbal, and the motor should exit the external force-induced stop state and resume normal operation.
[0098] The decision logic is executed in four branches: The first branch: The external force dwell flag is valid, but the duration condition and the target position condition are not met. In this case, the motor controller determines that the external force dwell parameter set is within its effective period. After determining that it is within the effective period, the motor controller skips this write operation and keeps the currently effective control parameters of the speed loop in the speed loop controller instance unchanged.
[0099] The second branch: The external force dwell flag is valid, and the duration condition has been met. In this case, regardless of whether the target position condition is met, the motor controller determines that the external force dwell parameter set is not within its effective period. After determining that it is not within its effective period, the motor controller clears the external force dwell flag, sets it from valid to invalid, and reselects the target control parameter set based on the currently effective speed feedback source, then performs the write operation.
[0100] The third branch: The external force dwell flag is valid, and the target position condition has been met. In this case, regardless of whether the duration condition is met, the motor controller determines that the external force dwell parameter set is not within its effective period. Subsequent processing is the same as the second branch.
[0101] The fourth branch: The external force dwell flag is invalid. In this case, the motor controller does not execute the preset termination condition judgment, but directly determines that the external force dwell parameter set is not within the effective period. After the judgment result is that it is not within the effective period, the motor controller normally executes the step of writing the speed loop control gain of the target control parameter set into the speed loop controller instance.
[0102] The specific operation of the above judgment logic is illustrated by taking the execution process of the roll axis under external force dragging scenario as an example. Under normal operation, the external force dwell flag is invalid, and the judgment result of each control cycle is the fourth branch. The motor controller performs the write operation normally, and the currently effective control parameters of the speed loop are kept paired with the currently effective speed feedback source.
[0103] When the user manually drags the roll axis, the external force detection module determines that the external force dragging is valid. The motor controller writes the speed loop control gain of the external force dwell parameter set into the speed loop controller instance, sets the external force dwell flag to valid, and records the current system clock count value as the effective start time.
[0104] Starting from the next control cycle, the motor controller reads the external force dwell flag and the effective period start time in each control cycle. If the external force dwell flag is valid, the motor controller calculates the elapsed time since the effective period started and checks the target position command receiving buffer. If the elapsed time is less than 3 seconds during which the user continues to drag without issuing a new target position command, the target position command receiving buffer is empty, and neither the duration condition nor the target position condition is met. The judgment result is the first branch, and the motor controller skips the write operation. The currently effective control parameters of the speed loop in the speed loop controller instance remain unchanged according to the values specified in the external force dwell parameter set.
[0105] Suppose the user drags continuously for 2 seconds and then releases the grip without issuing a new target position command. The elapsed time since the effective period began continues to increase. When the elapsed time reaches 3 seconds, the time condition is met, and the result is the second branch. The motor controller clears the external force dwell flag, reselects the target control parameter set based on the currently effective speed feedback source, performs the write operation, and the roll shaft restores its operating stiffness.
[0106] Suppose the user issues a new target position command 1.5 seconds after dragging. In the next control cycle, the motor controller checks the target position command receive buffer, finds a new target position command, and the target position conditions are met, resulting in the third branch. The motor controller clears the external force pause flag, reselects the target control parameter set and performs a write operation, the roll axis prematurely exits the external force pause state, and begins tracking the new target position. The actual effective duration is 1.5 seconds, which is less than the preset maximum duration of 3 seconds.
[0107] It should be noted that the setting and clearing of the external force stay flag, as well as the recording of the effective period start time, all occur within the control cycle and do not depend on external interrupts or asynchronous events. The external force drag determination signal and the target position command are both sampled within the control cycle, and the judgment logic is executed synchronously in each control cycle, with no race conditions.
[0108] This embodiment achieves precise management of the effective period of the external force dwell parameter set by reading the external force dwell flag and the effective period start time, and making judgments based on two preset end conditions: duration condition and target position condition. The external force dwell flag is set when the external force drag judgment is established, and the effective period start time is recorded synchronously to ensure that the start time of the effective period is strictly aligned with the writing time of the external force dwell parameter set. The judgment logic covers four branches: skipping the writing operation during the effective period to maintain the softening effect of the external force dwell parameter set, clearing the flag and resuming normal writing operations after the effective period ends. The preset duration upper limit ensures that the motor can automatically restore its operating stiffness after the external force is removed, without the need for additional exit criteria; the target position condition ensures that the motor responds immediately when the user issues a new motion command, without waiting for the duration upper limit to be reached. The above judgment logic is executed synchronously in each control cycle, which is consistent with the idempotent reset mechanism that is repeatedly executed in each control cycle, ensuring that the control parameters are not overwritten during the external force dwell period, and that the control parameters automatically restore their pairing relationship with the currently effective speed feedback source after the external force dwell ends.
[0109] The PID parameter synchronous switching method of the present invention can be widely used in motion control fields where speed feedback channel switching is frequent and closed-loop stability requirements are high. The following uses two typical scenarios, aerial gimbal and collaborative robot, as examples for illustration.
[0110] In aerial photography gimbal scenarios, this method can be applied to the entire process control of a three-axis stabilized gimbal for UAVs. After the UAV is powered on, the angle references of the joint angle sensors on each axis of the gimbal have not yet been established, and the velocity loop can only rely on the angular velocity feedback obtained from the angle sequence difference. At this time, the controller automatically selects a low integral gain parameter set that matches the high group delay feedback channel to ensure no oscillation occurs during calibration and homing. After calibration, the gimbal switches to angular velocity feedback directly output by the inertial measurement unit. In the next control cycle, the controller automatically writes the high integral gain parameter set into the velocity loop, restoring sufficient static stiffness and disturbance rejection capability, allowing the gimbal to maintain image stability even under airflow disturbances. The entire switching process requires no manual intervention, the integral accumulation remains continuous, and the image is smooth, significantly improving the usability of aerial footage and the user experience.
[0111] In collaborative robot scenarios, this method can be used for smooth transitions between different speed feedback modes in multi-joint servo drive systems. In teach mode, the operator directly drags the robotic arm. Upon detecting the external force, the controller automatically switches to a low-stiffness external force dwell parameter set, allowing the robotic arm to smoothly follow the operator's movements. After the teach period ends, the controller automatically restores the operating parameter set paired with the current speed feedback source, and the robotic arm returns to high-precision position tracking. If the robot joints are equipped with both encoder differential velocimetry and independent velocimetry sensors as feedback sources, this method ensures that parameter switching between the two feedback channels is completed automatically within the control cycle, avoiding the impact of torque jumps during switching on the end effector and ensuring human-robot collaboration safety.
[0112] As can be seen from the above applications, the method of the present invention supports automatic synchronization and matching of parameters and feedback sources, periodic correction of multiple write entry points, and priority protection during external force dwell periods in motion control scenarios such as aerial photography stabilization and collaborative robots where speed feedback channels can be switched and multiple working conditions coexist. It has good practical value and development prospects.
[0113] Figure 8 This is a schematic block diagram of a PID parameter synchronous switching device 600 provided in an embodiment of the present invention. Figure 8 As shown, corresponding to the above-described PID parameter synchronization switching method, the present invention also provides a PID parameter synchronization switching device 600. This PID parameter synchronization switching device 600 includes a unit for executing the above-described PID parameter synchronization switching method, and the device can be configured in terminals such as robots, power tools, and handheld gimbals.
[0114] Specifically, please refer to Figure 8 Specifically, the PID parameter synchronization switching device 600 includes: Feedback source acquisition unit 610 is used to acquire the currently effective speed feedback source, wherein the currently effective speed feedback source is the first speed feedback source or the second speed feedback source; The parameter set selection unit 620 is used to select a target control parameter set from multiple sets of control parameters pre-stored in the parameter storage area for the control axis according to the currently active speed feedback source. The multiple sets of control parameter sets include at least a first control parameter set corresponding to the first speed feedback source and a second control parameter set corresponding to the second speed feedback source. The integral gain of the second control parameter set is greater than the integral gain of the first control parameter set. The gain writing unit 630 is used to write the speed loop control gain of the target control parameter set into the speed loop controller instance corresponding to the control axis and update the currently effective control parameters of the speed loop. The speed loop control gain includes speed loop proportional gain, speed loop integral gain and speed loop differential gain. The control calculation unit 640 is used to perform control calculations on the position loop and the speed loop based on the updated control parameters currently in effect for the speed loop, and to output control commands.
[0115] In one embodiment, the feedback source acquisition unit 610 includes: The calibration status reading unit is used to read the calibration readiness status of each control axis, wherein the calibration readiness status is used to characterize whether the joint angle sensor of the corresponding control axis has completed the reference calibration; The second feedback source determination unit is used to determine the second speed feedback source as the currently effective speed feedback source if all the control axes are in the calibration ready state. The first feedback source determination unit is configured to determine the first speed feedback source as the currently effective speed feedback source if any of the control axes is not in the calibration ready state.
[0116] In one embodiment, the parameter set selection unit 620 includes: A feedback source determination unit is used to determine whether the currently effective speed feedback source is the first speed feedback source; The first parameter set selection unit is used to select the first control parameter set as the target control parameter set if the currently effective speed feedback source is the first speed feedback source. The second parameter set selection unit is used to select the second control parameter set as the target control parameter set if the currently effective speed feedback source is the second speed feedback source. The mode response selection unit is used to respond to the motor controller entering the speed-only closed-loop motion mode based on the target control parameter set.
[0117] In one embodiment, the gain writing unit 630 includes: The gain reading unit is used to read the speed loop proportional gain, the speed loop integral gain, and the speed loop differential gain from the target control parameter set. The gain assignment unit is used to write the speed loop proportional gain, the speed loop integral gain, and the speed loop differential gain into the corresponding currently active gain storage location in the speed loop controller instance; A state holding unit is used to maintain the continuous integral accumulation of the speed loop and the unchanged stored values of the multiple sets of control parameters in the parameter storage area during the writing process. An idempotent reset unit is used to repeatedly overwrite the speed loop proportional gain, the speed loop integral gain, and the speed loop differential gain into the speed loop controller instance within multiple consecutive control cycles, while the target control parameter set remains unchanged.
[0118] In one embodiment, the control arithmetic unit 640 includes: The deviation acquisition unit is used to acquire the position deviation of the control axis and the speed feedback amount provided by the currently active speed feedback source; A speed command generation unit is used to generate speed commands based on the position deviation and position loop control parameters; The control command generation unit is used to generate the control command based on the speed command, the speed feedback quantity, and the updated control parameters currently in effect of the speed loop, and drive the motor corresponding to the control axis.
[0119] In one embodiment, the PID parameter synchronization switching device 600 further includes: The pause activation unit is used to respond to the external force drag determination being established by writing the speed loop control gain of the external force pause parameter set into the speed loop controller instance and activating the effective period of the external force pause parameter set, the effective period being identified by the external force pause flag; The effective period determination unit is used to determine whether the external force dwell parameter set is within the effective period before writing the speed loop control gain of the target control parameter set into the speed loop controller instance in each control cycle. The write skip unit is used to skip the write if the external force dwell parameter set is within the effective period, and to maintain the currently effective control parameters of the speed loop in the speed loop controller instance; The normal write unit is used to write the speed loop control gain of the target control parameter set into the speed loop controller instance if the external force dwell parameter set is not within the effective period. The pause exit unit is used to clear the external force pause flag after the effective period ends, and reselect the target control parameter set according to the currently effective speed feedback source, and re-execute the step of writing the speed loop control gain of the target control parameter set into the speed loop controller instance.
[0120] In one embodiment, the effective period determination unit includes: The flag reading unit is used to read the external force stop flag and the effective period start time. The external force stop flag is set when the external force drag determination is established, and the effective period start time is recorded when the external force stop flag is set. The termination condition determination unit is used to determine whether the external force dwell parameter set meets the preset termination condition based on the external force dwell flag and the effective period start time. An effectiveness determination unit is used to determine that the external force stay parameter set is within the effectiveness period if the external force stay flag is valid and the preset end condition is not met. The failure determination unit is used to determine that the external force dwelling parameter set is not within the effective period if the external force dwelling flag is invalid or the preset termination condition has been met.
[0121] The aforementioned PID parameter synchronous switching device 600 can be implemented as a computer program, which can, for example... Figure 9 It runs on the computer device shown.
[0122] Please see Figure 9 , Figure 9 This is a schematic block diagram of a computer device 500 provided in an embodiment of this application. The computer device 500 can be a terminal or a server. The terminal can be an electronic device with communication functions, such as a robot, power tool, or handheld gimbal. The server can be a standalone server or a server cluster composed of multiple servers.
[0123] See Figure 9 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.
[0124] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform a PID parameter synchronous switching method.
[0125] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.
[0126] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a PID parameter synchronous switching method.
[0127] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0128] The processor 502 is used to run a computer program 5032 stored in a memory to implement the steps of the above method.
[0129] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0130] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0131] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When executed by a processor, the program instructions cause the processor to perform the steps of the above-described method.
[0132] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0133] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0134] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0135] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0136] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0137] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A PID parameter synchronous switching method applied to a motor controller, the motor controller being used to control at least one control axis, the motor controller having a dual-loop control structure with a position loop and a speed loop cascaded, the feedback quantity of the speed loop being configured to be selectable between a first speed feedback source and a second speed feedback source, the first speed feedback source having a first group delay, the second speed feedback source having a second group delay, the first group delay being greater than the second group delay, characterized in that, The method is performed for each of the control axes, and in each control cycle, the following steps are performed: Obtain the currently active speed feedback source, wherein the currently active speed feedback source is the first speed feedback source or the second speed feedback source; Based on the currently active speed feedback source, a target control parameter set is selected from multiple sets of control parameters pre-stored in the parameter storage area for the control axis. The multiple sets of control parameter sets include at least a first control parameter set corresponding to the first speed feedback source and a second control parameter set corresponding to the second speed feedback source. The integral gain of the second control parameter set is greater than the integral gain of the first control parameter set. Write the speed loop control gain of the target control parameter set into the speed loop controller instance corresponding to the control axis, and update the currently effective control parameters of the speed loop. The speed loop control gain includes speed loop proportional gain, speed loop integral gain and speed loop derivative gain. Based on the updated control parameters currently in effect for the velocity loop, control calculations are performed for the position loop and the velocity loop, and control commands are output.
2. The PID parameter synchronous switching method according to claim 1, characterized in that, The sources for obtaining the currently effective speed feedback include: Read the calibration readiness status of each control axis, the calibration readiness status being used to characterize whether the joint angle sensor of the corresponding control axis has completed the reference calibration; If all the control axes are in the calibration ready state, then the second speed feedback source is determined as the currently active speed feedback source; If any of the control axes is not in the calibration ready state, then the first speed feedback source is determined as the currently effective speed feedback source.
3. The PID parameter synchronous switching method according to claim 1, characterized in that, The step of selecting a target control parameter set from multiple sets of control parameters pre-stored in the parameter storage area for the control axis based on the currently active speed feedback source includes: Determine whether the currently active speed feedback source is the first speed feedback source; If the currently effective speed feedback source is the first speed feedback source, then the first control parameter set is selected as the target control parameter set; If the currently effective speed feedback source is the second speed feedback source, then the second control parameter set is selected as the target control parameter set; The motor controller responds to the target control parameter set by entering the speed-only closed-loop motion mode.
4. The PID parameter synchronous switching method according to claim 1, characterized in that, The example of writing the speed loop control gain of the target control parameter set into the speed loop controller corresponding to the control axis includes: Read the speed loop proportional gain, speed loop integral gain, and speed loop differential gain from the target control parameter set; Write the speed loop proportional gain, the speed loop integral gain, and the speed loop differential gain into the corresponding currently active gain storage location in the speed loop controller instance; During the writing process, the integral accumulation of the speed loop is kept continuous and the stored values of the multiple sets of control parameters in the parameter storage area are kept unchanged. During multiple consecutive control cycles, while the target control parameter set remains unchanged, the speed loop proportional gain, the speed loop integral gain, and the speed loop derivative gain are repeatedly written to the speed loop controller instance.
5. The PID parameter synchronous switching method according to claim 1, characterized in that, The process of performing control calculations on the position loop and the velocity loop based on the updated, currently effective control parameters of the velocity loop, and outputting control commands, includes: Obtain the position deviation of the control axis, and the speed feedback amount provided by the currently active speed feedback source; Based on the position deviation and position loop control parameters, a speed command is generated; Based on the speed command, the speed feedback, and the updated control parameters currently in effect for the speed loop, the control command is generated to drive the motor corresponding to the control axis.
6. The PID parameter synchronous switching method according to claim 1, characterized in that, The multiple sets of control parameters also include a set of external force dwell parameters, and the method further includes: In response to the determination that the external force drag is established, the speed loop control gain of the external force dwell parameter set is written into the speed loop controller instance, and the effective period of the external force dwell parameter set is enabled, the effective period being identified by the external force dwell flag; In each control cycle, before writing the speed loop control gain of the target control parameter set into the speed loop controller instance, it is determined whether the external force dwell parameter set is within the effective period. If the external force dwell parameter set is within the effective period, then skip this write and retain the currently effective control parameters of the speed loop in the speed loop controller instance; If the external force dwell parameter set is not within the effective period, then the speed loop control gain of the target control parameter set is written into the speed loop controller instance. After the effective period ends, the external force stay flag is cleared, and the target control parameter set is reselected according to the currently effective speed feedback source. The process of writing the speed loop control gain of the target control parameter set into the speed loop controller instance is then re-executed.
7. The PID parameter synchronous switching method according to claim 6, characterized in that, The step of determining whether the external force dwell parameter set is within the effective period includes: Read the external force stay flag and the effective period start time. The external force stay flag is set when the external force drag determination is established, and the effective period start time is recorded when the external force stay flag is set. Based on the external force dwell flag and the effective period start time, determine whether the external force dwell parameter set meets the preset end condition; If the external force stay flag is valid and the preset end condition is not met, then the external force stay parameter set is determined to be within the effective period; If the external force stay flag is invalid or the preset end condition has been met, then it is determined that the external force stay parameter set is not within the effective period.
8. A PID parameter synchronous switching device, characterized in that, Used to perform the PID parameter synchronization switching method as described in any one of claims 1 to 7.
9. A computer device, characterized in that, The computer device includes a memory and a processor connected to the memory; the memory is used to store a computer program; the processor is used to run the computer program stored in the memory to perform the steps of the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which includes program instructions that, when executed by a processor, can implement the steps of the method as described in any one of claims 1 to 7.
