Force – Base Class for Forces

class trep.Force(system[, name=None])
Parameters:
  • system (System) – An instance of System to add the force to.
  • name – A string that uniquely identifies the force.

This is the base class for all forces in a System. It should never be created directly. Forces are created by instantiating a specific type of force..

See trep.forces - Forces for the built-in types of forces. Additional forces can be added through either the Python or C-API.

Forces are used to include non-conservative and control forces in a mechanical system. Forces must be expressed in the generalized coordinates of the system. Conservative forces like gravity or spring-like potentials should be implemented using Potential instead.

Force Objects

Force.system

The System that this force belongs to.

(read-only)

Force.name

The name of this force or None.

Force.f(q)
Parameters:q (Config) – Configuration variable

Calculate the force on configuration variable q at the current state of the system.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_dq(q, q1)
Parameters:
  • q (Config) – Configuration variable
  • q1 (Config) – Configuration variable

Calculate the derivative of the force on configuration variable q with respect to the value of q1.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_ddq(q, dq1)
Parameters:
  • q (Config) – Configuration variable
  • dq1 (Config) – Configuration variable

Calculate the derivative of the force on configuration variable q with respect to the velocity of dq1.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_du(q, u1)
Parameters:
  • q (Config) – Configuration variable
  • u1 (Input) – Input variable

Calculate the derivative of the force on configuration variable q with respect to the value of u1.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_dqdq(q, q1, q2)
Parameters:
  • q (Config) – Configuration variable
  • q1 (Config) – Configuration variable
  • q2 (Config) – Configuration variable

Calculate the second derivative of the force on configuration variable q with respect to the value of q1 and the value of q2.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_ddqdq(q, dq1, q2)
Parameters:
  • q (Config) – Configuration variable
  • dq1 (Config) – Configuration variable
  • q2 (Config) – Configuration variable

Calculate the second derivative of the force on configuration variable q with respect to the velocity of dq1 and the value of q2.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_ddqddq(q, dq1, dq2)
Parameters:
  • q (Config) – Configuration variable
  • dq1 (Config) – Configuration variable
  • dq2 (Config) – Configuration variable

Calculate the second derivative of the force on configuration variable q with respect to the velocity of dq1 and the velocity of q2.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_dudq(q, u1, q2)
Parameters:
  • q (Config) – Configuration variable
  • u1 (Input) – Input variable
  • q2 (Config) – Configuration variable

Calculate the second derivative of the force on configuration variable q with respect to the value of u1 and the value of q2.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_duddq(q, u1, dq2)
Parameters:
  • q (Config) – Configuration variable
  • u1 (Input) – Input variable
  • dq2 (Config) – Configuration variable

Calculate the second derivative of the force on configuration variable q with respect to the value of u1 and the velocity of q2.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?
Force.f_dudu(q, u1, u2)
Parameters:
  • q (Config) – Configuration variable
  • u1 (Input) – Input variable
  • u2 (Input) – Input variable

Calculate the second derivative of the force on configuration variable q with respect to the value of u1 and the value of u2.

Required for Calculations
Desired Calculation Required
Continuous Dynamics ?
1st Derivative ?
2nd Derivative ?
Discrete Dynamics ?
1st Derivative ?
2nd Derivative ?

Verifying Derivatives of the Force

It is important that the derivatives of f() are correct. The easiest way to check their correctness is to approximate each derivative using numeric differentiation. These methods are provided to perform this test. The derivatives are only compared at the current configuration of the system. For improved coverage, try running each test several times at different configurations.

Force.validate_h_dq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_ddq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_du(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_dqdq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_ddqdq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_ddqddq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_dudq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_duddq(delta=1e-6, tolerance=1e-6, verbose=False)
Force.validate_h_dudu(delta=1e-6, tolerance=1e-6, verbose=False)
Parameters:
  • delta – Amount to add to each configuration, velocity, or input.
  • tolerance – Acceptable difference between the calculated and approximate derivatives
  • verbose – Boolean to print error and result messages.
Return type:

Boolean indicating if all tests passed

Check the derivatives against the approximate numeric derivative calculated from one less derivative (ie, approximate f_dq() from f() and f_dudq() from f_du()).

See System.test_derivative_dq(), System.test_derivative_ddq(), and System.test_derivative_du() for details of the approximation and comparison.

Visualization

Force.opengl_draw()

Draw a representation of this force in the current OpenGL context. The OpenGL coordinate frame will be in the System’s root coordinate frame.

This function is called by the automatic visualization tools. The default implementation does nothing.

Project Website

Table Of Contents

Previous topic

Input – Input Variables

Next topic

Potential – Base Class for Potential Energies

This Page