Class EncoderMotorL298 - GSTCH/SketchMadeEASY GitHub Wiki

Actuator EncoderMotorL298

Topic Specification
Description This class controls a rotating drive. The motor is controlled with a L298N H-bridge. This is able to control up to 2 motors. It uses a digital and a PWM pin to control one motor. The digital pin defines the direction, the PWM the speed. Create two objects of this class to control both motors.
An encoder motor has a rotary encoder to control the speed. The logic contains a PID regulator to hold the speed on the demanded value.
Sketch Made EASY supports up to 6 encoders in a sketch. This means that up to 6 encoder motors can be operated at the same time.
Constructor EncoderMotorL298(int DirectionPin, int SpeedPin, int SensorAPin, int SensorBPin, int aPPR, int GearRatio, int MaxSpeed)
Parameter
DirectionPin: Digital (Out) Pin
SpeedPin: Digital (Out) Pin with PWM
SensorAPin: Rotary Encoder A-Signal
SensorBPin: Rotary Encoder B-Signal
PPR: Pulses per Revolution of the rotary encoder
GearRatio: GearRatio: Gear ration of the motor
MaxSpeed: Sketch Made EASY includes an auto map from input to actuator. When set value to > 0, the map is active and maps speed to 0…MaxSpeed depending on the assigned input. When set value to 0, the logic takes the value of the input, assigned by a relation without map.
Range 0…255
Samples EncoderMotorL298* encoderMotor = new EncoderMotorL298(12, 10, 3, 4, 7, 34, 0);
Examples Test 40
Advanced More encoder motors:
Increase the const EASY_MAX_ENCODERS in the file “src\Kernel\RotaryEncoder.h” of the library.

Plot:
In the test are two #defines: define PLOT_ENCODERMOTOR and PLOT_ROTARYENCODER in the file “Common/BuildDefinition.h”. Uncomment one of them to plot with the Arduino IDE.

PLOT_ENCODERMOTOR
T: Target rotational speed [1/min]
REr: Rotary encoder rotational speed [1/min]
Ref: Filtered rotational speed (includes a low-pass filter) [1/min]
CS: Calculated speed, set by PID<BRP: Proportional term P of the regulator
I: Integrates past term I of the regulator
D: Diverential future term D of the regulator

There’s a constructor with the PID-factors (default 10/0/50):
EncoderMotorL298 (int DirectionPin, int SpeedPin, int SensorAPin, int SensorBPin, int PPR, int GearRatio, int MaxSpeed, float KP, float KI, float KD)


PLOT_ROTARYENCODER
Pos: Pulse Counter
RPMr: Rotational speed [1/min]
RPMf: Filtered rotational speed (includes a low-pass filter) [1/min]
⚠️ **GitHub.com Fallback** ⚠️