Giter VIP home page Giter VIP logo

ccontrol's Introduction

CControl

CControl is a library written in 100% ANSI C (C89) 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
  • Machine Learning

    • Robust Fisher Faces for image classification (ongoing)
    • Support Vector Machine
  • Control Engineering

    • Kalman filter update
    • Linear Quadratic Integral regulator
    • Model Predictive Control (Ongoing)
    • Model Reference Adaptive Control
    • Transfer function to state space
    • Stability check
    • Continuous to discrete
  • Filtering

    • Robust Principal Component Analysis
    • 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 and eigenvectors for symmetric matrices
    • Generalized eigenvalue problem for symmetric matrices
    • Eigenvalues and imaginary eigenvalues for general matrices
    • Hankel matrix
    • Inverse
    • Dot product
    • 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
    • Value min
    • Value max
    • Sort
    • Sum
  • Optimization

    • Linear programming
    • Non-Negative Least Squares
    • Quadratic programming
  • Statistics

    • Principal Component Analysis
    • Linear Discriminant Analysis
    • Randn
    • Mean
    • Standard deviation
    • Variance
    • Covariance
  • 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
/*
 ============================================================================
 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 ANSI C logic here - All examples can be found at the folder src/CControl/Documents/Examples */

	end = clock();
	cpu_time_used = ((float) (end - start)) / CLOCKS_PER_SEC;
	printf("\nTotal speed  was %f\n", cpu_time_used);


	return EXIT_SUCCESS;
}

TODO list

  • Change all vectors and matricies to size_t size from uint8_t, uint16_t and uint32_t size for more portability
  • All indexing and loop counting must have the data type size_t
  • Brackets { } for all statements
  • Rows are indexed with i and columns are indexed with j
  • All indexing of matricies should look like this
  • All integer constants must have U as ending
  • All floats constants must have f as ending
  • Matrix and vector operations must be optimal as possible, e.g.
/* Creating the identity matrix */
size_t i;
memset(A, 0U, row*column*sizeof(float)); 
float *A0 = A;
for(i = 0U; i < row; i++){
  A[i] = 1.0f;
  A += column;
}
A = A0;

Instead of

/* Creating the identity matrix */
size_t i, j;
memset(A, 0U, row*column*sizeof(float)); 
for(i = 0U; i < row; i++){
  for(j = 0U; j < column; j++){
    if(i == j){
      A[i*column + j] = 1.0f;
    }
  }
}
  • Integer multiplications such as row * columns must be of the data type size_t e.g size_t row_column = row*column;
  • Algorithms that need to have a signed variable e.g. linsolve_upper_triangular.c must be changed so they don't need a signed variable
  • Important to follow MISRA C standard as much as possible, even if this project is using dynamical memory allocation
  • uint8_t that either return the status 0 or 1 should be replaced with bool data type
  • Use a memory analyzer when running all the examples. Need to create a list of the status of all .c files.

Projects made with CControl

Fan Controller with Linear Quadratic Integral Control

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

a

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.

a

Simulation process:

a

Model Predictive Integral Temperature Controller

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.

a

a

Step answer of first order model.

a

Model Reference Adaptive CAN-bus controller

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

a

Square Root Uncented Kalman Filter for state estimation and parameter estimation

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

a

For parameter estimation

a

How to use this library with Eclipse CDT

I have made so both Microsoft Visual Studio users and Eclipce CDT can use this library without conflicts. Here is a tutorial how to configure your Eclipse CDT for this repository.

  1. I'd recommend Eclipse IDE for compiling this software. Eclipse IDE is a very boring IDE, but it's robust and trustable. The Eclipse IDE is always going to be available for you.

a

  1. Once you have Eclipse IDE installed. Show Git perspective.

a

  1. Select Git

a

  1. Copy ssh

a

  1. Clone git. Just press next and end with finish

a

  1. Import project

a

  1. Show view

a

  1. Select Git staging

a

  1. Every time you change a file and you want to update your repository

a

  1. If you don't have a C-compiler, here is a video how to set up a compiler

  2. Begin with your main.c file. Then go to src/CControl/Documents/Examples/ and select a .txt file and paste it into main.c file and press the green circle with a white triangle inside

  3. If you got problem with push your updates to this repository, the you need to configure your authorization. See this link

ccontrol's People

Contributors

danielmartensson avatar ooaj avatar pyxisgit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.