> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Constraint equation

This example considers the gear mechanism shown below.

![gear mechanism](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/rigid-body-dynamics/command-reference-for-rigid-dynamics-systems/2025-r2/images/gds_cmdref_ex_constraint1.jpg?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=b629fdad188e55ccfa934c707f4dcb5a)

A relation is created between two revolute joints to simulate a gear with a
ratio 2 M. Commands are used to enforce the ratio of velocities between the
two wheels, and create a linear relation between rotational velocities,
defined by:

(1)\*ω 1 + (-2)\*ω2 = 0

First, the joint objects are retrieved using their IDs:

```python theme={null}
j1id = CS_Joint.Find(_jid)
j2id = CS_Joint.Find(_jid)
```

![retrieving joint objects](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/rigid-body-dynamics/command-reference-for-rigid-dynamics-systems/2025-r2/images/gds_cmdref_ex_constraint2.jpg?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=c04c29608edda10d853c14481eb43539)

Next, the relationship between the two wheels is defined. The complete list of
commands is shown below. A description of these commands follows.

![defining relationship](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/rigid-body-dynamics/command-reference-for-rigid-dynamics-systems/2025-r2/images/gds_cmdref_ex_constraint3.jpg?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=f9e080a2e6180824f2bf825928fcbfd4)

1. A relation object is created and specified as a relation between velocities:

   ```text theme={null}
   rel=CS_Relation()
   rel.MotionType=CS_Relation.E_MotionType.E_Velocity
   ```

2. The constant coefficients that appear in the relation are created. The first constant term is created by:

   ```text theme={null}
   var1=CS_ConstantVariable()
   var1.SetConstantValues(System.Array[float]([1.]))
   ```

3. The second coefficient and constant right hand side are created by:

   ```text theme={null}
   var2=CS_ConstantVariable()
   var2.SetConstantValues(System.Array[float]([-2.]))
   varrhs=CS_ConstantVariable()
   varrhs.SetConstantValues(System.Array[float]([0.]))
   ```

4. The first term of relation (1) X ω\_1 is added to the relation object:

   ```python theme={null}
   rel.AddTerm(j1id,0,var1)
   ```

   The first argument is the joint object. The second argument defines the DOF
   (degrees of freedom) of the joint that are involved in the relation. Here, `0`
   represents the rotation, which is the joint's first and only DOF is the
   rotation.

5. The second term and right hand side are introduced in the same manner:

   ```text theme={null}
   rel.AddTerm(j2id,0,var2)
   rel.SetVariable (varrhs)
   ```

6. The relation is added to the list of relations:

   ```text theme={null}
   Env=CS_Environment.GetDefault()
   Env.Relations.Add(rel)
   ```
