examples/foc: replace the requested velocity input with a more general setpoint input.

This is the inital step to support torque/velocity/position control
This commit is contained in:
raiden00pl
2021-10-30 13:53:32 +02:00
committed by Xiang Xiao
parent 4001d27571
commit 2fb79db8b4
7 changed files with 78 additions and 69 deletions

View File

@@ -435,7 +435,8 @@ static int foc_motor_vel(FAR struct foc_motor_f32_s *motor, uint32_t vel)
/* Update motor velocity destination */
motor->vel_des = (vel * VEL_ADC_SCALE * motor->envp->velmax / 1000.0f);
motor->vel_des = (vel * SETPOINT_ADC_SCALE *
motor->envp->velmax / 1000.0f);
return OK;
}
@@ -771,21 +772,23 @@ static int foc_motor_handle(FAR struct foc_motor_f32_s *motor,
motor->mq.vbus = handle->vbus;
}
/* Update motor velocity destination */
/* Update motor velocity destination
* NOTE: only velocity control supported for now
*/
if (motor->mq.vel != handle->vel)
if (motor->mq.setpoint != handle->setpoint)
{
PRINTFV("Set vel=%" PRIu32 " for FOC driver %d!\n",
handle->vel, motor->envp->id);
PRINTFV("Set setpoint=%" PRIu32 " for FOC driver %d!\n",
handle->setpoint, motor->envp->id);
ret = foc_motor_vel(motor, handle->vel);
ret = foc_motor_vel(motor, handle->setpoint);
if (ret < 0)
{
PRINTF("ERROR: foc_motor_vel failed %d!\n", ret);
goto errout;
}
motor->mq.vel = handle->vel;
motor->mq.setpoint = handle->setpoint;
}
/* Update motor state */