-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.c
118 lines (109 loc) · 3.55 KB
/
test2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//include "/usr/include/linux/math.h"
#include <stdio.h>
#include "test1.h"
#include "glibc/math/math.h"
//#ifndef TEST1_H
//#define TEST1_H
struct vecteur {
float x_v;
float y_v;
float phi_v;
};
/*
struct matrice {
struct vecteur x_m;
struct vecteur y_m;
struct vecteur z_m;
};
struct vecteur multiplication_matrice_vecteur(struct matrice, struct vecteur) {
multiplication_vecteur_vecteur();
multiplication_vecteur_vecteur();
multiplication_vecteur_vecteur();
};
*/
void main(void) {
// 09/12/2019 à 11:53 d'après le schéma numérique produit avec Maple 2019 entre le 04/12/2019 et le 09/12/2019
int V = 109;
int dt = 1;
int l = 5;
int x = 0;
int y = 0;
int phi = 0;
FILE* fd = fopen("text.txt","wt");
//mfprintf(fd,'hello %s %d.\n','world',1);
//mfprintf(fd,'hello %s %d.\n','scilab',2);
//fprintf(fd, "ceci est un test.\n");
int i;
//int nombre = 0;
int res;
printf("Entrez une vitesse : ");
res = scanf("%i", &V);
int delta = 0;
//int res;
printf("Entrez un angle au volant : ");
res = scanf("%i", &delta);
for (i=0; i<1000; i++) {
//char c;
//c = getchar();
//putchar(c);
//printf("%c\n", c);
//fprintf(fd, "ceci est un test..\n");
//for k = 0:100
// dphi/dt = tan(0.01*t)/l
float phi = (tan(delta)/l)*dt + phi;
// fprintf(fd, "La valeur de l'orientation du vehicule vaut : %f\n", phi);
//disp(phi)
// dx/dt = V*cos(phi)
float x = V*cos(phi)*dt + x;
// fprintf(fd, "La valeur de la position en x du vehicule vaut : %f\n", x);
//plot(i,x);
//disp(x)
// dy/dt = V*sin(phi)
float y = V*sin(phi)*dt + y;
// fprintf(fd, "La valeur de la position en y du vehicule vaut : %f\n", y);
//disp(y)
//plot(x,y);//,'ro');
//X = [x; y; phi];
//U = [V; 0.01*i];
//disp("Etat du véhicule : ")
//disp(X)
//disp("Commande : ")
//disp(U)
/*
k = 1;
phi(i, k) = phi(i);
*/
// Linear approximation done here
//A = [1 ,0 ,-V*sin(phi)*dt; 0 ,1 ,V*cos(phi)*dt; 0 ,0 ,1];
float x_app = x -V*sin(phi)*dt*phi;
float y_app = y +V*cos(phi)*dt*phi;
float phi_app = phi;
// fprintf(fd, "La valeur de l'approximation de la position en x du vehicule vaut : %f\n", x_app);
// fprintf(fd, "La valeur de l'approximation de la position en y du vehicule vaut : %f\n", y_app);
// fprintf(fd, "La valeur de l'approximation de la position en phi du vehicule vaut : %f\n", phi_app);
//B = [cos(phi)*dt, 0; sin(phi)*dt, 0; tan(0.01*i)*dt/l, V*dt/(l*cos(0.01*i)^2)];
float u_x = V*cos(phi)*dt;
float u_y = delta*sin(phi)*dt;
float u_phi = V*tan(delta)*dt/l +delta*V*dt/(l*cos(delta)*cos(delta));
// fprintf(fd, "La valeur de l'approximation de la position en x du vehicule avec l'entree en x vaut : %f\n", x_app +u_x);
// fprintf(fd, "La valeur de l'approximation de la position en y du vehicule avec l'entree en y vaut : %f\n", y_app +u_y);
// fprintf(fd, "La valeur de l'approximation de la position en phi du vehicule avec l'entree en phi vaut : %f\n", phi_app +u_phi);
//C = [1, 0, 0; 0, 1, 0; 0, 0, 1];
//Xapp = A*X +B*U;
//plot(Xapp(1,:),Xapp(2,:),'g+-');
//disp("Etat approximé du véhicule : ")
//disp(Xapp)
//Y = C*X;
//disp(Y)
//end;
//mfprintf(fd,'This line is built with a column vector (26:28) %d.\n',[26:28].');
//mfprintf(fd,'This line is built with a row vector (26:28) %d.\n',[26:28]);
//mfprintf(fd,'This line is built with a matrix %.3f.\n',Xapp);
//mfprintf(fd,'This line is built with a matrix %.3f.\n',Y);
// fprintf(fd, "%f\t%f\t%f\t%f\t%f\t%f\t\n", phi, x, y, phi_app, x_app, y_app);
fprintf(fd, "%f\t%f\t%f\t%f\t\n", x, y, x_app, y_app);
}
//mclose(fd);
//plot(x,y,'ro');
}
//eof