Skip to content

Commit

Permalink
Virtual methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiaai committed Jan 26, 2024
1 parent 4a1eb93 commit c5a3357
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
36 changes: 18 additions & 18 deletions src/LDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ class LDS {
};
public:
LDS();
result_t start(); // Initialize and start; call from Arduino setup()
void stop(); // Stop the motor and scanning
void loop(); // Call frequently from Arduino loop()
virtual result_t start() = 0; // Initialize and start; call from Arduino setup()
virtual void stop() = 0; // Stop the motor and scanning
virtual void loop() = 0; // Call frequently from Arduino loop()

uint32_t getSerialBaudRate();
float getCurrentScanFreq();
float getTargetScanFreqHz();
int getSamplingRateHz();
bool isActive();
virtual uint32_t getSerialBaudRate() = 0;
virtual float getCurrentScanFreqHz() = 0;
virtual float getTargetScanFreqHz() = 0;
virtual int getSamplingRateHz() = 0;
virtual bool isActive() = 0;

result_t setScanTargetFreqHz(float freq);
result_t setScanPIDCoeffs(float Kp, float Ki, float Kd);
result_t setScanPIDSamplePeriodMs(uint32_t sample_period_ms);
virtual result_t setScanTargetFreqHz(float freq) = 0;
virtual result_t setScanPIDCoeffs(float Kp, float Ki, float Kd) = 0;
virtual result_t setScanPIDSamplePeriodMs(uint32_t sample_period_ms) = 0;

void setScanPointCallback(ScanPointCallback scan_callback);
void setMotorPinCallback(MotorPinCallback motor_pin_callback);
void setPacketCallback(PacketCallback packet_callback);
void setSerialReadCallback(SerialReadCallback serial_read_callback);
void setSerialWriteCallback(SerialWriteCallback serial_write_callback);
void setInfoCallback(InfoCallback info_callback);
void setErrorCallback(ErrorCallback error_callback);
virtual void setScanPointCallback(ScanPointCallback scan_callback);
virtual void setMotorPinCallback(MotorPinCallback motor_pin_callback);
virtual void setPacketCallback(PacketCallback packet_callback);
virtual void setSerialReadCallback(SerialReadCallback serial_read_callback);
virtual void setSerialWriteCallback(SerialWriteCallback serial_write_callback);
virtual void setInfoCallback(InfoCallback info_callback);
virtual void setErrorCallback(ErrorCallback error_callback);

static String resultCodeToString(result_t code);
static String infoCodeToString(info_t code);
Expand Down
5 changes: 2 additions & 3 deletions src/LDS_LDS02RR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int LDS_LDS02RR::getSamplingRateHz() {
}
LDS::result_t LDS_LDS02RR::setScanPIDCoeffs(float Kp, float Ki, float Kd) {
scanFreqPID.SetTunings(Kp, Ki, Kd);
return RESULT_OK;
}

LDS::result_t LDS_LDS02RR::setScanPIDSamplePeriodMs(uint32_t sample_period_ms) {
Expand All @@ -50,8 +51,6 @@ LDS::result_t LDS_LDS02RR::setScanPIDSamplePeriodMs(uint32_t sample_period_ms) {
}

void LDS_LDS02RR::loop() {
LDS::result_t result = LDS::RESULT_OK;

while (true) {
int c = readSerial();
if (c < 0)
Expand Down Expand Up @@ -128,7 +127,7 @@ void LDS_LDS02RR::enableMotor(bool enable) {

if (enable) {
setMotorPin(DIR_OUTPUT_PWM, LDS_MOTOR_PWM_PIN);
setMotorPin(enable ? pwm_val : VALUE_LOW, LDS_MOTOR_PWM_PIN);
setMotorPin(enable ? pwm_val : float(VALUE_LOW), LDS_MOTOR_PWM_PIN);
} else {
setMotorPin(DIR_OUTPUT_CONST, LDS_MOTOR_PWM_PIN);
setMotorPin(VALUE_LOW, LDS_MOTOR_PWM_PIN);
Expand Down

0 comments on commit c5a3357

Please sign in to comment.