Skip to content

Commit

Permalink
Correct class names
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiaai committed Jan 21, 2024
1 parent 8203c6d commit 4a1eb93
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ You can find the board schematics at [Makerspet repo](https://github.com/makersp
## Release notes

### v0.2.0
- YDLIDAR X4 class name bugfix
- example bugfix
- renamed classes

### v0.1.0
- initial release
2 changes: 1 addition & 1 deletion examples/lds_basic_esp32/lds_basic_esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const uint8_t LDS_MOTOR_PWM_PIN = 15; // LDS motor speed control using PWM
#define LDS_MOTOR_PWM_CHANNEL 2 // ESP32 PWM channel for LDS motor speed control

HardwareSerial LdSerial(2); // TX 17, RX 16
LDS_YDLIDARX4 lds;
LDS_YDLIDAR_X4 lds;

void setup() {
lds.setScanPointCallback(lds_scan_point_callback);
Expand Down
4 changes: 2 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#######################################

LDS KEYWORD1
LDS_YDLIDARX4 KEYWORD1
LDS_LDSRR02 KEYWORD1
LDS_YDLIDAR_X4 KEYWORD1
LDS_LDS02RR KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
Expand Down
40 changes: 20 additions & 20 deletions src/LDS_LDS02RR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "LDS_LDS02RR.h"

LDS_LDSRR02::LDS_LDSRR02() : LDS() {
LDS_LDS02RR::LDS_LDS02RR() : LDS() {
motor_enabled = false;
clearVars();

Expand All @@ -33,23 +33,23 @@ LDS_LDSRR02::LDS_LDSRR02() : LDS() {
scan_rpm = 0;
}

uint32_t LDS_LDSRR02::getSerialBaudRate() {
uint32_t LDS_LDS02RR::getSerialBaudRate() {
return 115200;
}

int LDS_LDSRR02::getSamplingRateHz() {
int LDS_LDS02RR::getSamplingRateHz() {
return 1800;
}
LDS::result_t LDS_LDSRR02::setScanPIDCoeffs(float Kp, float Ki, float Kd) {
LDS::result_t LDS_LDS02RR::setScanPIDCoeffs(float Kp, float Ki, float Kd) {
scanFreqPID.SetTunings(Kp, Ki, Kd);
}

LDS::result_t LDS_LDSRR02::setScanPIDSamplePeriodMs(uint32_t sample_period_ms) {
LDS::result_t LDS_LDS02RR::setScanPIDSamplePeriodMs(uint32_t sample_period_ms) {
scanFreqPID.SetSampleTime(sample_period_ms);
return LDS::RESULT_OK;
}

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

while (true) {
Expand All @@ -73,15 +73,15 @@ void LDS_LDSRR02::loop() {
}
}

bool LDS_LDSRR02::isActive() {
bool LDS_LDS02RR::isActive() {
return motor_enabled;
}

float LDS_LDSRR02::getCurrentScanFreqHz() {
float LDS_LDS02RR::getCurrentScanFreqHz() {
return scan_rpm/60.0f;
}

void LDS_LDSRR02::clearVars() {
void LDS_LDS02RR::clearVars() {
for (int ix = 0; ix < N_DATA_QUADS; ix++) {
aryDist[ix] = 0;
aryQuality[ix] = 0;
Expand All @@ -93,7 +93,7 @@ void LDS_LDSRR02::clearVars() {
eState = eState_Find_COMMAND; // This packet is done -- loLDS::RESULT_OK for next COMMAND byte
}

bool LDS_LDSRR02::isValidPacket() {
bool LDS_LDS02RR::isValidPacket() {
unsigned long chk32;
unsigned long checksum;
const int bytesToCheck = PACKET_LENGTH - 2;
Expand Down Expand Up @@ -123,7 +123,7 @@ bool LDS_LDSRR02::isValidPacket() {
return ((b1a == b1b) && (b2a == b2b));
}

void LDS_LDSRR02::enableMotor(bool enable) {
void LDS_LDS02RR::enableMotor(bool enable) {
motor_enabled = enable;

if (enable) {
Expand All @@ -136,7 +136,7 @@ void LDS_LDSRR02::enableMotor(bool enable) {
}

// TODO uint8 iQuad?
void LDS_LDSRR02::processSignalStrength(int iQuad) {
void LDS_LDS02RR::processSignalStrength(int iQuad) {
uint8_t dataL, dataM;
aryQuality[iQuad] = 0; // initialize
int iOffset = OFFSET_TO_4_DATA_READINGS + (iQuad * N_DATA_QUADS) + OFFSET_DATA_SIGNAL_LSB;
Expand All @@ -145,7 +145,7 @@ void LDS_LDSRR02::processSignalStrength(int iQuad) {
aryQuality[iQuad] = dataL | (dataM << 8);
}

byte LDS_LDSRR02::processDistance(int iQuad) {
byte LDS_LDS02RR::processDistance(int iQuad) {
// Data 0 to Data 3 are the 4 readings. Each one is 4 bytes long, and organized as follows :
// byte 0 : <distance 7:0>
// byte 1 : <"invalid data" flag> <"strength warning" flag> <distance 13:8>
Expand All @@ -166,14 +166,14 @@ byte LDS_LDSRR02::processDistance(int iQuad) {
return 0; // LDS::RESULT_OKay
}

void LDS_LDSRR02::processSpeed() {
void LDS_LDS02RR::processSpeed() {
// Extract motor speed from packet - two bytes little-endian, equals RPM/64
uint8_t scan_rph_low_byte = Packet[OFFSET_TO_SPEED_LSB];
uint8_t scan_rph_high_byte = Packet[OFFSET_TO_SPEED_MSB];
scan_rpm = float( (scan_rph_high_byte << 8) | scan_rph_low_byte ) / 64.0;
}

uint16_t LDS_LDSRR02::processIndex() {
uint16_t LDS_LDS02RR::processIndex() {
// processIndex - Process the packet element 'index'
// index is the index byte in the 90 packets, going from A0 (packet 0, readings 0 to 3) to F9
// (packet 89, readings 356 to 359).
Expand All @@ -185,7 +185,7 @@ uint16_t LDS_LDSRR02::processIndex() {
return angle;
}

LDS::result_t LDS_LDSRR02::processByte(int inByte) {
LDS::result_t LDS_LDS02RR::processByte(int inByte) {
// Switch, based on 'eState':
// State 1: We're scanning for 0xFA (COMMAND) in the input stream
// State 2: Build a complete data packet
Expand Down Expand Up @@ -238,7 +238,7 @@ LDS::result_t LDS_LDSRR02::processByte(int inByte) {
return result;
}

LDS::result_t LDS_LDSRR02::setScanTargetFreqHz(float freq) {
LDS::result_t LDS_LDS02RR::setScanTargetFreqHz(float freq) {
float rpm = freq * 60.0f;
if (rpm <= 0) {
scan_rpm_setpoint = DEFAULT_SCAN_RPM;
Expand All @@ -252,15 +252,15 @@ LDS::result_t LDS_LDSRR02::setScanTargetFreqHz(float freq) {
return LDS::RESULT_OK;
}

float LDS_LDSRR02::getTargetScanFreqHz() {
float LDS_LDS02RR::getTargetScanFreqHz() {
return scan_rpm_setpoint / 60.0f;
}

void LDS_LDSRR02::stop() {
void LDS_LDS02RR::stop() {
enableMotor(false);
}

LDS::result_t LDS_LDSRR02::start() {
LDS::result_t LDS_LDS02RR::start() {
enableMotor(true);
postInfo(INFO_MODEL, "LDS02RR");
postInfo(INFO_SAMPLING_RATE, String(getSamplingRateHz()));
Expand Down
4 changes: 2 additions & 2 deletions src/LDS_LDS02RR.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "LDS.h"
#include "PID_v1_0_0.h"

class LDS_LDSRR02 : public LDS {
class LDS_LDS02RR : public LDS {
public:
LDS_LDSRR02();
LDS_LDS02RR();

result_t start();
void stop();
Expand Down
40 changes: 20 additions & 20 deletions src/LDS_YDLIDAR_X4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

#include "LDS_YDLIDAR_X4.h"

LDS_YDLIDARX4::LDS_YDLIDARX4() : LDS() {
LDS_YDLIDAR_X4::LDS_YDLIDAR_X4() : LDS() {
motor_enabled = false;
target_scan_freq = sampling_rate = ERROR_UNKNOWN;
}

LDS::result_t LDS_YDLIDARX4::start() {
LDS::result_t LDS_YDLIDAR_X4::start() {
// Initialize
enableMotor(false);

Expand Down Expand Up @@ -93,29 +93,29 @@ LDS::result_t LDS_YDLIDARX4::start() {
return LDS::RESULT_OK;
}

uint32_t LDS_YDLIDARX4::getSerialBaudRate() {
uint32_t LDS_YDLIDAR_X4::getSerialBaudRate() {
return 128000;
}

float LDS_YDLIDARX4::getCurrentScanFreqHz() {
float LDS_YDLIDAR_X4::getCurrentScanFreqHz() {
return ERROR_NOT_IMPLEMENTED;
}

float LDS_YDLIDARX4::getTargetScanFreqHz() {
float LDS_YDLIDAR_X4::getTargetScanFreqHz() {
return target_scan_freq;
}

int LDS_YDLIDARX4::getSamplingRateHz() {
int LDS_YDLIDAR_X4::getSamplingRateHz() {
return sampling_rate;
}

void LDS_YDLIDARX4::stop() {
void LDS_YDLIDAR_X4::stop() {
if (isActive())
abort();
enableMotor(false);
}

void LDS_YDLIDARX4::enableMotor(bool enable) {
void LDS_YDLIDAR_X4::enableMotor(bool enable) {
motor_enabled = enable;

setMotorPin(DIR_INPUT, LDS_MOTOR_PWM_PIN);
Expand All @@ -125,23 +125,23 @@ void LDS_YDLIDARX4::enableMotor(bool enable) {
setMotorPin(enable ? VALUE_HIGH : VALUE_LOW, LDS_MOTOR_EN_PIN);
}

bool LDS_YDLIDARX4::isActive() {
bool LDS_YDLIDAR_X4::isActive() {
return motor_enabled;
}

LDS::result_t LDS_YDLIDARX4::setScanTargetFreqHz(float freq) {
LDS::result_t LDS_YDLIDAR_X4::setScanTargetFreqHz(float freq) {
return ERROR_NOT_IMPLEMENTED;
}

LDS::result_t LDS_YDLIDARX4::setScanPIDSamplePeriodMs(uint32_t sample_period_ms) {
LDS::result_t LDS_YDLIDAR_X4::setScanPIDSamplePeriodMs(uint32_t sample_period_ms) {
return ERROR_NOT_IMPLEMENTED;
}

LDS::result_t LDS_YDLIDARX4::setScanPIDCoeffs(float Kp, float Ki, float Kd) {
LDS::result_t LDS_YDLIDAR_X4::setScanPIDCoeffs(float Kp, float Ki, float Kd) {
return ERROR_NOT_IMPLEMENTED;
}

LDS::result_t LDS_YDLIDARX4::waitScanDot() {
LDS::result_t LDS_YDLIDAR_X4::waitScanDot() {
static int recvPos = 0;
static uint8_t package_Sample_Num = 0;
static int package_recvPos = 0;
Expand Down Expand Up @@ -399,18 +399,18 @@ LDS::result_t LDS_YDLIDARX4::waitScanDot() {
return LDS::RESULT_OK;
}

void LDS_YDLIDARX4::loop() {
void LDS_YDLIDAR_X4::loop() {
result_t result = waitScanDot();
if (result < 0)
postError(result, "waitScanDot()");
}

LDS::result_t LDS_YDLIDARX4::abort() {
LDS::result_t LDS_YDLIDAR_X4::abort() {
// stop the scanPoint operation
return sendCommand(LIDAR_CMD_FORCE_STOP, NULL, 0);
}

LDS::result_t LDS_YDLIDARX4::sendCommand(uint8_t cmd, const void * payload, size_t payloadsize) {
LDS::result_t LDS_YDLIDAR_X4::sendCommand(uint8_t cmd, const void * payload, size_t payloadsize) {
//send data to serial
cmd_packet pkt_header;
cmd_packet * header = &pkt_header;
Expand Down Expand Up @@ -439,7 +439,7 @@ LDS::result_t LDS_YDLIDARX4::sendCommand(uint8_t cmd, const void * payload, size
return LDS::RESULT_OK;
}

LDS::result_t LDS_YDLIDARX4::getDeviceInfo(device_info & info, uint32_t timeout) {
LDS::result_t LDS_YDLIDAR_X4::getDeviceInfo(device_info & info, uint32_t timeout) {
LDS::result_t ans;
uint8_t recvPos = 0;
uint32_t currentTs = millis();
Expand Down Expand Up @@ -473,7 +473,7 @@ LDS::result_t LDS_YDLIDARX4::getDeviceInfo(device_info & info, uint32_t timeout)
return ERROR_TIMEOUT;
}

LDS::result_t LDS_YDLIDARX4::waitResponseHeader(lidar_ans_header * header, uint32_t timeout) {
LDS::result_t LDS_YDLIDAR_X4::waitResponseHeader(lidar_ans_header * header, uint32_t timeout) {
// wait response header
int recvPos = 0;
uint32_t startTs = millis();
Expand Down Expand Up @@ -506,7 +506,7 @@ LDS::result_t LDS_YDLIDARX4::waitResponseHeader(lidar_ans_header * header, uint3
}

// ask the YDLIDAR for its device health
LDS::result_t LDS_YDLIDARX4::getHealth(device_health & health, uint32_t timeout) {
LDS::result_t LDS_YDLIDAR_X4::getHealth(device_health & health, uint32_t timeout) {
LDS::result_t ans;
uint8_t recvPos = 0;
uint32_t currentTs = millis();
Expand Down Expand Up @@ -540,7 +540,7 @@ LDS::result_t LDS_YDLIDARX4::getHealth(device_health & health, uint32_t timeout)
return ERROR_TIMEOUT;
}

LDS::result_t LDS_YDLIDARX4::startScan(bool force, uint32_t timeout ) {
LDS::result_t LDS_YDLIDAR_X4::startScan(bool force, uint32_t timeout ) {
// start the scanPoint operation
LDS::result_t ans;

Expand Down
4 changes: 2 additions & 2 deletions src/LDS_YDLIDAR_X4.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#pragma once
#include "LDS.h"

class LDS_YDLIDARX4 : public LDS {
class LDS_YDLIDAR_X4 : public LDS {
public:
LDS_YDLIDARX4();
LDS_YDLIDAR_X4();

result_t start();
void stop();
Expand Down

0 comments on commit 4a1eb93

Please sign in to comment.