✅ Práctica 10a
▷ #TSCLab #TCLab #ESP32 #Arduino #Control #MACI
En el siguiente blog se presenta la décima práctica y corresponde a la quinta del laboratorio de control de velocidad.
- Recopilar y guardar las RPM para crear un dataset.
Objetivos específicos:
- Comparar los resultados de movimiento con diferentes parámetros.
Materiales:
- Aplicación de escritorio CoolTerm
- PCB de Temperature Control Lab (TSC-Lab)
Introducción:
Una vez entendido todo el funcionamiento y control de velocidad del motor, se pretende crear un dataset para mejorar el mismo, lo que se hará es tomar 10 muestras tanto en un PWM de 255 y 0 durante un periodo de 13 segundos, dichos datos pueden ser modificados en la parte inicial del código de arduino.
Procedimiento:
Nota: revisar la práctica 1 donde se le recuerda a como utilizar la apliación CoolTerm.
Se asume que la placa del ESP-32 ha sido previamente instalada en el IDE de Arduino.
- Copiar el código en el IDE de Arduino:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
****************************** TSC-Lab ******************************* | |
***************************** PRACTICE 10 ***************************** | |
This practice is about data acquisition with square velocity input | |
By: Kevin E. Chica O | |
More information: https://tsc-lab.blogspot.com/ | |
*/ | |
//initial setting for data acquisition | |
int dutyCycleInitial = 255; | |
int dutyCycleFinish = 0; | |
int period = 13000; | |
int cycles = 10; | |
//separador library | |
#include <Separador.h> | |
Separador s; | |
//motor | |
int motor1Pin1 = 33; | |
int motor1Pin2 = 25; | |
int enable1Pin = 32; | |
int motor_status = 255; | |
// Setting PWM properties | |
const int freq = 30000; | |
const int pwmChannel = 0; | |
const int resolution = 8; | |
//move | |
String move_motor = "counterclockwise"; | |
int encoder = 27; | |
void motor( void *pvParameters ); | |
//void enviar( void *pvParameters ); | |
void RPM( void *pvParameters ); | |
volatile int counter = 0; | |
void interruption() // Function that runs during each interrupt | |
{ | |
counter++; | |
} | |
void setup() { | |
Serial.begin(115200); | |
// sets the pins as outputs: | |
pinMode(motor1Pin1, OUTPUT); | |
pinMode(motor1Pin2, OUTPUT); | |
pinMode(enable1Pin, OUTPUT); | |
// configure LED PWM functionalitites | |
ledcSetup(pwmChannel, freq, resolution); | |
// attach the channel to the GPIO to be controlled | |
ledcAttachPin(enable1Pin, pwmChannel); | |
attachInterrupt(encoder, interruption, RISING); | |
xTaskCreatePinnedToCore( | |
motor | |
, "MotorDC" // Descriptive name of the function (MAX 8 characters) | |
, 2048 // Size required in STACK memory | |
, NULL // INITIAL parameter to receive (void *) | |
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest. | |
, NULL // Variable that points to the task (optional) | |
, 1); // core 1 | |
xTaskCreatePinnedToCore( | |
RPM | |
, "RPM" // Descriptive name of the function (MAX 8 characters) | |
, 2048 // Size required in STACK memory | |
, NULL // INITIAL parameter to receive (void *) | |
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest. | |
, NULL // Variable that points to the task (optional) | |
, 1); // core 0 | |
} | |
void loop() { | |
} | |
void motor( void *pvParameters ) { | |
while (1) { | |
if (cycles > 0) { | |
digitalWrite(motor1Pin1, HIGH); | |
digitalWrite(motor1Pin2, LOW); | |
ledcWrite(pwmChannel, dutyCycleInitial); | |
motor_status = 255; | |
vTaskDelay(period); | |
digitalWrite(motor1Pin1, HIGH); | |
digitalWrite(motor1Pin2, LOW); | |
ledcWrite(pwmChannel, dutyCycleFinish); | |
motor_status = 0; | |
vTaskDelay(period); | |
cycles--; | |
} | |
} | |
} | |
void RPM( void *pvParameters ) { | |
while (1) { | |
vTaskDelay(999); | |
Serial.print(counter * 60); | |
Serial.print(","); | |
Serial.println(motor_status); | |
counter = 0; | |
} | |
} |
Repositories: https://github.com/vasanza/TSC-Lab/tree/main/Practice10
- Cargar el código a la placa.
- Abrir CoolTerm y realizar la configuración de la práctica 1 y guardar los datos.
Nota: así se verían los resultados en CoolTerm:
Resultados:
- Los archivos .csv generados de esta práctica se encuentran disponibles en IEEEDataPort: http://ieee-dataport.org/4138.
✅ Práctica 10b
Objetivo general:
- Visualizar los datos resultantes empleando código de Matlab.
Procedimiento:
- Ir al siguiente repositorio: https://github.com/vasanza/TSC-Lab/tree/main/Practice10b
- En el repositorio encontrará la carpeta completa que usaremos en Matlab, donde se incluyen funcionalidades.
- Para fines explicativos, a continuación solo detallamos el código main que usted encontrará en el repositorio.
- Luego de ejecutar el código de Matlab, podemo realizar la práctica 15.
TEMPERATURE AND SPEED CONTROL LAB (TSC-LAB)
Practice 10: Data acquisition with square velocity input
- Blog: https://tsc-lab.blogspot.com/
- GitHub: https://github.com/vasanza/TSC-Lab
- Matlab functions: https://github.com/vasanza/Matlab_Code
- IEEEDataPort: http://ieee-dataport.org/4138
- TSC-LAB configurations
- int dutyCycleInitial = 255;
- int dutyCycleFinish = 0;
- int period = 13000;
- int cycles = 50;
- 1 sample per second
Raw dataset preparation
clear;clc;%clear all
addpath(genpath('./src'))%functions folders
datapath = fullfile('./data/');%data folder
Raw dataset preprocessing
filenames = FindCSV(datapath);%List All CSV files
data=readtable(fullfile(datapath,filenames(1).name));%Select i CSV file
data=table2array(data);
DataNorm = fNormalization(data(:,1));%Normalization
DataFeatures = [max(DataNorm) min(DataNorm) mean(DataNorm)...
median(DataNorm) rms(DataNorm) std(DataNorm) ];%Feature extraction
Plot Raw TSC-LAB dataset
figure
plot(data);xlabel('Samples');ylabel('RPM');
title('Motor Speed');
legend('RPM','PWM');
Plot Normalization dataset
figure
plot(DataNorm);xlabel('Samples');ylabel('Normalized Values');
title('Normalized data graph');
legend('RPM');
Select a case
IN=data(:,end);%RPM motor
OUT=data(:,1);%PWM
figure
plot(OUT)
title('OUT');
System Identification
ident
Open the Classification Learner
%regressionLearner
%classificationLearner
Comments
Post a Comment