Limiting Motor Movement within a Defined Angle Window

Hi everyone, I’m working on a project where I need to limit the movement of my motor to a specific range due to physical constraints. The motor should only move within ±1 radian from its central position. The angle control works as expected, but I need to ensure that the motor doesn’t exceed this movement window.

In other words, I want to ensure that the motor doesn’t continue increasing the angle when it is at +1 rad to reach -1 rad by moving clockwise. Instead, it should move counterclockwise to reach -1 rad, staying within the defined window.

Here’s my setup:

  • Motor: BLDC gimbal motor with 7 pole pairs
  • Sensor: AS5600 magnetic sensor
  • Motor Driver: SimpleFOC Mini v1.0
  • Microcontroller: Arduino Nano Every

Thanks!

Hi @egg , welcome to SimpleFOC!

If you’re using angle control, then during operation this is automatic - angles are absolute, so let’s say you’re middle point is 0rad, then you have +1rad and -1rad as your limits.

But if you keep going forward from +1 rad then the angle will only increase, as our sensor abstraction tracks the full rotations. So it won’t take the “other path” to -1 rad because going forwards will never let it reach -1… Instead it will go backwards, pass through 0, and eventually reach -1 rad.

A more difficult question is what happens at startup, and how to handle the case that the position starts out of range. In this case you’ll have to take care of making sure the motor goes to the desired starting position using the desired direction.

On another note, I am not sure we support the Nano Every…

Hi @runger, thanks a lot for the answer.

Nano Every is not in the documentation, but I made it work by following this schematic and replacing the pins.

BLDCDriver3PWM driver = BLDCDriver3PWM(10, 9, 6, 8);

You are right, and it primarily happens during the initialization. Is there a way to control the start sequence?