|
|
@ -10,18 +10,24 @@ static void limit_input(s32 &input, s32 min, s32 max) { |
|
|
|
if (input < min) input = min; |
|
|
|
} |
|
|
|
|
|
|
|
void MiniRobotCtrlModule::initialize(uint16_t module_id, FeiTeServoMotor *bus, uint8_t idinbus) { |
|
|
|
void MiniRobotCtrlModule::initialize(uint16_t module_id, FeiTeServoMotor *bus, uint8_t idinbus, flash_config_t *cfg) { |
|
|
|
m_bus = bus; |
|
|
|
m_id = idinbus; |
|
|
|
m_module_id = module_id; |
|
|
|
|
|
|
|
m_cfg = *cfg; |
|
|
|
m_default_cfg = *cfg; |
|
|
|
|
|
|
|
m_bus->write_u8(m_id, feite::kRegServoRunMode, feite::kServoMode); |
|
|
|
m_thread.init("MiniRobotCtrlModule", 1024, osPriorityNormal); |
|
|
|
|
|
|
|
enable(1); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t MiniRobotCtrlModule::enable(u8 enable) { |
|
|
|
bool suc = m_bus->write_u8(m_id, feite::reg_add_e::kRegServoTorqueSwitch, enable); |
|
|
|
if (!suc) return err::ksubdevice_overtime; |
|
|
|
m_com_reg.module_enable = enable; |
|
|
|
return err::ksucc; |
|
|
|
} |
|
|
|
int32_t MiniRobotCtrlModule::stop(u8 stop_type) { |
|
|
@ -326,6 +332,7 @@ int32_t MiniRobotCtrlModule::module_read_adc(int32_t adcindex, int32_t *adc) { |
|
|
|
int32_t MiniRobotCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t &val) { |
|
|
|
switch (param_id) { |
|
|
|
MODULE_COMMON_PROCESS_REG_CB(); |
|
|
|
PROCESS_REG(kreg_motor_default_torque, REG_GET(m_cfg.default_torque), REG_SET(m_cfg.default_torque)); |
|
|
|
PROCESS_REG(kreg_module_input_state, module_readio(&val), ACTION_NONE); |
|
|
|
PROCESS_REG(kreg_robot_pos, motor_read_pos(&val), ACTION_NONE); |
|
|
|
default: |
|
|
@ -410,3 +417,15 @@ int32_t MiniRobotCtrlModule::motor_read_pos(int32_t *pos) { |
|
|
|
if (!m_bus->getNowPos(m_id, *pos)) return err::ksubdevice_overtime; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t MiniRobotCtrlModule::motor_easy_rotate(int32_t direction) { |
|
|
|
if (direction == 1) { |
|
|
|
return move_forward(m_cfg.default_torque); |
|
|
|
} else if (direction == -1) { |
|
|
|
return move_backward(m_cfg.default_torque); |
|
|
|
} else { |
|
|
|
return err::kparam_out_of_range; |
|
|
|
} |
|
|
|
} |
|
|
|
int32_t MiniRobotCtrlModule::motor_easy_move_by(int32_t distance) { return move_by(distance, 0, m_cfg.default_torque, nullptr); } |
|
|
|
int32_t MiniRobotCtrlModule::motor_easy_move_to(int32_t position) { return move_to(position, 0, m_cfg.default_torque, nullptr); } |
|
|
|
int32_t MiniRobotCtrlModule::motor_easy_move_to_zero(int32_t direction) { return motor_easy_move_to(0); } |