Expose motor position to control loop

Hi all,
For my next project I’d like to vary the torque of a motor based on its position, effectively turning the motor in to a spring with a variable / tunable spring rate.

I’m thinking a simple control loop that sets torque based on motor position would do the trick.

My question is can I read motor position from the simple foc library in the main loop of my Arduino code? If so how would it be achieved?

Any constructive thoughts would be much appreciated.

All the best
Barry M

I would probably start by reading the SimpleFOC documentation here:

void loop() {
  // IMPORTANT - call as frequently as possible
  // update the sensor values 
  // display the angle and the angular velocity to the terminal
1 Like

you may also find some interest in “haptic textures”, there are a few threads on this board discussing this. In those case they are using angle error with a separate control loop to create variable stiffness and software-defined detents. some of the code from those projects is usable for your purpose and may prove a nice set of examples to learn from.

1 Like

Thanks folk, that’s really helpful.
Many thanks again
Barry M

Please come back and post cool pics and videos, we are looking forward to seeing what others do.


1 Like