diff options
33 files changed, 736 insertions, 16 deletions
diff --git a/includes/lapack.h b/includes/lapack.h index 97576a6..ba568ce 100644 --- a/includes/lapack.h +++ b/includes/lapack.h @@ -180,6 +180,11 @@ extern int dgges_(char*,char*,char*,LAPACK_D_SELECT3,int*,double*,int*,double*,i int*,double*,double*,double*,double*,int*,double*,int*,double*, int*, \ int*,int*); +/*used in matrix balancing*/ +extern int dgebal_(char*,int*,double*,int*,int*,int*,double*,int*); +extern int dggbal_(char*,int*,double*,int*,double*,int*,int*,int*,double*, \ + double*,double*,int*); +extern int dgebak_(char*,char*,int*,int*,int*,double*,int*,double*,int*,int*); #ifdef __cplusplus } /* extern "C" */ diff --git a/includes/sci2clib.h b/includes/sci2clib.h index 1bc3371..d9de9a0 100644 --- a/includes/sci2clib.h +++ b/includes/sci2clib.h @@ -381,10 +381,20 @@ extern "C" { #include "int_lqr.h" #include "lqe.h" -#include "int_lqe.h" +#include "int_lqe.h" + +#include "obscont.h" +#include "int_obscont.h" #include "schur.h" -#include "int_schur.h" +#include "int_schur.h" + +#include "balanc.h" +#include "int_balanc.h" + +#include "rcond.h" +#include "int_rcond.h" + /*Functions related to opencv*/ /*#include "cvcore.hpp" #include "int_cvcore.hpp" diff --git a/macros/ASTManagement/AST2Ccode.bin b/macros/ASTManagement/AST2Ccode.bin Binary files differindex f931fd3..e5e0780 100644 --- a/macros/ASTManagement/AST2Ccode.bin +++ b/macros/ASTManagement/AST2Ccode.bin diff --git a/macros/ASTManagement/AST2Ccode.sci b/macros/ASTManagement/AST2Ccode.sci index b42fe95..8076d7e 100644 --- a/macros/ASTManagement/AST2Ccode.sci +++ b/macros/ASTManagement/AST2Ccode.sci @@ -153,10 +153,10 @@ while ~meof(fidAST) SharedInfo.Equal.Lhs = 1; // 1 means that we are inside the Lhs block of the Equal [EqualInArgName,EqualInArgScope,EqualNInArg] = AST_ReadEqualRhsNames(FileInfo,SharedInfo); - lengthNumber = length('Number_'); - if (part(EqualInArgScope,1:lengthNumber) == 'Number_') - SharedInfo.SkipNextEqual = 1 - end + // lengthNumber = length('Number_'); + // if (part(EqualInArgScope,1:lengthNumber) == 'Number_') + // SharedInfo.SkipNextEqual = 1 + // end SharedInfo.Equal.NInArg = EqualNInArg; for tmpcnt = 1:SharedInfo.Equal.NInArg SharedInfo.Equal.InArg(tmpcnt).Name = EqualInArgName(tmpcnt); diff --git a/macros/FunctionAnnotation/FA_SZ_OBSCNT.bin b/macros/FunctionAnnotation/FA_SZ_OBSCNT.bin Binary files differnew file mode 100644 index 0000000..70ce8df --- /dev/null +++ b/macros/FunctionAnnotation/FA_SZ_OBSCNT.bin diff --git a/macros/FunctionAnnotation/FA_SZ_OBSCNT.sci b/macros/FunctionAnnotation/FA_SZ_OBSCNT.sci new file mode 100644 index 0000000..80c0f95 --- /dev/null +++ b/macros/FunctionAnnotation/FA_SZ_OBSCNT.sci @@ -0,0 +1,17 @@ +function outsize = FA_SZ_OBSCNT(inval,insz1,insz2,nout) + + inval = eval(inval); + insz1 = eval(insz1); + insz2 = eval(insz2); + //nout = eval(nout); + no_of_st = int(inval); + no_of_in = insz2 - no_of_st; + no_of_op = insz1 - no_of_st; + if(nout == 1) + outsize(1) = string(no_of_st+no_of_op+2); + outsize(2) = string(no_of_st+no_of_in); + else + outsize(1) = string(no_of_st+no_of_in+no_of_op+2); + outsize(2) = string(no_of_st+no_of_in+no_of_op); + end +endfunction diff --git a/macros/FunctionAnnotation/lib b/macros/FunctionAnnotation/lib Binary files differindex 4053992..b36e12c 100644 --- a/macros/FunctionAnnotation/lib +++ b/macros/FunctionAnnotation/lib diff --git a/macros/FunctionAnnotation/names b/macros/FunctionAnnotation/names index e072098..3386d8e 100644 --- a/macros/FunctionAnnotation/names +++ b/macros/FunctionAnnotation/names @@ -21,6 +21,7 @@ FA_SZ_FROM_VAL FA_SZ_LINSPACE_ROW FA_SZ_LQE FA_SZ_LQR +FA_SZ_OBSCNT FA_SZ_OPAPEX FA_SZ_OPBACKSLASH FA_SZ_OPCC diff --git a/macros/Hardware/RasberryPi/RPI_DigitalIn.bin b/macros/Hardware/RasberryPi/RPI_DigitalIn.bin Binary files differindex ec8fd0d..f4c16f3 100644 --- a/macros/Hardware/RasberryPi/RPI_DigitalIn.bin +++ b/macros/Hardware/RasberryPi/RPI_DigitalIn.bin diff --git a/macros/Hardware/RasberryPi/RPI_DigitalIn.sci b/macros/Hardware/RasberryPi/RPI_DigitalIn.sci index 8775e4c..4df03f6 100644 --- a/macros/Hardware/RasberryPi/RPI_DigitalIn.sci +++ b/macros/Hardware/RasberryPi/RPI_DigitalIn.sci @@ -22,7 +22,8 @@ function state = RPI_DigitalIn(pin) // // ----------------------------------------------------------------- //Pins of header P1 which can be used as GPIO -supported_pins = [3,5,7,8,10,11,12,13,15,16,18,19,21,22,23,24,26] +supported_pins = [3,5,7,8,10,11,12,13,15,16,18,19,21,22,23,24,26,27,28,29,... + 31,31,33,35,36,37,38,40]; PinIsGPIO = members(pin, supported_pins); //Check if input pin supports GPIO diff --git a/macros/SymbolTable/ST_GetInArgInfo.bin b/macros/SymbolTable/ST_GetInArgInfo.bin Binary files differindex 4a31617..6eb16e3 100644 --- a/macros/SymbolTable/ST_GetInArgInfo.bin +++ b/macros/SymbolTable/ST_GetInArgInfo.bin diff --git a/macros/SymbolTable/ST_GetInArgInfo.sci b/macros/SymbolTable/ST_GetInArgInfo.sci index a81c115..9f5cbd4 100644 --- a/macros/SymbolTable/ST_GetInArgInfo.sci +++ b/macros/SymbolTable/ST_GetInArgInfo.sci @@ -129,6 +129,7 @@ for cntinarg = 1:NInArg PrintStringInfo('Input Argument '+string(cntinarg)+' is a symbol: '+tmpname+'.',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file');
// #RNU_RES_E
[TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ST_GetSymbolInfo(tmpname,FileInfo,SharedInfo);
+
if (TBFlagfound == 0)
if(ASTFunName == 'ode')
if((NInArg == 4 & cntinarg == 4) | (NInArg == 6 & cntinarg == 6))
diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin Binary files differindex ae688b2..bcc63fc 100644 --- a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin +++ b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.bin diff --git a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci index bcf2670..4afbbe6 100644 --- a/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci +++ b/macros/ToolInitialization/INIT_FillSCI2LibCDirs.sci @@ -6168,6 +6168,112 @@ PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file', INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+//------------------------------------
+//---- Class obscont -----------------
+//------------------------------------
+ClassName = 'OBSCONT';
+
+// --- Class Annotation. ---
+PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y');
+ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls);
+
+PrintStringInfo('NIN= 3',ClassFileName,'file','y');
+PrintStringInfo('NOUT= 1',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).TP= ''d''',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(1)= FA_SZ_1(FA_SZ_OBSCNT(IN(1).VAL,IN(1).SZ(1), ...
+ IN(1).SZ(2),NOutArg))',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(2)= FA_SZ_2(FA_SZ_OBSCNT(IN(1).VAL,IN(1).SZ(1), ...
+ IN(1).SZ(2),NOutArg))',ClassFileName,'file','y');
+
+PrintStringInfo('NIN= 3',ClassFileName,'file','y');
+PrintStringInfo('NOUT= 2',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).TP= ''d''',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(1)= FA_SZ_1(FA_SZ_OBSCNT(IN(1).VAL,IN(1).SZ(1), ...
+ IN(1).SZ(2),NOutArg))',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(2)= FA_SZ_2(FA_SZ_OBSCNT(IN(1).VAL,IN(1).SZ(1), ...
+ IN(1).SZ(2),NOutArg))',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).TP= ''d''',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).SZ(1)= ''1''',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).SZ(2)= ''2''',ClassFileName,'file','y');
+
+ClassFileName = fullfile(SCI2CLibCFLClsDir,ClassName+ExtensionCFuncListCls);
+PrintStringInfo('ss2d2d2'+ArgSeparator+'d2',ClassFileName,'file','y');
+PrintStringInfo('ss2d2d2'+ArgSeparator+'d2d2',ClassFileName,'file','y');
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'obscont';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
+
+//------------------------------------
+//---- Class balanc ------------------
+//------------------------------------
+ClassName = 'BALANC';
+
+// --- Class Annotation. ---
+PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y');
+ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls);
+
+PrintStringInfo('NIN= 1',ClassFileName,'file','y');
+PrintStringInfo('NOUT= 2',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).TP= IN(1).TP',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(1)= IN(1).SZ(1)',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(2)= IN(1).SZ(2)',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).TP= IN(1).TP',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).SZ(1)= IN(1).SZ(1)',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).SZ(2)= IN(1).SZ(2)',ClassFileName,'file','y');
+
+PrintStringInfo('NIN= 2',ClassFileName,'file','y');
+PrintStringInfo('NOUT= 4',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).TP= IN(1).TP',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(1)= IN(1).SZ(1)',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(2)= IN(1).SZ(2)',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).TP= IN(1).TP',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).SZ(1)= IN(1).SZ(1)',ClassFileName,'file','y');
+PrintStringInfo('OUT(2).SZ(2)= IN(1).SZ(2)',ClassFileName,'file','y');
+PrintStringInfo('OUT(3).TP= IN(1).TP',ClassFileName,'file','y');
+PrintStringInfo('OUT(3).SZ(1)= IN(1).SZ(1)',ClassFileName,'file','y');
+PrintStringInfo('OUT(3).SZ(2)= IN(1).SZ(2)',ClassFileName,'file','y');
+PrintStringInfo('OUT(4).TP= IN(1).TP',ClassFileName,'file','y');
+PrintStringInfo('OUT(4).SZ(1)= IN(1).SZ(1)',ClassFileName,'file','y');
+PrintStringInfo('OUT(4).SZ(2)= IN(1).SZ(2)',ClassFileName,'file','y');
+
+ClassFileName = fullfile(SCI2CLibCFLClsDir,ClassName+ExtensionCFuncListCls);
+PrintStringInfo('d2'+ArgSeparator+'d2d2',ClassFileName,'file','y');
+PrintStringInfo('d2d2'+ArgSeparator+'d2d2d2d2',ClassFileName,'file','y');
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'balanc';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
+//------------------------------------
+//---- Class RCOND -------------------
+//------------------------------------
+ClassName = 'RCOND';
+
+// --- Class Annotation. ---
+PrintStringInfo(' Adding Class: '+ClassName+'.',GeneralReport,'file','y');
+ClassFileName = fullfile(SCI2CLibCAnnClsDir,ClassName+ExtensionCAnnCls);
+
+PrintStringInfo('NIN= 1',ClassFileName,'file','y');
+PrintStringInfo('NOUT= 1',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).TP= ''d''',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(1)= ''1''',ClassFileName,'file','y');
+PrintStringInfo('OUT(1).SZ(2)= ''1''',ClassFileName,'file','y');
+
+ClassFileName = fullfile(SCI2CLibCFLClsDir,ClassName+ExtensionCFuncListCls);
+PrintStringInfo('d2'+ArgSeparator+'d0',ClassFileName,'file','y');
+
+// --- Annotation Function And Function List Function. ---
+FunctionName = 'rcond';
+PrintStringInfo(' Adding Function: '+FunctionName+'.',GeneralReport,'file','y');
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCAnnFunDir,ClassName,GeneralReport,ExtensionCAnnFun);
+INIT_GenAnnFLFunctions(FunctionName,SCI2CLibCFLFunDir,ClassName,GeneralReport,ExtensionCFuncListFun);
+
// ////////////////////////////////////////////
// /////PARTE INTRODOTTA DA ALBERTO MOREA
// /////////////////////////////////////////////
diff --git a/macros/findDeps/getAllHeaders.bin b/macros/findDeps/getAllHeaders.bin Binary files differindex f5bb98e..8ba5545 100644 --- a/macros/findDeps/getAllHeaders.bin +++ b/macros/findDeps/getAllHeaders.bin diff --git a/macros/findDeps/getAllHeaders.sci b/macros/findDeps/getAllHeaders.sci index b37f3e5..50ee358 100644 --- a/macros/findDeps/getAllHeaders.sci +++ b/macros/findDeps/getAllHeaders.sci @@ -151,7 +151,10 @@ function allHeaders = getAllHeaders(SharedInfo) "src/c/CACSD/includes/syslin.h" "src/c/CACSD/includes/lqr.h" "src/c/CACSD/includes/lqe.h" - "src/c/linearAlgebra/includes/schur.h"]; + "src/c/CACSD/includes/obscont.h" + "src/c/linearAlgebra/includes/schur.h" + "src/c/linearAlgebra/includes/balanc.h" + "src/c/linearAlgebra/includes/rcond.h"]; //Header files required for "Arduino" output Arduino_headers = [ diff --git a/macros/findDeps/getAllInterfaces.bin b/macros/findDeps/getAllInterfaces.bin Binary files differindex da506e8..66d7e55 100644 --- a/macros/findDeps/getAllInterfaces.bin +++ b/macros/findDeps/getAllInterfaces.bin diff --git a/macros/findDeps/getAllInterfaces.sci b/macros/findDeps/getAllInterfaces.sci index 32a0c6b..92f4db9 100644 --- a/macros/findDeps/getAllInterfaces.sci +++ b/macros/findDeps/getAllInterfaces.sci @@ -146,7 +146,10 @@ function allInterfaces = getAllInterfaces(SharedInfo) "src/c/CACSD/interfaces/int_syslin.h" "src/c/CACSD/interfaces/int_lqr.h" "src/c/CACSD/interfaces/int_lqe.h" - "src/c/linearAlgebra/interfaces/int_schur.h"]; + "src/c/CACSD/interfaces/int_obscont.h" + "src/c/linearAlgebra/interfaces/int_schur.h" + "src/c/linearAlgebra/interfaces/int_balanc.h" + "src/c/linearAlgebra/interfaces/int_rcond.h"]; //Interface files required for "Arduino" output Arduino_interfaces = [ diff --git a/macros/findDeps/getAllSources.bin b/macros/findDeps/getAllSources.bin Binary files differindex aa5d474..e233504 100644 --- a/macros/findDeps/getAllSources.bin +++ b/macros/findDeps/getAllSources.bin diff --git a/macros/findDeps/getAllSources.sci b/macros/findDeps/getAllSources.sci index 3f789b4..624de4b 100644 --- a/macros/findDeps/getAllSources.sci +++ b/macros/findDeps/getAllSources.sci @@ -981,8 +981,11 @@ function allSources = getAllSources(SharedInfo) "src/c/CACSD/syslin/dsyslina.c" "src/c/CACSD/lqr/dlqra.c" "src/c/CACSD/lqe/dlqea.c" + "src/c/CACSD/obscont/dobsconta.c" "src/c/linearAlgebra/schur/dschura.c" - "src/c/linearAlgebra/schur/dgschura.c"]; + "src/c/linearAlgebra/schur/dgschura.c" + "src/c/linearAlgebra/balanc/dbalanca.c" + "src/c/linearAlgebra/rcond/drconda.c"]; //Files to be inserted only if output format selected is 'Arduino'. Arduino_files = ["src/c/scilab-arduino/cmd_digital_out/u8cmd_digital_outs.c" diff --git a/src/c/CACSD/includes/obscont.h b/src/c/CACSD/includes/obscont.h new file mode 100644 index 0000000..f316adb --- /dev/null +++ b/src/c/CACSD/includes/obscont.h @@ -0,0 +1,28 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __OBSCONT_H__ +#define __OBSCONT_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +void dobsconta(double* sys, int sys_rows, int sys_cols, double* Kc, double* Kf, \ + double *K, double *r); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__OBSCONT_H__*/ diff --git a/src/c/CACSD/interfaces/int_obscont.h b/src/c/CACSD/interfaces/int_obscont.h new file mode 100644 index 0000000..fd3a823 --- /dev/null +++ b/src/c/CACSD/interfaces/int_obscont.h @@ -0,0 +1,29 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_OBSCONT_H__ +#define __INT_OBSCONT_H__ + + #ifdef __cplusplus + extern "C" { + #endif + +#define ss2d2d2obscontd2(in1,size1,in2,size2,in3,size3,out) \ + dobsconta(in1,size1[0],size1[1],in2,in3,out,NULL) + +#define ss2d2d2obscontd2d2(in1,size1,in2,size2,in3,size3,out1,out2) \ + dobsconta(in1,size1[0],size1[1],in2,in3,out1,out2) + + #ifdef __cplusplus + } /* extern "C" */ + #endif + +#endif /*__INT_OBSCONT_H__*/ diff --git a/src/c/CACSD/obscont/dobsconta.c b/src/c/CACSD/obscont/dobsconta.c new file mode 100644 index 0000000..7e29752 --- /dev/null +++ b/src/c/CACSD/obscont/dobsconta.c @@ -0,0 +1,284 @@ +/* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + +/*Function for calculating observer controller. + Refer 'obscont.sci' in scilab source.*/ + +#include <stdlib.h> +#include "matrixMultiplication.h" +#include "addition.h" + +void dobsconta(double* sys, int sys_rows, int sys_cols, double* Kc, double* Kf, \ + double *K, double *r) +{ + int no_of_states, no_of_inputs, no_of_outputs, dom = 1; + int row,col; + no_of_states = sys[sys_rows*(sys_cols-1)]; + no_of_inputs = sys[sys_rows*(sys_cols-1) + 1]; + no_of_outputs = sys_rows - no_of_states; + + int no_of_cols; + int no_of_rows; + + double *A, *B, *C, *D; + double *BKc, *KfC, *KfD,*DKc; + double *buf, *buf1, *buf2; + + A = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + B = (double*) malloc (no_of_states*no_of_inputs*sizeof(double)); + C = (double*) malloc (no_of_states*no_of_outputs*sizeof(double)); + D = (double*) malloc (no_of_inputs*no_of_outputs*sizeof(double)); + + BKc = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + KfC = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + KfD = (double*) malloc (no_of_states*no_of_inputs*sizeof(double)); + DKc = (double*) malloc (no_of_outputs*no_of_states*sizeof(double)); + buf = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + buf1 = (double*) malloc (no_of_states*no_of_inputs*sizeof(double)); + buf2 = (double*) malloc (no_of_outputs*no_of_states*sizeof(double)); + + /*Get A from system matrix*/ + for(col = 0; col < no_of_states; col++) + { + for(row = 0; row < no_of_states; row++) + { + A[col*no_of_states + row] = sys[col*sys_rows + row]; + } + } + + /*Get matrix B from system matrix*/ + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + B[col * no_of_states + row] = \ + sys[col * sys_rows + no_of_states*sys_rows + row]; + } + } + + /*Get matrix C from system matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + C[col * no_of_outputs + row] = \ + sys[no_of_states + (col*sys_rows) + row]; + } + } + + /*Get matrix D from system matrix*/ + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + D[col * no_of_outputs + row] = \ + sys[(no_of_states+col)*sys_rows + no_of_states + row]; + } + } + + dom = sys[(sys_rows*(sys_cols-2)) + no_of_states]; + + dmulma(B,no_of_states,no_of_inputs,Kc,no_of_inputs,no_of_states,BKc); + dmulma(Kf,no_of_states,no_of_outputs,C,no_of_outputs,no_of_states,KfC); + dmulma(Kf,no_of_states,no_of_outputs,D,no_of_outputs,no_of_inputs,KfD); + + /*Variables are reused to save memory*/ + /*A+BKc*/ + dadda(A,no_of_states*no_of_states,BKc,no_of_states*no_of_states,buf); + /*A+BKc+KfC*/ + dadda(KfC,no_of_states*no_of_states,buf,no_of_states*no_of_states,A); + /*KfDKc*/ + dmulma(KfD,no_of_states,no_of_inputs,Kc,no_of_inputs,no_of_states,BKc); + /*A+BKc+KfC+KfDKc*/ + dadda(A,no_of_states*no_of_states,BKc,no_of_states*no_of_states,buf); + + /*Dimensions of K*/ + no_of_cols = no_of_states + no_of_inputs + 2; + no_of_rows = no_of_states + no_of_outputs; + + if(r == NULL) + { + /*Dimensions of K*/ + no_of_cols = no_of_states + no_of_outputs + 2; + no_of_rows = no_of_states + no_of_inputs; + + for(col = 0; col < no_of_states; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col*no_of_rows + row] = buf[col*no_of_states + row]; + } + + } + + /*Copy matrix -Kf in out matrix*/ + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col * no_of_rows + no_of_states*no_of_rows + row] \ + = -1.0*Kf[col * no_of_states + row]; + } + } + + /*Copy matrix Kc in out matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + K[no_of_states + (col*no_of_rows) + row] = Kc[col * no_of_inputs + row]; + } + } + + K[(no_of_rows*(no_of_cols-2)) + no_of_states] = dom; + /*Insert no of states and inputs in last column*/ + K[(no_of_rows*(no_of_cols-1))] = no_of_states; + K[(no_of_rows*(no_of_cols-1))+1] = no_of_outputs; + /*For K, no_of_outputs is no of inputs*/ + + } + else + { + /*Dimensions of K*/ + no_of_cols = no_of_states + no_of_inputs + no_of_outputs + 2; + no_of_rows = no_of_states + no_of_outputs + no_of_inputs; + + r[0] = no_of_outputs; + r[1] = no_of_inputs; + + for(col = 0; col < no_of_states; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col*no_of_rows + row] = buf[col*no_of_states + row]; + } + + } + + /*Copy matrix -Kf in out matrix*/ + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col * no_of_rows + no_of_states*no_of_rows + row] \ + = -1.0*Kf[col * no_of_states + row]; + } + } + + /*B+Kf*D*/ + dadda(B,no_of_states*no_of_inputs,KfD,no_of_states*no_of_inputs,buf1); + + /*Copy matrix (B+KfD) in out matrix*/ + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col * no_of_rows + (no_of_states+no_of_outputs)*no_of_rows \ + + row] = buf1[col * no_of_states + row]; + } + } + + /*DKc*/ + dmulma(D,no_of_outputs,no_of_inputs,Kc,no_of_inputs,no_of_states,DKc); + /*C+DKc*/ + dadda(C,no_of_outputs*no_of_states,DKc,no_of_outputs*no_of_states,buf2); + + /*Copy matrix Kc in out matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + K[no_of_states + (col*no_of_rows) + row] \ + = Kc[col * no_of_inputs + row]; + } + } + + /*Copy -(C+DKc) in out matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + K[(no_of_states+no_of_inputs) + (col*no_of_rows) + row] \ + = -1.0*buf2[col * no_of_outputs + row]; + } + } + + /*Block 22 for K*/ + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + K[no_of_states + (col*no_of_rows) + no_of_states*no_of_rows \ + + row] = 0; + } + } + + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + if(row == col) + K[no_of_states + (col*no_of_rows) + \ + (no_of_states+no_of_outputs)*no_of_rows + row] = 1; + else + K[no_of_states + (col*no_of_rows) + \ + (no_of_states+no_of_outputs)*no_of_rows + row] = 0; + } + } + + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + if(row == col) + K[no_of_states + no_of_inputs + (col*no_of_rows) + \ + no_of_states*no_of_rows + row] = 1; + else + K[no_of_states + no_of_inputs + (col*no_of_rows) + \ + no_of_states*no_of_rows + row] = 0; + } + } + + + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + K[no_of_states + no_of_inputs + (col*no_of_rows) + \ + (no_of_states+no_of_outputs)*no_of_rows + row] \ + = -1.0*D[col*no_of_inputs + row]; + } + } + + + K[(no_of_rows*(no_of_cols-2))+ no_of_states] = dom; + /*Insert no of states and inputs in last column*/ + K[(no_of_rows*(no_of_cols-1))] = no_of_states; + K[(no_of_rows*(no_of_cols-1))+1] = no_of_outputs + no_of_inputs; + /*For K, (no_of_outputs+no_of_inputs) is no of inputs*/ + + + } + + + free(A); + free(B); + free(C); + free(D); + free(BKc); + free(KfC); + free(KfD); + free(DKc); + free(buf); + free(buf1); + free(buf2); +} diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c index fa86025..f5fefe0 100644 --- a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c +++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c @@ -21,9 +21,10 @@ /*This array maps pin numbers on RPi board, with pin numbers corrsponding to WiringPi library*/ -int phy_pin[] = {17, 17, 8, 17, 9, 17, 7, 15, 17, 16, /*Pin 1 to 10*/ - 0, 1, 2, 17, 3, 4, 17, 5, 12, 17, /*Pin 11 to 20*/ - 13, 6, 14, 10, 17, 11 }; /*Pin 21 to 26*/ +int phy_pin[] = {17, 17, 8, 17, 9, 17, 7, 15, 17, 16, /*Pin 1 to 10*/ + 0, 1, 2, 17, 3, 4, 17, 5, 12, 17, /*Pin 11 to 20*/ + 13, 6, 14, 10, 17, 11, 30, 31, 21, 17, /*Pin 21 to 30*/ + 22, 26, 23, 17, 24, 27, 25, 28, 17, 29 }; /*Pin 31 to 40*/ /*pin is reduced by one as arrayiindex starts from 0 and pin no starts from 1*/ void u8RPIDigitalSetups(uint8 pin, uint8 direction) diff --git a/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h b/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h index 76a229e..14df95b 100644 --- a/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h +++ b/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h @@ -29,13 +29,13 @@ void u16RPISerialSendDatas(int fd, uint16 data); void i16RPISerialSendDatas(int fd, int16 data); void sRPISerialSendDatas(int fd, float data); void dRPISerialSendDatas(int fd, double data); -void u8RPISerialSendDataa(int fd, void* data, int size); +void u8RPISerialSendDataa(int fd, uint8* data, int size); void i8RPISerialSendDataa(int fd, int8* data, int size); void u16RPISerialSendDataa(int fd, uint16* data, int size); void i16RPISerialSendDataa(int fd, int16* data, int size); void sRPISerialSendDataa(int fd, float* data, int size); void dRPISerialSendDataa(int fd, double* data, int size); -void gRPISerialSendDatas(int fd, void* data, int size); +void gRPISerialSendDatas(int fd, uint8* data, int size); int16 i16RPISerialDataAvails(int fd); int16 i16RPISerialGetChars(int fd); diff --git a/src/c/hardware/rasberrypi/serial/u8RPISerialSetups.c b/src/c/hardware/rasberrypi/serial/u16RPISerialSetups.c index cde4cba..cde4cba 100644 --- a/src/c/hardware/rasberrypi/serial/u8RPISerialSetups.c +++ b/src/c/hardware/rasberrypi/serial/u16RPISerialSetups.c diff --git a/src/c/linearAlgebra/balanc/dbalanca.c b/src/c/linearAlgebra/balanc/dbalanca.c new file mode 100644 index 0000000..558c614 --- /dev/null +++ b/src/c/linearAlgebra/balanc/dbalanca.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ + +/*Funtion to balance given square matrix to improve its condition number*/ +#include "balanc.h" +#include "lapack.h" +#include "stdlib.h" +#include "string.h" +#include "eye.h" + +void dbalanca(double* in1, int rows, double* in2, double* out1, \ + double* out2, double* out3, double* out4) +{ + char JOB = 'B'; + char RSIDE = 'R'; + char LSIDE = 'L'; + + int ILO, IHI, INFO; + double *buf1, *buf2, *LSCALE, *RSCALE; + double *LWORK; + + + if(in2 == NULL) + { + /*Single input matrix*/ + buf1 = (double*) malloc((double) rows*rows*sizeof(double)); + LSCALE = (double*) malloc((double) rows*sizeof(double)); + + /*copy input to temp buf as lapack function modifies input*/ + memcpy(buf1,in1,rows*rows*sizeof(double)); + + dgebal_(&JOB,&rows,buf1,&rows,&ILO,&IHI,LSCALE,&INFO); + deyea(out2,rows,rows); + dgebak_(&JOB,&RSIDE,&rows,&ILO,&IHI,LSCALE,&rows,out2,&rows,&INFO); + + /*copy computed matrix to output*/ + memcpy(out1,buf1,rows*rows*sizeof(double)); + } + else + { + /*two matrices as inputs*/ + buf1 = (double*) malloc((double) rows*rows*sizeof(double)); + buf2 = (double*) malloc((double) rows*rows*sizeof(double)); + LSCALE = (double*) malloc((double) rows*sizeof(double)); + RSCALE = (double*) malloc((double) rows*sizeof(double)); + LWORK = (double*) malloc((double) 6*rows*sizeof(double)); + + /*copy input to temp buf as lapack function modifies input*/ + memcpy(buf1,in1,rows*rows*sizeof(double)); + memcpy(buf2,in2,rows*rows*sizeof(double)); + + dggbal_(&JOB,&rows,buf1,&rows,buf2,&rows,&ILO,&IHI,LSCALE,RSCALE, \ + LWORK,INFO); + deyea(out3,rows,rows); + deyea(out4,rows,rows); + + dgebak_(&JOB,&LSIDE,&rows,&ILO,&IHI,LSCALE,&rows,out3,&rows,&INFO); + dgebak_(&JOB,&RSIDE,&rows,&ILO,&IHI,LSCALE,&rows,out4,&rows,&INFO); + + /*copy computed matrix to output*/ + memcpy(out1,buf1,rows*rows*sizeof(double)); + memcpy(out2,buf2,rows*rows*sizeof(double)); + + } + +}
\ No newline at end of file diff --git a/src/c/linearAlgebra/includes/balanc.h b/src/c/linearAlgebra/includes/balanc.h new file mode 100644 index 0000000..dcc66b2 --- /dev/null +++ b/src/c/linearAlgebra/includes/balanc.h @@ -0,0 +1,27 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __BALANC_H__ +#define __BALANC_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +void dbalanca(double* in1, int rows, double* in2, double* out1, \ + double* out2, double* out3, double* out4); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__BALANC_H__*/ diff --git a/src/c/linearAlgebra/includes/rcond.h b/src/c/linearAlgebra/includes/rcond.h new file mode 100644 index 0000000..4796f02 --- /dev/null +++ b/src/c/linearAlgebra/includes/rcond.h @@ -0,0 +1,26 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __RCOND_H__ +#define __RCOND_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +double drconda(double* in1, int rows); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__RCOND_H__*/ diff --git a/src/c/linearAlgebra/interfaces/int_balanc.h b/src/c/linearAlgebra/interfaces/int_balanc.h new file mode 100644 index 0000000..a16ba8c --- /dev/null +++ b/src/c/linearAlgebra/interfaces/int_balanc.h @@ -0,0 +1,29 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_BALANC_H__ +#define __INT_BALANC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define d2balancd2d2(in1,size1,out1,out2) dbalanca(in1,size1[0],NULL,out1, \ + out2,NULL,NULL) + +#define d2d2balancd2d2d2d2(in1,size1,in2,size2,out1,out2,out3,out4) \ + dbalanca(in1,size1[0],in2,out1,out2,out3,out4) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__INT_BALANC_H__*/ diff --git a/src/c/linearAlgebra/interfaces/int_rcond.h b/src/c/linearAlgebra/interfaces/int_rcond.h new file mode 100644 index 0000000..6e6a445 --- /dev/null +++ b/src/c/linearAlgebra/interfaces/int_rcond.h @@ -0,0 +1,25 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_RCOND_H__ +#define __INT_RCOND_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define d2rcondd0(in1,size1) drconda(in1,size1[0]) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__INT_RCOND_H__*/ diff --git a/src/c/linearAlgebra/rcond/drconda.c b/src/c/linearAlgebra/rcond/drconda.c new file mode 100644 index 0000000..2082e9d --- /dev/null +++ b/src/c/linearAlgebra/rcond/drconda.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ + +/*Funtion to find inverse condition number of square matrix*/ + +#include "lapack.h" +#include "stdlib.h" +#include "string.h" + +double drconda(double* in1, int rows) +{ + double *buf, *IPIV, *LDWORK, *LIWORK; + int INFO; + char one = '1'; + double ANORM; + double RCOND = 1; + + buf = (double*) malloc((double) rows*rows*sizeof(double)); + IPIV = (double*) malloc((double) rows*sizeof(double)); + LIWORK = (double*) malloc((double) rows*sizeof(double)); + LDWORK = (double*) malloc((double) 4*rows*sizeof(double)); + + /*Copy input in temp buf, as lapack modifies input*/ + memcpy(buf,in1,rows*rows*sizeof(double)); + + ANORM = dlange_(&one,&rows,&rows,buf,&rows,LDWORK); + + dgetrf_(&rows,&rows,buf,&rows,IPIV,&INFO); + + if(INFO == 0) + { + dgecon_(&one,&rows,buf,&rows,&ANORM,&RCOND,LDWORK,LIWORK,&INFO); + } + + return RCOND; + +}
\ No newline at end of file diff --git a/src/c/linearAlgebra/schur/dschura.c b/src/c/linearAlgebra/schur/dschura.c index 79c4197..802caa8 100644 --- a/src/c/linearAlgebra/schur/dschura.c +++ b/src/c/linearAlgebra/schur/dschura.c @@ -10,7 +10,7 @@ Email: toolbox@scilab.in */ -/*Fucntion to find schur decomposition of given square matrix */ +/*Funtion to find schur decomposition of given square matrix */ #include "schur.h" #include "lapack.h" #include "stdlib.h" |