CControl is a library written in 100% C code. No external libraries and 100% platform independent. The purpose with this library is to fit advanced tools for really small embedded systems or desktop as well. Here I have focused on practical numerical methods and selected the methods that works best in practice. It has been a lot of work finding the best methods and best algorithms.
Main focuses are:
-
Artificial Intelligence
- Astar algorithm for quick path finding
- Point-in-polygon algorithm for checking if a point is inside the area
-
Control Engineering
- Kalman filter update
- Linear Quadratic Integral regulator
- Model Predictive Control with linear programming
- Model Predictive Control with quadratic programming
- Model Reference Adaptive Control
- Transfer function to state space
- Stability check
- Continuous to discrete
-
Filtering
- Particle filter
- Filtfilt
- Square Root Unscented Kalman Filter
-
Linear Algebra
- Balance matrix
- Cholesky decomposition
- Cholesky update
- QR decomposition
- LUP decomposition
- Determinant
- Discrete Lyapunov solver
- Eigenvalues symmetric + Eigenvectors
- Random real eigenvalues and random imaginary eigenvalues
- Hankel matrix
- Inverse
- Pseudo inverse
- Linear solver
- Nonlinear solver
- Multiplication
- Singular Value Decomposition Golup Reinsch
- Singular Value Decomposition Jacobi One Sided
- Transpose
- Norm
- Matrix exponential
-
Miscellaneous
- Concatenate
- Cut matrix
- Insert sub matrix into matrix
- Print matrix or vector
- Saturation
- Sign
- Randn
- Mean
- Standard deviation
- Value min
- Value max
- Sort
- Sum
-
Optimization
- Linear programming maximization
- Linear programming minimization
- Quadratic programming
-
System Identification
- Observer Kalman Filter identification
- Eigensystem Realization Algorithm
- Recursive Least Square with forgetting factor and kalman filter identification
- Square Root Unscented Kalman Filter for parameter estimation
- I'd recommend
Eclipse IDE
for compiling this software.Eclipse IDE
is a very boring IDE, but it's robust and trustable. TheEclipse IDE
is always going to be available for you.
- Once you have
Eclipse IDE
installed. Show Git perspective.
- Select
Git
- Copy ssh
- Clone git. Just press next and end with finish
- Import project
- Show view
- Select
Git staging
- Every time you change a file and you want to update your repository
-
If you don't have a
C-compiler
, here is a video how to set up a compiler -
Begin with your
main.c
file. Then go tosrc/CControl/Documents/Examples/
and select a.txt
file and paste it intomain.c
file and press
/*
============================================================================
Name : Main.c
Author : <Your Name Here>
Version : 1.0
Copyright : MIT
Description : Initial template
============================================================================
*/
#include "CControl/Headers/Functions.h"
int main() {
clock_t start, end;
float cpu_time_used;
start = clock();
/* Your logic here */
end = clock();
cpu_time_used = ((float) (end - start)) / CLOCKS_PER_SEC;
printf("\nTotal speed was %f\n", cpu_time_used);
return EXIT_SUCCESS;
}
Find a good pratical function that always comes in handy. An algorithm for example. When you writing your code, remember these steps:
- Use "valgrind --tool=exp-sgcheck ./CControl" to check if your output in Debug folder is correct. For windows users,
Dr.Memory
works too - Use pointers/arrays as much as you can
- No malloc, calloc or free - No dynamic memory allocation in other words
1D
arrays are only allowed. When you are indexing an1D
, then you usingmy_array[i*column_length + j]
wherei
is row index andj
is column index andcolumn_length
is column length ofmy_array
- Only
floats
are allowed because some processors don't havedouble
implemented C99
standard is only allowed because I want it to followMISRA C
standard as much as possible- Your code must come with an example
- Write
clean code
, that means no slack variables or unnecessary #defines, don't try to compute everything in one single functions, minimize input arguments if it's possible, focus on practical implementation, focus on memory
I have created a controller for a fan. The controller works as it read the temperature sensor and it compare the temperature sensor with the potentiometer, which is the reference set point. If the error is large between the temperature sensor and the potentiometer, then the fan is going to turn on high, or low, depending on if the error is negative or positive.
The goal with this system is that I'm going to implement this on a heat source. The fan is going to blow warm air onto a object and the object is holding the temperature sensor. If the fan is blowing to much warm air, then the controller is going to turn down the speed of the fan so the temperature of the object meets the reference
I have been using Matavecontrol and Mataveid to estimate and creating the kalman gain matrix and the LQR control law with integral action. I'm the author of both Matavecontrol and Mataveid.
Identification process. Here I have using the Observer Kalman Filter Identification and Eigen System Realization methods.
Simulation process:
This is a Model Predictive Controller, with integral action. It uses linear programming instead of quadratic programming for the optimization. This controller works well.
This predictive controller have a wiring diagram if you want to build the same controller for your temperature project.
Step answer of first order model.
This is a MRAC project, Model Reference Adaptive Controller. This controls the a Sonceboz stepper motor with CAN-bus J1939-21 protocol. The purpose is to control a big wheel with two multivariable hydraulical valves.
See the movie in the project folder.
Library for SAE J1939 https://github.com/DanielMartensson/Open-SAE-J1939
This is the latest Uncented Kalman Filter. MATLAB is using the same algorithm. A .m
file is available at the SR-UKF
folder.
For state estimation
For parameter estimation