ardunio_matlab
TRANSCRIPT
-
7/26/2019 Ardunio_matlab
1/6
Control and Automation Laboratory-Ho Chi Minh City University of Technology
Edited by Quoc Chi Nguyen, Ha Quang Thinh Ngo, and Phuong Tung Pham-1strev
SDNG TH VIN ARDUINO SIMULINKTRONG IU KHIN
-
7/26/2019 Ardunio_matlab
2/6
Control and Automation Laboratory-Ho Chi Minh City University of Technology
Edited by Quoc Chi Nguyen, Ha Quang Thinh Ngo, and Phuong Tung Pham-1strev
1.CI T TH VIN ARDUINO
Chn mc Add-Ons ti phn cng v.
Ci t giArduinovArduino Uno/Nano/Mega2560. Sau khi ci t hon tt, trong giaodin workspace ca Matlab chy 3 file arduino.m , contents.m v install_arduino.mtrongth mc ArduinoIOSimulink.
Sau khi ci t Simulink Library s xut hin hai th vin Arduino IO v Simulinksupport package of Arduino Hardware.
-
7/26/2019 Ardunio_matlab
3/6
Control and Automation Laboratory-Ho Chi Minh City University of Technology
Edited by Quoc Chi Nguyen, Ha Quang Thinh Ngo, and Phuong Tung Pham-1strev
Trong th mc ArduinoIOsimul ink \pde , cn upload 1 trong 5 sketches vo Arduinomega 2560
adio.pde : analog and digital IO & basic serial
adioe.pde : adio.pde + encoders support adioes.pde : adioe.pde + servo support
motor_v1.pde : adioes.pde + Adafruit Motor Shield v1
motor_v2.pde : adioes.pde + Adafruit Motor Shield v2
Vi 2 sketches motor_v1.pde v motor_v2.pde cn chp 2 th vin AdafruitMotorShieldv AFMotor vo th vin ca Arduino.
Vi vic sdng cc chn IO iu khin ng c, ch cn upload file adioe.pde lc.
2.
Cc KHI TRONG TH VIN ARDUINO IO
Arduino Digital Read:c gi trdigital tpin c chn, trvgi tr0 v 1.
Arduino Analog Read: c gi tranalog tpin c chn, trvgitrt0 n 1023.
Arduino Digital Read: Xut gi tr digital (0 v 1) vo pin cchn
Arduino Analog Read: Xut gi tr analog (0-255) vo pin cchn
Arduino IO Setup: Dng thit lp Serial (COM) port caArduino
-
7/26/2019 Ardunio_matlab
4/6
Control and Automation Laboratory-Ho Chi Minh City University of Technology
Edited by Quoc Chi Nguyen, Ha Quang Thinh Ngo, and Phuong Tung Pham-1strev
Real-time Pacer: Thit lp t l gia thi gian m phng(Simulation time) v thi gian thc (Real time).
Encoder Read:Dng c vtr ca encoder, trvgi tr-32768n 32767.
Encoder Reset: Khi kim tra tnh hiu u vo, nu ln hnkhng Encoder c xc lp sReset vgi tr0.
Ngoi ra cn cc khi ng dng iu khin cc loi ng c nh DCmotor, RCservo, Stepper motor.
3.NG DNG TH VIN ARDUINOIO TRONG IU KHIN NG C
Mc tiu: Sdng th vin ArduinoIO iu khin vtr ng c bng biu khin PID
3.1. Phn cng hthng
- Board Arduino Mega 2560
- L298 DFRobot
- ng c DC- Encoder
3.2. iu khin ng c sdng biu khin PID
3.2.1. Thit lp hthng
thit lp h thng m phng, c thsdng 2 khi Arduino IO Setup v Real-timepacer.
3.2.2. iu khin ng c
Ta a tnh hiu vo PIN4 (M1) chn chiu quay cho ng c v a xung PWM (0-255) vo PIN5 (E1) cho vic iu khin tc ng c.
-
7/26/2019 Ardunio_matlab
5/6
Control and Automation Laboratory-Ho Chi Minh City University of Technology
Edited by Quoc Chi Nguyen, Ha Quang Thinh Ngo, and Phuong Tung Pham-1strev
Hnh 2.2.1: S iu khin tc ng c
3.2.3. c Encoder v tnh vn tc
c Encoder th vin ArduinoIO htr2 khi Encoder Read
c Encoder
Hnh 2.2.2: S c vtr encoder
Gi tr ly trc tip t khi Encoder Read ch c th s dng vi thi gian m
phng ngn. Vi thi gian m phng ln, gi trvt qu khong 32767, encoder s tng reset li gi tr -32768.
3.2.4. Xy dng b iu khin PID
-
7/26/2019 Ardunio_matlab
6/6
Control and Automation Laboratory-Ho Chi Minh City University of Technology
Edited by Quoc Chi Nguyen, Ha Quang Thinh Ngo, and Phuong Tung Pham-1strev