Control PID para Motor DC con encoder - Arduino

Control PID para Motor DC con encoder - Arduino

Detailed Overview of Motor Control Project Using Arduino

In this section, the speaker introduces a project involving motor control using an Arduino board. The focus is on creating a controller within the Arduino for a DC motor with an encoder.

Motor and Encoder Setup

  • The motor used in the project is a common DC motor with an encoder, featuring 6 pins for power supply and encoder connections.
  • The encoder has 4 pins: 2 for power (ground and 5V) and 2 for phase signals. Only one phase will be utilized for speed control purposes.

Project Development Phases

  • The project will be divided into three main parts: reading the encoder signal, adding a potentiometer, and integrating the driver (L298N) for open-loop control.
  • The final phase involves implementing a controller based on difference equations in Arduino to regulate motor speed.

Additional Components and Considerations

  • An LCD display will be added towards the end of the project after successful testing.
  • The methodology used in this project can be applied to various systems beyond just motor control, such as inverted pendulums or robotic arms.

Reading Encoder Signal with Arduino

This part focuses on setting up the Arduino to read signals from the encoder attached to the DC motor.

Establishing Encoder Reading

  • Define a pin (e.g., pin 3) on the Arduino for connecting to the encoder's digital output.
  • Configure pin settings as input and set up serial monitoring to observe readings.

Interrupt Function for Signal Counting

  • Implement an interrupt function to count rising edges of pulses from the encoder signal.
  • Utilize interrupts to accurately count pulse transitions rather than individual high/low states.

Testing Encoder Readings

  • Display pulse counts via serial communication to verify proper functioning of signal counting.
  • Test functionality by manually rotating the encoder and observing corresponding pulse increments.

Calculating Frequency from Pulse Counts

This segment delves into converting accumulated pulse counts into frequency measurements using time intervals.

Time-Based Frequency Calculation

  • Introduce time delays (e.g., 1 second delay using delay(1000)).
  • Calculate frequency by dividing pulse counts within specified time intervals (e.g., pulses per second).

New Section

In this section, the speaker discusses the process of resetting a counter to zero and visualizing interruptions accumulating in the serial port every second. The focus is on measuring pulses per second using a counter.

Counter Reset and Pulse Measurement

  • The counter resets to zero, displaying interruptions accumulated by the counter in the serial port each second.
  • Opening the serial port shows pulse measurements per second, highlighting the issue of delays in programming for multitasking.
  • Introducing the millis function as an alternative to delay for multitasking purposes.
  • Explaining how millis function operates by executing tasks within a specified time frame without delaying subsequent tasks.
  • Setting up variables for millis function usage to avoid delays in code execution.

New Section

This part delves into utilizing internal variables and loops with if conditions to manage time intervals effectively using millis function for multitasking applications.

Utilizing Millis Function for Time Management

  • Defining internal variables and creating an if loop to compare current time with previous time interval set by millis function.
  • Explaining how millis tracks processing time from start and updating variables based on elapsed time compared to predefined intervals.
  • Ensuring timely updates by adjusting variable values within the loop structure without causing delays in external code execution.

New Section

This segment focuses on integrating milli functions effectively into code logic to maintain accurate pulse measurements while eliminating delays that could impact overall program performance.

Integrating Millis Function for Improved Performance

  • Implementing milli functions within code logic to achieve precise pulse measurements without disruptive delays.
  • Verifying functionality through serial port output, confirming accurate pulse measurement integration with milli functions.

New Section

Here, the discussion shifts towards testing revolutions per minute (RPM), requiring motor movement instead of manual input for RPM measurement accuracy.

Testing Revolutions Per Minute (RPM)

  • Transitioning from manual input testing to motor-driven RPM measurement setup for increased accuracy.
  • Connecting components including potentiometer, driver 298N, and encoder for motor movement control during RPM testing.

New Section

This part details setting up an open-loop system using a potentiometer to control motor speed and capture RPM data from an encoder during testing procedures.

Open-loop System Setup for Motor Control

  • Defining potentiometer input and PWM output variables essential for controlling motor speed in an open-loop system setup.

Setting Up Motor Control System

In this section, the speaker discusses setting up a motor control system using an Arduino board and various components.

Understanding Analog Write and Output Scaling

  • The speaker explains dividing 100 by 1000 to get 0.1 and mentions analog write output scaling from 0 to 255.
  • Analog write ranges from 0 to 255, while the input scale is from 0 to 100, necessitating a conversion for accurate motor movement control.

Calculating RPM for Motor Movement

  • The process involves calculating RPM based on encoder pulses per second and potentiometer values.
  • Differentiating between pulses per second (pps) and revolutions per minute (rpm) for accurate motor speed monitoring.

Understanding Motor Specifications

This section delves into the specifications of the motor being used in the setup, including encoder details and gear reduction ratios.

Motor Components and Resolutions

  • Detailed explanation of the motor components, encoder resolution, gear reduction ratio of 1:34, and maximum speed specifications.
  • The motor's resolution is defined by its encoder with 11 pulses per revolution, aided by a gear reduction ratio of 1:34 for precise movement control.

Calculating RPM for Motor Shaft

Here, the focus shifts to calculating RPM specifically for the motor shaft considering gear reductions and encoder resolutions.

Deriving RPM Equations

  • Formulating equations to calculate RPM based on encoder pulses per second and gear reduction ratios.
  • Explaining how pulse counts are converted into revolutions using encoder resolutions and gear reduction factors.

Optimizing RPM Measurement Frequency

This part emphasizes optimizing measurement frequency for accurate RPM readings through interval adjustments in code implementation.

Enhancing Measurement Precision

  • Multiplying pulse counts by time intervals to derive accurate RPM values every minute instead of every second.
  • Adjusting measurement intervals from one second to one-tenth of a second for enhanced precision in obtaining real-time RPM data.

Motor Speed Control Demonstration

Demonstrating practical application by controlling motor speed through potentiometer adjustments with real-time feedback on RPM readings.

Real-Time Speed Control

  • Observing motor speed changes in response to potentiometer adjustments with corresponding changes in displayed RPM values.

Setting up RPM Motor Control

In this section, the speaker demonstrates setting up RPM motor control using a potentiometer and monitoring the motor's RPM in real-time.

Programming Control PID

  • The speaker discusses setting up SharePoint and double M output, along with measuring the main shaft's RPM.
  • Explains the structure of a PID controller as proportional, integral, and derivative components within a closed loop system.
  • Transitioning from continuous functions to discrete signals for microcontrollers by converting transfer functions to Z-transform.
  • Introducing a zero-order hold before Z-transform to handle discrete signals in controllers like microcontrollers.
  • Performing Z-transform on the PID controller components to obtain their transformed values for programming.

Programming Control PID in Microcontroller

This section delves into transforming Z-transformed PID functions into difference equations for implementation in microcontrollers.

Transforming Transfer Functions

  • Converting Z-transformed functions into a set of difference equations essential for programming in microcontrollers.
  • Describing how terms involving zeta are handled in difference equations, emphasizing previous terms' influence on subsequent ones.
  • Formulating the complete set of difference equations representing the PID controller for programming on Arduino boards.

Defining Constants and Variables

  • Setting up constants such as Kp (proportional gain), Ki (integral gain), and Kd (derivative gain), crucial for tuning the controller's performance.
  • Defining variables like error terms and tuning parameters necessary for implementing the PID control algorithm effectively.

Detailed Explanation of Error Handling and Output Adjustment

In this section, the speaker delves into error handling within a recursive framework and discusses the adjustment of output values for effective system operation.

Error Handling in Recursive Operations

  • The error 2 value should be set based on error 1 after completing an operation within the recursive equation.
  • Emphasizes that error 1 and error 2 values need to be updated recursively for proper functioning.

Output Adjustment for System Stability

  • Suggests saturating the output value (v) to prevent it from exceeding operational limits, ensuring stability.
  • Introduces conditional statements to control output behavior based on predefined thresholds, enhancing system reliability.

Implementation of Output Saturation and Delay

This segment focuses on implementing output saturation techniques and introducing delays for smoother system responses.

Saturation Control and Delay Implementation

  • Discusses saturating the analog output signal to prevent exceeding maximum limits, ensuring safe operation.
  • Introduces a delay mechanism to soften transitions in output signals, promoting stability during system operations.

System Testing and Performance Evaluation

The speaker demonstrates testing procedures and evaluates system performance under varying parameters.

System Testing Process

  • Initiates system testing by activating motor functions through serial port communication.
  • Utilizes a plotter tool to visualize system behavior and assess response characteristics effectively.

Optimizing System Response with Parameter Adjustments

Focuses on optimizing system response by adjusting key parameters like Kp, Ki, and Kd for enhanced performance.

Parameter Optimization Impact

  • Modifies proportional (Kp), integral (Ki), and derivative (Kd) gains to observe changes in system response time.
  • Demonstrates how parameter adjustments influence speed of response, showcasing trade-offs between speed and stability.

Incorporating LCD Display for Enhanced Monitoring

Details the integration of an LCD display for real-time monitoring of system variables without computer dependency.

LCD Integration Process

  • Outlines connections required for integrating an LCD display with Arduino board for visual data representation.

[Música] vean a kl lcd si muevo el cerco en lo bajo [Aplausos] -

The speaker demonstrates moving the fence down using KL LCD, receiving applause from the audience.

Demonstrating Fence Movement

  • The speaker showcases moving the fence down with KL LCD.
  • Applause follows the successful demonstration of the fence movement.

[Aplausos] muy bien eso ha sido todo por esta oportunidad -

The session concludes with applause as the speaker wraps up, inviting replication and questions from the audience for future sessions.

Conclusion and Invitation

  • Applause fills the room as the session comes to an end.
  • The speaker encourages replication of demonstrated techniques by the audience.
  • Audience members are invited to ask any questions they may have.
Video description

✅Compra cursos completos: https://www.patreon.com/jesuscorreaperu Vamos a relajarnos un poco y vamos a programar en Arduino. La idea es realizar el control PID de un motor DC con encoder (facil de conseguir en cualquier tienda). Lo veremos desde las conexiones, la medición del encoder paso a paso, hasta el controlador PID que estará en forma de ecuación de diferencias. Todo muy sencillo si le pones atención. Úsalo en tus proyectos de cursos académicos. NOTA: Si deseas adquirir los archivos del video o asesoria vía zoom. Escríbame al correo (jesus_cor2630@hotmail.com / jcorreaay@unitru.edu.pe). NOTA: Si le interesa llevar una capacitación completa de temas relacionados a la automatización industrial, la industria 4.0, análisis de información, o de gerencia de mantenimiento y gerencia de procesos productivos. Escríbame al correo (jesus_cor2630@hotmail.com / jcorreaay@unitru.edu.pe). Instagram https://www.instagram.com/jcorreaay/?... 0:00 Intro 3:07 Lectura pulsos encoder 7:15 Lectura pulsos/seg encoder 13:10 Lectura RPM motor 26:52 Control PID en arduino 38:25 Prueba del PID 43:33 Añadimos el LCD