Skip to content
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

adding motors for multibody joints #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 178 additions & 93 deletions src.ts/dynamics/multibody_joint.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import {RawImpulseJointSet, RawJointAxis, RawMultibodyJointSet} from "../raw";
import {Rotation, Vector, VectorOps, RotationOps} from "../math";
import {
RawGenericJoint,
RawMultibodyJointSet,
RawRigidBodySet,
RawJointAxis,
} from "../raw";

import {
FixedImpulseJoint,
ImpulseJointHandle,
// MultibodyJointHandle,
JointType,
MotorModel,
PrismaticImpulseJoint,
RevoluteImpulseJoint,
} from "./impulse_joint";

import {RigidBody, RigidBodyHandle} from "./rigid_body";
import {RigidBodySet} from "./rigid_body_set";
// #if DIM3
import {Quaternion} from "../math";
import {SphericalImpulseJoint} from "./impulse_joint";
// #endif

/**
Expand All @@ -20,15 +28,22 @@ export type MultibodyJointHandle = number;

export class MultibodyJoint {
protected rawSet: RawMultibodyJointSet; // The MultibodyJoint won't need to free this.
// protected bodySet: RigidBodySet; // The MultibodyJoint won’t need to free this.
handle: MultibodyJointHandle;

constructor(rawSet: RawMultibodyJointSet, handle: MultibodyJointHandle) {
constructor(
rawSet: RawMultibodyJointSet,
// bodySet: RigidBodySet,
handle: MultibodyJointHandle,
) {
this.rawSet = rawSet;
// this.bodySet = bodySet;
this.handle = handle;
}

public static newTyped(
rawSet: RawMultibodyJointSet,
// bodySet: RigidBodySet,
handle: MultibodyJointHandle,
): MultibodyJoint {
switch (rawSet.jointType(handle)) {
Expand All @@ -47,6 +62,11 @@ export class MultibodyJoint {
}
}

/** @internal */
public finalizeDeserialization(bodySet: RigidBodySet) {
// this.bodySet = bodySet;
}

/**
* Checks if this joint is still valid (i.e. that it has
* not been deleted from the joint set yet).
Expand All @@ -56,66 +76,90 @@ export class MultibodyJoint {
}

// /**
// * The unique integer identifier of the first rigid-body this joint it attached to.
// */
// public bodyHandle1(): RigidBodyHandle {
// return this.rawSet.jointBodyHandle1(this.handle);
// }
//
// /**
// * The unique integer identifier of the second rigid-body this joint is attached to.
// */
// public bodyHandle2(): RigidBodyHandle {
// return this.rawSet.jointBodyHandle2(this.handle);
// }
//
// /**
// * The type of this joint given as a string.
// * The first rigid-body this joint it attached to.
// */
// public type(): JointType {
// return this.rawSet.jointType(this.handle);
// public body1(): RigidBody {
// return this.bodySet.get(this.rawSet.jointBodyHandle1(this.handle));
// }
//
// // #if DIM3
// /**
// * The rotation quaternion that aligns this joint's first local axis to the `x` axis.
// * The second rigid-body this joint is attached to.
// */
// public frameX1(): Rotation {
// return RotationOps.fromRaw(this.rawSet.jointFrameX1(this.handle));
// }
//
// // #endif
//
// // #if DIM3
// /**
// * The rotation matrix that aligns this joint's second local axis to the `x` axis.
// */
// public frameX2(): Rotation {
// return RotationOps.fromRaw(this.rawSet.jointFrameX2(this.handle));
// }
//
// // #endif
//
// /**
// * The position of the first anchor of this joint.
// *
// * The first anchor gives the position of the points application point on the
// * local frame of the first rigid-body it is attached to.
// */
// public anchor1(): Vector {
// return VectorOps.fromRaw(this.rawSet.jointAnchor1(this.handle));
// }
//
// /**
// * The position of the second anchor of this joint.
// *
// * The second anchor gives the position of the points application point on the
// * local frame of the second rigid-body it is attached to.
// */
// public anchor2(): Vector {
// return VectorOps.fromRaw(this.rawSet.jointAnchor2(this.handle));
// public body2(): RigidBody {
// return this.bodySet.get(this.rawSet.jointBodyHandle2(this.handle));
// }

/**
* The type of this joint given as a string.
*/
public type(): JointType {
return this.rawSet.jointType(this.handle);
}

// #if DIM3
/**
* The rotation quaternion that aligns this joint's first local axis to the `x` axis.
*/
public frameX1(): Rotation {
return RotationOps.fromRaw(this.rawSet.jointFrameX1(this.handle));
}

// #endif

// #if DIM3
/**
* The rotation matrix that aligns this joint's second local axis to the `x` axis.
*/
public frameX2(): Rotation {
return RotationOps.fromRaw(this.rawSet.jointFrameX2(this.handle));
}

// #endif

/**
* The position of the first anchor of this joint.
*
* The first anchor gives the position of the application point on the
* local frame of the first rigid-body it is attached to.
*/
public anchor1(): Vector {
return VectorOps.fromRaw(this.rawSet.jointAnchor1(this.handle));
}

/**
* The position of the second anchor of this joint.
*
* The second anchor gives the position of the application point on the
* local frame of the second rigid-body it is attached to.
*/
public anchor2(): Vector {
return VectorOps.fromRaw(this.rawSet.jointAnchor2(this.handle));
}

/**
* Sets the position of the first anchor of this joint.
*
* The first anchor gives the position of the application point on the
* local frame of the first rigid-body it is attached to.
*/
public setAnchor1(newPos: Vector) {
const rawPoint = VectorOps.intoRaw(newPos);
this.rawSet.jointSetAnchor1(this.handle, rawPoint);
rawPoint.free();
}

/**
* Sets the position of the second anchor of this joint.
*
* The second anchor gives the position of the application point on the
* local frame of the second rigid-body it is attached to.
*/
public setAnchor2(newPos: Vector) {
const rawPoint = VectorOps.intoRaw(newPos);
this.rawSet.jointSetAnchor2(this.handle, rawPoint);
rawPoint.free();
}

/**
* Controls whether contacts are computed between colliders attached
* to the rigid-bodies linked by this joint.
Expand All @@ -139,42 +183,83 @@ export class UnitMultibodyJoint extends MultibodyJoint {
*/
protected rawAxis?(): RawJointAxis;

// /**
// * Are the limits enabled for this joint?
// */
// public limitsEnabled(): boolean {
// return this.rawSet.jointLimitsEnabled(this.handle, this.rawAxis());
// }
//
// /**
// * The min limit of this joint.
// */
// public limitsMin(): number {
// return this.rawSet.jointLimitsMin(this.handle, this.rawAxis());
// }
//
// /**
// * The max limit of this joint.
// */
// public limitsMax(): number {
// return this.rawSet.jointLimitsMax(this.handle, this.rawAxis());
// }
//
// public configureMotorModel(model: MotorModel) {
// this.rawSet.jointConfigureMotorModel(this.handle, this.rawAxis(), model);
// }
//
// public configureMotorVelocity(targetVel: number, factor: number) {
// this.rawSet.jointConfigureMotorVelocity(this.handle, this.rawAxis(), targetVel, factor);
// }
//
// public configureMotorPosition(targetPos: number, stiffness: number, damping: number) {
// this.rawSet.jointConfigureMotorPosition(this.handle, this.rawAxis(), targetPos, stiffness, damping);
// }
//
// public configureMotor(targetPos: number, targetVel: number, stiffness: number, damping: number) {
// this.rawSet.jointConfigureMotor(this.handle, this.rawAxis(), targetPos, targetVel, stiffness, damping);
// }
/**
* Are the limits enabled for this joint?
*/
public limitsEnabled(): boolean {
return this.rawSet.jointLimitsEnabled(this.handle, this.rawAxis());
}

/**
* The min limit of this joint.
*/
public limitsMin(): number {
return this.rawSet.jointLimitsMin(this.handle, this.rawAxis());
}

/**
* The max limit of this joint.
*/
public limitsMax(): number {
return this.rawSet.jointLimitsMax(this.handle, this.rawAxis());
}

/**
* Sets the limits of this joint.
*
* @param min - The minimum bound of this joint’s free coordinate.
* @param max - The maximum bound of this joint’s free coordinate.
*/
public setLimits(min: number, max: number) {
this.rawSet.jointSetLimits(this.handle, this.rawAxis(), min, max);
}

public configureMotorModel(model: MotorModel) {
this.rawSet.jointConfigureMotorModel(
this.handle,
this.rawAxis(),
model,
);
}

public configureMotorVelocity(targetVel: number, factor: number) {
this.rawSet.jointConfigureMotorVelocity(
this.handle,
this.rawAxis(),
targetVel,
factor,
);
}

public configureMotorPosition(
targetPos: number,
stiffness: number,
damping: number,
) {
this.rawSet.jointConfigureMotorPosition(
this.handle,
this.rawAxis(),
targetPos,
stiffness,
damping,
);
}

public configureMotor(
targetPos: number,
targetVel: number,
stiffness: number,
damping: number,
) {
this.rawSet.jointConfigureMotor(
this.handle,
this.rawAxis(),
targetPos,
targetVel,
stiffness,
damping,
);
}
}

export class FixedMultibodyJoint extends MultibodyJoint {}
Expand Down
Loading