|
|
@ -38,6 +38,8 @@ static chip_cfg_t chipcfg = { |
|
|
|
.huart = &DEBUG_UART, |
|
|
|
.debuglight = DEBUG_LIGHT_GPIO, |
|
|
|
}; |
|
|
|
TMC5130 m_motor1; |
|
|
|
static int32_t m_velocity; |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 代码 * |
|
|
@ -56,7 +58,6 @@ void regfn() { |
|
|
|
osDelay(atoi(argv[1])); |
|
|
|
}); |
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*******************************************************************************
|
|
|
|
* 步进电机 * |
|
|
|
*******************************************************************************/ |
|
|
@ -76,52 +77,40 @@ void regfn() { |
|
|
|
*/ |
|
|
|
cmdScheduler.registerCmd("step_motor_setvelocity", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(2); |
|
|
|
|
|
|
|
StepMotor* motor = NULL; |
|
|
|
GET_MOTOR(motor); |
|
|
|
|
|
|
|
motor->setVelocity(atoi(argv[2])); |
|
|
|
int motorid = atoi(argv[1]); |
|
|
|
m_velocity = atoi(argv[2]); |
|
|
|
}); |
|
|
|
cmdScheduler.registerCmd("step_motor_set_acc", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(2); |
|
|
|
|
|
|
|
StepMotor* motor = NULL; |
|
|
|
GET_MOTOR(motor); |
|
|
|
|
|
|
|
motor->setAcc(atoi(argv[2])); |
|
|
|
m_motor1.setAcceleration(atoi(argv[2])); |
|
|
|
}); |
|
|
|
cmdScheduler.registerCmd("step_motor_set_dec", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(2); |
|
|
|
|
|
|
|
StepMotor* motor = NULL; |
|
|
|
GET_MOTOR(motor); |
|
|
|
|
|
|
|
motor->setDec(atoi(argv[2])); |
|
|
|
m_motor1.setDeceleration(atoi(argv[2])); |
|
|
|
}); |
|
|
|
cmdScheduler.registerCmd("step_motor_moveto", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(2); |
|
|
|
|
|
|
|
StepMotor* motor = NULL; |
|
|
|
GET_MOTOR(motor); |
|
|
|
|
|
|
|
motor->moveTo(atoi(argv[2])); |
|
|
|
ZLOGI(TAG, "step_motor_moveto %d %d", atoi(argv[2]), m_velocity); |
|
|
|
m_motor1.moveTo(atoi(argv[2]), m_velocity); |
|
|
|
}); |
|
|
|
cmdScheduler.registerCmd("step_motor_moveby", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(2); |
|
|
|
|
|
|
|
StepMotor* motor = NULL; |
|
|
|
GET_MOTOR(motor); |
|
|
|
|
|
|
|
motor->moveBy(atoi(argv[2])); |
|
|
|
ZLOGI(TAG, "step_motor_moveby %d %d", atoi(argv[2]), m_velocity); |
|
|
|
m_motor1.moveBy(atoi(argv[2]), m_velocity); |
|
|
|
}); |
|
|
|
cmdScheduler.registerCmd("step_motor_rotate", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(2); |
|
|
|
|
|
|
|
StepMotor* motor = NULL; |
|
|
|
GET_MOTOR(motor); |
|
|
|
|
|
|
|
motor->rotate(atoi(argv[2])); |
|
|
|
ZLOGI(TAG, "step_motor_rotate %d %d", atoi(argv[2]), m_velocity); |
|
|
|
if (atoi(argv[2]) > 0) { |
|
|
|
m_motor1.rotate(m_velocity); |
|
|
|
} else if (atoi(argv[2]) == 0) { |
|
|
|
m_motor1.stop(); |
|
|
|
} else { |
|
|
|
m_motor1.rotate(-m_velocity); |
|
|
|
} |
|
|
|
}); |
|
|
|
#if 0
|
|
|
|
|
|
|
|
cmdScheduler.registerCmd("step_motor_movetozero", [](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { |
|
|
|
CHECK_ARGC(1); |
|
|
|
|
|
|
@ -173,8 +162,6 @@ void regfn() { |
|
|
|
#define MOTOR1_SPI_MODE_SELECT PB4
|
|
|
|
// TMC5130HImpl m_tmc5130motor;
|
|
|
|
|
|
|
|
TMC5130 m_motor1; |
|
|
|
|
|
|
|
void Main::run() { |
|
|
|
/*******************************************************************************
|
|
|
|
* 系统初始化 * |
|
|
@ -197,9 +184,11 @@ void Main::run() { |
|
|
|
m_motor1.setIHOLD_IRUN(1, 20, 0); |
|
|
|
m_motor1.setMotorShaft(true); |
|
|
|
|
|
|
|
m_motor1.setAcceleration(300000); |
|
|
|
m_motor1.setDeceleration(300000); |
|
|
|
|
|
|
|
m_motor1.setIHOLD_IRUN(MOTOR_IHOLD, MOTOR_IRUN, 0); |
|
|
|
|
|
|
|
m_motor1.setAcceleration(CFG_ACC); |
|
|
|
m_motor1.setDeceleration(CFG_DEC); |
|
|
|
m_velocity = CFG_VELOCITY; |
|
|
|
} |
|
|
|
|
|
|
|
int i = 1; |
|
|
|