You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.1 KiB
82 lines
2.1 KiB
//
|
|
// Created by iflyt on 2025/3/3.
|
|
//
|
|
|
|
#include "motor_manager.h"
|
|
|
|
// 初始化单例实例指针
|
|
MotorManager* MotorManager::instance = nullptr;
|
|
|
|
MotorManager::MotorManager() {}
|
|
|
|
// 获取单例实例
|
|
MotorManager* MotorManager::ins() {
|
|
if (instance == nullptr) {
|
|
instance = new MotorManager();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
// 获取某个电机的位置
|
|
int32_t MotorManager::getMotorPosition(int motorIndex) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return 0;
|
|
}
|
|
return motors[motorIndex].getPosition();
|
|
}
|
|
|
|
// 设置某个电机的目标位置
|
|
void MotorManager::setMotorTargetPosition(int motorIndex, int32_t targetPosition) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return;
|
|
}
|
|
motors[motorIndex].setTargetPosition(targetPosition);
|
|
}
|
|
|
|
// 设置某个电机的速度
|
|
void MotorManager::setMotorSpeed(int motorIndex, int32_t speed) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return;
|
|
}
|
|
motors[motorIndex].setSpeed(speed);
|
|
}
|
|
|
|
// 获取某个电机的速度
|
|
int32_t MotorManager::getMotorSpeed(int motorIndex) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return 0;
|
|
}
|
|
return motors[motorIndex].getRTSpeed();
|
|
}
|
|
|
|
// 获取某个电机的运动状态
|
|
uint8_t MotorManager::getMotorMovingStatus(int motorIndex) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return 0;
|
|
}
|
|
return motors[motorIndex].isMoving();
|
|
}
|
|
|
|
// 获取某个电机的编码器位置
|
|
int32_t MotorManager::getMotorEncoderPosition(int motorIndex) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return 0;
|
|
}
|
|
return motors[motorIndex].getEncoderPosition();
|
|
}
|
|
|
|
// 设置某个电机的编码器位置
|
|
void MotorManager::setMotorEncoderPosition(int motorIndex, int32_t encoderPos) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return;
|
|
}
|
|
motors[motorIndex].setEncoderPosition(encoderPos);
|
|
}
|
|
|
|
// 新增设置电机是否运动的接口
|
|
void MotorManager::setMotorMoving(int motorIndex, bool moving) {
|
|
if (motorIndex < 0 || motorIndex >= 3) {
|
|
return;
|
|
}
|
|
motors[motorIndex].setMoving(moving);
|
|
}
|