# Position Clamp Stimulus

## Watch the video tutorial on this subject!

The position clamp gives you the ability to maintain a joint at a given rotation. You can add this stimulus to any of the joints. It is true that you could do something similar by setting a hinge joint to be a servo motor and then just specifying the position. However, due to the way the physics engine is implemented in Vortex it is not possible for us to know exactly how much force it is producing to offset other forces acting on it. We can find the total torque on the joint, but not how much the motor is producing. This stimulus allows us to get that information. It is also much closer to the setup that is physically used by scientists in their experiments. The users specifies two attachment positions somewhere on the body part that is being rotated. The position clamp generates forces that are applied at the primary attachment that point directly towards or away from the secondary attachment depending on the sign of the force to be applied. The magnitude of the force that is applied is determined by a PID feedback controller that attempts to maintain a desired position. You can then measure the amount of force the controller is applying to maintain that position.

Figure 1 shows an example from an experiment where the lever ratio of a virtual grasshopper leg was calculated. Weights were attached along the same path that the muscles used to attach from the femur to the tibia. The weights tried to flex or extend the tibia. A position clamp was used to try and maintain the tibia at a specified rotation. We were able to measure the force required by the position clamp at a variety of rotations for each the flexor and extensor muscles to compute the lever ratio. This is one example of how the position clamp can be used.

 Figure 1. Using the position clamp to measure the lever ratio of a grasshopper leg.

A proportional-integral-derivative controller (PID controller) is a common feedback loop component in industrial control systems. The controller takes a measured value from a process or other apparatus and compares it with a reference setpoint value. The difference (or "error" signal) is then used to adjust some input to the process in order to bring the process' measured value back to its desired setpoint. Unlike simpler controllers, the PID can adjust process outputs based on the history and rate of change of the error signal, which gives more accurate and stable control. PID controllers do not require advanced mathematics to design and can be easily adjusted (or "tuned") to the desired application, unlike more complicated control algorithms based on optimal control theory. For more details on PID controllers please see the rest of this explanation on wikipedia.

### Position Clamp Properties

Clamp Properties

Derivative Gain
The gain of the derivative portion of the controller.
Default value: 0.1
Acceptable Values: Any value greater than or equal to 0.

Integrator Gain
The gain of the integrative portion of the controller.
Default value: 0
Acceptable Values: Any value greater than or equal to 0.

Max Force
The maximum force that the position clamp controller can apply.
Default value: 1 KN
Acceptable Values: Any value greater than 0.

Max Integrator Value
The integrator is a type of memory. So it is slowly accumulates or decrements as time goes on. This sets a ceiling for the maximum integrator gain value that it can reach.
Default value: 0.1
Acceptable Values: Any value greater than or equal the current Integrator Gain.

Position
The position of the joint that clamp is to maintain. This value is in radians.
Default value: 0 rad
Acceptable Values: Any value between PI and -PI.

Primary Attachment
This is an existing attchment located on the part that will be rotated. The force generated by the clamp will be applied to the part at the location of this attachment and pointing towards the secondary attachment. It is the users responsibilty to make sure that the attachments are located so the force applied will produce rotations in the correct direction to allow the clamp to maintain the desired position. This property provides a drop-down list of all attachments in this organism.
Default value: None
Acceptable Values: Any existing Attachment.

Proportional Gain
The gain of the proportional portion of the controller.
Default value: 1
Acceptable Values: Any value greater than or equal to 0.

Secondary Attachment
This is an existing attchment located on the part that will be rotated. The force generated by the clamp will be applied to the part at the location of the primary attachment and pointing towards this attachment. It is the users responsibilty to make sure that the attachments are located so the force applied will produce rotations in the correct direction to allow the clamp to maintain the desired position. This property provides a drop-down list of all attachments in this organism.
Default value: None
Acceptable Values: Any existing Attachment.

Stimulus Properties

Always Active
If this property is true then the stimulus is always active and the start and end times are ignored. If it is false then the stimulus is only applied between the start and end times.
Default value: False
Acceptable Values: True/False.

Body Part
A read-only property that tells which motorized joint will be moved.

Enabled
Determines if this stimulus is applied or not. If this is false then the stimulus is ignored. If it is true then it is applied.
Default value: True
Acceptable Values: True/False.

End Time
This is the time when the stimulus is stopped.
Default value: 5 s
Acceptable Values: Any value greater than the Start Time.

Name
The name of the stimulus.
Default value: Stimulus_?
Acceptable Values: Any string.

Structure
A read-only property that tells which structure the selected joint is contained within.

Start Time
This is the time when the stimulus will start.
Default value: 0 s
Acceptable Values: Any value less than the End Time and greater than or equal 0.