RcdMathLib_doc
Open Source Library for Linear and Non-linear Algebra
magnetic_based_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
3  * 2020 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License v2.1. See the file LICENSE in the top level directory for more
7  * details.
8  */
9 
26 #include <stdio.h>
27 
28 #include "matrix.h"
29 #include "vector.h"
30 #include "utils.h"
31 #include "trilateration.h"
33 
35 {
36  puts("***************** Magnetic-based system example *****************");
37  matrix_t ref_pos_matrix[4][3] = {
38  { 100.395, 16.781, 1.084 }, //P1
39  { 100.937, 22.941, 1.072 }, //P2
40  { 106.229, 22.716, 1.064 }, //P3
41  { 106.3, 16.8, 2.35 } //P4
42  };
43 
44  matrix_t true_pos[3] = { 102, 18, 2.308 }; // is usually unknown // Sensor8a3
45 
46  /* magnetic field strengths to the reference stations */
47  matrix_t B_vec[4] = { 43.2630, 3.0620, 1.4890, 4.5361 };
48  /* Elevation angles to the reference stations */
49  matrix_t theta_vec[4] = { 31.3710, 12.4870, 11.7280, 0.5352 };
50  uint8_t ref_point_num = 4;
51  matrix_t r0_vec[ref_point_num];
52 
53  for (uint8_t i = 0; i < ref_point_num; i++) {
54 
55  r0_vec[i] = magnetic_based_get_r(B_vec[i],
56  utils_to_radian(theta_vec[i]), K_T);
57 
58  }
59 
60  /* estimated position */
61  matrix_t est_pos[4];
62  trilateration2(ref_point_num, ref_pos_matrix, r0_vec,
63  est_pos, NULL);
64 
65  printf("true position = ");
66  vector_flex_print(3, true_pos, 5, 4);
67  puts("");
68 
69  printf("estimated position = ");
70  vector_flex_print(3, &est_pos[1], 5, 7);
71  puts("");
72 
73 }
vector_flex_print
void vector_flex_print(uint32_t length, vector_t arr[], uint8_t before_dot, uint8_t after_dot)
Display the values of the vector's elements.
Definition: vector.c:284
trilateration.h
Implement the trilateration algorithm.
utils_to_radian
double utils_to_radian(double deg_angle)
Convert the angle from degrees to radians.
Definition: utils.c:31
magnetic_based_position.h
Functions of of DC-pulsed, magnetic localization system.
matrix.h
Matrix computations.
utils.h
Utilities for linear algebra.
magnetic_based_test
void magnetic_based_test(void)
Example of a magnetic-based localization system.
Definition: magnetic_based_test.c:34
trilateration2
void trilateration2(uint8_t anchor_num, matrix_t anchor_pos_matrix[anchor_num][3], matrix_t dist_arr[], matrix_t solution_x1[], matrix_t solution_x2[])
Implement the trilateration algorithm.
Definition: trilateration.c:69
K_T
#define K_T
The number of turns of the wire.
Definition: magnetic_based_position.h:75
matrix_t
#define matrix_t
Define the data type of the matrix elements.
Definition: matrix.h:38
magnetic_based_get_r
matrix_t magnetic_based_get_r(matrix_t B, matrix_t theta, matrix_t k)
Computes the distance between a mobile station and a reference stations of a magnet-based localizatio...
Definition: magnetic_based_position.c:166
vector.h
Vector computations.