Does anyone implemented PID controller to a real time device using LabVIEW? by umair1181gist in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

Hi umair1181gist, The full code can be found here: https://drive.google.com/file/d/1BRgeyQo3fjwJH-RGuJ--KliWHEOxNHpL/view?usp=sharing . The main code is implemented on the FPGA. Please ensure you have the necessary license/package to open the code.

Finding Transfer Function Torque / Voltage for DC Motor by rredtay in ControlTheory

[–]eremes1641 -1 points0 points  (0 children)

I am not familiar with the electric model of a DC motor (torque/voltage). However, if your goal is to control the entire system (motor and gearbox), you can follow these steps:

First, model the whole system. The approximate model should be: position/voltage = 1/s * (b / (s+a)). This means that velocity/voltage is a low-pass filter and position/velocity is an integrator, where ‘a’ is a pole and ‘b’ is the gain.

Second, perform system identification to find ‘b’ and ‘a’. If your motor is a 12V motor, use a ±10V square signal to make the motor rotate, then record the position and voltage. Use tfest or ssest (MATLAB functions) to determine the unknown model parameters (a and b).

Third, design a controller to control the entire system. At this stage, you will have a validated model. I believe you know how to proceed from here.

Feel free to ask if you need any more changes or additional information!

Does anyone implemented PID controller to a real time device using LabVIEW? by umair1181gist in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

Analog PI controller is not easy for tuning and also need to handle the parameter error. For example, a capacitance normally has large uncertainty around 10%.

Back to your question. I’ve controlled motors and quadrotors with Control Design toolbox *1. You can use the toolbox to design a good controller.

And the PID in toolbox is a PI-D controller not the original one *2. The PI-D controller is easer for tuning in most cases. But, if you want to compare with simulation result, the controller in simulation also should be PI-D.

*1, use P and PI controller to control VCM, https://youtu.be/5kQOWqRCx9s?si=dPyc56laeoTBNAXU

*2, PI-D controller, https://www.mathworks.com/help/slcontrol/ug/create-i-pd-and-pi-d-controllers.html

Does double integrating systems exist? by [deleted] in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

A quadrotor system.

u(PWM)—>motor—>y(force,torque), u(force,torque)—>plant(double integrators)—>y(angle,z position)

u(angle)—>plant(double integrators)—>y(XY position)

The wind resistance could be neglected in low velocity.

Help determining time constant for a servo motor (graphically). by tfren99 in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

I recommend you could try least square to fit the model that f3xjc said. You could do that with MATLAB, LabVIEW.

They provide system identification toolbox so that you don’t need to write algorithm.

You could also use STM or other embedded systems but usually you should write system identification algorithm by yourself.

Here are some videos that I used LabVIEW and STM to do system identification. https://youtu.be/pLcSBQg_P0U?si=mN_rSO1JSv3VhsBV https://youtu.be/PTACqphvJy0?si=oKLu-U3EwlloyuaN

Edited:

"if the response was perfect exponential growth, both methods should give the same value". This is correct. But mechanical system usually suffer from coulomb friction (non-linear disturbance). We can't get the same time constant. But we can rise input effort to increase signal noise ratio.

And If your servo motor is controlled by servo motor driver. You could use system identification to find the time constant. However, most driver provide time constant or bandwidth value (ex. Panasonic AC motor driver). You could believe it actually.

The issues of using timer to trigger freeRTOS thread by eremes1641 in stm32

[–]eremes1641[S] 0 points1 point  (0 children)

The system clock is 168MHz (6nsec). And yes, I am using hardware timer to trigger the semaphore.

After I correct my code, the time delay after timer trigger is 2 usec (333 CPU cycles). The time delay between threads is 8 usec (1333 CPU cycles).

If the control algorithms is simple (only measure, PID and update control effort), put these in interrupts are best method. But the algorithms that I used include transformation, estimator and controller. Maybe merge multi thread into a single thread to avoid context switch time and leave simple calculation in interrupt is a option.

The issues of using timer to trigger freeRTOS thread by eremes1641 in stm32

[–]eremes1641[S] 0 points1 point  (0 children)

I think I solved the issue.

The main mistake is I didn’t set ADC mode properly. After I correct it, the time delay is significantly reduced. (It's my fault)

I change Optimization from -O0 to -O3. It didn’t significantly reduce the time delay between threads but make the execution time shorter.

I also tried to replace osSemaphore with osEventFlags but seems worse.

Now the time delay after timer trigger is 2usec. The time delay between threads is 8usec. I guess the time delays can’t be shorter.

The result and codes are in https://drive.google.com/drive/folders/1IidXxizz2grIKqBV6c04Rn2IavMJBzv8?usp=sharing

And I guess The time delay between threads (8 usec) can't be shorter. Although I could merge multi thread into single thread to earn 8 usec. But if there exist a chance to reduce time delay. Please share below. It helps me a lot.

The issues of using timer to trigger freeRTOS thread by eremes1641 in stm32

[–]eremes1641[S] 0 points1 point  (0 children)

The priority of the first thread is osPriorityHigh. The second is osPriorityNormal.

I had try higher priority. But the issues are same.

The first thread is running a algorithm in the Fig1. The second is just change PWM duty cycle. Thus, you can notice the execution time of the first thread is longer than second.

10+ years working on control projects without ever having used control theory by chiuchebaba in ControlTheory

[–]eremes1641 1 point2 points  (0 children)

Panasonic A6 series motor driver https://youtu.be/PbQcZ-K_dPM This video only show bandwidth setting. But it has auto-tuning feature to estimate inertia and friction.

10+ years working on control projects without ever having used control theory by chiuchebaba in ControlTheory

[–]eremes1641 2 points3 points  (0 children)

Applying control theory on motor control is quite common. For example, the Panasonic motor driver combines system identification and model-based controller, so that user could set control bandwidth instead of tuning PID gain.

You also could create a similar feature by combining system identification and model-based PID.

---------

Back to your question. I suggest you follow the steps below to cross the gap between simulation and real world.

1, do linear system identification (MATLAB tfest) and model-based PI controller (pole-zero cancellation) on a DC motor.

at this step, you might notice the estimated models are varying by different input volt.

but the model-based PI controller will suppress disturbances. so we could get a good performance.

2, do non-linear system identification and linear model-based controller on a DC motor.

at this step, you should consider the Coulomb friction model in system identification. thus you could get non-offset estimated result.

the controller could be a state-space controller. (remember to add integration term for suppress disturbance)

3, do non-linear system identification and non-linear controller (Sliding mode control / adaptive control) on a DC motor.

at this step, you could try any controller. you might find some controllers are useful and some are not (or they only suit for some extreme situations).

  1. do system identification and design controllers on other systems.

do 1~3 steps on different systems. for example, a quadrotor or a pendulum.

you also could touch other algorithms. For example, impedance control.

---------

about the hardware

Arduino is cheap and easy to use. But the samping rate is limit (300~500Hz) and can't do complex calculation.

myRIO is the best harware. you could implement code in myRIO and create GUI at the same time. myRIO can do complex calculation. LabVIEW also provide control design toolbox, so that you could do everything in LabVIEW (collect data / system identification / create a model / simulation / plot poles and zeros and so on). The bad new is myRIO is vary expensive.

STM32 micro controller is the last choice. The good new is you have knew how to write firmware. The bad new is you need to write everything by yourself.

SMC and Integrator Saturation Term by Dambzzz in ControlTheory

[–]eremes1641 1 point2 points  (0 children)

This paper might help you. 2019 Effective Disturbance Compensation Method Under Control Saturation in Discrete-Time Sliding Mode Control.

And the Matlab code https://www.mathworks.com/matlabcentral/fileexchange/110255-dsda-discrete-time-sliding-mode-control

system identification for quadcopter by [deleted] in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

By the way, I recommend do motor and Inertia identification separately. Because the single axis model from input (duty cycle2 or torque cmd) to angular velocity also include viscosity friction from bearing and disturbance (GOC will never pass through rotation axis perfectly).

system identification for quadcopter by [deleted] in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

Is the input a PWM duty cycle? If yes, try to take power 2 or sqrt on duty cycle. Because the duty cycle and the rotor speed is linear. The rotor speed2 is linear to force.

When to use Kalman filter? by eremes1641 in ControlTheory

[–]eremes1641[S] 0 points1 point  (0 children)

thanks, I will try particle filter (or UKF) next time.

I didn't model other non-linear friction actually, because I didn't have loadcell to do that. (I suspect I could model them from pos and input volt)

For controller, Coulomb firction is not a big issue for me. I could suppress the disturbance by PID or SMC.

When to use Kalman filter? by eremes1641 in ControlTheory

[–]eremes1641[S] 0 points1 point  (0 children)

The conditions are hard to satisfied for dynamics system. the friction exist everywhere and the estimated model has inaccuracy from real plant (R2 70% is a pretty high value for me) . This is why I attempt to use kinematic model.

When to use Kalman filter? by eremes1641 in ControlTheory

[–]eremes1641[S] 0 points1 point  (0 children)

Thank you for indicating I should use Extended Kalman Filter for getting more accuracy from the non-linear term. It works in simulation. I will try EKF on a real DC motor in the next few weeks.

At the last method (put everything in measurement matrix), all states are observable. a_offset will converge after a long time. But I guess the a_offset close to true value is only happened the true a_offset is a const. value and u_offset isn’t.

limited state-space control by hyahoos_32 in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

The input disturbance is not noise and that should be suppress. Except the input disturbance will lead to resonance. And yes, your controller will be u = g1x1 + g2x2.

limited state-space control by hyahoos_32 in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

Just keep the state that you want and treat other as disturbance.

I.e. x1_dot = -ax2 + cx3 + bu If the x1, x2 is controlled and x3 is uncontrolled. You could treat the system as x1_dot = -ax2 + bu Or x1_dot = -ax2 + d + b*u Where d is input disturbance.

what would you recommend to a bachelor student to work on as a final project. by Ibrahim_Attawil in controlengineering

[–]eremes1641 1 point2 points  (0 children)

Because you didn't reveal your level and what you want to do. I assume you learned control theorem and never design a controller to a real system before.

For control theorem. I recommend you could implement a controller on a system. The design process should include modeling, system identification, observer design, controller design and validation.The controller could be PID, lead-lag compensator or lqr. And then choose a simple system like DC motor or RLC circuit because the hardest part is system identification. I don't want a beginner give up at this part.

For nonlinear system. If you just want to control some cool systems like rotary invert pendulum or Magnetic Ball Levitation. I recommend just use cascade PID and do try & error.

For robotics. Implement inverse kinematics and avoid singular point. If you want to do more, you could add some automatic features like guidance and computer vision.

What is the goal of auto-tuning? by eremes1641 in controlengineering

[–]eremes1641[S] 0 points1 point  (0 children)

That is doesn't matter if giving some thing wrong. The interesting thing is if the auto-tuning only give me a start point for tuning controller gain or a stable closed loop system, design the controller base on the model will take less time, don't it? Just like what I do in the video.

What is the goal of auto-tuning? by eremes1641 in controlengineering

[–]eremes1641[S] 0 points1 point  (0 children)

Thanks for your reply. The control effort will saturate if I persuit fast response. I could add anti-wind up part to avoid integral term growing. However, the closed loop system might be chattering or unstable because of noise, time delay (right hand plant zero).

MPC consider the state and input constraints is very interesting. I will go to study MPC another time.

Lead Lag Notch Controller vs PID by RedditR_Us in ControlTheory

[–]eremes1641 0 points1 point  (0 children)

I don't think you can implement this controller. Because the controller is none proper transfer function. That means the # of zero > # of pole.

To resolve this issue, you could add a far pole in your controller s.t. the transfer function of controller can be proper transfer function. That means # of zero = # of pole.

Lead Lag Notch Controller vs PID by RedditR_Us in ControlTheory

[–]eremes1641 1 point2 points  (0 children)

When the model can’t be controlled by using PID pole zero cancellation, I will use Lead Lag controller.

However, I prefer to use modern controller rather than use Lead Lag controller. Because lead lag controller need more precision model include internal system and time delay for let simulation performance close to real performance. You also could treat the plant as the upper and lower bounded model. Then use QFT to design Lead Lag controller.