Class EncoderMotorL9110 - GSTCH/SketchMadeEASY GitHub Wiki

Actuator EncoderMotorL9110

Topic Specification
Description This class controls a rotating drive. The motor is controlled with a L9110S H-bridge. This is able to control up to 2 motors. It uses two PWM pins (one per direction of rotation) to control one motor. 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 EncoderMotorL9110(int PinA, int PinB, int SensorAPin, int SensorBPin, int aPPR, int GearRatio, int MaxSpeed)
Parameter
PinA: Digital (Out) Pin with PWM for direction of rotation 1
PinB: Digital (Out) Pin with PWM for direction of rotation 1
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 EncoderMotorL9110* encoderMotor = new EncoderMotorL9110(11, 12, 3, 4, 7, 34, 0);
Examples Example 16‐EncoderMotor and LED controlled by FlySky FS‐i6X‐RemoteControl
Test 42
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):
EncoderMotorL9110(int PinA, int PinB, 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** ⚠️