# Torsional Spring Replication?

**URL:** <https://discourse.odriverobotics.com/t/torsional-spring-replication/11873>\
**Category:** Projects\
**Created:** [September 22, 2024, 8:51pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873 "2024-09-22T20:51:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![D\_Camille](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/d_camille/32/6496_2.png) [@D\_Camille](https://discourse.odriverobotics.com/u/D_Camille)\
**Post date:** [September 22, 2024, 8:51pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/1 "2024-09-22T20:51:05Z")

</div>

Hi! I am working on a project trying to simulate a torsional spring using a motor. We want to adjust the stiffness of the simulated torsional spring in order to produce different results in our project by changing the torque of the motor. I currently plan on using the Odrive Pro to do this.

Does anyone have recommendations or advice on using the ODrive Pro? Is it good for adjusting torque values? I saw that the GUI has a torque control setting, any tips on using it? Thanks!

---

<div class="post-metadata">

**Author:** ![solomondg](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@solomondg](https://discourse.odriverobotics.com/u/solomondg)\
**Post date:** [September 23, 2024, 10:15pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/2 "2024-09-23T22:15:33Z")

</div>

Hi! ODrive is definitely a great choice for this! The ODrive supports precise torque, velocity, and position control. Note you’ll need to know your motor’s torque constant (Nm/A) to ensure torque accuracy. Typically, the torque constant is 8.27/KV, where KV is the speed constant in RPM/V (a more commonly provided motor value).

You can specify a direct torque value in the GUI (or over USB, UART, or CAN), that’s typical. Note though that this will be a constant torque, and not a position-dependent torque as a torsional spring will provide. To simulate this, you can put the ODrive in position control mode with a vel\_integrator\_gain of 0 and a vel\_gain of 1. Then, your pos\_gain will be the spring constant, in units of Nm/revolution. If you have a desired spring constant in the units of Nm/rad, you can multiply it by 2pi to get Nm/revolution. However, if you just want a constant torque, then you can simply set the torque from your external motion controller (computer, microcontroller, etc).

---

<div class="post-metadata">

**Author:** ![D\_Camille](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/d_camille/32/6496_2.png) [@D\_Camille](https://discourse.odriverobotics.com/u/D_Camille)\
**Post date:** [November 11, 2024, 5:20pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/3 "2024-11-11T17:20:14Z")

</div>

Hello, thank you for this reply! Could you explain this a little bit more please? It sounds like it is exactly what we are looking to do within our project, thank you!

How does changing the velocity integrator gain and velocity gain allow the position gain to act as a spring constant? Is there a derived equation to represent this system? I understand that this is a series of PID Controllers placed together and how the system functions in that manner, but would like a little clarification on how changing these variables will allow the position gain to act as a spring constant.

---

<div class="post-metadata">

**Author:** ![solomondg](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@solomondg](https://discourse.odriverobotics.com/u/solomondg)\
**Post date:** [November 11, 2024, 6:39pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/4 "2024-11-11T18:39:58Z")

</div>

EDIT: Disregard, made a mistake here, will update soon 🙂

Hi! So:

To oversimplify, the position controller generates a velocity setpoint, and the velocity controller generates a torque setpoint, which is then executed by the ODrive’s torque controller.

The velocity controller equation is:  
Torque setpoint (Nm) = vel\_error (rev/s) \* vel\_gain (Nm/rev/s) + ∫vel\_error (rev/s \* s) \* vel\_integrator\_gain (Nm/rev/s \* s)

The position controller equation is:  
Velocity setpoint (rev/s) = pos\_error (rev) \* pos\_gain (rev/s/rev)

If you set vel\_integrator\_gain to 0, then this simplifies to

Torque setpoint (Nm) = pos\_error \* pos\_gain \* vel\_gain

Then with vel\_gain == 1, this simplifies further to:

Torque setpoint (Nm) = pos\_error \* pos\_gain

The torsional spring equation is T = k \* θ, where `T` is torque in Nm, `k` is spring constant in Nm/radian, and `θ` is angular displacement (in radian). This is exactly the same as the prior `Torque setpoint (Nm) = pos_error * pos_gain`, (pos\_gain == k, pos\_error == θ), except with the unit of turns in radians instead of revolutions.

So e.g. if you set vel\_integrator\_gain to 0, vel\_gain to 1, and pos\_gain to 10, then in closed-loop position control with a position setpoint of 0, your system will behave as a spring with a torsional constant of 10 Nm/rev (or 2pi\*10 Nm/rad)

---

<div class="post-metadata">

**Author:** ![D\_Camille](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/d_camille/32/6496_2.png) [@D\_Camille](https://discourse.odriverobotics.com/u/D_Camille)\
**Post date:** [November 12, 2024, 6:03am UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/5 "2024-11-12T06:03:42Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![solomondg](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@solomondg](https://discourse.odriverobotics.com/u/solomondg)\
**Post date:** [November 12, 2024, 9:31pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/6 "2024-11-12T21:31:19Z")

</div>

EDIT: I made a mistake here, will update soon 🙂

---

<div class="post-metadata">

**Author:** ![D\_Camille](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/d_camille/32/6496_2.png) [@D\_Camille](https://discourse.odriverobotics.com/u/D_Camille)\
**Post date:** [November 12, 2024, 10:37pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/7 "2024-11-12T22:37:28Z")

</div>

Okay, thanks!

---

<div class="post-metadata">

**Author:** ![solomondg](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@solomondg](https://discourse.odriverobotics.com/u/solomondg)\
**Post date:** [November 19, 2024, 10:04pm UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/8 "2024-11-19T22:04:51Z")

</div>

Hi! Sorry it took me so long to reply.

My error was forgetting that the vel\_error was vel\_target - vel\_actual 🙂

In this case, vel\_gain will act as a damping coefficient, so instead of setting vel\_gain to be 1, you will have to set vel\_gain very low, then multiply pos\_gain by 1/vel\_gain.

For instance, instead of setting vel\_gain to 1 and pos\_gain to 10, you’d have to set vel\_gain to 0.001 and pos\_gain to 10/0.001 = 10000 to get the same 10 Nm/rev torsional spring constant (and you will have the additional damping coefficient of 0.001 Nm/rev/s from vel\_gain, but this is likely low enough to be ignored).

---

<div class="post-metadata">

**Author:** ![madcowswe](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/madcowswe/32/1138_2.png) [@madcowswe](https://discourse.odriverobotics.com/u/madcowswe)\
**Post date:** [November 20, 2024, 1:46am UTC](https://discourse.odriverobotics.com/t/torsional-spring-replication/11873/9 "2024-11-20T01:46:05Z")

</div>

Some more info on the math here:

> [@Want to change PI control to PD control](https://discourse.odriverobotics.com/t/want-to-change-pi-control-to-pd-control/2860/4):
>
> Here is how to transform your gains to use the cascaded controller, assuming you don’t have any feed-forward velocity (if you do you can do the same thing but include that). We currently have: current = vel\_gain \* (desired\_vel - actual\_vel) and desired\_vel = pos\_gain \* (desired\_pos - actual\_pos). Substitute in desired\_vel into the 1st formula, and you get: current = vel\_gain \* (pos\_gain \* (desired\_pos - actual\_pos) - actual\_vel) Multiply in vel\_gain: current = vel\_gain \* pos\_gain \* (desir…
