#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <robomath.h>
#include "laser-nav.h"
Functions | |
void | time2angle (struct pln_time_state ts, struct pln_aangle_state *aas) |
D=S2 F C=R3 +-------------+-------------+ | | | | | +H | | | | | R1+ +L=S1 =K| | | +r | | +G | | | | | +-------------+-------------+ A=S3 E B=R2. | |
void | aangle2angle (struct pln_aangle_state aas, struct pln_angle_state *as) |
Convert absolute angles to relative angles (to angles between reflectors). | |
void | pln_get_line (struct pln_point a, struct pln_point b, struct pln_line *line) |
Get line parametrization from 2 points. | |
void | pln_get_oline (struct pln_line line, struct pln_point c, struct pln_line *oline) |
Get the ortogonal line if we know 1 line and the cross point. | |
void | pln_solve_quad (struct pln_fquad quad, struct pln_compl *sol1, struct pln_compl *sol2) |
Solve quadratic equation. | |
void | pln_solve_2quad (struct pln_fquad_2var form1, struct pln_fquad_2var form2, struct pln_point *sol1, struct pln_point *sol2) |
Solve 2 quadratic equations with 2 unknown variables. | |
void | pln_circ_line_cross (struct pln_circle circle, struct pln_line line, struct pln_point *sol1, struct pln_point *sol2) |
Find cross points of the line and the circle (condisering the line cross center of the circle). | |
void | pln_get_circle2 (struct pln_circ c, struct pln_circle *circle) |
Get parameters of the circle if we know 1 angle and 3 points. | |
void | pln_get_circle (struct pln_circ c, struct pln_circle *circle) |
Get parameters of the circle if we know 1 angle and 3 points. | |
void | pln_circ2form (struct pln_circle circle, struct pln_fquad_2var *form) |
Get parameters of the quadratic equations from the circle parameters. | |
void | pln_get_position (struct pln_angle_state as, struct pln_pos_state *pos) |
Get position from the measured angles. | |
void | pln_set_points () |
Set values of points we already know for later use. | |
int | cmpang (const void *a, const void *b) |
Compare evaluation of angles. | |
void | pln_pos2ang (struct pln_pos_state ps, struct pln_aangle_state *aas) |
Convert position to angles. | |
void | test_angles (struct pln_point *positions, int *poscount) |
Test all possible positions. | |
void | pln_coordinate (struct pln_pos_state estpos, struct pln_aangle_state aas, struct pln_angle_state *as) |
Angle coordinations. | |
void | test_coordination () |
Test pln_coordinate() function. | |
void | pln_sel_angles (struct pln_pos_state estpos, double *angles, int angcount, struct pln_aangle_state *maas) |
Select angles most probable from all measured angles. | |
void | test_sel_angles () |
Generate random angles and test if the function pln_sel_angles() works correctly. | |
void | pln_cal_position (unsigned int *times, unsigned int timecnt, struct pln_pos_state act_pos, struct pln_pos_state *est_pos) |
Calculate position from measured times and from the actual position. | |
void | test_cal_position (struct pln_point *positions, int *poscount) |
Test this library. |
void aangle2angle | ( | struct pln_aangle_state | aas, | |
struct pln_angle_state * | as | |||
) |
Convert absolute angles to relative angles (to angles between reflectors).
aas | absolute angles | |
as | relative angles |
int cmpang | ( | const void * | a, | |
const void * | b | |||
) |
Compare evaluation of angles.
Used by qsort().
void pln_cal_position | ( | unsigned int * | times, | |
unsigned int | timecnt, | |||
struct pln_pos_state | act_pos, | |||
struct pln_pos_state * | est_pos | |||
) |
Calculate position from measured times and from the actual position.
times | measured times. The period is expected on the 1st position. | |
timecnt | number of measured times | |
act_pos | actual position | |
est_pos | calculated position |
void pln_circ2form | ( | struct pln_circle | circle, | |
struct pln_fquad_2var * | form | |||
) |
Get parameters of the quadratic equations from the circle parameters.
circle | parameters of the circle | |
form | quadratic formular |
void pln_circ_line_cross | ( | struct pln_circle | circle, | |
struct pln_line | line, | |||
struct pln_point * | sol1, | |||
struct pln_point * | sol2 | |||
) |
Find cross points of the line and the circle (condisering the line cross center of the circle).
circle | parameters of the circle | |
line | parameters of the line | |
sol1 | cross point 1 | |
sol2 | cross point 2 |
void pln_coordinate | ( | struct pln_pos_state | estpos, | |
struct pln_aangle_state | aas, | |||
struct pln_angle_state * | as | |||
) |
Angle coordinations.
From the estimated position (x,y,head) and measured times determine correctly angles needed to count the position by measured angles.
estpos | estimated position | |
aas | measured angles (after selection) | |
as | angles between reflectors (correctly aligned) |
void pln_get_circle | ( | struct pln_circ | c, | |
struct pln_circle * | circle | |||
) |
Get parameters of the circle if we know 1 angle and 3 points.
c | angle and points that we already know | |
circle | output circle |
void pln_get_circle2 | ( | struct pln_circ | c, | |
struct pln_circle * | circle | |||
) |
Get parameters of the circle if we know 1 angle and 3 points.
This function is similar to another one in this program, but it works only with ortogonal sides.
c | angle and points that we already know | |
circle | output circle |
Get line parametrization from 2 points.
a | point A | |
b | point B | |
line | output line |
Get the ortogonal line if we know 1 line and the cross point.
line | the line that we know | |
c | the cross point between 2 lines | |
oline | ortogonal output line |
void pln_get_position | ( | struct pln_angle_state | as, | |
struct pln_pos_state * | pos | |||
) |
Get position from the measured angles.
FUNCTION PROTOTYPES.
as | angles between reflectors | |
pos | enumerated position |
void pln_pos2ang | ( | struct pln_pos_state | ps, | |
struct pln_aangle_state * | aas | |||
) |
Convert position to angles.
ps | position to be converted | |
aas | 3 angles between head and reflectors |
void pln_sel_angles | ( | struct pln_pos_state | estpos, | |
double * | angles, | |||
int | angcount, | |||
struct pln_aangle_state * | maas | |||
) |
Select angles most probable from all measured angles.
Use estimated position to evaluate them.
estpos | estimated position | |
angles | measured angles (times) | |
angcount | amount of measured angles | |
maas | selected angles |
void pln_set_points | ( | ) |
Set values of points we already know for later use.
void pln_solve_2quad | ( | struct pln_fquad_2var | form1, | |
struct pln_fquad_2var | form2, | |||
struct pln_point * | sol1, | |||
struct pln_point * | sol2 | |||
) |
Solve 2 quadratic equations with 2 unknown variables.
form1 | equation 1 | |
form2 | equation 2 | |
sol1 | solution 1 | |
sol2 | solution 2 |
Solve quadratic equation.
quad | parameters of the quadratic equation | |
sol1 | solution 1 | |
sol2 | solution 2 |
void test_angles | ( | struct pln_point * | positions, | |
int * | poscount | |||
) |
Test all possible positions.
Convert positions to angles and then do the reverse conversion.
positions | positions of wanted points | |
poscount | count of positions |
void test_cal_position | ( | struct pln_point * | positions, | |
int * | poscount | |||
) |
Test this library.
Set some actual position, give it measured times and hope that everything will works correctly.
positions | positions of wanted points | |
poscount | count of positions |
void test_coordination | ( | ) |
Test pln_coordinate() function.
For any value of head`s angle it should return the same alfa, beta and gama.
void test_sel_angles | ( | ) |
Generate random angles and test if the function pln_sel_angles() works correctly.
void time2angle | ( | struct pln_time_state | ts, | |
struct pln_aangle_state * | aas | |||
) |
D=S2 F C=R3 +-------------+-------------+ | | | | | +H | | | | | R1+ +L=S1 =K| | | +r | | +G | | | | | +-------------+-------------+ A=S3 E B=R2.
Fixed points (known points) [x,y] A - [0,0] B - [width,0] C - [width,height] D - [0,height] E - [width/2,0] F - [width/2,height] G - [width/2,height/4] H - [width/2,height/4*3] K - [0,height/2] L - [width,height/2] Our reflectors R1, R2, R3 Opponent`s reflectors S1, S2, S3
Unknown point r - Position of the robot
Angles: theta1 = from robot`s head to the first reflector theta2 = from robot`s head to the second reflector theta3 = from robot`s head to the third reflector alfa = angle R3-r-R2 (S2-r-S3) beta = angle R1-r-R3 (S3-r-S1) gama = angle R1-r-R2 (S1-r-S2)
Angle`s sense - counterclockwise
Terminology:
ts | measured times and period | |
aas | absolute angles |