Skip to content

Commit

Permalink
Removed ifdef In shared/physics.h - Just Using C++ Compatible Version…
Browse files Browse the repository at this point in the history
… Now:
  • Loading branch information
garethellis0 committed Mar 5, 2020
1 parent bf3bcfa commit 106cf37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
22 changes: 10 additions & 12 deletions src/firmware/main/shared/physics.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ float min_angle_delta(float angle1, float angle2)
* \param[in] matrix the matrix to multiply
*/
void matrix_mult(float* lhs, int lhs_len, const float* rhs, int rhs_len,
const float matrix[lhs_len][rhs_len])
const float** matrix)
{
for (int j = 0; j < lhs_len; ++j)
{
Expand All @@ -103,7 +103,7 @@ void matrix_mult(float* lhs, int lhs_len, const float* rhs, int rhs_len,
* \param[in] matrix the matrix to multiply
*/
void matrix_mult_t(float* lhs, int lhs_len, const float* rhs, int rhs_len,
const float matrix[rhs_len][lhs_len])
const float** matrix)
{
for (int j = 0; j < lhs_len; ++j)
{
Expand All @@ -126,8 +126,8 @@ void matrix_mult_t(float* lhs, int lhs_len, const float* rhs, int rhs_len,
* \param[in] lmatrix left matrix to multiply
* \param[in] rmatrix right matrix to multiply
*/
void mm_mult(int lm_rows, int rm_rows, int rm_cols, const float lmatrix[lm_rows][rm_rows],
const float rmatrix[rm_rows][rm_cols], float matrix_out[lm_rows][rm_cols])
void mm_mult(int lm_rows, int rm_rows, int rm_cols, const float** lmatrix,
const float** rmatrix, float** matrix_out)
{
int i;
int j;
Expand Down Expand Up @@ -159,9 +159,8 @@ void mm_mult(int lm_rows, int rm_rows, int rm_cols, const float lmatrix[lm_rows]
* \param[in] lmatrix left matrix to multiply
* \param[in] rmatrix right matrix to transpose multiply
*/
void mm_mult_t(int lm_rows, int rm_rows, int rm_cols,
const float lmatrix[lm_rows][rm_cols],
const float rmatrix[rm_rows][rm_cols], float matrix_out[lm_rows][rm_rows])
void mm_mult_t(int lm_rows, int rm_rows, int rm_cols, const float** lmatrix,
const float** rmatrix, float** matrix_out)
{
int i;
int j;
Expand Down Expand Up @@ -193,7 +192,7 @@ void mm_mult_t(int lm_rows, int rm_rows, int rm_cols,
* \param[in] B source matrix
*
*/
void mm_copy(int nrows, int ncols, float A[nrows][ncols], float B[nrows][ncols])
void mm_copy(int nrows, int ncols, float** A, float** B)
{
int i;
int j;
Expand All @@ -216,7 +215,7 @@ void mm_copy(int nrows, int ncols, float A[nrows][ncols], float B[nrows][ncols])
* \param[in] b source matrix
*/

void mm_add(int nrows, int ncols, float a[nrows][ncols], const float b[nrows][ncols])
void mm_add(int nrows, int ncols, float** a, const float** b)
{
int i, j;
for (i = 0; i < nrows; i++)
Expand All @@ -237,8 +236,7 @@ void mm_add(int nrows, int ncols, float a[nrows][ncols], const float b[nrows][nc
* \param[in] b source matrix 2
*/

void mm_sub(int nrows, int ncols, const float a[nrows][ncols],
const float b[nrows][ncols], float c[nrows][ncols])
void mm_sub(int nrows, int ncols, const float** a, const float** b, float** c)
{
int i, j;
for (i = 0; i < nrows; i++)
Expand All @@ -257,7 +255,7 @@ void mm_sub(int nrows, int ncols, const float a[nrows][ncols],
* \param[in] n number of rows and columns
*/

void mm_inv(int n, float a[n][n])
void mm_inv(int n, float** a)
{
float det, temp;
float temp_m[n][n];
Expand Down
33 changes: 5 additions & 28 deletions src/firmware/main/shared/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ float norm2(float a1, float a2);
void rotate(float speed3[2], float angle);

// Vector addition
void vectorSub(float* a, const float* b, int len);
void vectorSub(float *a, const float *b, int len);
// Vector addition
void vectorAdd(float* a, const float* b, int len);
void vectorAdd(float *a, const float *b, int len);
// Vector copy
void vectorCopy(float* a, const float* b, int len);
void vectorCopy(float *a, const float *b, int len);

// polar cartesian transforms
void Cart2Pol(float vec[2]);
Expand All @@ -119,28 +119,6 @@ void PolAcc2Cart(float const loc[2], float const vel[2], float const Pacc[2],
// C++ does not allow variable length arguments, but we would still like to
// enforce them when possible, so we compile this differently depending
// on what language this header is being used in
#ifndef __cplusplus
void matrix_mult(float* lhs, int lhs_len, const float* rhs, int rhs_len,
const float matrix[lhs_len][rhs_len]);
void matrix_mult_t(float* lhs, int lhs_len, const float* rhs, int rhs_len,
const float matrix[lhs_len][rhs_len]);

void mm_mult(int lm_rows, int rm_rows, int rm_cols, const float lmatrix[lm_rows][rm_rows],
const float rmatrix[rm_rows][rm_cols], float matrix_out[lm_rows][rm_cols]);

void mm_mult_t(int lm_rows, int rm_rows, int rm_cols,
const float lmatrix[lm_rows][rm_rows],
const float rmatrix[rm_rows][rm_cols], float matrix_out[lm_rows][rm_cols]);

void mm_copy(int nrows, int ncols, float A[nrows][ncols], float B[nrows][ncols]);

void mm_add(int nrows, int ncols, float a[nrows][ncols], const float b[nrows][ncols]);

void mm_sub(int nrows, int ncols, const float a[nrows][ncols],
const float b[nrows][ncols], float c[nrows][ncols]);

void mm_inv(int n, float a[n][n]);
#else
void matrix_mult(float *lhs, int lhs_len, const float *rhs, int rhs_len,
const float **matrix);
void matrix_mult_t(float *lhs, int lhs_len, const float *rhs, int rhs_len,
Expand All @@ -159,10 +137,9 @@ void mm_add(int nrows, int ncols, float **a, const float **b);
void mm_sub(int nrows, int ncols, const float **a, const float **b, float **c);

void mm_inv(int n, float **a);
#endif

void decompose_radial(const float speed, float* vf, const float* init_pos,
const float* final_pos);
void decompose_radial(const float speed, float *vf, const float *init_pos,
const float *final_pos);

float dot_product(const float vec1[], const float vec2[], const int size);

Expand Down

0 comments on commit 106cf37

Please sign in to comment.