Class EncoderMotorI2C - GSTCH/SketchMadeEASY GitHub Wiki

Actuator EncoderMotorI2C

Topic Specification
Description This class controls a rotating drive. The motor is controlled with an Adafruit Motor Shield Version 2. This is able to control up to 4 motors. It’s connected via I2C Bus. Up to 32 are stackable.
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 EncoderMotorI2C(int MotorNr, int SensorAPin, int SensorBPin, int PPR, int GearRatio, int MaxSpeed)
Parameter
MotorNr: Motor 1 to 4 of the shield
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 EncoderMotorI2C* encoderMotor = new EncoderMotorI2C(2, 3, 4, 7, 34, 0);
Examples Test 41
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):
EncoderMotorI2C(int MotorNr, 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** ⚠️