Revision 256 branch/colomban/Emb_App/programme_principal_etud.c

View differences:

programme_principal_etud.c
124 124
unsigned short      dist ;
125 125
unsigned short      k=4; //pour augmenter la vitesse jusqu'a la position souhait?e
126 126
unsigned short      ka=1;
127
unsigned short 		cpt;
127 128
void vitesse(unsigned short vit);
129
CanFrame comm;
130
CanFrame req;
131
UINT flag;
128 132

  
129 133
void main()
130 134
{   
......
142 146
	sta_cyc(ID_acqui);
143 147
	sta_tsk(ID_periph_rx);
144 148
	sta_tsk(ID_asserv);
145
	sta_tsk(ID_roue);
149
	sta_tsk(ID_roue);
150
	sta_tsk(ID_capteur);
151
	
146 152
	dly_tsk(1500);
147 153
	
148 154
    while(1)
......
150 156
		LED_J=1;
151 157
		
152 158
		LED_J=0;
159
		vitesse(30);
160
        
153 161
		
154
        vitesse(20);
155
		
156 162
	}
157 163
	
158 164
}
......
165 171

  
166 172
{
167 173
		unsigned short consigne = 400;
168
		CanFrame comm;
169
	    CanFrame req;
170
		UINT flag;
171 174
		while(1){
172 175
			
173 176
			req.data.id = 'R';
......
187 190
} 
188 191

  
189 192
void vitesse(unsigned short vit){
190
		CanFrame comm;
191 193
		comm.data.id = 'V';
192 194
		comm.data.rtr = 0;
193 195
		comm.data.val = vit;
......
198 200

  
199 201
void asserv_roue(){
200 202
	unsigned short consignes = 770;
201
	    CanFrame comm;
202
	    CanFrame req;
203
		UINT flag;
203
	    
204 204
		while(1){
205
			
206 205
			req.data.id = 'U';
207 206
			req.data.rtr = 1;
208 207
			periph[ADDR('U')].ev=0X01;
209 208
			snd_dtq(CanTx, req.msg);
210 209
			wai_flg(ev_periph,0X01,TWF_ANDW, &flag);
211 210
			dist=periph[ADDR('U')].val;
212
			
211
			if(dist>1600){
212
					comm.data.id = 'D';
213
					comm.data.rtr = 0;
214
					comm.data.val = 0;
215
					snd_dtq(CanTx, comm.msg);
216
					dly_tsk(150);
217
				
218
				}
213 219
			comm.data.id = 'D';
214 220
			comm.data.rtr = 0;
215 221
			comm.data.val = ka*(-consignes + dist);
......
217 223
			
218 224
		
219 225
		}		
220
	}
226
	}
227

  
228
void capteur(){
229
	     	while(1)
230
			{
231
			req.data.id = 'C';
232
			req.data.rtr = 1;
233
			periph[ADDR('C')].ev=0X01;
234
			snd_dtq(CanTx, req.msg);
235
			wai_flg(ev_periph,0X01,TWF_ANDW, &flag);
236
			cpt=periph[ADDR('C')].val;
237
			
238
	}
239
}

Also available in: Unified diff