|
@ -102,10 +102,11 @@ static void reginfo_init() { |
|
|
/*86*/ REG_INFO_INIT(kRegServoAccMultiple /* */, 1, UNSIGN, 0); // 86 加速度倍数
|
|
|
/*86*/ REG_INFO_INIT(kRegServoAccMultiple /* */, 1, UNSIGN, 0); // 86 加速度倍数
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FeiTeServoMotor::regServo(uint8_t id, feite_servo_model_number_t model_type) { |
|
|
|
|
|
|
|
|
void FeiTeServoMotor::regServo(uint8_t id, feite_servo_model_number_t model_type, bool shaft) { |
|
|
feite_servo_info_t info; |
|
|
feite_servo_info_t info; |
|
|
info.id = id; |
|
|
info.id = id; |
|
|
info.model_type = model_type; |
|
|
info.model_type = model_type; |
|
|
|
|
|
info.shaft = shaft; |
|
|
if (info.model_type == ksts5420m_c001) { |
|
|
if (info.model_type == ksts5420m_c001) { |
|
|
info.support_mode0 = true; |
|
|
info.support_mode0 = true; |
|
|
info.support_mode1 = true; |
|
|
info.support_mode1 = true; |
|
@ -116,8 +117,8 @@ void FeiTeServoMotor::regServo(uint8_t id, feite_servo_model_number_t model_type |
|
|
|
|
|
|
|
|
info.regDefaultVal_servoMinAngle = 1; |
|
|
info.regDefaultVal_servoMinAngle = 1; |
|
|
info.regDefaultVal_servoMaxAngle = 4094; |
|
|
info.regDefaultVal_servoMaxAngle = 4094; |
|
|
|
|
|
|
|
|
info.angleConverCoefficient = 360 / 4096.0; |
|
|
|
|
|
|
|
|
info.range = 4096; |
|
|
|
|
|
info.angleConverCoefficient = 360 / 4096.0; |
|
|
} else if (info.model_type == kscs009) { |
|
|
} else if (info.model_type == kscs009) { |
|
|
info.support_mode0 = true; |
|
|
info.support_mode0 = true; |
|
|
info.support_mode1 = false; |
|
|
info.support_mode1 = false; |
|
@ -127,6 +128,7 @@ void FeiTeServoMotor::regServo(uint8_t id, feite_servo_model_number_t model_type |
|
|
info.isSCS = true; |
|
|
info.isSCS = true; |
|
|
info.regDefaultVal_servoMinAngle = 20; |
|
|
info.regDefaultVal_servoMinAngle = 20; |
|
|
info.regDefaultVal_servoMaxAngle = 1003; |
|
|
info.regDefaultVal_servoMaxAngle = 1003; |
|
|
|
|
|
info.range = 1024; |
|
|
info.angleConverCoefficient = 300 / 1024.0; |
|
|
info.angleConverCoefficient = 300 / 1024.0; |
|
|
} |
|
|
} |
|
|
regServoInfo(&info); |
|
|
regServoInfo(&info); |
|
@ -187,6 +189,12 @@ bool FeiTeServoMotor::runInMode0(uint8_t id, int32_t limitTorque, int32_t speed, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (info->isSCS) { |
|
|
if (info->isSCS) { |
|
|
|
|
|
if (info->shaft) { |
|
|
|
|
|
pos3600 = 3600 - pos3600; |
|
|
|
|
|
} |
|
|
|
|
|
if (pos3600 < 0) { |
|
|
|
|
|
pos3600 = 0; |
|
|
|
|
|
} |
|
|
if (limitTorque <= 0) limitTorque = 0; |
|
|
if (limitTorque <= 0) limitTorque = 0; |
|
|
if (limitTorque > 1000) limitTorque = 1000; |
|
|
if (limitTorque > 1000) limitTorque = 1000; |
|
|
|
|
|
|
|
@ -207,6 +215,12 @@ bool FeiTeServoMotor::runInMode0(uint8_t id, int32_t limitTorque, int32_t speed, |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
if (info->shaft) { |
|
|
|
|
|
pos3600 = 3600 - pos3600; |
|
|
|
|
|
} |
|
|
|
|
|
if (pos3600 < 0) { |
|
|
|
|
|
pos3600 = 0; |
|
|
|
|
|
} |
|
|
if (limitTorque <= 0) limitTorque = 0; |
|
|
if (limitTorque <= 0) limitTorque = 0; |
|
|
if (limitTorque > 1000) limitTorque = 1000; |
|
|
if (limitTorque > 1000) limitTorque = 1000; |
|
|
|
|
|
|
|
@ -233,6 +247,75 @@ bool FeiTeServoMotor::runInMode0(uint8_t id, int32_t limitTorque, int32_t speed, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool FeiTeServoMotor::setInMode0(uint8_t id) { |
|
|
|
|
|
zlock_guard l(m_mutex); |
|
|
|
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
|
|
|
|
|
|
|
|
|
if (!info) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode0 id:%d not find", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (info->isSCS) { |
|
|
|
|
|
// 由于SCS型号的舵机如果当前工作在模式2下,
|
|
|
|
|
|
// 则 kRegServoRunTime 控制运行方向和扭矩,这里需要将其修改为0,让其停下来
|
|
|
|
|
|
stop(id); |
|
|
|
|
|
DO(write_reg(id, kRegServoMinAngle, info->regDefaultVal_servoMinAngle)); |
|
|
|
|
|
DO(write_reg(id, kRegServoMaxAngle, info->regDefaultVal_servoMaxAngle)); |
|
|
|
|
|
return true; |
|
|
|
|
|
} else { |
|
|
|
|
|
int32_t val = 0; |
|
|
|
|
|
int32_t nowmode = 0; |
|
|
|
|
|
DO(read_reg(id, kRegServoRunMode, &nowmode)); |
|
|
|
|
|
if (nowmode != 0) { |
|
|
|
|
|
DO(write_reg(id, kRegServoRunMode, (uint8_t)0)); |
|
|
|
|
|
} |
|
|
|
|
|
DO(write_reg(id, kRegServoTorqueSwitch, 1)); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
bool FeiTeServoMotor::setInMode1(uint8_t id) { |
|
|
|
|
|
zlock_guard l(m_mutex); |
|
|
|
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
|
|
|
|
|
|
|
|
|
if (!info) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode0 id:%d not find", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (!info->support_mode1) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode1 id:%d not support", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (info->isSCS) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode1 id:%d not support", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} else { |
|
|
|
|
|
stop(id); |
|
|
|
|
|
int32_t nowmode = 0; |
|
|
|
|
|
DO(read_reg(id, kRegServoRunMode, &nowmode)); |
|
|
|
|
|
if (nowmode != 1) { |
|
|
|
|
|
DO(write_reg(id, kRegServoRunMode, (uint8_t)1)); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool FeiTeServoMotor::setInMode2(uint8_t id) { |
|
|
|
|
|
zlock_guard l(m_mutex); |
|
|
|
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
|
|
|
|
|
|
|
|
|
if (!info) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode0 id:%d not find", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (!info->support_mode2) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode2 id:%d not support", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return setInMode0(id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bool FeiTeServoMotor::isSupportMode0(uint8_t id) { |
|
|
bool FeiTeServoMotor::isSupportMode0(uint8_t id) { |
|
|
zlock_guard l(m_mutex); |
|
|
zlock_guard l(m_mutex); |
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
@ -268,6 +351,10 @@ bool FeiTeServoMotor::runInMode1(uint8_t id, int32_t limitTorque, int32_t speed) |
|
|
ZLOGE(TAG, "runInMode1 id:%d not support", id); |
|
|
ZLOGE(TAG, "runInMode1 id:%d not support", id); |
|
|
return false; |
|
|
return false; |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
if (info->shaft) { |
|
|
|
|
|
speed = -speed; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (limitTorque <= 0) limitTorque = 0; |
|
|
if (limitTorque <= 0) limitTorque = 0; |
|
|
if (limitTorque > 1000) limitTorque = 1000; |
|
|
if (limitTorque > 1000) limitTorque = 1000; |
|
|
stop(id); |
|
|
stop(id); |
|
@ -282,6 +369,82 @@ bool FeiTeServoMotor::runInMode1(uint8_t id, int32_t limitTorque, int32_t speed) |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int16_t getcalibrate(int16_t nowpos, int16_t aftercalibratepos) { |
|
|
|
|
|
int16_t calibrate = nowpos - aftercalibratepos; |
|
|
|
|
|
while (true) { |
|
|
|
|
|
if (calibrate > 2047) { |
|
|
|
|
|
calibrate -= 4094; |
|
|
|
|
|
} else if (calibrate < -2047) { |
|
|
|
|
|
calibrate += 4094; |
|
|
|
|
|
} else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return calibrate; |
|
|
|
|
|
} |
|
|
|
|
|
bool FeiTeServoMotor::setCurPos(uint8_t id, int32_t pos3600) { |
|
|
|
|
|
zlock_guard l(m_mutex); |
|
|
|
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
|
|
|
|
|
|
|
|
|
if (!info) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode0 id:%d not find", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (info->isSCS) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode1 id:%d not support", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} else { |
|
|
|
|
|
if (info->range != 4096) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (info->shaft) { |
|
|
|
|
|
pos3600 = 3600 - pos3600; |
|
|
|
|
|
} |
|
|
|
|
|
int32_t motor_pos = pos3600 / 10.0 / info->angleConverCoefficient; |
|
|
|
|
|
return setCurPos4096(id, motor_pos); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool FeiTeServoMotor::isSupportSetCurPos(uint8_t id) { |
|
|
|
|
|
zlock_guard l(m_mutex); |
|
|
|
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
|
|
|
|
|
|
|
|
|
if (!info) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode0 id:%d not find", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (info->isSCS) { |
|
|
|
|
|
ZLOGE(TAG, "runInMode1 id:%d not support", id); |
|
|
|
|
|
return false; |
|
|
|
|
|
} else { |
|
|
|
|
|
if (info->range != 4096) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool FeiTeServoMotor::setCurPos4096(uint8_t id, int32_t targetpos4095) { |
|
|
|
|
|
DO(setInMode0(id)); |
|
|
|
|
|
|
|
|
|
|
|
int32_t nowpos = 0; |
|
|
|
|
|
int32_t nowposcalibration = 0; |
|
|
|
|
|
DO(write_reg(id, feite::reg_add_e::kRegServoTorqueSwitch, 0)); |
|
|
|
|
|
DO(write_reg(id, kRegServoCalibration, 0)); |
|
|
|
|
|
|
|
|
|
|
|
DO(read_reg(id, kRegServoCurrentPos, &nowpos)); |
|
|
|
|
|
int16_t newcalibrate = getcalibrate(nowpos, targetpos4095); |
|
|
|
|
|
DO(write_reg(id, kRegServoLockFlag, 0)); |
|
|
|
|
|
DO(write_reg(id, kRegServoCalibration, newcalibrate)); |
|
|
|
|
|
DO(write_reg(id, kRegServoLockFlag, 1)); |
|
|
|
|
|
|
|
|
|
|
|
DO(write_reg(id, kRegServoTargetPos, targetpos4095)); |
|
|
|
|
|
DO(write_reg(id, feite::reg_add_e::kRegServoTorqueSwitch, 1)); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bool FeiTeServoMotor::runInMode2(uint8_t id, int32_t torque) { |
|
|
bool FeiTeServoMotor::runInMode2(uint8_t id, int32_t torque) { |
|
|
zlock_guard l(m_mutex); |
|
|
zlock_guard l(m_mutex); |
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
|
feite_servo_info_t* info = getServoInfo(id); |
|
@ -296,6 +459,10 @@ bool FeiTeServoMotor::runInMode2(uint8_t id, int32_t torque) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (info->isSCS) { |
|
|
if (info->isSCS) { |
|
|
|
|
|
if (info->shaft) { |
|
|
|
|
|
torque = -torque; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
stop(id); |
|
|
stop(id); |
|
|
DO(write_reg(id, kRegServoMinAngle, 0)); |
|
|
DO(write_reg(id, kRegServoMinAngle, 0)); |
|
|
DO(write_reg(id, kRegServoMaxAngle, 0)); |
|
|
DO(write_reg(id, kRegServoMaxAngle, 0)); |
|
@ -352,6 +519,17 @@ bool FeiTeServoMotor::getPos(uint8_t id, int32_t* pos) { |
|
|
// ZLOGI(TAG, "getPos id:%d pos:%d", id, *pos);
|
|
|
// ZLOGI(TAG, "getPos id:%d pos:%d", id, *pos);
|
|
|
|
|
|
|
|
|
*pos = (*pos) * info->angleConverCoefficient * 10 + 0.5; |
|
|
*pos = (*pos) * info->angleConverCoefficient * 10 + 0.5; |
|
|
|
|
|
|
|
|
|
|
|
if (info->shaft) { |
|
|
|
|
|
*pos = 3600 - *pos; |
|
|
|
|
|
} |
|
|
|
|
|
if (*pos < 0) { |
|
|
|
|
|
*pos = 0; |
|
|
|
|
|
} |
|
|
|
|
|
if (*pos > 3600) { |
|
|
|
|
|
*pos = 3600; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
bool FeiTeServoMotor::isMove(uint8_t id, int32_t* move) { |
|
|
bool FeiTeServoMotor::isMove(uint8_t id, int32_t* move) { |
|
|