# Encoder target\_angle as non-zero speed?

**URL:** <https://community.sparkfun.com/t/encoder-target-angle-as-non-zero-speed/69573>\
**Category:** Artemis\
**Created:** [September 15, 2026, 4:35pm UTC](https://community.sparkfun.com/t/encoder-target-angle-as-non-zero-speed/69573 "2026-09-15T16:35:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [September 15, 2026, 4:35pm UTC](https://community.sparkfun.com/t/encoder-target-angle-as-non-zero-speed/69573/1 "2026-09-15T16:35:48Z")

</div>

Hello,

We use: two gimbal SparkFun 12V 3-Phase BLDC motors with encoders AS5048A [Gimbal Motor with Encoder - 12V, 467RPM - SparkFun Electronics](https://www.sparkfun.com/gimbal-motor-with-encoder-12v-587rpm.html) ; two SparkFun 3-Phase Brushless TMC6300 motor-drivers; one SparkFun Artemis RedBoard ATP microcontroller board; one Lipo 7.4V 5200 mAh battery.  
We need to write a code to control the motors. I found out that this example position PID-control code [Position Control example | Arduino-FOC](https://docs.simplefoc.com/position_control_example) can be edited to match our project. However, there are some issues. One of them is that _ **target\_angle** _ is the zero speed point as far as I can see. That is, the rotor stops and is held at a target angle. We need to accelerate the rotors until they reach a target angle. Right after the rotors pass a target angle, they have to coast or to continue to move at a low speed. Could someone please tell how to make _ **target\_angle** _ as the non-zero speed point? Thank you.

---

<div class="post-metadata">

**Author:** ![TS-Russell](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/ts-russell/32/6092_2.png) [@TS-Russell](https://community.sparkfun.com/u/TS-Russell)\
**Post date:** [September 15, 2026, 7:30pm UTC](https://community.sparkfun.com/t/encoder-target-angle-as-non-zero-speed/69573/2 "2026-09-15T19:30:57Z")

</div>

You can accomplish this in a lot of different ways, I think the easiest is to combine the angle control and velocity control examples into one code that combines their use (angle until it is reached, velocity can have it spin at a speed for x seconds and then switch _back_ to angle control and loop

Something like adding

```auto
if (fabs(motor.shaft_angle - target_angle) < 0.05) {
    motor.controller = MotionControlType::velocity;
    motor.target = low_coast_speed; // rad/s
}

```

The other easy-ish way I can think of is to use torque control based on the angle:

````auto
// Simple bang‑bang, 0.05 for friction compensation
if (motor.shaft_angle < target_angle) {
    motor.move(0.5); // accelerate
} else {
    motor.move(0.05); // small torque to keep coasting
}```
````

---

<div class="post-metadata">

**Author:** ![B](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@B](https://community.sparkfun.com/u/B)\
**Post date:** [September 16, 2026, 10:40pm UTC](https://community.sparkfun.com/t/encoder-target-angle-as-non-zero-speed/69573/3 "2026-09-16T22:40:27Z")

</div>

Thank you, TS-Russell. We use _ **motor.controller = MotionControlType::angle** _ . I think how the PID-control code executes is the following. Say, _ **target\_angle** _ is set as 180 degrees or pi (in radians because the code defines speed in radians per second). The function _ **motor.velocity\_limit** _ _ **=** _ sets a maximal velocity during the 180-degree distance. Therefore, the PID-control code corrects the rotor’s motion so that the rotor moves for the 180-degree distance and stops exactly at the 180th degree without overshooting or undershooting.

The function _**motor.move()**_ uses _ **target\_angle** _ as its argument, not a velocity value. Hence, _**motor.move(0.5)**_ means that the rotor moves for the 0.5-radian distance at the max speed set by the function _ **motor.velocity\_limit =** _ . Therefore, the rotor should be stopped and held at the 0.5th angle. As a result, it is unclear how to make the rotor coast or decrease its speed (without being held) right after the rotor passes _ **target\_angle = 0.5** _ ? If I mistake something, please let me know.
