|
|
@ -289,10 +289,13 @@ int32_t MiniRobotCtrlModule::module_get_error(int32_t *iserror) { |
|
|
|
* @brief TODO: |
|
|
|
* Ìí¼Ó¹ýÔØ¼ì²â |
|
|
|
*/ |
|
|
|
*iserror = 0; |
|
|
|
*iserror = m_errorcode; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t MiniRobotCtrlModule::module_clear_error() { |
|
|
|
m_errorcode = 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t MiniRobotCtrlModule::module_clear_error() { return 0; } |
|
|
|
|
|
|
|
int32_t MiniRobotCtrlModule::module_set_param(int32_t param_id, int32_t param_value) { return err::kmodule_not_find_config_index; } |
|
|
|
int32_t MiniRobotCtrlModule::module_get_param(int32_t param_id, int32_t *param_value) { return err::kmodule_not_find_config_index; } |
|
|
@ -313,13 +316,54 @@ int32_t MiniRobotCtrlModule::motor_enable(int32_t varenable) { return enable(var |
|
|
|
int32_t MiniRobotCtrlModule::motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return rotate(direction, motor_velocity, acc, nullptr); } |
|
|
|
int32_t MiniRobotCtrlModule::motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return move_by(distance, motor_velocity, acc, nullptr); } |
|
|
|
int32_t MiniRobotCtrlModule::motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return move_to(position, motor_velocity, acc, nullptr); } |
|
|
|
int32_t MiniRobotCtrlModule::motor_move_to_with_torque(int32_t direction, int32_t torque) { |
|
|
|
int32_t MiniRobotCtrlModule::motor_rotate_with_torque(int32_t direction, int32_t torque) { |
|
|
|
if (direction >= 0) { |
|
|
|
return move_forward(torque); |
|
|
|
} else { |
|
|
|
return move_backward(torque); |
|
|
|
} |
|
|
|
} |
|
|
|
void MiniRobotCtrlModule::set_errorcode(int32_t errorcode) { m_errorcode = errorcode; } |
|
|
|
|
|
|
|
int32_t MiniRobotCtrlModule::motor_move_to_torque(int32_t targetpos, int32_t torque, int32_t overtime) { |
|
|
|
ZLOGI(TAG, "move_backward torque:%d", torque); |
|
|
|
|
|
|
|
if (!m_bus->ping(m_id)) return err::ksubdevice_overtime; |
|
|
|
limit_input(torque, 0, 1000); |
|
|
|
|
|
|
|
m_thread.stop(); |
|
|
|
if (!m_bus->moveTo(m_id, targetpos, 0, torque)) return err::ksubdevice_overtime; |
|
|
|
m_thread.start([this, torque, overtime, targetpos]() { |
|
|
|
int32_t entertime = zos_get_tick(); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
if (m_thread.getExitFlag()) break; |
|
|
|
|
|
|
|
if (overtime != 0 && zos_haspassedms(entertime) > overtime) { |
|
|
|
ZLOGI(TAG, "motor_move_to_torque %d overtime", m_id); |
|
|
|
stop(0); |
|
|
|
set_errorcode(err::kmotor_run_overtime); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t nowpos = 0; |
|
|
|
uint8_t moveFlag = 0; |
|
|
|
|
|
|
|
m_bus->getNowPos(m_id, nowpos); |
|
|
|
m_bus->getMoveFlag(m_id, moveFlag); |
|
|
|
|
|
|
|
if (nowpos - targetpos < 10 && moveFlag == 0) { |
|
|
|
ZLOGI(TAG, "motor_move_to_torque %d succ", m_id); |
|
|
|
stop(0); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
m_thread.sleep(10); |
|
|
|
} |
|
|
|
stop(0); |
|
|
|
}); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t MiniRobotCtrlModule::motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } |
|
|
|
int32_t MiniRobotCtrlModule::motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } |
|
|
|