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

Update challenges to new numbering system #489

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c75dae9
Initial changes to challenges and minor bug fixes
tcorbly Oct 16, 2024
d032840
Update exports and add JBC 10 and 11 with a couple bugs
tcorbly Oct 18, 2024
a508618
Fix scale and positioning bug
chrismbirmingham Oct 18, 2024
9009ba3
Remove duplicate line
tcorbly Oct 18, 2024
d9a1a64
Merge branch 'updateChallenges' into updateChallenges
tcorbly Oct 19, 2024
3b14bf7
Merge pull request #490 from chrismbirmingham/updateChallenges
tcorbly Oct 19, 2024
edb3b11
Exclude chassis from node min maxes
tcorbly Oct 20, 2024
1f7048b
Push JBC 0 and boundingBox tests
tcorbly Oct 21, 2024
ca3a58f
Fix circle issue in challenge 11
tcorbly Oct 21, 2024
03ea7ac
JBC 15 completion
tcorbly Oct 21, 2024
98fa7a0
Fix missing nodes
tcorbly Oct 21, 2024
954726d
Fix upright conditions on JBC 15
tcorbly Oct 21, 2024
f408cef
Comment out bounding boxes and fixes to JBC 0
tcorbly Oct 22, 2024
182d937
Add JBC 19 and 20. New chassis with lever sensor collider. Mats not m…
tcorbly Oct 23, 2024
dc63ff7
JBC 21 finished. Fixed bug where inches was not converting from meter…
tcorbly Oct 23, 2024
269aa52
Make demobot show 0 rotation when loaded. Remove extra console logs
tcorbly Oct 23, 2024
114b529
Fix robot position bug and add JBC 23
tcorbly Oct 29, 2024
69b7c7f
Add challenge part of JBC 23, change some logic
tcorbly Oct 29, 2024
266e9f8
Include ET sensor fix that is on master
tcorbly Oct 29, 2024
b36cdd6
Now using Babylon intersectsMesh function to see if two meshes intersect
erinharrington-12 Oct 29, 2024
bfd90c3
Added JBC16-Pick-Em-Up-New scene and challenge
erinharrington-12 Oct 29, 2024
9d0b6bc
Added JBC16 to state reducer in challenges.ts and scenes.ts
erinharrington-12 Oct 29, 2024
730f72c
Complete JBC 22. Cleanup in 15 and 23
tcorbly Oct 30, 2024
463fea7
Cleanup JBC 0-2
tcorbly Oct 30, 2024
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
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"editor.formatOnSave": true, // optional
"editor.formatOnSaveMode": "file", // required to format on save
"files.autoSave": "onFocusChange", // optional but recommended
"vs-code-prettier-eslint.prettierLast": "false" // set as "true" to run 'prettier' last not first
"vs-code-prettier-eslint.prettierLast": "false",
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
} // set as "true" to run 'prettier' last not first
}
5 changes: 0 additions & 5 deletions src/components/Challenge/ChallengeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,6 @@ class ChallengeMenu extends React.PureComponent<Props, State> {

</Item>

<Item theme={theme} onClick={onEndChallengeClick} style={{ position: 'relative' }}>
<ItemIcon icon={faFlagCheckered} /> End Challenge

</Item>

<Item theme={theme} onClick={this.onLayoutClick_} style={{ position: 'relative' }}>
<ItemIcon icon={faClone} /> Layout
{subMenu.type === SubMenu.Type.LayoutPicker ? (
Expand Down
27 changes: 14 additions & 13 deletions src/simulator/ScriptManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ScriptSceneBinding {
readonly geometry: Dict<Geometry>;
addGeometry(geometry: Geometry, id?: string): string;
removeGeometry(id: string): void;

gravity: Vector3wUnits;

camera: Camera;
Expand Down Expand Up @@ -148,7 +148,7 @@ class ScriptManager {
refCounts.set(filterId, 1);
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
if (this[onChangedKey]) this[onChangedKey](listener.nodeId, new Set(refCounts.keys()));
};
Expand Down Expand Up @@ -209,7 +209,7 @@ namespace ScriptManager {
}

export const collision = construct<Collision>(Type.Collision);

export interface IntersectionStart {
type: Type.IntersectionStart;
nodeId: string;
Expand Down Expand Up @@ -256,7 +256,7 @@ namespace ScriptManager {
}

export const render = construct<Render>(Type.Render);

export interface Collision {
type: Type.Collision;
nodeId: string;
Expand All @@ -265,7 +265,7 @@ namespace ScriptManager {
}

export const collision = construct<Collision>(Type.Collision);

export interface Intersection {
type: Type.Intersection;
nodeId: string;
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace ScriptManager {
constructor(script: Script, manager: ScriptManager) {
this.script_ = script;
this.manager_ = manager;

this.spawnFunc_({
scene: this,
RotationwUnits,
Expand All @@ -342,6 +342,7 @@ namespace ScriptManager {
Distance,
Mass,
Angle,
Date,
}, this.script_.code);
}

Expand Down Expand Up @@ -415,7 +416,7 @@ namespace ScriptManager {
if (this.onUnbind) this.onUnbind(nodeId);
this.boundNodeIds_.delete(nodeId);
}

dispose() {
// TODO: This code could be more efficient. We need to unregister the collision and intersection listeners
// from the parent, but doing it as a single operation would be better.
Expand All @@ -439,7 +440,7 @@ namespace ScriptManager {
if (resolvedId in this.manager_.scene.nodes) {
throw new Error(`Node with id ${resolvedId} already exists`);
}

onNodeAdd(resolvedId, node);

return resolvedId;
Expand All @@ -455,7 +456,7 @@ namespace ScriptManager {

onNodeRemove(id);
}

setNode(id: string, node: Node): void {
const { onNodeChange } = this.manager_;
if (!onNodeChange) return;
Expand Down Expand Up @@ -496,7 +497,7 @@ namespace ScriptManager {

onGeometryRemove(id);
}

get gravity(): Vector3wUnits {
return this.manager_.scene.gravity;
}
Expand Down Expand Up @@ -568,7 +569,7 @@ namespace ScriptManager {
this.manager_.removeIntersectionRefCounts_(listener);
break;
}

delete this.listeners_[handle];
}

Expand All @@ -584,13 +585,13 @@ namespace ScriptManager {
setChallengeEventValue(eventId: string, value: boolean) {
if (!this.manager_.onChallengeSetEventValue) return;
this.manager_.onChallengeSetEventValue(eventId, value);
this.getChallengeEventValue(eventId,value);
this.getChallengeEventValue(eventId, value);
}

getChallengeEventValue(eventId: string, value: boolean) {
if (!this.manager_.onChallengeGetEventValue) return;
return value;
this.getChallengeEventValue(eventId,value);
this.getChallengeEventValue(eventId, value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/simulator/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class Space {
const distance = Vector3wUnits.distance(position, bPositionConv);

// If varies by more than 0.5cm, consider it a change
if (distance.value > 0.005) {
if (distance.value > 0.0025) {
change.position = Vector3wUnits.toTypeGranular(bPositionConv, position.x.type, position.y.type, position.z.type);
}
}
Expand Down
68 changes: 34 additions & 34 deletions src/simulator/babylonBindings/RobotBinding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import { Scene as babylonScene, TransformNode, PhysicsViewer, Vector3, IPhysicsEnabledObject,
Mesh, PhysicsJoint, IPhysicsEnginePluginV2, PhysicsConstraintAxis, Physics6DoFConstraint,
PhysicsConstraintMotorType, PhysicsConstraintAxisLimitMode,
import {
Scene as babylonScene, TransformNode, PhysicsViewer, Vector3, IPhysicsEnabledObject,
Mesh, PhysicsJoint, IPhysicsEnginePluginV2, PhysicsConstraintAxis, Physics6DoFConstraint,
PhysicsConstraintMotorType, PhysicsConstraintAxisLimitMode,
} from '@babylonjs/core';

import '@babylonjs/core/Physics/physicsEngineComponent';
Expand Down Expand Up @@ -30,6 +31,7 @@ import ReflectanceSensor from './sensors/ReflectanceSensor';
import SensorObject from './sensors/SensorObject';
import SensorParameters from './sensors/SensorParameters';
import LightSensor from './sensors/LightSensor';
import LocalizedString from '../../util/LocalizedString';

class RobotBinding {
/** Type 'RobotBinding' is missing the following properties from type
Expand Down Expand Up @@ -101,7 +103,7 @@ class RobotBinding {

private createSensor_ = <T extends Node.FrameLike, O, S extends SensorObject<T, O>>(s: { new(parameters: SensorParameters<T>): S }) => (id: string, definition: T): S => {
const parent = this.links_[definition.parentId];

return new s({
id,
definition,
Expand Down Expand Up @@ -138,7 +140,7 @@ class RobotBinding {

private bParentChild_ = (id: string, parentId: string): { bParent: Mesh; bChild: Mesh; childId: string; } => {
if (!parentId) throw new Error(`Missing parent: "${parentId}" for node "${id}"`);

const children = this.childrenNodeIds_[id];
if (children.length !== 1) throw new Error(`"${id}" must have exactly one child`);

Expand Down Expand Up @@ -184,7 +186,7 @@ class RobotBinding {
const maxForce = 50000;

bMotor.setAxisFriction(PhysicsConstraintAxis.ANGULAR_Z, 0);
bMotor.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, maxForce);
bMotor.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, maxForce);
bMotor.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.FREE);
bMotor.setAxisMotorTarget(PhysicsConstraintAxis.ANGULAR_Z, velocity);

Expand Down Expand Up @@ -227,7 +229,7 @@ class RobotBinding {
*/
for (let port = 0; port < 4; ++port) {
const motorId = this.motorPorts_[port];

// If no motor is bound to the port, skip it.
if (!motorId) continue;

Expand Down Expand Up @@ -286,9 +288,9 @@ class RobotBinding {
// If the motor is in pwm mode and the direction is idle, set the motor target to 0.
if (mode === Motor.Mode.Pwm && (direction === Motor.Direction.Idle || direction === Motor.Direction.Brake)) {
this.setMotorVelocity_(bMotor, 0);
if (Math.abs(velocity) < 10) {
bMotor.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.LOCKED);
}
// if (Math.abs(velocity) < 10) {
// bMotor.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.LOCKED);
// }
continue;
}

Expand Down Expand Up @@ -319,11 +321,11 @@ class RobotBinding {
// this.brakeAt_[port] = undefined;
// }


let pwm_adj = 0;
// If the motor is not in pwm mode, and we are not done, calculate the pwm value.
if (mode !== Motor.Mode.Pwm && !done) {

// This code is taken from Wombat-Firmware for parity.
const pErr = speedGoal - velocity;
const dErr = pErr - this.lastPErrs_[port];
Expand Down Expand Up @@ -353,10 +355,10 @@ class RobotBinding {
pwm = plug * clamp(-400, pwm, 400);

if (writePwm) writeCommands.push(WriteCommand.motorPwm({ port, pwm }));

const normalizedPwm = pwm / 400;
const nextAngularVelocity = normalizedPwm * velocityMax * 2 * Math.PI / ticksPerRevolution;
console.log("nextAngularVelocity", nextAngularVelocity);
// console.log("nextAngularVelocity", nextAngularVelocity);
this.setMotorVelocity_(bMotor, nextAngularVelocity);

}
Expand Down Expand Up @@ -400,7 +402,7 @@ class RobotBinding {
}
}

const currentAngle = this.hingeAngle_(servoId, servo.parentId);
const currentAngle = this.hingeAngle_(servoId, servo.parentId);
const targetAangle = this.lastServoEnabledAngle_[i];

let cur_angle = 0;
Expand All @@ -413,7 +415,7 @@ class RobotBinding {

if (cur_angle.toFixed(5) !== targetAangle.toFixed(5)) {
if (cur_angle < targetAangle) {
bServo.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, targetAangle);
bServo.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, targetAangle);
bServo.setAxisMotorTarget(PhysicsConstraintAxis.ANGULAR_Z, Math.PI * .4);
}
if (cur_angle > targetAangle) {
Expand Down Expand Up @@ -530,13 +532,12 @@ class RobotBinding {
const newOriginE = RawEuler.fromQuaternion(rawOrigin.orientation);
const Robot_OriginE = RawEuler.fromQuaternion(rawInternalOrigin.orientation);

const default_offset = 0; // -1 * Math.PI / 2;

const default_offset = LocalizedString.getOriginal(this.robot_.name) === 'Demobot' ? -1 * Math.PI / 2 : Math.PI / 2;

const UpdatedEulerOrigin = RawEuler.create(
newOriginE.x + Robot_OriginE.x,
newOriginE.y + Robot_OriginE.y + default_offset,
newOriginE.z + Robot_OriginE.z,
newOriginE.x,
newOriginE.y + default_offset,
newOriginE.z,
"xyz"
);

Expand All @@ -559,10 +560,9 @@ class RobotBinding {
weight.physicsBody.setAngularVelocity(Vector3.Zero());
weight.physicsBody.setLinearVelocity(Vector3.Zero());
}

rootTransformNode.position = RawVector3.toBabylon(rawOrigin.position || RawVector3.ZERO)
.add(RawVector3.toBabylon(rawInternalOrigin.position || RawVector3.ZERO));


rootTransformNode.position = RawVector3.toBabylon(rawOrigin.position || RawVector3.ZERO);

rootTransformNode.rotationQuaternion = RawQuaternion.toBabylon(RawEuler.toQuaternion(UpdatedEulerOrigin));

for (const link of Object.values(this.links_)) {
Expand Down Expand Up @@ -618,7 +618,7 @@ class RobotBinding {
if (node.type !== Node.Type.Link) continue;

const bNode = await createLink(nodeId, node, this.bScene_, this.robot_, this.colliders_);
if (this.physicsViewer_ && bNode.physicsBody) this.physicsViewer_.showBody(bNode.physicsBody);
if (this.physicsViewer_ && bNode.physicsBody) this.physicsViewer_.showBody(bNode.physicsBody);

bNode.metadata = { id: this.robotSceneId_, selected: false } as SceneMeshMetadata;
this.links_[nodeId] = bNode;
Expand All @@ -628,7 +628,7 @@ class RobotBinding {
for (const nodeId of nodeIds) {
const node = robot.nodes[nodeId];
if (node.type === Node.Type.Link || node.type === Node.Type.IRobotCreate) continue;

switch (node.type) {
case Node.Type.Weight: {
const bNode = createWeight(nodeId, node, this.bScene_, this.robot_, this.links_);
Expand All @@ -639,7 +639,7 @@ class RobotBinding {
const { bParent, bChild } = this.bParentChild_(nodeId, node.parentId);
const bJoint = createHinge(nodeId, node, this.bScene_, bParent, bChild);

bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 1000000000);
bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 1000000000);
bJoint.setAxisMotorType(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintMotorType.VELOCITY);
// Start motor in locked position so the wheels don't slide
bJoint.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.LOCKED);
Expand All @@ -657,10 +657,10 @@ class RobotBinding {
// -90 is upright and closed; 0 is forward and open
const { bParent, bChild } = this.bParentChild_(nodeId, node.parentId);
const bJoint = createHinge(nodeId, node, this.bScene_, bParent, bChild);
bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 10000000);
bJoint.setAxisMotorType(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintMotorType.VELOCITY);
bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 10000000);
bJoint.setAxisMotorType(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintMotorType.VELOCITY);
// Start the servos at 0
bJoint.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, Angle.toRadiansValue(Angle.degrees(0)));
bJoint.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, Angle.toRadiansValue(Angle.degrees(0)));
bJoint.setAxisMinLimit(PhysicsConstraintAxis.ANGULAR_Z, Angle.toRadiansValue(Angle.degrees(-1)));

this.servos_[nodeId] = bJoint;
Expand Down Expand Up @@ -715,9 +715,9 @@ class RobotBinding {
const node = robot.nodes[nodeId];
if (node.type !== Node.Type.IRobotCreate) continue;
this.createBinding_ = new CreateBinding(
workerInstance.createSerial,
this.createMotors_,
this.createAnalogSensors_,
workerInstance.createSerial,
this.createMotors_,
this.createAnalogSensors_,
this.createDigitalSensors_
);
}
Expand Down
Loading
Loading