Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
Matrix.h
00001 #ifndef __DCM_MATRIX_H 00002 #define __DCM_MATRIX_H 00003 00004 /** Matrix math library */ 00005 00006 #define SINGULAR_MATRIX (1<<0) 00007 #define ERR1 (1<<1) 00008 #define ERR2 (1<<2) 00009 #define ERR3 (1<<3) 00010 00011 /** Take cross product of two 3x1 vectors: v1 x v2 = vectorOut 00012 * @param v1 is the first vector 00013 * @param v2 is the second vector 00014 * @returns vectorOut = v1 x v2 00015 */ 00016 void Vector_Cross_Product(float vectorOut[3], float v1[3], float v2[3]); 00017 00018 /** Multiple 3x1 vector by scalar: vectorOut = vectorIn times scale2 00019 * @param vectorIn the vector 00020 * @param scale2 is the scalar 00021 * @returns vectorOut the result 00022 */ 00023 void Vector_Scale(float vectorOut[3], float vectorIn[3], float scale2); 00024 00025 /** TDot product of two 3x1 vectors vector1 . vector2 00026 * @param vector1 is the first vector 00027 * @param vector2 is the second vector 00028 * @returns float result of dot product 00029 */ 00030 float Vector_Dot_Product(float vector1[3], float vector2[3]); 00031 00032 /** Adds two 3x1 vectors: vectorOut = vectorIn1 + vectorIn2 00033 * @param vectorIn1 is the first vector 00034 * @param vectorIn2 is the second vector 00035 * @returns vectorOut is the result of the addition 00036 */ 00037 void Vector_Add(float vectorOut[3], float vectorIn1[3], float vectorIn2[3]); 00038 00039 /** Adds two 3x3 matrices: C = A + B 00040 * @param A is the first vector 00041 * @param B is the second vector 00042 * @returns C is the result of the addition 00043 */ 00044 void Matrix_Add(float C[3][3], float A[3][3], float B[3][3]); 00045 00046 /** Adds two n x m matrices: C = A + B 00047 * @param A is the first vector 00048 * @param B is the second vector 00049 * @param n is the rows of A, B, C 00050 * @param m is the columns of A, B, C 00051 * @returns C is the result of the addition 00052 */ 00053 void Matrix_Add(int n, int m, float *C, float *A, float *B); 00054 00055 void Matrix_Subtract(int n, int m, float *C, float *A, float *B); 00056 00057 /** Multiplies two 3x3 matrices to get a third 3x3 matrix: c = ab 00058 * @param a is the first vector 00059 * @param b is the second vector 00060 * @returns c as the result of the mutliplication 00061 */ 00062 void Matrix_Multiply(float c[3][3], float a[3][3], float b[3][3]); 00063 00064 /** Multiplies two 3x3 matrices to get a third 3x3 matrix: c = ab 00065 * @param A is the first matrix 00066 * @param B is the second matrix 00067 * @param n is the rows of A 00068 * @param p is the columns of A and rows of B 00069 * @param m is the columns of B 00070 * @returns C as the result of the mutliplication 00071 */ 00072 void Matrix_Multiply(int n, int m, int p, float *C, float *A, float *B); 00073 00074 void Matrix_Transpose(int n, int m, float *C, float *A); 00075 00076 void Matrix_Inverse(int n, float *A); 00077 00078 void Matrix_Inverse(int n, float *C, float *A); 00079 00080 void Matrix_Copy(int n, int m, float *C, float *A); 00081 00082 /** Prints out an m x m matrix 00083 * @param A is the matrix to print 00084 * @param name is the name to print out along with the vector 00085 */ 00086 void Matrix_print(int n, int m, float *A, const char *name); 00087 00088 /** Prints out a 1 x 3 vector 00089 * @param A is the 1 x 3 vector to print 00090 * @param name is the name to print out along with the vector 00091 */ 00092 void Vector_Print(float A[3], const char *name); 00093 00094 #endif
Generated on Tue Jul 12 2022 14:09:25 by 1.7.2