Direct force input during position control for haptics

I have a BLDC motor being position controlled using Simple FOC for a haptic knob. While I want to position to be controlled I would also like to generate impulses (separate from the position control) to create “ticking”/“clicking” effects.

Currently I request rapid/large position changes to effect these results but this involves tricking/over coming the position/velocity control loops to generate the result.

However, directly requesting torque (current) outputs appears to be the most transparent method of generating impulses.

Is there a means of modifying the current request from the velocity_controller before it enters the current control torque_controller?

Or do I need to extend the library?

Yes, motor.current_sp is the velocity controller output, which is set in motor.move. You can modify it before calling motor.loopFOC (which is what updates the PWM outputs to the motor).

If you’re using TorqueControlType::voltage then you’ll need to set motor.voltage.q = motor.current_sp as well. Or recalculate it taking into account the motor velocity if you’re using voltage-based current limiting (probably not necessary for a haptic knob).

If you’d like to understand why, open BLDCMotor.cpp and look in the function BLDCMotor::move. In the MotionControlType::angle and MotionControlType::velocity cases, after running the velocity PID it checks for TorqueControlType::voltage and calculates the voltage. That code really should be moved to loopFOC.