LinearSpring – Linear spring between two points

LinearSpring creates a spring force between the origins of two coordinate frames in 3D space:

\[x = ||p_1 - p_2||\]\[V(q) = -k(x - x_0)^2\]

where \(p_1\) and \(p_2\) are the origins of two coordinate frames, \(k\) is the spring stiffness and \(x_0\) is the natural length of the spring.

Implemented Calculations
Calculation Implemented
V Y
V_dq Y
V_dqdq Y
V_dqdqdq Y

Warning

The current implementation will fail if \(p_1\) equals \(p_2\) and \(x_0\) is nonzero because of a divide by zero problem.

If the two points are equal and \(x_0\) is not zero, there should be a force. But since there is no vector between the two points, the direction of this force is undefined. When the natural length is zero, this problem can be corrected because the force also goes to zero.

Examples

We can create a simple 1D harmonic oscillator using LinearSpring with a frame that is free to translate:

import trep
from trep import tx,ty,tz,rx,ry,rz

# Create a sytem with one mass that moves in the x direction.
system = trep.System()
system.import_frames([tx('x', mass=1, name='block')])

trep.potentials.LinearSpring(system, 'World', 'block', k=20, x0=1)

# Remember to avoid x = 0 in simulation.
system.get_config('x').q = 0.5

The LinearSpring works between arbitrary frames, not just frames connected by a translation. Here, we create two pendulums and connect their masses with a spring:

import trep
from trep import tx,ty,tz,rx,ry,rz

system = trep.System()
system.import_frames([
    ry('theta1'), [
        tz(2, mass=1, name='pend1')
        ],
    tx(1), [
        ry('theta2'), [
            tz(2, mass=1, name='pend2')
            ]]
    ])

trep.potentials.LinearSpring(system, 'pend1', 'pend2', k=20, x0=0.9)

LinearSpring Objects

class trep.potentials.LinearSpring(system, frame1, frame2, k[, x0=0.0, name=None])

Create a new spring between frame1 and frame2. The frames must already exist in the system.

LinearSpring.frame1

The coordinate frame at one end of the spring.

(read only)

LinearSpring.frame1

The coordinate frame at the other end of the spring.

(read only)

LinearSpring.x0

The natural length of the spring.

LinearSpring.k

The spring constant of the spring.