| 12
 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
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 
 | #pragma once
 
namespace TP1 {
 
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
 
	/// <summary>
	/// Description résumée de Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			Tab_V1 = gcnew array< double >(1000); // allocation dynamique de 1000 éléments
			ind = 0 ; // initialisation de lindice
			k = 1.0 ; // facteur de conversion de la donnée reçue
			serialPort1->Open(); // ouverture du port
			Taff_V1 = gcnew array< PointF >(1000); // allocation les 1000 points du tableau Taff_V1
			Vmin = 0 ; // ordonnée la plus faible à afficher
			Vmax = 255 ; // ordonnée la plus élevée à afficher
			dy = Vmax-Vmin;
			y0 = Vmin;
			pen = gcnew Pen( Color::Blue,1.0f ); // couleur, taille du trait
			pen2 = gcnew Pen( Color::Black,1.0f );// couleur, taille du trait
			pen2->DashStyle = System::Drawing::Drawing2D::DashStyle::Dash; // pointillés
 
			//Initialisation des paramètres d'asservissement
			kp1V=0,kp1I=0,kp2V=0,kp2I=0,ki1V=0,ki1I=0,ki2V=0,ki2I=0;
 
 
		}
 
	protected:
		/// <summary>
		/// Nettoyage des ressources utilisées.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
 
	private: System::Windows::Forms::Button^  button_envoyer;
	protected: 
 
 
	private:
		/// <summary>
		/// Variable nécessaire au concepteur.
		UInt16 compteur; // entier 16 bits non signé
 
		char kp1V,kp1I,kp2V,kp2I,ki1V,ki1I,ki2V,ki2I;
 
		array< double >^ Tab_V1; // déclaration du tableau de "double"
		UInt16 ind ; // indice utilisé pour le stockage
		double k ; // variable servant à convertir léchelle de la donnée reçue
		array< PointF >^ Taff_V1; // déclaration du tableau de PointF (identique à une structure de deux doubles X et Y : chaque élément de Taff_V1 est accessible par la syntaxe Taff_V1[i].X et Taff_V1[i].Y)
		double Vmin, Vmax, dy, y0; // variables permettant la mise à léchelle de la courbe
		Pen^ pen; // déclaration de la variable pen définissant le style de tracé
		Pen^ pen2; // style de tracé de la grille
	private: System::Windows::Forms::Button^  button_reception;
	private: System::Windows::Forms::TextBox^  textBox_kp1V;
 
 
 
	private: System::IO::Ports::SerialPort^  serialPort1;
	private: System::Windows::Forms::PictureBox^  pictureBox1;
 
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label3;
 
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::Label^  label7;
	private: System::Windows::Forms::Label^  label8;
	private: System::Windows::Forms::Label^  label9;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label10;
	private: System::Windows::Forms::TextBox^  textBox_ki1V;
	private: System::Windows::Forms::TextBox^  textBox_ki1V;
	private: System::ComponentModel::IContainer^  components;
 
 
 
 
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette méthode avec l'éditeur de code.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->button_envoyer = (gcnew System::Windows::Forms::Button());
			this->button_reception = (gcnew System::Windows::Forms::Button());
			this->textBox_kp1V = (gcnew System::Windows::Forms::TextBox());
			this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->textBox_ki1V = (gcnew System::Windows::Forms::TextBox());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			this->SuspendLayout();
			// 
			// button_envoyer
			// 
			this->button_envoyer->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button_envoyer->Location = System::Drawing::Point(195, 145);
			this->button_envoyer->Name = L"button_envoyer";
			this->button_envoyer->Size = System::Drawing::Size(147, 52);
			this->button_envoyer->TabIndex = 1;
			this->button_envoyer->Text = L"Envoyer";
			this->button_envoyer->UseVisualStyleBackColor = true;
			this->button_envoyer->Click += gcnew System::EventHandler(this, &Form1::button_envoyer_Click);
			// 
			// button_reception
			// 
			this->button_reception->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, 
				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
			this->button_reception->Location = System::Drawing::Point(385, 145);
			this->button_reception->Name = L"button_reception";
			this->button_reception->Size = System::Drawing::Size(147, 52);
			this->button_reception->TabIndex = 2;
			this->button_reception->Text = L"Réception";
			this->button_reception->UseVisualStyleBackColor = true;
			this->button_reception->Click += gcnew System::EventHandler(this, &Form1::button_reception_Click);
			// 
			// textBox_kp1V
			// 
			this->textBox_kp1V->Location = System::Drawing::Point(78, 54);
			this->textBox_kp1V->Name = L"textBox_kp1V";
			this->textBox_kp1V->Size = System::Drawing::Size(44, 20);
			this->textBox_kp1V->TabIndex = 3;
			this->textBox_kp1V->TextChanged += gcnew System::EventHandler(this, &Form1::textBox_kp1V_TextChanged);
			// 
			// serialPort1
			// 
			this->serialPort1->BaudRate = 115200;
			this->serialPort1->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &Form1::serialPort1_DataReceived);
			// 
			// pictureBox1
			// 
			this->pictureBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
				| System::Windows::Forms::AnchorStyles::Left) 
				| System::Windows::Forms::AnchorStyles::Right));
			this->pictureBox1->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
			this->pictureBox1->Location = System::Drawing::Point(148, 257);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(437, 226);
			this->pictureBox1->TabIndex = 4;
			this->pictureBox1->TabStop = false;
			this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox1_Paint);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(501, 35);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(31, 13);
			this->label1->TabIndex = 6;
			this->label1->Text = L"PID1";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(24, 57);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(26, 13);
			this->label2->TabIndex = 6;
			this->label2->Text = L"Kp :";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(24, 90);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(22, 13);
			this->label3->TabIndex = 6;
			this->label3->Text = L"Ki :";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label5->Location = System::Drawing::Point(24, 9);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(286, 16);
			this->label5->TabIndex = 6;
			this->label5->Text = L"Asservissement de la boucle de Vitesse";
			this->label5->Click += gcnew System::EventHandler(this, &Form1::label5_Click);
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(618, 35);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(31, 13);
			this->label6->TabIndex = 6;
			this->label6->Text = L"PID2";
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label7->Location = System::Drawing::Point(428, 9);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(287, 16);
			this->label7->TabIndex = 6;
			this->label7->Text = L"Asservissement de la boucle de Courant";
			this->label7->Click += gcnew System::EventHandler(this, &Form1::label5_Click);
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(84, 35);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(31, 13);
			this->label8->TabIndex = 6;
			this->label8->Text = L"PID1";
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(201, 35);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(31, 13);
			this->label9->TabIndex = 6;
			this->label9->Text = L"PID2";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(449, 57);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(26, 13);
			this->label4->TabIndex = 6;
			this->label4->Text = L"Kp :";
			// 
			// label10
			// 
			this->label10->AutoSize = true;
			this->label10->Location = System::Drawing::Point(449, 90);
			this->label10->Name = L"label10";
			this->label10->Size = System::Drawing::Size(22, 13);
			this->label10->TabIndex = 6;
			this->label10->Text = L"Ki :";
			// 
			// textBox_ki1V
			// 
			this->textBox_ki1V->Location = System::Drawing::Point(78, 82);
			this->textBox_ki1V->Name = L"textBox_ki1V";
			this->textBox_ki1V->Size = System::Drawing::Size(100, 20);
			this->textBox_ki1V->TabIndex = 7;
			this->textBox_ki1V->TextChanged += gcnew System::EventHandler(this, &Form1::textBox_ki1V_TextChanged);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(784, 572);
			this->Controls->Add(this->textBox_ki1V);
			this->Controls->Add(this->label10);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label7);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->label9);
			this->Controls->Add(this->label6);
			this->Controls->Add(this->label8);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->pictureBox1);
			this->Controls->Add(this->textBox_kp1V);
			this->Controls->Add(this->button_reception);
			this->Controls->Add(this->button_envoyer);
			this->Location = System::Drawing::Point(78, 87);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->TextChanged += gcnew System::EventHandler(this, &Form1::textBox_ki1V_TextChanged);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();
 
		}
#pragma endregion
	private: System::Void button_envoyer_Click(System::Object^  sender, System::EventArgs^  e) {
 
		//Prise en compte des paramètres saisie dans la texbox
		try {kp1V=Convert::ToUInt16(textBox_kp1V->Text);}
		catch ( System::OverflowException^ ) { }
		catch ( System::FormatException^ ) { }
		catch ( System::ArgumentException^ ) { }
 
		try {ki1V=Convert::ToUInt16(textBox_ki1V->Text);}
		catch ( System::OverflowException^ ) { }
		catch ( System::FormatException^ ) { }
		catch ( System::ArgumentException^ ) { }
 
			 }
 
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void button_reception_Click(System::Object^  sender, System::EventArgs^  e) {
 
			 }
 
private: System::Void textBox_kp1V_TextChanged(System::Object^  sender, System::EventArgs^  e) {
 
		 }
 
private: System::Void serialPort1_DataReceived(System::Object^  sender, System::IO::Ports::SerialDataReceivedEventArgs^  e) {
			Byte x ; // les déclarations sont possibles dans le code
			UInt16 n = serialPort1->BytesToRead;// nb de valeurs contenues dans le buffer
			while(n--) // on lit (donc vide) et on traite les n données du buffer
			{
			x=serialPort1->ReadByte(); // lecture dune valeur du buffer
			Tab_V1[ind++] = k*(double)x; // remise à léchelle
			if (ind >= 1000)
			{
			ind=0 ; // évite le débordement du tableau
			}
			}
		 pictureBox1->Invalidate() ;
		 }
private: System::Void pictureBox1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
		 Graphics^ g = e->Graphics; // variable g pointant sur la fenêtre graphique
		if(pictureBox1->Width < 5) return; // détecte si la fenêtre est trop petite
		if(pictureBox1->Height < 5) return;
		for(UInt16 i=0;i<1000;i++) // calcul du tableau de points pour laffichage
		{
		Taff_V1[i].X = pictureBox1->Width*(double)i/1000.0; // abscisse
		Taff_V1[i].Y = (pictureBox1->Height-5)-(pictureBox1->Height-5)*(Tab_V1[i]-y0)/dy; // ordonnée
		}
		g->DrawLines( pen, Taff_V1); // trace de la courbe complète
		grid(g,pictureBox1->Height,pictureBox1->Width,10);
		 }
private: void grid(Graphics^ g, UInt16 hauteur, UInt16 largeur, double frac) {
		if(frac<=1) return;
		double dx,dy;
		dx = (double)largeur/frac;
		dy = (double)(hauteur-5)/frac;
		for(double i=1;i<frac;i++)
		{
		g->DrawLine(pen2,i*dx,0.0,i*dx,(float)hauteur-5);
		g->DrawLine(pen2,0.0,i*dy,(float)largeur,i*dy);
		}
		}
 
 
private: System::Void label5_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox_ki1V_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox_ki1V_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
};
} | 
Partager