From 4b5899f9516141a84b731a213769456db52310a8 Mon Sep 17 00:00:00 2001 From: "Ilia O." Date: Fri, 16 Aug 2024 23:03:52 -0700 Subject: [PATCH] YDLIDAR SCL stub --- src/LDS_YDLIDAR_SCL.cpp | 63 +++++++++++++++++++++++++++++++++++++++++ src/LDS_YDLIDAR_SCL.h | 32 +++++++++++++++++++++ src/lds_all_models.h | 1 + 3 files changed, 96 insertions(+) create mode 100644 src/LDS_YDLIDAR_SCL.cpp create mode 100644 src/LDS_YDLIDAR_SCL.h diff --git a/src/LDS_YDLIDAR_SCL.cpp b/src/LDS_YDLIDAR_SCL.cpp new file mode 100644 index 0000000..0678fe3 --- /dev/null +++ b/src/LDS_YDLIDAR_SCL.cpp @@ -0,0 +1,63 @@ +// Copyright 2023-2024 REMAKE.AI, KAIA.AI, MAKERSPET.COM +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Based on https://github.com/YDLIDAR/lidarCar/ + +#include "LDS_YDLIDAR_SCL.h" + +const char* LDS_YDLIDAR_SCL::getModelName() { return "YDLIDAR SCL"; } + +LDS::result_t LDS_YDLIDAR_SCL::start() { + enableMotor(true); + postInfo(INFO_MODEL, getModelName()); + return LDS::RESULT_OK; +} + +uint32_t LDS_YDLIDAR_SCL::getSerialBaudRate() { + return 115200; +} + +float LDS_YDLIDAR_SCL::getTargetScanFreqHz() { + return DEFAULT_VALUE; +} + +int LDS_YDLIDAR_SCL::getSamplingRateHz() { + return 3000; +} + +float LDS_YDLIDAR_SCL::getCurrentScanFreqHz() { + return LDS_YDLIDAR_X4::getCurrentScanFreqHz(); +} + +LDS::result_t LDS_YDLIDAR_SCL::stop() { + enableMotor(false); + return RESULT_OK; +} + +void LDS_YDLIDAR_SCL::enableMotor(bool enable) { + motor_enabled = enable; + + if (enable) { + // Drive PWM + //setMotorPin(DIR_INPUT, LDS_MOTOR_PWM_PIN); + setMotorPin(DIR_OUTPUT_CONST, LDS_MOTOR_PWM_PIN); + setMotorPin(VALUE_HIGH, LDS_MOTOR_PWM_PIN); + } else { + setMotorPin(DIR_OUTPUT_CONST, LDS_MOTOR_PWM_PIN); + setMotorPin(VALUE_LOW, LDS_MOTOR_PWM_PIN); + } + + // Entire LDS on/off + //setMotorPin(enable ? VALUE_HIGH : VALUE_LOW, LDS_MOTOR_PWM_PIN); +} \ No newline at end of file diff --git a/src/LDS_YDLIDAR_SCL.h b/src/LDS_YDLIDAR_SCL.h new file mode 100644 index 0000000..dbf1e14 --- /dev/null +++ b/src/LDS_YDLIDAR_SCL.h @@ -0,0 +1,32 @@ +// Copyright 2023-2024 REMAKE.AI, KAIA.AI, MAKERSPET.COM +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Based on https://github.com/YDLIDAR/lidarCar/ + +#pragma once +#include "LDS_YDLIDAR_X4.h" + +class LDS_YDLIDAR_SCL : public LDS_YDLIDAR_X4 { + public: + virtual result_t start() override; + virtual result_t stop() override; + virtual const char* getModelName() override; + + virtual float getCurrentScanFreqHz() override; + virtual uint32_t getSerialBaudRate() override; + virtual float getTargetScanFreqHz() override; + virtual int getSamplingRateHz() override; + protected: + virtual void enableMotor(bool enable) override; +}; diff --git a/src/lds_all_models.h b/src/lds_all_models.h index a371b00..8de6388 100644 --- a/src/lds_all_models.h +++ b/src/lds_all_models.h @@ -18,6 +18,7 @@ #include "LDS_YDLIDAR_X3_PRO.h" #include "LDS_YDLIDAR_X3.h" #include "LDS_YDLIDAR_X2_X2L.h" +#include "LDS_YDLIDAR_SCL.h" #include "LDS_NEATO_XV11.h" #include "LDS_LDS02RR.h" #include "LDS_RPLIDAR_A1.h"