Rigid Bodies
ProtoTwin simulates rigid bodies, which are idealized bodies that do not deform. Rigid bodies may be dynamic or kinematic and it is important to understand the difference between them and when each type should be used.
Types
Dynamic
Dynamic rigid bodies are bodies that have a finite mass and inertia tensor. They can be influenced by forces such as gravity and respond to collisions with other rigid bodies. Dynamic rigid bodies are typically used for parts/loads that move through the machine and for parts of the machine that are moved by joints or driven by motors.
Kinematic
Kinematic rigid bodies are bodies that have an infinite mass. They are not influenced by forces and can only be moved by setting their velocity or position. They can influence dynamic rigid bodies through collisions, but are not themselves influenced by collisions. Kinematic rigid bodies are typically used for parts of a machine that can be assumed to be physically fixed/grounded, such as conveyors.
Attached
Specifies that the entity should have no rigid body, but that its collider should be attached to the nearest ancestor’s rigid body in the hierarchy. This can be used to create compound/composite collision geometry (such as a table consisting of a table top and four legs).
Mass and Inertia
The mass for the rigid body can be specified directly. The inertia tensor is calculated automatically from the collision geometry attached to the rigid body. Interactions (constraints) involving rigid bodies with high mass ratios require many iterations to converge. It is recommended to reduce mass ratios where possible, and to increase the solver iterations to improve stability when necessary.
Damping
Linear and angular damping can be used to approximate air resistance and joint friction. The values represent a percentage of the linear and angular velocities respectively that should be lost each time-step.
Axis Locks
Translation and rotation for a rigid body can be restricted in and about one or more of the global axes. This can be used to restrict motion to a 2D plane, or to disable rotation entirely.
Velocity
Both dynamic and kinematic rigid bodies have a linear and angular velocity. You can query these velocities at any time using a custom scripted component. ProtoTwin additionally includes the linear velocity sensor and angular velocity sensor components, which provide signal outputs for reading the velocity values from PLCs and/or Python clients.
import { Component, type Entity, type Handle, PhysicsComponent } from "prototwin";
export class VelocitySensor extends Component {
public physics: Handle<PhysicsComponent> = this.handle(PhysicsComponent);
constructor(entity: Entity) {
super(entity);
}
public override postUpdate(dt: number) {
// Use postUpdate() to get the velocities after the physics time-step has been completed.
const component = this.physics.value;
if (component !== null) {
const linear = component.linearVelocity;
const angular = component.angularVelocity;
}
}
}
Force / Torque
A force and/or torque can be applied to dynamic rigid bodies using a custom scripted component. You can apply these at the center-of-mass or at an aribtrary position.
import { Component, type Entity, type Handle, PhysicsComponent, Vec3, ForceSpace } from "prototwin";
export class ApplyForce extends Component {
public physics: Handle<PhysicsComponent> = this.handle(PhysicsComponent);
constructor(entity: Entity) {
super(entity);
}
public override update(dt: number) {
// Use update() to apply forces in the current physics time-step.
const component = this.physics.value;
if (component !== null) {
component.applyForce(new Vec3(10, 0, 0), ForceSpace.World);
component.applyTorque(new Vec3(0, 0, 1), ForceSpace.Local);
}
}
}
Hierarchy
ProtoTwin supports hierarchies of rigid bodies, which generally isn’t reliably supported by other industrial simulation software. If a child entity has a rigid body then any movement of the parent due to physics doesn’t affect the child. This can be useful if your CAD is organized into a hiararchy, such as boxes stacked on a pallet.