清理编码器+死代码+可读性整理: 删除ENCODER类(含UB析构), MotorController简化为PWM+GPIO裸控制器, 移除mortor_kp/ki/kd全局变量, 排除vl53l0x/zebra_detect死代码, 修复image_cv行列写反, 清理无关include

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
spdis
2026-06-10 15:15:34 +08:00
parent d284e18407
commit 114d93cec7
16 changed files with 264 additions and 519 deletions
+7 -43
View File
@@ -1,22 +1,14 @@
/*
* @Author: ilikara 3435193369@qq.com
* @Date: 2024-10-10 14:36:42
* @LastEditors: ilikara 3435193369@qq.com
* @LastEditTime: 2025-03-21 10:41:17
* @FilePath: /smartcar/src/MotorController.cpp
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* MotorController — 直流电机控制器实现
*/
#include "MotorController.h"
MotorController::MotorController(int pwmchip, int pwmnum, int gpioNum, unsigned int period_ns,
double kp, double ki, double kd, double targetSpeed,
int encoder_pwmNum, int encoder_gpioNum, int encoder_dir_)
: pwmController(pwmchip, pwmnum), directionGPIO(gpioNum), pidController(kp, ki, kd, targetSpeed, INCREMENTAL, 80),
encoder(encoder_pwmNum, encoder_gpioNum), encoder_dir(encoder_dir_)
MotorController::MotorController(int pwmchip, int pwmnum, int gpioNum, unsigned int period_ns)
: pwmController(pwmchip, pwmnum), directionGPIO(gpioNum)
{
pwmController.setPeriod(period_ns); // 设置 PWM 周期
pwmController.setPeriod(period_ns);
directionGPIO.setDirection("out");
pwmController.enable(); // 启用 PWM
pwmController.enable();
}
MotorController::~MotorController(void)
@@ -26,37 +18,9 @@ MotorController::~MotorController(void)
void MotorController::updateduty(double dutyCycle)
{
int newduty = pwmController.readPeriod() * abs(dutyCycle) / 100.0;
int newduty = pwmController.readPeriod() * std::abs(dutyCycle) / 100.0;
if (newduty != pwmController.readDutyCycle())
{
pwmController.setDutyCycle(newduty);
}
// 根据 PID 输出设置 GPIO 的方向
if (dutyCycle > 0)
{
directionGPIO.setValue(1); // 正向
}
else
{
directionGPIO.setValue(0); // 反向
}
//std::cout << encoder.pulse_counter_update() << std::endl;
}
void MotorController::updateSpeed(void)
{
double encoderReading = encoder.pulse_counter_update() * encoder_dir;
// std::cout << encoderReading << std::endl;
double output = pidController.update(encoderReading);
// int dutyCycle = static_cast<int>(output);
// 设置 PWM 占空比
updateduty(output);
std::cout << encoderReading << " " << output << std::endl;
}
void MotorController::updateTarget(int speed)
{
pidController.setTarget(speed);
directionGPIO.setValue(dutyCycle > 0);
}