Skip to content

Implement adjustable center of gravity [AARD-1921] #1259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

ariesninjadev
Copy link
Contributor

Task

AARD-1921

This PR adds a config for robots that allows you to move their center of gravity, and allows you to adjust the torque output consequence (the functional equivalent of scaling the weight of the robot).

Symptom

A user may wish to observe the physical output of the robot when its weight is at a pre-calculated or desired position. This is most often used for setting safety limits on move/rotation speeds.

Solution

To simulate a modified center-of-gravity, we compute the lever arm between where the gravitational force acts and where it "should" act, and gives us a rotational moment (torque). This torque is calculated, dampened (to avoid Jolt-related inaccuracies), and then distributed to each rigid body.

Verification

Place the center-of-gravity at various points and observe the effect on the robot's balance. Verifying using real values is not feasible due to limitations in Jolt.


Before merging, ensure the following criteria are met:

  • All acceptance criteria outlined in the ticket are met.
  • Necessary test cases have been added and updated.
  • A feature toggle or safe disable path has been added (if applicable).
  • User-facing polish:
    • Ask: "Is this ready-looking?"
  • Cross-linking between Jira and GitHub:
    • PR links to the relevant Jira issue.
    • Jira ticket has a comment referencing this PR.

@ariesninjadev ariesninjadev self-assigned this Aug 6, 2025
@ariesninjadev ariesninjadev added the physics Relating to either the underlying physics engine or the usage of it label Aug 6, 2025
@ariesninjadev ariesninjadev requested a review from a team as a code owner August 6, 2025 17:44
@ariesninjadev ariesninjadev added the gameplay Relating to the playability of Synthesis label Aug 6, 2025
@ariesninjadev ariesninjadev requested a review from a team as a code owner August 6, 2025 17:44
Copy link
Member

@rutmanz rutmanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to standardize our language around Center of Mass vs Center of Gravity?

Comment on lines +511 to +522
if (rootNodeId) {
const robotTransform = convertJoltMat44ToThreeMatrix4(
World.physicsSystem.getBody(rootNodeId).GetWorldTransform()
)
const robotWorldPos = new THREE.Vector3()
const robotWorldQuat = new THREE.Quaternion()
const robotWorldScale = new THREE.Vector3()
robotTransform.decompose(robotWorldPos, robotWorldQuat, robotWorldScale)

const worldCoG = this._modifiedCenterOfGravity.clone()
worldCoG.applyQuaternion(robotWorldQuat)
worldCoG.add(robotWorldPos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code looks duplicated from earlier


const mass = 1 / inverseMass

const correctionFactor = (mass / totalMass) * this._cogEffectStrength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is a coefficient here on the gravity force?

}

const CenterOfGravityInterface: React.FC<CenterOfGravityInterfaceProps> = ({ selectedRobot }) => {
const gizmoRef = useRef<GizmoSceneObject | undefined>(undefined)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the physics of the robot should be paused while doing this so it doesn't move around while you're setting the CoM

setEffectStrength(value)
selectedRobot.cogEffectStrength = value
}}
tooltip="Adjusts how strongly the modified center of gravity affects the robot's physics (0 = no effect, 1 = normal, 2 = exaggerated)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like what does exaggerated mean? Shouldn't there be a "correct" amount? And why is it a discrete integer slider?

Copy link
Contributor Author

@ariesninjadev ariesninjadev Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like what does exaggerated mean?

See above:

This PR adds a config for robots that allows you to ... adjust the torque output consequence (the functional equivalent of scaling the weight of the robot).

Shouldn't there be a "correct" amount? And why is it a discrete integer slider?

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think it would make more sense to give it units and call it mass

Copy link
Contributor Author

@ariesninjadev ariesninjadev Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think it would make more sense to give it units

It's a scale

and call it mass

sure

Copy link
Member

@rutmanz rutmanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops meant to request changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gameplay Relating to the playability of Synthesis physics Relating to either the underlying physics engine or the usage of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants