Revision 150 branch/matteozzi/Emb_App/programme_principal_etud.c

View differences:

programme_principal_etud.c
121 121
//				correspondant au nom du v?hicule si le nom se termine par '*'
122 122

  
123 123

  
124
unsigned short alpha=0;
124
unsigned short retour=0;
125
unsigned short consigne;
126
CanFrame comm;
127
CanFrame requete, reponse;
128
unsigned short vitesse;
129

  
130
void asservissement(consigne){
131
	requete.data.id='R';
132
	requete.data.rtr=1;
133
	snd_dtq(CanTx, requete.msg);
134
	rcv_dtq(CanRx, &reponse.msg);
135
	retour=reponse.data.val;
136
	
137
	if(consigne!=retour)
138
	{
139
		comm.data.id='T';
140
		comm.data.rtr=0;
141
		comm.data.val=consigne-retour;
142
		snd_dtq(CanTx, comm.msg);
143
	}
144
	else
145
	{			
146
		comm.data.id='T';
147
		comm.data.rtr=0;
148
		comm.data.val=0;
149
		snd_dtq(CanTx, comm.msg);
150
	}
151
}
152

  
153
void commande(vitesse){
154
	comm.data.id='V';
155
	comm.data.rtr=0;
156
	comm.data.val=vitesse;
157
	snd_dtq(CanTx, comm.msg);
158
}
159

  
125 160

  
126 161
void main()
127 162
{
128
	
129
	CanFrame comm;
130
	CanFrame requete, reponse;
163

  
164

  
131 165
	
132 166
	ports_mcu();
133 167
    lcd_init();
......
148 182
		dly_tsk(100);
149 183
		LED_J=0;
150 184
		dly_tsk(100);
151
		
152
		requete.data.id='R';
153
		requete.data.rtr=1;
154
		snd_dtq(CanTx, requete.msg);
155
		rcv_dtq(CanRx, &reponse.msg);
156
		alpha=reponse.data.val;
157
		
158
		if(alpha>450)
159
		{
160
			comm.data.id='T';
161
			comm.data.rtr=0;
162
			comm.data.val=0;
163
			snd_dtq(CanTx, comm.msg);
164
			dly_tsk(10);
165
		}
166
		else
167
		{
168
			comm.data.id='T';
169
			comm.data.rtr=0;
170
			comm.data.val=100;
171
			snd_dtq(CanTx, comm.msg);
172
			dly_tsk(10);
173
		}
185
		asservissement(450);
186
		commande(20);
174 187
    }
175 188
}
176 189

  

Also available in: Unified diff