Skip to content

Commit

Permalink
Fix robot position bug and add JBC 23
Browse files Browse the repository at this point in the history
  • Loading branch information
tcorbly committed Oct 29, 2024
1 parent 269aa52 commit 114b529
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/simulator/babylonBindings/RobotBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ class RobotBinding {
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 @@ -561,8 +561,7 @@ class RobotBinding {
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));

Expand Down
5 changes: 4 additions & 1 deletion src/simulator/babylonBindings/SceneBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class SceneBinding {
this.gizmoManager_.rotationGizmoEnabled = true;
this.gizmoManager_.scaleGizmoEnabled = false;
this.gizmoManager_.usePointerToAttachGizmos = false;
// Un comment for boudning boxes in scene
// Uncomment for bounding boxes in scene
// this.gizmoManager_.boundingBoxGizmoEnabled = true;
// this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1));

Expand Down Expand Up @@ -960,6 +960,9 @@ class SceneBinding {

// Update intersections
for (const nodeId in this.intersectionFilters_) {
const nodeMeshes = this.nodeMeshes_(nodeId);
if (nodeMeshes.length === 0) continue;

try {
const nodeBoundingBoxes = this.nodeBoundingBoxes_(nodeId);
const filterIds = this.intersectionFilters_[nodeId];
Expand Down
1 change: 1 addition & 0 deletions src/simulator/definitions/scenes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './jbc18-Stackerz-New';
export * from './jbc19-Bump-New';
export * from './jbc20-Amazing-New';
export * from './jbc21-Proximity-New';
export * from './jbc23-Find-the-Black-Line-New';
export * from './jbc24-Walk-the-Line-New';
export * from './moonSandbox';
// export * from './jbc2b-Ring-Around-the-Cans-Sr';
Expand Down
2 changes: 1 addition & 1 deletion src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const uprightCan = `
// When a can is standing upright, the upright condition is met.
const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity();
const yAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y));
const yAngle = (nodeId) => 180 / Math.PI * -1 * Math.asin(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y));
scene.addOnRenderListener(() => {
Expand Down
92 changes: 92 additions & 0 deletions src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Scene from '../../../state/State/Scene';
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from '../../../util/math/unitMath';
import { Distance } from '../../../util';
import LocalizedString from '../../../util/LocalizedString';
import Script from '../../../state/State/Scene/Script';
import { createBaseSceneSurfaceA, canPositions } from './jbcBase';
import { Color } from '../../../state/State/Scene/Color';

const baseScene = createBaseSceneSurfaceA();

const foundBlack = `
scene.addOnIntersectionListener('robot', (type, otherNodeId) => {
const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, {
...scene.nodes[nodeId],
visible
});
console.log('Robot crossing black line', type, otherNodeId);
if(scene.programStatus === 'running'){
if(scene.nodes['robot'].state.getAnalogValue(1) > 2000) {
scene.setChallengeEventValue('stopAtBlackLine', type === 'start');
setNodeVisible('otherNodeId', true);
}
}
}, 'blackLine');
`;

function randomCircle(): Vector3wUnits {
const circles = [2, 4, 6, 9, 11];
const randomCircle = circles[Math.floor(Math.random() * circles.length)];
console.log('randomCircle: ', randomCircle);
const circle: Vector3wUnits = {
...canPositions[randomCircle - 1],
};
console.log('circle: ', circle);
return circle;
}

const ROBOT_ORIGIN: ReferenceFramewUnits = {
position: { ...randomCircle() },
orientation: RotationwUnits.eulerDegrees(0, 180, 0)
};

export const JBC_23: Scene = {
...baseScene,
name: { [LocalizedString.EN_US]: 'JBC 23' },
description: {
[LocalizedString.EN_US]: `Junior Botball Challenge 23: Find the Black Line`,
},
scripts: {
foundBlack: Script.ecmaScript('Found Black Line', foundBlack),
},
geometry: {
...baseScene.geometry,
blackLine_geom: {
type: "box",
size: {
x: Distance.inches(24),
y: Distance.centimeters(10),
z: Distance.inches(0.65),
},
},
},
nodes: {
...baseScene.nodes,
robot: {
...baseScene.nodes['robot'],
origin: ROBOT_ORIGIN,
startingOrigin: ROBOT_ORIGIN,
},
blackLine: {
type: "object",
geometryId: "blackLine_geom",
name: { [LocalizedString.EN_US]: "Black Line" },
visible: true,
origin: {
position: {
x: Distance.centimeters(0),
y: Distance.centimeters(-1.9),
z: Distance.inches(5.95),
},
},
material: {
type: "basic",
color: {
type: "color3",
color: Color.rgb(255, 255, 255),
},
},
},
},
};
2 changes: 1 addition & 1 deletion src/state/reducer/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const DEFAULT_SCENES: Scenes = {
jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }),
jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }),
// jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }),
// jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }),
jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }),
jbc24: Async.loaded({ value: JBC_SCENES.JBC_24 }),
// scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }),
// lightSensorTest: Async.loaded({ value: JBC_SCENES.lightSensorTest }),
Expand Down

0 comments on commit 114b529

Please sign in to comment.