-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtalkk.cpp
186 lines (119 loc) · 3.78 KB
/
talkk.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//ros::init(argc, argv, "Points");
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
#include <ros/console.h>
#include <iostream>
#include <vector>
#define PI 3.14159265
#include <math.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
struct Point{
float x[100];
float y[100];
float theta[100];
};
char * strtoupper( char * dest, const char * src ) {
char * result = dest;
while( *dest++ = toupper( *src++ ) );
return result;
}
const float pi = 3.14159265358979323846;
// fonction 1
void generPoint(int d, float v ,float dt, float omega )
{ Point pInit ;
pInit.x[0] = 0;
pInit.y [0]= 0;
pInit.theta[0] = 0*(pi/180) ;
for(int h=0 ;h<((d/v)/dt);h++){
pInit.x[h+1]=pInit.x[h]-v*dt* sin(pInit.theta[h]+(dt*omega)/2);
pInit.y[h+1]=pInit.y[h]+v*dt* cos(pInit.theta[h]+(dt*omega)/2);
pInit.theta[h+1]=pInit.theta[h]+dt*omega;
printf(" coord d'un point (x,y,theta) %f\t %f\t %f\t \n" ,pInit.x[h+1],pInit.y[h+1],pInit.theta[h+1]);
}
}
// fonction 2
//float move_forward(float deltafi,int q )
//{
//float omegaa = deltafi*q ;
//return (omegaa);
//}
int main(int argc, char** argv) {
ros::init(argc, argv, "talker");
ros::NodeHandle nh;
ros::Publisher talkk_pub=nh.advertise<std_msgs::String>("very_important_message",100);
ros::Rate loop_rate(1); //hz
const float pi = 3.14159265358979323846;
struct Point pInit ; //point, pointFinal;
int n,d,q,i,k,j,a; //le nombre de trajectoire
d=1; // la distance en metre
float deltafi_av,deltafi_dg,omega,omegaa, dt,v; // les parametres
while(ros::ok())
{ loop_rate.sleep();
char commande[20] ;
//initialisation des points (x,y,theta)
printf("Coordonees du point initial sont x ,y ,theta : %f \t %f \t %f \n", pInit.x[0],pInit.y[0],pInit.theta[0]);
// commande pour declarer le n ,dt,v
printf("Donner la val de n " );
scanf("%d",&n);
scanf("%f",&v);
printf("donner la valeur de dt ");
scanf("%f",&dt);
//les zone definit pour les commande (radion)
deltafi_av=(0.3)/n; // pour la commande avant
deltafi_dg=(0.4)/n;
// la boucle de omega par rapport aux nmbrs de trajectoire
i=(-(n-1)/2);
while (i<=(n-1)/2) {
omega= (((0.8/n)/dt)*i); //omerga calculer avec deltaFi(l'angle entre les trajectoires)
// pour chaque omega un nmbr h de point generer
printf(" pour la val omega %f\n", omega);
generPoint( d, v , dt, omega );
i++;
}
//-------------------------la commande -------------------------------
while (k ) {
printf("Donner la commande :");
scanf("%s",commande);
char * input = commande ;
char result[20];
strtoupper( result, input );
//printf("%s", result);
char E[] = "AV";
char A[] = "AG";
char B[] = "AD";
if( strcmp(result,E) == 0)
{
// trajectoires de la commande avant
for (int q=(-(n-1)/2);q<=((n-1)/2);q++) {
omegaa = (deltafi_av/dt)*q ;
printf(" pour la val omega %f\n", omegaa);
generPoint( d, v , dt, omegaa );
}
}
else if ( strcmp(result,A) == 0)
// trajectoires pour la commande gauche
{ for(int q=0 ; q< n;q++) {
omegaa = (0.3/dt) +((deltafi_dg/dt)*q); // omega + (0.3/dt)=> omega + le omega dela dernier trajectoire de la commande avant
printf(" pour la val omega %f\n", omegaa);
generPoint( d, v , dt, omegaa );
}
}
else if ( strcmp(result,B) == 0)
// trajectoires pour la commande droit
{ for(int q=0; q<n ;q++) {
omegaa = (-0.3/dt)+((deltafi_dg/dt)*-q);
printf(" pour la val omega %f\n", omegaa);
generPoint( d, v , dt, omegaa );
}
}
else k++ ;
}
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}