From c75dae9ad5f5cddcb09ced673033848f7385e6e9 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Wed, 16 Oct 2024 13:07:29 -0600 Subject: [PATCH 01/22] Initial changes to challenges and minor bug fixes --- .vscode/settings.json | 5 +- src/components/Challenge/ChallengeMenu.tsx | 5 - src/simulator/Space.ts | 2 +- src/simulator/babylonBindings/RobotBinding.ts | 2 +- src/simulator/babylonBindings/SceneBinding.ts | 14 +- .../jbc10-Solo-Joust.ts} | 10 +- .../jbc10b-Solo-Joust-Jr.ts} | 10 +- .../{jbc12.ts => archived/jbc12-Unload-Em.ts} | 10 +- .../jbc13-Clean-the-Mat.ts} | 10 +- .../jbc15b-Bump-Bump.ts} | 10 +- .../jbc17b-Walk-the-Line-2.ts} | 10 +- .../jbc20-Rescue-the-Cans.ts} | 10 +- .../{jbc21.ts => archived/jbc21-Foot-Tall.ts} | 10 +- .../jbc2b-Ring-Around-the-Cans-Sr.ts} | 10 +- .../jbc2c-Back-It-Up.ts} | 10 +- ...c2d-Ring-Around-the-Can-and-Back-It-Up.ts} | 10 +- .../jbc4b-Barrel-Racing.ts} | 10 +- .../jbc6c-Empty-the-Garage.ts} | 8 +- .../jbc8b-Serpentine-Jr.ts} | 10 +- .../challenges/{ => archived}/test.ts | 10 +- src/simulator/definitions/challenges/jbc0.ts | 89 ++++ src/simulator/definitions/challenges/jbc1.ts | 29 +- .../challenges/jbc12-Add-It-Up-New.ts | 154 +++++++ .../challenges/jbc14-Dance-Party.ts | 133 ++++++ ...{jbc19.ts => jbc17-Mountain-Rescue-New.ts} | 0 .../{jbc22.ts => jbc18-Stackerz-New.ts} | 0 src/simulator/definitions/challenges/jbc2.ts | 4 +- .../{jbc17.ts => jbc24-Walk-the-Line-New.ts} | 0 ...{jbc3.ts => jbc3-Precision-Parking-New.ts} | 0 .../{jbc8.ts => jbc4-Serpentine-New.ts} | 0 src/simulator/definitions/challenges/jbc5.ts | 177 ++++---- .../{jbc4.ts => jbc6-Figure-Eight-New.ts} | 0 .../{jbc6.ts => jbc7-Load-Em-Up-New.ts} | 0 .../{jbc7.ts => jbc8-Bulldozer-Mania-New.ts} | 0 ...{jbc7b.ts => jbc9-Cover-Your-Bases-New.ts} | 2 +- src/simulator/definitions/nodes/index.ts | 19 + src/simulator/definitions/robots/demobot.ts | 2 +- .../jbc10-Solo-Joust.ts} | 14 +- .../jbc10b-Solo-Joust-Jr.ts} | 10 +- .../{jbc12.ts => archived/jbc12-Unload-Em.ts} | 12 +- .../jbc13-Clean-the-Mat.ts} | 12 +- .../jbc15b-Bump-Bump.ts} | 14 +- .../jbc17b-Walk-the-Line-2.ts} | 14 +- .../jbc20-Rescue-the-Cans.ts} | 12 +- .../{jbc21.ts => archived/jbc21-Foot-Tall.ts} | 12 +- .../jbc2b-Ring-Around-the-Cans-Sr.ts} | 12 +- .../jbc2c-Back-It-Up.ts} | 12 +- ...c2d-Ring-Around-the-Can-and-Back-It-Up.ts} | 12 +- .../jbc3b-Parallel-Parking.ts} | 6 +- .../jbc3c-Quick-Get-Away.ts} | 6 +- .../jbc4b-Barrel-Racing.ts} | 12 +- .../jbc5b-Line-Dance.ts} | 6 +- .../jbc5c-Synchronized-Dancing.ts} | 6 +- .../jbc6b-Pick-Em-Up.ts} | 6 +- .../jbc6c-Empty-the-Garage.ts} | 10 +- .../jbc8b-Serpentine-Jr.ts} | 12 +- .../jbc9b-Balancing-Act.ts} | 6 +- src/simulator/definitions/scenes/index.ts | 66 +-- src/simulator/definitions/scenes/jbc0.ts | 234 ++++++++++ src/simulator/definitions/scenes/jbc1.ts | 39 +- .../{jbc9.ts => jbc12-Add-It-Up-New.ts} | 0 .../definitions/scenes/jbc14-Dance-Party.ts | 126 ++++++ ...{jbc19.ts => jbc17-Mountain-Rescue-New.ts} | 0 .../{jbc22.ts => jbc18-Stackerz-New.ts} | 0 src/simulator/definitions/scenes/jbc2.ts | 10 +- .../{jbc17.ts => jbc24-Walk-the-Line-New.ts} | 0 ...{jbc3.ts => jbc3-Precision-Parking-New.ts} | 44 +- .../{jbc8.ts => jbc4-Serpentine-New.ts} | 0 src/simulator/definitions/scenes/jbc5.ts | 425 ++++++++++++++---- .../{jbc4.ts => jbc6-Figure-Eight-New.ts} | 0 .../{jbc6.ts => jbc7-Load-Em-Up-New.ts} | 0 .../{jbc7.ts => jbc8-Bulldozer-Mania-New.ts} | 0 ...{jbc7b.ts => jbc9-Cover-Your-Bases-New.ts} | 0 src/simulator/definitions/scenes/jbcBase.ts | 60 ++- src/state/State/Scene/Material.ts | 14 +- src/state/reducer/challenges.ts | 189 ++++---- src/state/reducer/scenes.ts | 59 +-- 77 files changed, 1672 insertions(+), 585 deletions(-) rename src/simulator/definitions/challenges/{jbc10.ts => archived/jbc10-Solo-Joust.ts} (86%) rename src/simulator/definitions/challenges/{jbc10b.ts => archived/jbc10b-Solo-Joust-Jr.ts} (86%) rename src/simulator/definitions/challenges/{jbc12.ts => archived/jbc12-Unload-Em.ts} (89%) rename src/simulator/definitions/challenges/{jbc13.ts => archived/jbc13-Clean-the-Mat.ts} (92%) rename src/simulator/definitions/challenges/{jbc15b.ts => archived/jbc15b-Bump-Bump.ts} (86%) rename src/simulator/definitions/challenges/{jbc17b.ts => archived/jbc17b-Walk-the-Line-2.ts} (76%) rename src/simulator/definitions/challenges/{jbc20.ts => archived/jbc20-Rescue-the-Cans.ts} (93%) rename src/simulator/definitions/challenges/{jbc21.ts => archived/jbc21-Foot-Tall.ts} (74%) rename src/simulator/definitions/challenges/{jbc2b.ts => archived/jbc2b-Ring-Around-the-Cans-Sr.ts} (95%) rename src/simulator/definitions/challenges/{jbc2c.ts => archived/jbc2c-Back-It-Up.ts} (92%) rename src/simulator/definitions/challenges/{jbc2d.ts => archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts} (93%) rename src/simulator/definitions/challenges/{jbc4b.ts => archived/jbc4b-Barrel-Racing.ts} (94%) rename src/simulator/definitions/challenges/{jbc6c.ts => archived/jbc6c-Empty-the-Garage.ts} (93%) rename src/simulator/definitions/challenges/{jbc8b.ts => archived/jbc8b-Serpentine-Jr.ts} (90%) rename src/simulator/definitions/challenges/{ => archived}/test.ts (78%) create mode 100644 src/simulator/definitions/challenges/jbc0.ts create mode 100644 src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts create mode 100644 src/simulator/definitions/challenges/jbc14-Dance-Party.ts rename src/simulator/definitions/challenges/{jbc19.ts => jbc17-Mountain-Rescue-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc22.ts => jbc18-Stackerz-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc17.ts => jbc24-Walk-the-Line-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc3.ts => jbc3-Precision-Parking-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc8.ts => jbc4-Serpentine-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc4.ts => jbc6-Figure-Eight-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc6.ts => jbc7-Load-Em-Up-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc7.ts => jbc8-Bulldozer-Mania-New.ts} (100%) rename src/simulator/definitions/challenges/{jbc7b.ts => jbc9-Cover-Your-Bases-New.ts} (98%) rename src/simulator/definitions/scenes/{jbc10.ts => archived/jbc10-Solo-Joust.ts} (91%) rename src/simulator/definitions/scenes/{jbc10b.ts => archived/jbc10b-Solo-Joust-Jr.ts} (88%) rename src/simulator/definitions/scenes/{jbc12.ts => archived/jbc12-Unload-Em.ts} (94%) rename src/simulator/definitions/scenes/{jbc13.ts => archived/jbc13-Clean-the-Mat.ts} (94%) rename src/simulator/definitions/scenes/{jbc15b.ts => archived/jbc15b-Bump-Bump.ts} (91%) rename src/simulator/definitions/scenes/{jbc17b.ts => archived/jbc17b-Walk-the-Line-2.ts} (91%) rename src/simulator/definitions/scenes/{jbc20.ts => archived/jbc20-Rescue-the-Cans.ts} (88%) rename src/simulator/definitions/scenes/{jbc21.ts => archived/jbc21-Foot-Tall.ts} (80%) rename src/simulator/definitions/scenes/{jbc2b.ts => archived/jbc2b-Ring-Around-the-Cans-Sr.ts} (96%) rename src/simulator/definitions/scenes/{jbc2c.ts => archived/jbc2c-Back-It-Up.ts} (95%) rename src/simulator/definitions/scenes/{jbc2d.ts => archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts} (95%) rename src/simulator/definitions/scenes/{jbc3b.ts => archived/jbc3b-Parallel-Parking.ts} (55%) rename src/simulator/definitions/scenes/{jbc3c.ts => archived/jbc3c-Quick-Get-Away.ts} (55%) rename src/simulator/definitions/scenes/{jbc4b.ts => archived/jbc4b-Barrel-Racing.ts} (97%) rename src/simulator/definitions/scenes/{jbc5b.ts => archived/jbc5b-Line-Dance.ts} (54%) rename src/simulator/definitions/scenes/{jbc5c.ts => archived/jbc5c-Synchronized-Dancing.ts} (56%) rename src/simulator/definitions/scenes/{jbc6b.ts => archived/jbc6b-Pick-Em-Up.ts} (64%) rename src/simulator/definitions/scenes/{jbc6c.ts => archived/jbc6c-Empty-the-Garage.ts} (95%) rename src/simulator/definitions/scenes/{jbc8b.ts => archived/jbc8b-Serpentine-Jr.ts} (96%) rename src/simulator/definitions/scenes/{jbc9b.ts => archived/jbc9b-Balancing-Act.ts} (55%) create mode 100644 src/simulator/definitions/scenes/jbc0.ts rename src/simulator/definitions/scenes/{jbc9.ts => jbc12-Add-It-Up-New.ts} (100%) create mode 100644 src/simulator/definitions/scenes/jbc14-Dance-Party.ts rename src/simulator/definitions/scenes/{jbc19.ts => jbc17-Mountain-Rescue-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc22.ts => jbc18-Stackerz-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc17.ts => jbc24-Walk-the-Line-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc3.ts => jbc3-Precision-Parking-New.ts} (95%) rename src/simulator/definitions/scenes/{jbc8.ts => jbc4-Serpentine-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc4.ts => jbc6-Figure-Eight-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc6.ts => jbc7-Load-Em-Up-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc7.ts => jbc8-Bulldozer-Mania-New.ts} (100%) rename src/simulator/definitions/scenes/{jbc7b.ts => jbc9-Cover-Your-Bases-New.ts} (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7ebda95d..ad1d38f8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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 } \ No newline at end of file diff --git a/src/components/Challenge/ChallengeMenu.tsx b/src/components/Challenge/ChallengeMenu.tsx index a00cd2cf..ed717c1e 100644 --- a/src/components/Challenge/ChallengeMenu.tsx +++ b/src/components/Challenge/ChallengeMenu.tsx @@ -270,11 +270,6 @@ class ChallengeMenu extends React.PureComponent { - - End Challenge - - - Layout {subMenu.type === SubMenu.Type.LayoutPicker ? ( diff --git a/src/simulator/Space.ts b/src/simulator/Space.ts index e04724c8..c91f34e6 100644 --- a/src/simulator/Space.ts +++ b/src/simulator/Space.ts @@ -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); } } diff --git a/src/simulator/babylonBindings/RobotBinding.ts b/src/simulator/babylonBindings/RobotBinding.ts index eaa90ecb..fbdc365a 100644 --- a/src/simulator/babylonBindings/RobotBinding.ts +++ b/src/simulator/babylonBindings/RobotBinding.ts @@ -356,7 +356,7 @@ class RobotBinding { const normalizedPwm = pwm / 400; const nextAngularVelocity = normalizedPwm * velocityMax * 2 * Math.PI / ticksPerRevolution; - console.log("nextAngularVelocity", nextAngularVelocity); + // console.log("nextAngularVelocity", nextAngularVelocity); this.setMotorVelocity_(bMotor, nextAngularVelocity); } diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index 1cabc512..789f918c 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -714,7 +714,7 @@ class SceneBinding { const meshcopy = meshes .map(mesh => mesh.physicsBody) - .filter(body => !body); + .filter(body => body); if (meshcopy.length === 0) continue; @@ -727,6 +727,7 @@ class SceneBinding { .map(mesh => mesh.physicsBody); for (const body of meshcopy) { + body.setCollisionCallbackEnabled(true); const observable = body.getCollisionObservable(); observable.add(this.onCollideEvent_); } @@ -752,14 +753,17 @@ class SceneBinding { ) => { const collider = collisionEvent.collider; - const collidedWith = collisionEvent.collidedAgainst; + const collidedAgainst = collisionEvent.collidedAgainst; const point = collisionEvent.point; + const distance = collisionEvent.distance; + const impulse = collisionEvent.impulse; + const normal = collisionEvent.normal; if (!('metadata' in collider.transformNode)) return; - if (!('metadata' in collidedWith.transformNode)) return; + if (!('metadata' in collidedAgainst.transformNode)) return; const colliderMetadata = collider.transformNode.metadata as SceneMeshMetadata; - const collidedWithMetadata = collidedWith.transformNode.metadata as SceneMeshMetadata; + const collidedWithMetadata = collidedAgainst.transformNode.metadata as SceneMeshMetadata; if (!colliderMetadata) return; if (!collidedWithMetadata) return; @@ -769,6 +773,8 @@ class SceneBinding { otherNodeId: collidedWithMetadata.id, point: Vector3wUnits.fromRaw(RawVector3.fromBabylon(point), RENDER_SCALE), })); + + return { collider, collidedAgainst, point, distance, impulse, normal }; }; diff --git a/src/simulator/definitions/challenges/jbc10.ts b/src/simulator/definitions/challenges/archived/jbc10-Solo-Joust.ts similarity index 86% rename from src/simulator/definitions/challenges/jbc10.ts rename to src/simulator/definitions/challenges/archived/jbc10-Solo-Joust.ts index 48c4e2ed..c824ed3d 100644 --- a/src/simulator/definitions/challenges/jbc10.ts +++ b/src/simulator/definitions/challenges/archived/jbc10-Solo-Joust.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 10' }, diff --git a/src/simulator/definitions/challenges/jbc10b.ts b/src/simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr.ts similarity index 86% rename from src/simulator/definitions/challenges/jbc10b.ts rename to src/simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr.ts index 1c048cc2..c9b3cbce 100644 --- a/src/simulator/definitions/challenges/jbc10b.ts +++ b/src/simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 10B' }, diff --git a/src/simulator/definitions/challenges/jbc12.ts b/src/simulator/definitions/challenges/archived/jbc12-Unload-Em.ts similarity index 89% rename from src/simulator/definitions/challenges/jbc12.ts rename to src/simulator/definitions/challenges/archived/jbc12-Unload-Em.ts index 5cb0f4ab..6bc30570 100644 --- a/src/simulator/definitions/challenges/jbc12.ts +++ b/src/simulator/definitions/challenges/archived/jbc12-Unload-Em.ts @@ -1,8 +1,8 @@ -import Author from "../../../db/Author"; -import Challenge from "../../../state/State/Challenge"; -import Expr from "../../../state/State/Challenge/Expr"; -import LocalizedString from "../../../util/LocalizedString"; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from "../../../../db/Author"; +import Challenge from "../../../../state/State/Challenge"; +import Expr from "../../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: "JBC Challenge 12" }, diff --git a/src/simulator/definitions/challenges/jbc13.ts b/src/simulator/definitions/challenges/archived/jbc13-Clean-the-Mat.ts similarity index 92% rename from src/simulator/definitions/challenges/jbc13.ts rename to src/simulator/definitions/challenges/archived/jbc13-Clean-the-Mat.ts index 7f36e8f3..2b18bddd 100644 --- a/src/simulator/definitions/challenges/jbc13.ts +++ b/src/simulator/definitions/challenges/archived/jbc13-Clean-the-Mat.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 13' }, diff --git a/src/simulator/definitions/challenges/jbc15b.ts b/src/simulator/definitions/challenges/archived/jbc15b-Bump-Bump.ts similarity index 86% rename from src/simulator/definitions/challenges/jbc15b.ts rename to src/simulator/definitions/challenges/archived/jbc15b-Bump-Bump.ts index 53ddb22c..dbe5bb05 100644 --- a/src/simulator/definitions/challenges/jbc15b.ts +++ b/src/simulator/definitions/challenges/archived/jbc15b-Bump-Bump.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 15B' }, diff --git a/src/simulator/definitions/challenges/jbc17b.ts b/src/simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2.ts similarity index 76% rename from src/simulator/definitions/challenges/jbc17b.ts rename to src/simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2.ts index 9b67f049..5a73d36c 100644 --- a/src/simulator/definitions/challenges/jbc17b.ts +++ b/src/simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 17B' }, diff --git a/src/simulator/definitions/challenges/jbc20.ts b/src/simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans.ts similarity index 93% rename from src/simulator/definitions/challenges/jbc20.ts rename to src/simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans.ts index ee1f82ff..62d3f21b 100644 --- a/src/simulator/definitions/challenges/jbc20.ts +++ b/src/simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 20' }, diff --git a/src/simulator/definitions/challenges/jbc21.ts b/src/simulator/definitions/challenges/archived/jbc21-Foot-Tall.ts similarity index 74% rename from src/simulator/definitions/challenges/jbc21.ts rename to src/simulator/definitions/challenges/archived/jbc21-Foot-Tall.ts index 49e1c1d4..d18fae61 100644 --- a/src/simulator/definitions/challenges/jbc21.ts +++ b/src/simulator/definitions/challenges/archived/jbc21-Foot-Tall.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 21' }, diff --git a/src/simulator/definitions/challenges/jbc2b.ts b/src/simulator/definitions/challenges/archived/jbc2b-Ring-Around-the-Cans-Sr.ts similarity index 95% rename from src/simulator/definitions/challenges/jbc2b.ts rename to src/simulator/definitions/challenges/archived/jbc2b-Ring-Around-the-Cans-Sr.ts index b1f2b323..661e564f 100644 --- a/src/simulator/definitions/challenges/jbc2b.ts +++ b/src/simulator/definitions/challenges/archived/jbc2b-Ring-Around-the-Cans-Sr.ts @@ -1,8 +1,8 @@ -import Author from "../../../db/Author"; -import Challenge from "../../../state/State/Challenge"; -import Expr from "../../../state/State/Challenge/Expr"; -import LocalizedString from "../../../util/LocalizedString"; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from "../../../../db/Author"; +import Challenge from "../../../../state/State/Challenge"; +import Expr from "../../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: "JBC Challenge 2B" }, diff --git a/src/simulator/definitions/challenges/jbc2c.ts b/src/simulator/definitions/challenges/archived/jbc2c-Back-It-Up.ts similarity index 92% rename from src/simulator/definitions/challenges/jbc2c.ts rename to src/simulator/definitions/challenges/archived/jbc2c-Back-It-Up.ts index 0ff8427d..dd92602d 100644 --- a/src/simulator/definitions/challenges/jbc2c.ts +++ b/src/simulator/definitions/challenges/archived/jbc2c-Back-It-Up.ts @@ -1,8 +1,8 @@ -import Author from "../../../db/Author"; -import Challenge from "../../../state/State/Challenge"; -import Expr from "../../../state/State/Challenge/Expr"; -import LocalizedString from "../../../util/LocalizedString"; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from "../../../../db/Author"; +import Challenge from "../../../../state/State/Challenge"; +import Expr from "../../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: "JBC Challenge 2C" }, diff --git a/src/simulator/definitions/challenges/jbc2d.ts b/src/simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts similarity index 93% rename from src/simulator/definitions/challenges/jbc2d.ts rename to src/simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts index f31a908d..96e45bcd 100644 --- a/src/simulator/definitions/challenges/jbc2d.ts +++ b/src/simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 2D' }, diff --git a/src/simulator/definitions/challenges/jbc4b.ts b/src/simulator/definitions/challenges/archived/jbc4b-Barrel-Racing.ts similarity index 94% rename from src/simulator/definitions/challenges/jbc4b.ts rename to src/simulator/definitions/challenges/archived/jbc4b-Barrel-Racing.ts index 43344e26..0fa40218 100644 --- a/src/simulator/definitions/challenges/jbc4b.ts +++ b/src/simulator/definitions/challenges/archived/jbc4b-Barrel-Racing.ts @@ -1,8 +1,8 @@ -import Author from "../../../db/Author"; -import Challenge from "../../../state/State/Challenge"; -import Expr from "../../../state/State/Challenge/Expr"; -import LocalizedString from "../../../util/LocalizedString"; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from "../../../../db/Author"; +import Challenge from "../../../../state/State/Challenge"; +import Expr from "../../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: "JBC Challenge 4B" }, diff --git a/src/simulator/definitions/challenges/jbc6c.ts b/src/simulator/definitions/challenges/archived/jbc6c-Empty-the-Garage.ts similarity index 93% rename from src/simulator/definitions/challenges/jbc6c.ts rename to src/simulator/definitions/challenges/archived/jbc6c-Empty-the-Garage.ts index 0bc62844..d35d49a2 100644 --- a/src/simulator/definitions/challenges/jbc6c.ts +++ b/src/simulator/definitions/challenges/archived/jbc6c-Empty-the-Garage.ts @@ -1,7 +1,7 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; import tr from '@i18n'; diff --git a/src/simulator/definitions/challenges/jbc8b.ts b/src/simulator/definitions/challenges/archived/jbc8b-Serpentine-Jr.ts similarity index 90% rename from src/simulator/definitions/challenges/jbc8b.ts rename to src/simulator/definitions/challenges/archived/jbc8b-Serpentine-Jr.ts index fec7ae4f..95ad4097 100644 --- a/src/simulator/definitions/challenges/jbc8b.ts +++ b/src/simulator/definitions/challenges/archived/jbc8b-Serpentine-Jr.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'JBC Challenge 8B' }, diff --git a/src/simulator/definitions/challenges/test.ts b/src/simulator/definitions/challenges/archived/test.ts similarity index 78% rename from src/simulator/definitions/challenges/test.ts rename to src/simulator/definitions/challenges/archived/test.ts index 9dfc8d74..663abc73 100644 --- a/src/simulator/definitions/challenges/test.ts +++ b/src/simulator/definitions/challenges/archived/test.ts @@ -1,8 +1,8 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; -import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import Author from '../../../../db/Author'; +import Challenge from '../../../../state/State/Challenge'; +import Expr from '../../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../../programming/compiler/ProgrammingLanguage"; export default { name: { [LocalizedString.EN_US]: 'Test' }, diff --git a/src/simulator/definitions/challenges/jbc0.ts b/src/simulator/definitions/challenges/jbc0.ts new file mode 100644 index 00000000..922172ef --- /dev/null +++ b/src/simulator/definitions/challenges/jbc0.ts @@ -0,0 +1,89 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 0' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 0: Drive Straight`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + leaveStartBox: { + name: { [LocalizedString.EN_US]: 'Robot Left Start' }, + description: { [LocalizedString.EN_US]: 'Robot left starting box' }, + }, + robotTouchingLine: { + name: { [LocalizedString.EN_US]: 'Robot Touching Line B' }, + description: { [LocalizedString.EN_US]: 'Robot is touching line B' }, + }, + reachedEnd: { + name: { [LocalizedString.EN_US]: 'Robot Reached End' }, + description: { [LocalizedString.EN_US]: 'Robot reached the end of the mat' }, + }, + offMat: { + name: { [LocalizedString.EN_US]: 'Robot Off Mat' }, + description: { [LocalizedString.EN_US]: 'Robot left the mat' }, + }, + }, + success: { + exprs: { + + // End of Mat Events + reachedEnd: { + type: Expr.Type.Event, + eventId: 'reachedEnd', + }, + + // Start Box Events + leaveStartBox: { + type: Expr.Type.Event, + eventId: 'leaveStartBox', + }, + leaveStartBoxOnce: { + type: Expr.Type.Once, + argId: 'leaveStartBox', + }, + + + completion: { + type: Expr.Type.And, + argIds: ['leaveStartBoxOnce', 'reachedEnd'], + }, + }, + rootId: 'completion', + }, + failure: { + exprs: { + // Line B Event + robotTouchingLine: { + type: Expr.Type.Event, + eventId: 'robotTouchingLine', + }, + + // Off Mat Event + offMat: { + type: Expr.Type.Event, + eventId: 'offMat', + }, + + failure: { + type: Expr.Type.Or, + argIds: ['robotTouchingLine', 'offMat'], + }, + }, + rootId: 'failure', + }, + sceneId: 'jbc0', +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc1.ts b/src/simulator/definitions/challenges/jbc1.ts index 4a77553a..ef413d09 100644 --- a/src/simulator/definitions/challenges/jbc1.ts +++ b/src/simulator/definitions/challenges/jbc1.ts @@ -19,17 +19,18 @@ export default { defaultLanguage: 'c', events: { can9Touched: { - name: { [LocalizedString.EN_US]: 'Can A Touched' }, + name: { [LocalizedString.EN_US]: 'Can 9 Touched' }, description: { [LocalizedString.EN_US]: 'Can A touched' }, }, - canAIntersects: { - name: { [LocalizedString.EN_US]: 'Can A Intersects' }, - description: { [LocalizedString.EN_US]: 'Can A intersects circle 9' }, + + can9Intersects: { + name: { [LocalizedString.EN_US]: 'Can 9 Intersects' }, + description: { [LocalizedString.EN_US]: 'Can 9 intersects circle 9' }, }, - canAUpright: { - name: { [LocalizedString.EN_US]: 'Can A Upright' }, - description: { [LocalizedString.EN_US]: 'Can A upright on circle 9' }, + can9Upright: { + name: { [LocalizedString.EN_US]: 'Can 9 Upright' }, + description: { [LocalizedString.EN_US]: 'Can 9 upright on circle 9' }, }, leaveStartBox: { @@ -50,15 +51,15 @@ export default { }, // Intersects Events - canAIntersects: { + can9Intersects: { type: Expr.Type.Event, - eventId: 'canAIntersects', + eventId: 'can9Intersects', }, // Upright Events - canAUpright: { + can9Upright: { type: Expr.Type.Event, - eventId: 'canAUpright', + eventId: 'can9Upright', }, // Start Box Events @@ -88,15 +89,15 @@ export default { }, // Intersects and upright logic - aIntersectsUpright: { + can9IntersectsUpright: { type: Expr.Type.And, - argIds: ['canAIntersects', 'canAUpright'], + argIds: ['can9Intersects', 'can9Upright'], }, // Success Logic = Can A upright, intersects and touched completion: { type: Expr.Type.And, - argIds: ['can9Touched', 'aIntersectsUpright', 'startingBox'], + argIds: ['can9Touched', 'can9IntersectsUpright', 'startingBox'], }, }, rootId: 'completion', diff --git a/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts b/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts new file mode 100644 index 00000000..728a4c7a --- /dev/null +++ b/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts @@ -0,0 +1,154 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + description: { + [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Add It Up', + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + start: { + name: { [LocalizedString.EN_US]: 'Robot Begins In start' }, + description: { [LocalizedString.EN_US]: 'Robot begins in starting box' }, + }, + passed1: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 1' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 1' }, + }, + passed2: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 2' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 2' }, + }, + passed3: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 3' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 3' }, + }, + passed4: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 4' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 4' }, + }, + passed5: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 5' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 5' }, + }, + passed6: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 6' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 6' }, + }, + passed7: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 7' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 7' }, + }, + passed8: { + name: { [LocalizedString.EN_US]: 'Robot Touched Circle 8' }, + description: { [LocalizedString.EN_US]: 'Robot passed through circle 8' }, + }, + }, + success: { + exprs: { + // Start Box Event + start: { + type: Expr.Type.Event, + eventId: 'start', + }, + startOnce: { + type: Expr.Type.Once, + argId: 'start', + }, + + // Passed Through Circles Events + passed1: { + type: Expr.Type.Event, + eventId: 'passed1', + }, + passed1Once: { + type: Expr.Type.Once, + argId: 'passed1', + }, + + passed2: { + type: Expr.Type.Event, + eventId: 'passed2', + }, + passed2Once: { + type: Expr.Type.Once, + argId: 'passed2', + }, + passed3: { + type: Expr.Type.Event, + eventId: 'passed3', + }, + passed3Once: { + type: Expr.Type.Once, + argId: 'passed3', + }, + passed4: { + type: Expr.Type.Event, + eventId: 'passed4', + }, + passed4Once: { + type: Expr.Type.Once, + argId: 'passed4', + }, + passed5: { + type: Expr.Type.Event, + eventId: 'passed5', + }, + passed5Once: { + type: Expr.Type.Once, + argId: 'passed5', + }, + passed6: { + type: Expr.Type.Event, + eventId: 'passed6', + }, + passed6Once: { + type: Expr.Type.Once, + argId: 'passed6', + }, + passed7: { + type: Expr.Type.Event, + eventId: 'passed7', + }, + passed7Once: { + type: Expr.Type.Once, + argId: 'passed7', + }, + passed8: { + type: Expr.Type.Event, + eventId: 'passed8', + }, + passed8Once: { + type: Expr.Type.Once, + argId: 'passed8', + }, + + + passedSerpentine: { + type: Expr.Type.And, + argIds: ["passed1Once", "passed2Once","passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], + }, + + // Success logic + completion: { + type: Expr.Type.And, + argIds: ['startOnce', 'passedSerpentine'], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc8', +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc14-Dance-Party.ts b/src/simulator/definitions/challenges/jbc14-Dance-Party.ts new file mode 100644 index 00000000..4e2a1123 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc14-Dance-Party.ts @@ -0,0 +1,133 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 5: Dance Party`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + leaveStartBox: { + name: { [LocalizedString.EN_US]: 'Robot Left Start' }, + description: { [LocalizedString.EN_US]: 'Robot left starting box' }, + }, + clockwise360: { + name: { [LocalizedString.EN_US]: 'Robot 360 Clockwise' }, + description: { + [LocalizedString.EN_US]: 'Robot turned 360 degrees clockwise', + }, + }, + counterClockwise360: { + name: { [LocalizedString.EN_US]: 'Robot 360 Counter Clockwise' }, + description: { + [LocalizedString.EN_US]: 'Robot turned 360 degrees counter clockwise', + }, + }, + driveForward: { + name: { [LocalizedString.EN_US]: 'Robot Drove Forward' }, + description: { + [LocalizedString.EN_US]: 'Robot drove forward', + }, + }, + driveBackward: { + name: { [LocalizedString.EN_US]: 'Robot Drove Backward' }, + description: { + [LocalizedString.EN_US]: 'Robot drove backward', + }, + }, + waveServo: { + name: { [LocalizedString.EN_US]: 'Robot Wave Servo' }, + description: { + [LocalizedString.EN_US]: 'Robot waved servo up and down at least once', + }, + }, + }, + success: { + exprs: { + // Waving Event + waveServo: { + type: Expr.Type.Event, + eventId: 'waveServo', + }, + waveServoOnce: { + type: Expr.Type.Once, + argId: 'waveServo', + }, + + // Turning Events + clockwise360: { + type: Expr.Type.Event, + eventId: 'clockwise360', + }, + clockwise360Once: { + type: Expr.Type.Once, + argId: 'clockwise360', + }, + counterClockwise360: { + type: Expr.Type.Event, + eventId: 'counterClockwise360', + }, + counterClockwise360Once: { + type: Expr.Type.Once, + argId: 'counterClockwise360', + }, + turning: { + type: Expr.Type.And, + argIds: ['clockwise360Once', 'counterClockwise360Once'], + }, + + // Start Box Events + leaveStartBox: { + type: Expr.Type.Event, + eventId: 'leaveStartBox', + }, + leaveStartBoxOnce: { + type: Expr.Type.Once, + argId: 'leaveStartBox', + }, + + // Driving Events + driveForward: { + type: Expr.Type.Event, + eventId: 'driveForward', + }, + driveForwardOnce: { + type: Expr.Type.Once, + argId: 'driveForward', + }, + driveBackward: { + type: Expr.Type.Event, + eventId: 'driveBackward', + }, + driveBackwardOnce: { + type: Expr.Type.Once, + argId: 'driveBackward', + }, + + driving: { + type: Expr.Type.And, + argIds: ['driveForwardOnce', 'driveBackwardOnce'], + }, + + completion: { + type: Expr.Type.And, + argIds: ['leaveStartBoxOnce', 'turning', 'driving', 'waveServoOnce'], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc5', +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc19.ts b/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc19.ts rename to src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts diff --git a/src/simulator/definitions/challenges/jbc22.ts b/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc22.ts rename to src/simulator/definitions/challenges/jbc18-Stackerz-New.ts diff --git a/src/simulator/definitions/challenges/jbc2.ts b/src/simulator/definitions/challenges/jbc2.ts index f52cd3c5..979c9860 100644 --- a/src/simulator/definitions/challenges/jbc2.ts +++ b/src/simulator/definitions/challenges/jbc2.ts @@ -138,7 +138,7 @@ export default { }, // Intersects and upright logic - IntersectsUpright: { + intersectsUpright: { type: Expr.Type.And, argIds: ["can6Intersects", "can6Upright"], }, @@ -148,7 +148,7 @@ export default { type: Expr.Type.And, argIds: [ "can6NotTouched", - "IntersectsUpright", + "intersectsUpright", "startingBox", "rightSideOnce", "topSideOnce", diff --git a/src/simulator/definitions/challenges/jbc17.ts b/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc17.ts rename to src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts diff --git a/src/simulator/definitions/challenges/jbc3.ts b/src/simulator/definitions/challenges/jbc3-Precision-Parking-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc3.ts rename to src/simulator/definitions/challenges/jbc3-Precision-Parking-New.ts diff --git a/src/simulator/definitions/challenges/jbc8.ts b/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc8.ts rename to src/simulator/definitions/challenges/jbc4-Serpentine-New.ts diff --git a/src/simulator/definitions/challenges/jbc5.ts b/src/simulator/definitions/challenges/jbc5.ts index 4e2a1123..9b20c774 100644 --- a/src/simulator/definitions/challenges/jbc5.ts +++ b/src/simulator/definitions/challenges/jbc5.ts @@ -1,133 +1,154 @@ -import Author from '../../../db/Author'; -import Challenge from '../../../state/State/Challenge'; -import Expr from '../../../state/State/Challenge/Expr'; -import LocalizedString from '../../../util/LocalizedString'; +import Author from "../../../db/Author"; +import Challenge from "../../../state/State/Challenge"; +import Expr from "../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + name: { [LocalizedString.EN_US]: "JBC Challenge 5" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 5: Dance Party`, + [LocalizedString.EN_US]: `Junior Botball Challenge 5: Odd Numbers`, }, author: { type: Author.Type.Organization, - id: 'kipr', + id: "kipr", }, code: { 'c': ProgrammingLanguage.DEFAULT_CODE.c, 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, 'python': ProgrammingLanguage.DEFAULT_CODE.python, }, - defaultLanguage: 'c', + defaultLanguage: "c", events: { - leaveStartBox: { - name: { [LocalizedString.EN_US]: 'Robot Left Start' }, - description: { [LocalizedString.EN_US]: 'Robot left starting box' }, + touchedEvenCircle: { + name: { [LocalizedString.EN_US]: "Even Circle Touched" }, + description: { [LocalizedString.EN_US]: "Even circle touched" }, }, - clockwise360: { - name: { [LocalizedString.EN_US]: 'Robot 360 Clockwise' }, - description: { - [LocalizedString.EN_US]: 'Robot turned 360 degrees clockwise', - }, + wrongOrder: { + name: { [LocalizedString.EN_US]: "Circle Touched Out of Order" }, + description: { [LocalizedString.EN_US]: "Circle was touched out of order" }, }, - counterClockwise360: { - name: { [LocalizedString.EN_US]: 'Robot 360 Counter Clockwise' }, - description: { - [LocalizedString.EN_US]: 'Robot turned 360 degrees counter clockwise', - }, + circle1Touched: { + name: { [LocalizedString.EN_US]: "Circle 1 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 1 was touched" }, }, - driveForward: { - name: { [LocalizedString.EN_US]: 'Robot Drove Forward' }, - description: { - [LocalizedString.EN_US]: 'Robot drove forward', - }, + circle3Touched: { + name: { [LocalizedString.EN_US]: "Circle 3 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 3 was touched" }, }, - driveBackward: { - name: { [LocalizedString.EN_US]: 'Robot Drove Backward' }, - description: { - [LocalizedString.EN_US]: 'Robot drove backward', - }, + circle5Touched: { + name: { [LocalizedString.EN_US]: "Circle 5 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 5 was touched" }, }, - waveServo: { - name: { [LocalizedString.EN_US]: 'Robot Wave Servo' }, - description: { - [LocalizedString.EN_US]: 'Robot waved servo up and down at least once', - }, + circle7Touched: { + name: { [LocalizedString.EN_US]: "Circle 7 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 7 was touched" }, + }, + circle9Touched: { + name: { [LocalizedString.EN_US]: "Circle 9 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 9 was touched" }, + }, + circle11Touched: { + name: { [LocalizedString.EN_US]: "Circle 11 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 11 was touched" }, }, }, success: { exprs: { - // Waving Event - waveServo: { + // Touch Events + circle1Touched: { type: Expr.Type.Event, - eventId: 'waveServo', + eventId: 'circle1Touched', }, - waveServoOnce: { + circle1TouchedOnce: { type: Expr.Type.Once, - argId: 'waveServo', + argId: 'circle1Touched' }, - - // Turning Events - clockwise360: { + circle3Touched: { type: Expr.Type.Event, - eventId: 'clockwise360', + eventId: 'circle3Touched', }, - clockwise360Once: { + circle3TouchedOnce: { type: Expr.Type.Once, - argId: 'clockwise360', + argId: 'circle3Touched' }, - counterClockwise360: { + circle5Touched: { type: Expr.Type.Event, - eventId: 'counterClockwise360', + eventId: 'circle5Touched', }, - counterClockwise360Once: { + circle5TouchedOnce: { type: Expr.Type.Once, - argId: 'counterClockwise360', - }, - turning: { - type: Expr.Type.And, - argIds: ['clockwise360Once', 'counterClockwise360Once'], + argId: 'circle5Touched' }, - - // Start Box Events - leaveStartBox: { + circle7Touched: { type: Expr.Type.Event, - eventId: 'leaveStartBox', + eventId: 'circle7Touched', }, - leaveStartBoxOnce: { + circle7TouchedOnce: { type: Expr.Type.Once, - argId: 'leaveStartBox', + argId: 'circle7Touched' }, - - // Driving Events - driveForward: { + circle9Touched: { type: Expr.Type.Event, - eventId: 'driveForward', + eventId: 'circle9Touched', }, - driveForwardOnce: { + circle9TouchedOnce: { type: Expr.Type.Once, - argId: 'driveForward', + argId: 'circle9Touched' }, - driveBackward: { + circle11Touched: { type: Expr.Type.Event, - eventId: 'driveBackward', + eventId: 'circle11Touched', }, - driveBackwardOnce: { + circle11TouchedOnce: { type: Expr.Type.Once, - argId: 'driveBackward', + argId: 'circle11Touched' }, - driving: { + // Success = All Circles Touched + completion: { type: Expr.Type.And, - argIds: ['driveForwardOnce', 'driveBackwardOnce'], + argIds: [ + 'circle1TouchedOnce', + 'circle3TouchedOnce', + 'circle5TouchedOnce', + 'circle7TouchedOnce', + 'circle9TouchedOnce', + 'circle11TouchedOnce', + ], + }, + }, + rootId: "completion", + }, + failure: { + exprs: { + touchedEvenCircle: { + type: Expr.Type.Event, + eventId: 'touchedEvenCircle', + }, + touchedEvenCircleOnce: { + type: Expr.Type.Once, + argId: 'touchedEvenCircle' + }, + wrongOrder: { + type: Expr.Type.Event, + eventId: 'wrongOrder', + }, + wrongOrderOnce: { + type: Expr.Type.Once, + argId: 'wrongOrder' }, - completion: { - type: Expr.Type.And, - argIds: ['leaveStartBoxOnce', 'turning', 'driving', 'waveServoOnce'], + // Failure = Touched Even Circle or Touched Circle in Wrong Order + failure: { + type: Expr.Type.Or, + argIds: [ + 'touchedEvenCircleOnce', + 'wrongOrderOnce', + ], }, }, - rootId: 'completion', + rootId: "failure" }, - sceneId: 'jbc5', + sceneId: "jbc5", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc4.ts b/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc4.ts rename to src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts diff --git a/src/simulator/definitions/challenges/jbc6.ts b/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc6.ts rename to src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts diff --git a/src/simulator/definitions/challenges/jbc7.ts b/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts similarity index 100% rename from src/simulator/definitions/challenges/jbc7.ts rename to src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts diff --git a/src/simulator/definitions/challenges/jbc7b.ts b/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts similarity index 98% rename from src/simulator/definitions/challenges/jbc7b.ts rename to src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts index 5a5cd762..ee145b12 100644 --- a/src/simulator/definitions/challenges/jbc7b.ts +++ b/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts @@ -193,7 +193,7 @@ export default { // Success Logic = Can A upright, intersects and touched completion: { type: Expr.Type.And, - argIds: ['robotNoTouchFirstOnceNot','startingBox', 'AllIntersectsUpright'], + argIds: ['robotNoTouchFirstOnceNot', 'startingBox', 'AllIntersectsUpright'], }, }, rootId: 'completion', diff --git a/src/simulator/definitions/nodes/index.ts b/src/simulator/definitions/nodes/index.ts index f37bdd08..530747d0 100644 --- a/src/simulator/definitions/nodes/index.ts +++ b/src/simulator/definitions/nodes/index.ts @@ -26,6 +26,19 @@ const canTemplate: Node.TemplatedNode = { faceUvs: [RawVector2.ZERO, RawVector2.ZERO, RawVector2.create(1, 0), RawVector2.create(0, 1), RawVector2.ZERO, RawVector2.ZERO], }; +const circleTemplate: Node.TemplatedNode = { + type: "object", + geometryId: "circle", + material: { + type: "pbr", + emissive: { + type: "color3", + color: Color.rgba(255, 255, 255, 0.25), + }, + }, +}; + + const lifescienceTemplate: Node.TemplatedNode = { type: 'object', geometryId: 'can', @@ -311,6 +324,7 @@ const habitatControlTemplate: Node.TemplatedNode = { export const preBuiltTemplates = Object.freeze>>({ 'can': canTemplate, + 'circle': circleTemplate, 'sciencepad': sciencePadTemplate, 'lifescience': lifescienceTemplate, 'radscience': radscienceTemplate, @@ -339,6 +353,11 @@ export const preBuiltGeometries = Object.freeze>({ height: Distance.centimeters(11.15), radius: Distance.centimeters(3), }, + 'circle': { + type: 'cylinder', + height: Distance.centimeters(0.1), + radius: Distance.centimeters(3), + }, 'lifescience': { type: 'cylinder', height: Distance.centimeters(7), diff --git a/src/simulator/definitions/robots/demobot.ts b/src/simulator/definitions/robots/demobot.ts index 46c6d72d..a8b0d1de 100644 --- a/src/simulator/definitions/robots/demobot.ts +++ b/src/simulator/definitions/robots/demobot.ts @@ -26,7 +26,7 @@ export const DEMOBOT: Robot = { lightSensor: Node.lightSensor({ parentId: 'chassis', origin: { - position: Vector3wUnits.meters(0.3, 0, 0), + position: Vector3wUnits.centimeters(0, 3.5, 0), orientation: RotationwUnits.eulerDegrees(90, 0, 0), }, analogPort: 2, diff --git a/src/simulator/definitions/scenes/jbc10.ts b/src/simulator/definitions/scenes/archived/jbc10-Solo-Joust.ts similarity index 91% rename from src/simulator/definitions/scenes/jbc10.ts rename to src/simulator/definitions/scenes/archived/jbc10-Solo-Joust.ts index e813bb20..961a454e 100644 --- a/src/simulator/definitions/scenes/jbc10.ts +++ b/src/simulator/definitions/scenes/archived/jbc10-Solo-Joust.ts @@ -1,10 +1,10 @@ -import Scene from '../../../state/State/Scene'; -import { ReferenceFramewUnits } from '../../../util/math/unitMath'; -import { Distance } from '../../../util'; -import LocalizedString from '../../../util/LocalizedString'; -import Script from '../../../state/State/Scene/Script'; -import { createBaseSceneSurfaceB, createCanNode } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; +import Scene from '../../../../state/State/Scene'; +import { ReferenceFramewUnits } from '../../../../util/math/unitMath'; +import { Distance } from '../../../../util'; +import LocalizedString from '../../../../util/LocalizedString'; +import Script from '../../../../state/State/Scene/Script'; +import { createBaseSceneSurfaceB, createCanNode } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; const baseScene = createBaseSceneSurfaceB(); diff --git a/src/simulator/definitions/scenes/jbc10b.ts b/src/simulator/definitions/scenes/archived/jbc10b-Solo-Joust-Jr.ts similarity index 88% rename from src/simulator/definitions/scenes/jbc10b.ts rename to src/simulator/definitions/scenes/archived/jbc10b-Solo-Joust-Jr.ts index 6f0b4975..41ee4f8b 100644 --- a/src/simulator/definitions/scenes/jbc10b.ts +++ b/src/simulator/definitions/scenes/archived/jbc10b-Solo-Joust-Jr.ts @@ -1,8 +1,8 @@ -import Scene from "../../../state/State/Scene"; -import { Distance } from "../../../util"; -import LocalizedString from '../../../util/LocalizedString'; -import { Color } from '../../../state/State/Scene/Color'; -import { createBaseSceneSurfaceB, createCanNode } from './jbcBase'; +import Scene from "../../../../state/State/Scene"; +import { Distance } from "../../../../util"; +import LocalizedString from '../../../../util/LocalizedString'; +import { Color } from '../../../../state/State/Scene/Color'; +import { createBaseSceneSurfaceB, createCanNode } from '../jbcBase'; const baseScene = createBaseSceneSurfaceB(); diff --git a/src/simulator/definitions/scenes/jbc12.ts b/src/simulator/definitions/scenes/archived/jbc12-Unload-Em.ts similarity index 94% rename from src/simulator/definitions/scenes/jbc12.ts rename to src/simulator/definitions/scenes/archived/jbc12-Unload-Em.ts index 0d5f9063..e5c460b2 100644 --- a/src/simulator/definitions/scenes/jbc12.ts +++ b/src/simulator/definitions/scenes/archived/jbc12-Unload-Em.ts @@ -1,9 +1,9 @@ -import Scene from '../../../state/State/Scene'; -import LocalizedString from '../../../util/LocalizedString'; -import Script from '../../../state/State/Scene/Script'; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; -import { Distance } from '../../../util'; +import Scene from '../../../../state/State/Scene'; +import LocalizedString from '../../../../util/LocalizedString'; +import Script from '../../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; +import { Distance } from '../../../../util'; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc13.ts b/src/simulator/definitions/scenes/archived/jbc13-Clean-the-Mat.ts similarity index 94% rename from src/simulator/definitions/scenes/jbc13.ts rename to src/simulator/definitions/scenes/archived/jbc13-Clean-the-Mat.ts index 6461f896..40815410 100644 --- a/src/simulator/definitions/scenes/jbc13.ts +++ b/src/simulator/definitions/scenes/archived/jbc13-Clean-the-Mat.ts @@ -1,9 +1,9 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from "../../../util/LocalizedString"; -import Script from "../../../state/State/Scene/Script"; -import { createCanNode, createBaseSceneSurfaceA } from "./jbcBase"; -import { Color } from "../../../state/State/Scene/Color"; -import { Distance , Angle } from "../../../util"; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from "../../../../util/LocalizedString"; +import Script from "../../../../state/State/Scene/Script"; +import { createCanNode, createBaseSceneSurfaceA } from "../jbcBase"; +import { Color } from "../../../../state/State/Scene/Color"; +import { Distance , Angle } from "../../../../util"; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc15b.ts b/src/simulator/definitions/scenes/archived/jbc15b-Bump-Bump.ts similarity index 91% rename from src/simulator/definitions/scenes/jbc15b.ts rename to src/simulator/definitions/scenes/archived/jbc15b-Bump-Bump.ts index 67b9138d..5d5eeaea 100644 --- a/src/simulator/definitions/scenes/jbc15b.ts +++ b/src/simulator/definitions/scenes/archived/jbc15b-Bump-Bump.ts @@ -1,10 +1,10 @@ -import Scene from '../../../state/State/Scene'; -import { ReferenceFramewUnits, RotationwUnits } from '../../../util/math/unitMath'; -import { Distance } from '../../../util'; -import LocalizedString from '../../../util/LocalizedString'; -import Script from '../../../state/State/Scene/Script'; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; +import Scene from '../../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits } from '../../../../util/math/unitMath'; +import { Distance } from '../../../../util'; +import LocalizedString from '../../../../util/LocalizedString'; +import Script from '../../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc17b.ts b/src/simulator/definitions/scenes/archived/jbc17b-Walk-the-Line-2.ts similarity index 91% rename from src/simulator/definitions/scenes/jbc17b.ts rename to src/simulator/definitions/scenes/archived/jbc17b-Walk-the-Line-2.ts index 40d6f940..609a4372 100644 --- a/src/simulator/definitions/scenes/jbc17b.ts +++ b/src/simulator/definitions/scenes/archived/jbc17b-Walk-the-Line-2.ts @@ -1,10 +1,10 @@ -import Scene from "../../../state/State/Scene"; -import { ReferenceFramewUnits } from '../../../util/math/unitMath'; -import { Distance } from "../../../util"; -import { createCanNode, createBaseSceneSurfaceB } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; -import Script from '../../../state/State/Scene/Script'; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import { ReferenceFramewUnits } from '../../../../util/math/unitMath'; +import { Distance } from "../../../../util"; +import { createCanNode, createBaseSceneSurfaceB } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; +import Script from '../../../../state/State/Scene/Script'; +import LocalizedString from '../../../../util/LocalizedString'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc20.ts b/src/simulator/definitions/scenes/archived/jbc20-Rescue-the-Cans.ts similarity index 88% rename from src/simulator/definitions/scenes/jbc20.ts rename to src/simulator/definitions/scenes/archived/jbc20-Rescue-the-Cans.ts index 32e1f6ea..d060ecc5 100644 --- a/src/simulator/definitions/scenes/jbc20.ts +++ b/src/simulator/definitions/scenes/archived/jbc20-Rescue-the-Cans.ts @@ -1,9 +1,9 @@ -import Scene from '../../../state/State/Scene'; -import { ReferenceFramewUnits } from '../../../util/math/unitMath'; -import { Distance } from '../../../util'; -import LocalizedString from '../../../util/LocalizedString'; -import Script from '../../../state/State/Scene/Script'; -import { createBaseSceneSurfaceA, createCanNode } from './jbcBase'; +import Scene from '../../../../state/State/Scene'; +import { ReferenceFramewUnits } from '../../../../util/math/unitMath'; +import { Distance } from '../../../../util'; +import LocalizedString from '../../../../util/LocalizedString'; +import Script from '../../../../state/State/Scene/Script'; +import { createBaseSceneSurfaceA, createCanNode } from '../jbcBase'; import tr from '@i18n'; const uprightCans = ` diff --git a/src/simulator/definitions/scenes/jbc21.ts b/src/simulator/definitions/scenes/archived/jbc21-Foot-Tall.ts similarity index 80% rename from src/simulator/definitions/scenes/jbc21.ts rename to src/simulator/definitions/scenes/archived/jbc21-Foot-Tall.ts index d66135e1..139d1dd4 100644 --- a/src/simulator/definitions/scenes/jbc21.ts +++ b/src/simulator/definitions/scenes/archived/jbc21-Foot-Tall.ts @@ -1,9 +1,9 @@ -import Scene from '../../../state/State/Scene'; -import LocalizedString from '../../../util/LocalizedString'; -import { Distance } from '../../../util'; -import { createBaseSceneSurfaceA, createCanNode } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; -import Script from '../../../state/State/Scene/Script'; +import Scene from '../../../../state/State/Scene'; +import LocalizedString from '../../../../util/LocalizedString'; +import { Distance } from '../../../../util'; +import { createBaseSceneSurfaceA, createCanNode } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; +import Script from '../../../../state/State/Scene/Script'; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc2b.ts b/src/simulator/definitions/scenes/archived/jbc2b-Ring-Around-the-Cans-Sr.ts similarity index 96% rename from src/simulator/definitions/scenes/jbc2b.ts rename to src/simulator/definitions/scenes/archived/jbc2b-Ring-Around-the-Cans-Sr.ts index c00ce0b1..727b2c85 100644 --- a/src/simulator/definitions/scenes/jbc2b.ts +++ b/src/simulator/definitions/scenes/archived/jbc2b-Ring-Around-the-Cans-Sr.ts @@ -1,9 +1,9 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; -import { Color } from "../../../state/State/Scene/Color"; -import { Distance } from "../../../util"; -import Script from "../../../state/State/Scene/Script"; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; +import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; +import { Color } from "../../../../state/State/Scene/Color"; +import { Distance } from "../../../../util"; +import Script from "../../../../state/State/Scene/Script"; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc2c.ts b/src/simulator/definitions/scenes/archived/jbc2c-Back-It-Up.ts similarity index 95% rename from src/simulator/definitions/scenes/jbc2c.ts rename to src/simulator/definitions/scenes/archived/jbc2c-Back-It-Up.ts index e7d45f3b..458d9094 100644 --- a/src/simulator/definitions/scenes/jbc2c.ts +++ b/src/simulator/definitions/scenes/archived/jbc2c-Back-It-Up.ts @@ -1,9 +1,9 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from "../../../util/LocalizedString"; -import Script from "../../../state/State/Scene/Script"; -import { createCanNode, createBaseSceneSurfaceA } from "./jbcBase"; -import { Color } from "../../../state/State/Scene/Color"; -import { Distance } from "../../../util"; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from "../../../../util/LocalizedString"; +import Script from "../../../../state/State/Scene/Script"; +import { createCanNode, createBaseSceneSurfaceA } from "../jbcBase"; +import { Color } from "../../../../state/State/Scene/Color"; +import { Distance } from "../../../../util"; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc2d.ts b/src/simulator/definitions/scenes/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts similarity index 95% rename from src/simulator/definitions/scenes/jbc2d.ts rename to src/simulator/definitions/scenes/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts index 6bbeeffe..908a44a4 100644 --- a/src/simulator/definitions/scenes/jbc2d.ts +++ b/src/simulator/definitions/scenes/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up.ts @@ -1,9 +1,9 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from "../../../util/LocalizedString"; -import Script from "../../../state/State/Scene/Script"; -import { createCanNode, createBaseSceneSurfaceA } from "./jbcBase"; -import { Color } from "../../../state/State/Scene/Color"; -import { Distance } from "../../../util"; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from "../../../../util/LocalizedString"; +import Script from "../../../../state/State/Scene/Script"; +import { createCanNode, createBaseSceneSurfaceA } from "../jbcBase"; +import { Color } from "../../../../state/State/Scene/Color"; +import { Distance } from "../../../../util"; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc3b.ts b/src/simulator/definitions/scenes/archived/jbc3b-Parallel-Parking.ts similarity index 55% rename from src/simulator/definitions/scenes/jbc3b.ts rename to src/simulator/definitions/scenes/archived/jbc3b-Parallel-Parking.ts index 69901082..b54f951a 100644 --- a/src/simulator/definitions/scenes/jbc3b.ts +++ b/src/simulator/definitions/scenes/archived/jbc3b-Parallel-Parking.ts @@ -1,7 +1,7 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; -import { createBaseSceneSurfaceA } from './jbcBase'; +import { createBaseSceneSurfaceA } from '../jbcBase'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc3c.ts b/src/simulator/definitions/scenes/archived/jbc3c-Quick-Get-Away.ts similarity index 55% rename from src/simulator/definitions/scenes/jbc3c.ts rename to src/simulator/definitions/scenes/archived/jbc3c-Quick-Get-Away.ts index 5e84afa1..25879be2 100644 --- a/src/simulator/definitions/scenes/jbc3c.ts +++ b/src/simulator/definitions/scenes/archived/jbc3c-Quick-Get-Away.ts @@ -1,7 +1,7 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; -import { createBaseSceneSurfaceA } from './jbcBase'; +import { createBaseSceneSurfaceA } from '../jbcBase'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc4b.ts b/src/simulator/definitions/scenes/archived/jbc4b-Barrel-Racing.ts similarity index 97% rename from src/simulator/definitions/scenes/jbc4b.ts rename to src/simulator/definitions/scenes/archived/jbc4b-Barrel-Racing.ts index 414e7612..145501d6 100644 --- a/src/simulator/definitions/scenes/jbc4b.ts +++ b/src/simulator/definitions/scenes/archived/jbc4b-Barrel-Racing.ts @@ -1,9 +1,9 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from "../../../util/LocalizedString"; -import Script from "../../../state/State/Scene/Script"; -import { createCanNode, createBaseSceneSurfaceA } from "./jbcBase"; -import { Color } from "../../../state/State/Scene/Color"; -import { Distance } from "../../../util"; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from "../../../../util/LocalizedString"; +import Script from "../../../../state/State/Scene/Script"; +import { createCanNode, createBaseSceneSurfaceA } from "../jbcBase"; +import { Color } from "../../../../state/State/Scene/Color"; +import { Distance } from "../../../../util"; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc5b.ts b/src/simulator/definitions/scenes/archived/jbc5b-Line-Dance.ts similarity index 54% rename from src/simulator/definitions/scenes/jbc5b.ts rename to src/simulator/definitions/scenes/archived/jbc5b-Line-Dance.ts index cb126563..8f1375ff 100644 --- a/src/simulator/definitions/scenes/jbc5b.ts +++ b/src/simulator/definitions/scenes/archived/jbc5b-Line-Dance.ts @@ -1,7 +1,7 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; -import { createBaseSceneSurfaceA } from './jbcBase'; +import { createBaseSceneSurfaceA } from '../jbcBase'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc5c.ts b/src/simulator/definitions/scenes/archived/jbc5c-Synchronized-Dancing.ts similarity index 56% rename from src/simulator/definitions/scenes/jbc5c.ts rename to src/simulator/definitions/scenes/archived/jbc5c-Synchronized-Dancing.ts index 9f9bfbbf..21335466 100644 --- a/src/simulator/definitions/scenes/jbc5c.ts +++ b/src/simulator/definitions/scenes/archived/jbc5c-Synchronized-Dancing.ts @@ -1,7 +1,7 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; -import { createBaseSceneSurfaceB } from './jbcBase'; +import { createBaseSceneSurfaceB } from '../jbcBase'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc6b.ts b/src/simulator/definitions/scenes/archived/jbc6b-Pick-Em-Up.ts similarity index 64% rename from src/simulator/definitions/scenes/jbc6b.ts rename to src/simulator/definitions/scenes/archived/jbc6b-Pick-Em-Up.ts index af2411f2..1d6beb7e 100644 --- a/src/simulator/definitions/scenes/jbc6b.ts +++ b/src/simulator/definitions/scenes/archived/jbc6b-Pick-Em-Up.ts @@ -1,7 +1,7 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; -import { createBaseSceneSurfaceA, createCanNode } from './jbcBase'; +import { createBaseSceneSurfaceA, createCanNode } from '../jbcBase'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/jbc6c.ts b/src/simulator/definitions/scenes/archived/jbc6c-Empty-the-Garage.ts similarity index 95% rename from src/simulator/definitions/scenes/jbc6c.ts rename to src/simulator/definitions/scenes/archived/jbc6c-Empty-the-Garage.ts index c7810a0a..0ead9208 100644 --- a/src/simulator/definitions/scenes/jbc6c.ts +++ b/src/simulator/definitions/scenes/archived/jbc6c-Empty-the-Garage.ts @@ -1,11 +1,11 @@ -import Scene from "../../../state/State/Scene"; -import { Color } from '../../../state/State/Scene/Color'; -import Script from '../../../state/State/Scene/Script'; -import { Distance } from "../../../util"; +import Scene from "../../../../state/State/Scene"; +import { Color } from '../../../../state/State/Scene/Color'; +import Script from '../../../../state/State/Scene/Script'; +import { Distance } from "../../../../util"; import tr from '@i18n'; -import { createBaseSceneSurfaceA, createCanNode } from './jbcBase'; +import { createBaseSceneSurfaceA, createCanNode } from '../jbcBase'; // import jbc6c from "../challenges/jbc6c"; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc8b.ts b/src/simulator/definitions/scenes/archived/jbc8b-Serpentine-Jr.ts similarity index 96% rename from src/simulator/definitions/scenes/jbc8b.ts rename to src/simulator/definitions/scenes/archived/jbc8b-Serpentine-Jr.ts index cf46ff62..ab88acd1 100644 --- a/src/simulator/definitions/scenes/jbc8b.ts +++ b/src/simulator/definitions/scenes/archived/jbc8b-Serpentine-Jr.ts @@ -1,9 +1,9 @@ -import Scene from '../../../state/State/Scene'; -import LocalizedString from '../../../util/LocalizedString'; -import Script from '../../../state/State/Scene/Script'; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; -import { Distance } from '../../../util'; +import Scene from '../../../../state/State/Scene'; +import LocalizedString from '../../../../util/LocalizedString'; +import Script from '../../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; +import { Distance } from '../../../../util'; const baseScene = createBaseSceneSurfaceA(); diff --git a/src/simulator/definitions/scenes/jbc9b.ts b/src/simulator/definitions/scenes/archived/jbc9b-Balancing-Act.ts similarity index 55% rename from src/simulator/definitions/scenes/jbc9b.ts rename to src/simulator/definitions/scenes/archived/jbc9b-Balancing-Act.ts index 94ef403b..b1a80891 100644 --- a/src/simulator/definitions/scenes/jbc9b.ts +++ b/src/simulator/definitions/scenes/archived/jbc9b-Balancing-Act.ts @@ -1,7 +1,7 @@ -import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; +import Scene from "../../../../state/State/Scene"; +import LocalizedString from '../../../../util/LocalizedString'; -import { createBaseSceneSurfaceA } from './jbcBase'; +import { createBaseSceneSurfaceA } from '../jbcBase'; import tr from '@i18n'; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index fabb64dd..62295fa6 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -1,38 +1,40 @@ export * from './jbcSandboxA'; export * from './jbcSandboxB'; +export * from './jbc0'; export * from './jbc1'; export * from './jbc2'; -export * from './jbc2b'; -export * from './jbc2c'; -export * from './jbc2d'; -export * from './jbc3'; -export * from './jbc3b'; -export * from './jbc3c'; -export * from './jbc4'; -export * from './jbc4b'; +// export * from './jbc2b-Ring-Around-the-Cans-Sr'; +// export * from './jbc2c-Back-It-Up'; +// export * from './jbc2d-Ring-Around-the-Can-and-Back-It-Up'; +export * from './jbc3-Precision-Parking-New'; +// export * from './jbc3b-Parallel-Parking'; +// export * from './jbc3c-Quick-Get-Away'; export * from './jbc5'; -export * from './jbc5b'; -export * from './jbc5c'; -export * from './jbc6'; -export * from './jbc6b'; -export * from './jbc6c'; -export * from './jbc7'; -export * from './jbc7b'; -export * from './jbc8'; -export * from './jbc8b'; -export * from './jbc9'; -export * from './jbc9b'; -export * from './jbc10'; -export * from './jbc10b'; -export * from './jbc12'; -export * from './jbc13'; -export * from './jbc15b'; -export * from './jbc17'; -export * from './jbc17b'; -export * from './jbc19'; -export * from './jbc20'; -export * from './jbc21'; -export * from './jbc22'; -export * from './scriptPlayground'; -export * from './lightSensorTest'; +export * from './jbc6-Figure-Eight-New'; +// export * from './jbc4b-Barrel-Racing'; +// export * from './jbc14-Dance-Party'; +// export * from './jbc5b-Line-Dance'; +// export * from './jbc5c-Synchronized-Dancing'; +export * from './jbc7-Load-Em-Up-New'; +// export * from './jbc6b-Pick-Em-Up'; +// export * from './jbc6c-Empty-the-Garage'; +export * from './jbc8-Bulldozer-Mania-New'; +// export * from './jbc7b-Cover-Your-Bases'; +export * from './jbc4-Serpentine-New'; +// export * from './jbc8b-Serpentine-Jr'; +export * from './jbc12-Add-It-Up-New'; +// export * from './jbc9b-Balancing-Act'; +// export * from './jbc10-Solo-Joust'; +// export * from './jbc10b-Solo-Joust-Jr'; +// export * from './jbc12-Unload-Em'; +// export * from './jbc13-Clean-the-Mat'; +// export * from './jbc15b-Bump-Bump'; +export * from './jbc24-Walk-the-Line-New'; +// export * from './jbc17b-Walk-the-Line-2'; +export * from './jbc17-Mountain-Rescue-New'; +// export * from './jbc20-Rescue-the-Cans'; +// export * from './jbc21-Foot-Tall'; +export * from './jbc18-Stackerz-New'; +// export * from './scriptPlayground'; +// export * from './lightSensorTest'; export * from './moonSandbox'; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0.ts new file mode 100644 index 00000000..5e56246f --- /dev/null +++ b/src/simulator/definitions/scenes/jbc0.ts @@ -0,0 +1,234 @@ +import Scene from '../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits } from '../../../util/math/unitMath'; +import { Distance } from '../../../util'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createBaseSceneSurfaceB, createCanNode } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +const baseScene = createBaseSceneSurfaceB(); + +const leftStartBox = ` + +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot left start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('leaveStartBox', type === 'end'); + } + +}, 'startBox'); +`; + +const touchingLine = ` +// If the robot wheels touch Line B, it fails the challenge + +const getYawRotation = (nodeId)=> { + const node = scene.nodes[nodeId]; + + if (!node || !node.origin || !node.origin.orientation) { + // Return 0 if the node, its origin, or its orientation doesn't exist + return 0; + } + + // Extract the quaternion from the node's orientation + const quaternion = RotationwUnits.toRawQuaternion(node.origin.orientation || EULER_IDENTITY); + + // Calculate yaw (rotation around Y-axis) + const siny_cosp = 2 * (quaternion.w * quaternion.y + quaternion.x * quaternion.z); + const cosy_cosp = 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z); + const yaw = 180 / Math.PI * Math.atan2(siny_cosp, cosy_cosp); + + return yaw; +}; + +const getWheelXPosition = (nodeId, wheelXDistance) => { + const node = scene.nodes[nodeId]; + const robotXOrigin = node.startingOrigin.position.x; + const wheelXOrigin = Distance.add(robotXOrigin, wheelXDistance, 'meters'); + + const robotXPosition = node.origin.position.x; + const yawRad = (getYawRotation(nodeId) + 45) * Math.PI / 180; + const wheelXPosition = Distance.add(robotXPosition, Distance.centimeters(Distance.toCentimetersValue(wheelXOrigin) * Math.cos(yawRad)), 'centimeters'); + return wheelXPosition; +}; + +scene.addOnRenderListener(() => { + const leftWheelXPosition = getWheelXPosition('robot', Distance.centimeters(-7.492)); + const rightWheelXPosition = getWheelXPosition('robot', Distance.centimeters(7.492)); + console.log('Left: ', leftWheelXPosition.value, 'Right: ', rightWheelXPosition.value); + const leftWheelTouching = leftWheelXPosition.value > 0.5; + const rightWheelTouching = rightWheelXPosition.value < -0.5; + const robotTouchingLine = leftWheelTouching || rightWheelTouching; + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('robotTouchingLine', robotTouchingLine); + } +}); +`; + +const reachedEnd = ` +// If the robot reaches the end, it completes the challenge + +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot reached end!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('reachedEnd', type === 'start'); + } + +}, 'endBox'); +`; + +const offMat = ` +// If the robot leaves the mat, it fails the challenge +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot off mat!', type, otherNodeId); + const visible = type === 'start'; + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('offMat', visible); + setNodeVisible('endOfMat', visible); + } +}, 'endOfMat'); +`; + +const ROBOT_ORIGIN: ReferenceFramewUnits = { + ...baseScene.nodes['robot'].origin, + position: { + ...baseScene.nodes['robot'].origin.position, + }, +}; + +export const JBC_0: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 0' }, + description: { + [LocalizedString.EN_US]: 'Junior Botball Challenge 0: Drive Straight', + }, + scripts: { + leftStartBox: Script.ecmaScript('Robot Left Start', leftStartBox), + touchingLine: Script.ecmaScript('Robot Touching Line', touchingLine), + reachedEnd: Script.ecmaScript('Robot Reached End', reachedEnd), + offMat: Script.ecmaScript('Robot Off Mat', offMat), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + startBox_geom: { + type: 'box', + size: { + x: Distance.meters(1.77), + y: Distance.centimeters(0.1), + z: Distance.centimeters(30), + }, + }, + endBox_geom: { + type: 'box', + size: { + x: Distance.inches(24), + y: Distance.centimeters(15), + z: Distance.centimeters(0), + }, + }, + endOfMat_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.inches(24), + }, + }, + }, + nodes: { + ...baseScene.nodes, + robot: { + ...baseScene.nodes['robot'], + startingOrigin: ROBOT_ORIGIN, + origin: ROBOT_ORIGIN, + }, + mainSurface: { + type: 'object', + geometryId: 'mainSurface_geom', + name: { [LocalizedString.EN_US]: 'Mat Surface' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 0, 0), + }, + }, + }, + startBox: { + type: 'object', + geometryId: 'startBox_geom', + name: { [LocalizedString.EN_US]: 'Start Box' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.89), + z: Distance.centimeters(0.685), + }, + }, + material: { + type: 'pbr', + emissive: { + type: 'color3', + color: Color.rgb(0, 0, 255), + }, + }, + }, + endBox: { + type: 'object', + geometryId: 'endBox_geom', + name: { [LocalizedString.EN_US]: 'End Box' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(0), + z: Distance.inches(43.685), // 24 for half the mat and 19.685 for the mat's origin + }, + }, + material: { + type: 'pbr', + emissive: { + type: 'color3', + color: Color.rgb(0, 255, 0), + }, + }, + }, + endOfMat: { + type: 'object', + geometryId: 'endOfMat_geom', + name: { [LocalizedString.EN_US]: 'End of Mat' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.89), + z: Distance.inches(59.2), + }, + }, + material: { + type: 'pbr', + emissive: { + type: 'color3', + color: Color.rgb(255, 0, 0), + }, + }, + }, + }, +}; diff --git a/src/simulator/definitions/scenes/jbc1.ts b/src/simulator/definitions/scenes/jbc1.ts index 5bf8a851..e70de8df 100644 --- a/src/simulator/definitions/scenes/jbc1.ts +++ b/src/simulator/definitions/scenes/jbc1.ts @@ -18,7 +18,7 @@ const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { scene.addOnIntersectionListener('can9', (type, otherNodeId) => { console.log('Can 9 placed!', type, otherNodeId); const visible = type === 'start'; - scene.setChallengeEventValue('canAIntersects', visible); + scene.setChallengeEventValue('can9Intersects', visible); setNodeVisible('circle9', visible); }, 'circle9'); @@ -46,13 +46,18 @@ scene.addOnIntersectionListener('robot', (type, otherNodeId) => { `; const robotTouches = ` -scene.onBind = nodeId => { - scene.addOnCollisionListener(nodeId, (otherNodeId, point)=> { - console.log('Can A touched!', otherNodeId, point); - scene.setChallengeEventValue(nodeId + 'Touched', true); - }, 'robot'); -}; +// scene.onBind = nodeId => { +// scene.addOnCollisionListener(nodeId, (otherNodeId, point)=> { +// console.log('Can 9 touched!', otherNodeId, point); +// scene.setChallengeEventValue(nodeId + 'Touched', true); +// }, 'robot'); +// }; +scene.addOnCollisionListener('can9', (otherNodeId) => { + console.log('Robot touched Can 9!'); + scene.setChallengeEventValue('can9Touched', true); +}, 'robot'); `; + const uprightCans = ` // When a can is standing upright, the upright condition is met. @@ -63,14 +68,9 @@ const yAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wU scene.addOnRenderListener(() => { - // const currTime = Date.now(); - // const timeDiff = currTime - startTime; - const upright9 = yAngle('can9') < 5; - // if(timeDiff > 1000) { - // console.log('can9 angle: ', yAngle('can9')); - // startTime = currTime; - // } - scene.setChallengeEventValue('canAUpright', upright9); + const upright9 = yAngle('can9') > 5; + // console.log('can9 angle: ', yAngle('can9')); + scene.setChallengeEventValue('can9Upright', upright9); }); `; @@ -106,7 +106,7 @@ export const JBC_1: Scene = { size: { x: Distance.meters(3.54), y: Distance.centimeters(0.1), - z: Distance.centimeters(0), + z: Distance.inches(10), }, }, }, @@ -153,7 +153,6 @@ export const JBC_1: Scene = { }, }, }, - 'startBox': { type: 'object', geometryId: 'startBox_geom', @@ -163,18 +162,18 @@ export const JBC_1: Scene = { position: { x: Distance.centimeters(0), y: Distance.centimeters(-6.9), - z: Distance.centimeters(0), + z: Distance.centimeters(2), }, }, material: { type: 'pbr', emissive: { type: 'color3', - color: Color.rgb(255, 255, 255), + color: Color.rgb(0, 255, 255), }, }, }, - can9: { + 'can9': { ...createCanNode(9, { x: Distance.centimeters(0), y: Distance.centimeters(0), z: Distance.centimeters(85.4) }), scriptIds: ['robotTouches'] } diff --git a/src/simulator/definitions/scenes/jbc9.ts b/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc9.ts rename to src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts diff --git a/src/simulator/definitions/scenes/jbc14-Dance-Party.ts b/src/simulator/definitions/scenes/jbc14-Dance-Party.ts new file mode 100644 index 00000000..7126dbe9 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc14-Dance-Party.ts @@ -0,0 +1,126 @@ +import Scene from '../../../../state/State/Scene'; +import LocalizedString from '../../../../util/LocalizedString'; +import Script from '../../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; +import { Color } from '../../../../state/State/Scene/Color'; +import { Distance } from '../../../../util'; + +const baseScene = createBaseSceneSurfaceA(); + +const leftStartBox = ` + +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot left start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('leaveStartBox', type === 'end'); + } + +}, 'startBox'); +`; + +const goingBackwards = ` +let degrees = []; +scene.addOnRenderListener(() => { + + const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); + const xAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.X, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.X)); + let angle = xAngle('robot'); + console.log(angle); + if(angle >= 179 && angle <= 180){ + degrees[0] = 0; + degrees[1] = 180; + + } + if(angle <= 1 && (degrees[1] == 180)&& ((scene.nodes['robot'].state.motors[0].pwm > scene.nodes['robot'].state.motors[3].pwm) || scene.nodes['robot'].state.motors[3].direction === 2)){ + scene.setChallengeEventValue('counterClockwise360', true); + degrees.pop(); + degrees.pop(); + } + else if (angle <=1 && (degrees[1] == 180) && (scene.nodes['robot'].state.motors[3].pwm > scene.nodes['robot'].state.motors[0].pwm) && scene.nodes['robot'].state.motors[3].direction != 2 ) + { + scene.setChallengeEventValue('clockwise360', true); + degrees.pop(); + degrees.pop(); + } + console.log("0 PDM: " + scene.nodes['robot'].state.motors[0].pwm); + console.log("3 PDM: " + scene.nodes['robot'].state.motors[3].pwm); + console.log("0 direction: " + scene.nodes['robot'].state.motors[0].direction); + console.log("3 direction: " + scene.nodes['robot'].state.motors[3].direction); + console.log(degrees) ; +}); + +`; + +export const JBC_5: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 5' }, + description: { + [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Dance Party', + }, + scripts: { + goingBackwards: Script.ecmaScript('Going Backwards', goingBackwards), + leftStartBox: Script.ecmaScript('Robot Reentered Start', leftStartBox), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + startBox_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.centimeters(0), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: 'object', + geometryId: 'mainSurface_geom', + name: { [LocalizedString.EN_US]: 'Mat Surface' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 0, 0), + }, + }, + }, + startBox: { + type: 'object', + geometryId: 'startBox_geom', + name: { [LocalizedString.EN_US]: 'Start Box' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.centimeters(0), + }, + }, + material: { + type: 'pbr', + emissive: { + type: 'color3', + color: Color.rgb(255, 255, 255), + }, + }, + }, + }, +}; diff --git a/src/simulator/definitions/scenes/jbc19.ts b/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc19.ts rename to src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts diff --git a/src/simulator/definitions/scenes/jbc22.ts b/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc22.ts rename to src/simulator/definitions/scenes/jbc18-Stackerz-New.ts diff --git a/src/simulator/definitions/scenes/jbc2.ts b/src/simulator/definitions/scenes/jbc2.ts index 9cdd5a42..f2b50e06 100644 --- a/src/simulator/definitions/scenes/jbc2.ts +++ b/src/simulator/definitions/scenes/jbc2.ts @@ -77,6 +77,7 @@ scene.addOnIntersectionListener('robot', (type, otherNodeId) => { }, ['rightSideCan', 'topSideCan', 'leftSideCan']); `; + const uprightCans = ` // When a can is standing upright, the upright condition is met. @@ -87,13 +88,8 @@ const yAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wU scene.addOnRenderListener(() => { - // const currTime = Date.now(); - // const timeDiff = currTime - startTime; - const upright6 = yAngle('can6') < 5; - // if(timeDiff > 1000) { - // console.log('can6 angle: ', yAngle('can6')); - // startTime = currTime; - // } + const upright6 = yAngle('can6') > 5; + // console.log('can6 angle: ', yAngle('can6')); scene.setChallengeEventValue('can6Upright', upright6); }); diff --git a/src/simulator/definitions/scenes/jbc17.ts b/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc17.ts rename to src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts diff --git a/src/simulator/definitions/scenes/jbc3.ts b/src/simulator/definitions/scenes/jbc3-Precision-Parking-New.ts similarity index 95% rename from src/simulator/definitions/scenes/jbc3.ts rename to src/simulator/definitions/scenes/jbc3-Precision-Parking-New.ts index 08608725..512a0bbf 100644 --- a/src/simulator/definitions/scenes/jbc3.ts +++ b/src/simulator/definitions/scenes/jbc3-Precision-Parking-New.ts @@ -300,7 +300,7 @@ export const JBC_3: Scene = { RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, - RawVector2.create(0, 1), RawVector2.create(1, 0), // TOP + RawVector2.create(0, -1), RawVector2.create(1, 0), // TOP RawVector2.ZERO, RawVector2.ZERO, ], }, @@ -336,7 +336,7 @@ export const JBC_3: Scene = { RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, - RawVector2.create(0, 1), RawVector2.create(1, 0), // TOP + RawVector2.create(0, -1), RawVector2.create(1, 0), // TOP RawVector2.ZERO, RawVector2.ZERO, ], }, @@ -372,7 +372,7 @@ export const JBC_3: Scene = { RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, RawVector2.ZERO, - RawVector2.create(0, 1), RawVector2.create(1, 0), // TOP + RawVector2.create(0, -1), RawVector2.create(1, 0), // TOP RawVector2.ZERO, RawVector2.ZERO, ], }, @@ -401,7 +401,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Green Garage node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(0), @@ -421,7 +421,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Yellow Garage node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(18.5), @@ -441,7 +441,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Blue Garage node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(-14), @@ -462,7 +462,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Green Garage Right Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(-11.5), @@ -482,7 +482,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Green Garage Left Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(12), @@ -502,7 +502,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Green Garage Top Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(0), @@ -547,7 +547,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Blue Garage Right Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(-19.2), @@ -567,7 +567,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Blue Garage Left Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(-5), @@ -587,7 +587,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Blue Garage Top Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(-19.2), @@ -627,7 +627,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Yellow Garage Right Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(29.3), @@ -647,7 +647,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Yellow Garage Left Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(9.3), @@ -667,7 +667,7 @@ export const JBC_3: Scene = { type: 'object', geometryId: 'n_geom', name: { [LocalizedString.EN_US]: 'Yellow Garage Top Boundary node' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(18.3), @@ -683,19 +683,5 @@ export const JBC_3: Scene = { }, }, }, - can12: { - // Created an invisible can to attach script - ...createCanNode( - 12, - { - x: Distance.centimeters(11), - y: Distance.centimeters(0), - z: Distance.centimeters(91), - }, - false, - false - ), - scriptIds: ['garageIntersects'], - }, }, }; diff --git a/src/simulator/definitions/scenes/jbc8.ts b/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc8.ts rename to src/simulator/definitions/scenes/jbc4-Serpentine-New.ts diff --git a/src/simulator/definitions/scenes/jbc5.ts b/src/simulator/definitions/scenes/jbc5.ts index 662496da..e715c4a1 100644 --- a/src/simulator/definitions/scenes/jbc5.ts +++ b/src/simulator/definitions/scenes/jbc5.ts @@ -1,91 +1,150 @@ -import Scene from '../../../state/State/Scene'; -import LocalizedString from '../../../util/LocalizedString'; -import Script from '../../../state/State/Scene/Script'; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; -import { Color } from '../../../state/State/Scene/Color'; -import { Distance } from '../../../util'; +import Scene from "../../../state/State/Scene"; +import LocalizedString from "../../../util/LocalizedString"; +import Script from "../../../state/State/Scene/Script"; +import { createCanNode, createBaseSceneSurfaceA, createCircleNode, canPositions } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; const baseScene = createBaseSceneSurfaceA(); -const leftStartBox = ` +const oddNumberIntersects = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + +let circles = new Set(['circle1', 'circle3', 'circle5', 'circle7', 'circle9', 'circle11']); +const evenCircles = new Set(['circle2', 'circle4', 'circle6', 'circle8', 'circle10', 'circle12']); + +let circlesMap = new Map([ + ['circle1', false], + ['circle3', false], + ['circle5', false], + ['circle7', false], + ['circle9', false], + ['circle11', false], +]); + +// When the robot is touching a circle with an odd number, the circle glows scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot left start box!', type, otherNodeId); - if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('leaveStartBox', type === 'end'); + console.log('Robot intersects!', type, otherNodeId); + if (evenCircles.has(otherNodeId)) { + scene.setChallengeEventValue('touchedEvenCircle', true); + return; } - -}, 'startBox'); -`; + else { + switch (otherNodeId) { + case 'circle1': + circlesMap.set(otherNodeId, true); + scene.setChallengeEventValue('circle1Touched', true); + setNodeVisible(otherNodeId, true); + circles.delete('circle1'); + break; + case 'circle3': + if (circlesMap.get('circle1')) { + circlesMap.set(otherNodeId, true); + scene.setChallengeEventValue('circle3Touched', true); + setNodeVisible(otherNodeId, true); + circles.delete(otherNodeId); + break; + } + else { + scene.setChallengeEventValue('wrongOrder', true); + break; + } + case 'circle5': + if (circlesMap.get('circle3')) { + circlesMap.set(otherNodeId, true); + scene.setChallengeEventValue('circle5Touched', true); + setNodeVisible(otherNodeId, true); + circles.delete(otherNodeId); + break; + } + else { + scene.setChallengeEventValue('wrongOrder', true); + break; + } + case 'circle7': + if (circlesMap.get('circle5')) { + circlesMap.set(otherNodeId, true); + scene.setChallengeEventValue('circle7Touched', true); + setNodeVisible(otherNodeId, true); + circles.delete(otherNodeId); + break; + } + else { + scene.setChallengeEventValue('wrongOrder', true); + break; + } + case 'circle9': + if (circlesMap.get('circle7')) { + circlesMap.set(otherNodeId, true); + scene.setChallengeEventValue('circle9Touched', true); + setNodeVisible(otherNodeId, true); + circles.delete(otherNodeId); + break; + } + else { + scene.setChallengeEventValue('wrongOrder', true); + break; + } + case 'circle11': + if (circlesMap.get('circle9')) { + circlesMap.set(otherNodeId, true); + scene.setChallengeEventValue('circle11Touched', true); + setNodeVisible(otherNodeId, true); + circles.delete(otherNodeId); + break; + } + else { + scene.setChallengeEventValue('wrongOrder', true); + break; + } + default: + console.warn('Unknown circle: ', otherNodeId); + break; -const goingBackwards = ` -let degrees = []; -scene.addOnRenderListener(() => { - - const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); - const xAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.X, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.X)); - let angle = xAngle('robot'); - console.log(angle); - if(angle >= 179 && angle <= 180){ - degrees[0] = 0; - degrees[1] = 180; - - } - if(angle <= 1 && (degrees[1] == 180)&& ((scene.nodes['robot'].state.motors[0].pwm > scene.nodes['robot'].state.motors[3].pwm) || scene.nodes['robot'].state.motors[3].direction === 2)){ - scene.setChallengeEventValue('counterClockwise360', true); - degrees.pop(); - degrees.pop(); - } - else if (angle <=1 && (degrees[1] == 180) && (scene.nodes['robot'].state.motors[3].pwm > scene.nodes['robot'].state.motors[0].pwm) && scene.nodes['robot'].state.motors[3].direction != 2 ) - { - scene.setChallengeEventValue('clockwise360', true); - degrees.pop(); - degrees.pop(); + } } - console.log("0 PDM: " + scene.nodes['robot'].state.motors[0].pwm); - console.log("3 PDM: " + scene.nodes['robot'].state.motors[3].pwm); - console.log("0 direction: " + scene.nodes['robot'].state.motors[0].direction); - console.log("3 direction: " + scene.nodes['robot'].state.motors[3].direction); - console.log(degrees) ; -}); + +}, new Set([...circles, ...evenCircles])); `; export const JBC_5: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 5' }, + name: { [LocalizedString.EN_US]: "JBC 5" }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Dance Party', + [LocalizedString.EN_US]: "Junior Botball Challenge 5: Odd Numbers", }, scripts: { - goingBackwards: Script.ecmaScript('Going Backwards', goingBackwards), - leftStartBox: Script.ecmaScript('Robot Reentered Start', leftStartBox), + oddNumberIntersects: Script.ecmaScript("Odd Number Intersects", oddNumberIntersects), }, geometry: { ...baseScene.geometry, mainSurface_geom: { - type: 'box', + type: "box", size: { x: Distance.meters(3.54), y: Distance.centimeters(0.1), z: Distance.meters(3.54), }, }, - startBox_geom: { - type: 'box', - size: { - x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.centimeters(0), - }, + circle_geom: { + type: "cylinder", + height: Distance.centimeters(0.1), + radius: Distance.centimeters(3), }, + }, + nodes: { ...baseScene.nodes, mainSurface: { - type: 'object', - geometryId: 'mainSurface_geom', - name: { [LocalizedString.EN_US]: 'Mat Surface' }, + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, visible: false, origin: { position: { @@ -95,32 +154,240 @@ export const JBC_5: Scene = { }, }, material: { - type: 'basic', + type: "basic", color: { - type: 'color3', + type: "color3", color: Color.rgb(0, 0, 0), }, }, }, - startBox: { - type: 'object', - geometryId: 'startBox_geom', - name: { [LocalizedString.EN_US]: 'Start Box' }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.centimeters(0), - }, - }, - material: { - type: 'pbr', - emissive: { - type: 'color3', - color: Color.rgb(255, 255, 255), - }, - }, - }, + // circle1: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 1' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[0], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle2: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 2' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[1], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle3: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 3' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[2], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle4: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 4' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[3], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle5: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 5' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[4], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle6: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 6' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[5], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle7: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 7' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[6], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle8: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 8' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[7], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle9: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 9' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[8], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle10: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 10' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[9], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle11: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 11' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[10], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + // circle12: { + // type: 'object', + // geometryId: 'circle_geom', + // name: { [LocalizedString.EN_US]: 'Circle 12' }, + // visible: false, + // origin: { + // position: { + // ...canPositions[11], + // }, + // }, + // material: { + // type: 'pbr', + // emissive: { + // type: 'color3', + // color: Color.rgb(255, 255, 255), + // }, + // }, + // }, + circle1: createCircleNode(1, undefined, false, false), + circle2: createCircleNode(2, undefined, false, false), + circle3: createCircleNode(3, undefined, false, false), + circle4: createCircleNode(4, undefined, false, false), + circle5: createCircleNode(5, undefined, false, false), + circle6: createCircleNode(6, undefined, false, false), + circle7: createCircleNode(7, undefined, false, false), + circle8: createCircleNode(8, undefined, false, false), + circle9: createCircleNode(9, undefined, false, false), + circle10: createCircleNode(10, undefined, false, false), + circle11: createCircleNode(11, undefined, false, false), + circle12: createCircleNode(12, undefined, false, false), }, }; diff --git a/src/simulator/definitions/scenes/jbc4.ts b/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc4.ts rename to src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts diff --git a/src/simulator/definitions/scenes/jbc6.ts b/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc6.ts rename to src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts diff --git a/src/simulator/definitions/scenes/jbc7.ts b/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc7.ts rename to src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts diff --git a/src/simulator/definitions/scenes/jbc7b.ts b/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts similarity index 100% rename from src/simulator/definitions/scenes/jbc7b.ts rename to src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts diff --git a/src/simulator/definitions/scenes/jbcBase.ts b/src/simulator/definitions/scenes/jbcBase.ts index 457c7c03..90dd9a6c 100644 --- a/src/simulator/definitions/scenes/jbcBase.ts +++ b/src/simulator/definitions/scenes/jbcBase.ts @@ -3,6 +3,7 @@ import { Angle, Distance, Mass } from "../../../util"; import Node from "../../../state/State/Scene/Node"; import Camera from "../../../state/State/Scene/Camera"; import Scene from "../../../state/State/Scene"; +import { Color } from "../../../state/State/Scene/Color"; import AbstractRobot from '../../../programming/AbstractRobot'; import Author from '../../../db/Author'; @@ -100,18 +101,25 @@ export function createBaseSceneSurfaceA(): Scene { visible: true, physics: { type: 'box', - restitution: .3, - friction: 1, + restitution: 0.1, + friction: 10, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(192, 192, 192), + }, }, }, 'light0': { type: 'point-light', - intensity: 1, + intensity: 0.75, name: tr('Light'), startingOrigin: LIGHT_ORIGIN, origin: LIGHT_ORIGIN, visible: true - } + }, }, camera: Camera.arcRotate({ radius: Distance.meters(1), @@ -135,7 +143,7 @@ export function createBaseSceneSurfaceA(): Scene { } export function createBaseSceneSurfaceB(): Scene { - + return { name: tr('Base Scene - Surface B'), @@ -174,10 +182,17 @@ export function createBaseSceneSurfaceB(): Scene { restitution: 0.1, friction: 10, }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(192, 192, 192), + }, + }, }, 'light0': { type: 'point-light', - intensity: 10000, + intensity: 0.75, name: tr('Light'), startingOrigin: LIGHT_ORIGIN, origin: LIGHT_ORIGIN, @@ -230,10 +245,41 @@ export function createCanNode(canNumber: number, canPosition?: Vector3wUnits, ed }; } +/** + * Helper function to create a Node for a circle + * @param circleNumber The 1-index circle number + * @param circlePosition The position of the circle. If not provided, the position is determined using circleNumber + * @param editable Whether the circle is editable + * @param visible Whether the circle is visible + * @returns A circle Node that can be inserted into a Scene + */ +export function createCircleNode(circleNumber: number, circlePosition: Vector3wUnits, editable?: boolean, visible?: boolean): Node { + const position: Vector3wUnits = { + x: canPositions[circleNumber - 1].x, + y: Distance.centimeters(-6.9), + z: canPositions[circleNumber - 1].z + }; + + const origin: ReferenceFramewUnits = { + position: circlePosition ?? position, + orientation: RotationwUnits.eulerDegrees(0, 0, 0), + }; + + return { + type: 'from-jbc-template', + templateId: 'circle', + name: Dict.map(tr('Circle %s'), (str: string) => sprintf(str, circleNumber)), + startingOrigin: origin, + origin, + editable: editable ?? false, + visible: visible ?? false, + }; +} + /** * Positions of cans 1 - 12, based on the circles on JBC Surface A */ -const canPositions: Vector3wUnits[] = [ +export const canPositions: Vector3wUnits[] = [ { x: Distance.centimeters(22.7), // can 1 y: Distance.centimeters(0), diff --git a/src/state/State/Scene/Material.ts b/src/state/State/Scene/Material.ts index cfaf1dcb..9a259a9d 100644 --- a/src/state/State/Scene/Material.ts +++ b/src/state/State/Scene/Material.ts @@ -16,7 +16,7 @@ namespace Material { if (!prev && next) return Patch.outerChange(prev, next); if (prev && !next) return Patch.outerChange(prev, next); if (prev.color === next.color) return Patch.none(prev); - + return Patch.innerChange(prev, next, { type: Patch.none(prev.type), color: Patch.outerChange(prev.color, next.color) @@ -32,7 +32,7 @@ namespace Material { export namespace Texture { export const diff = (prev: Texture, next: Texture): Patch => { if (prev.uri === next.uri) return Patch.none(prev); - + return Patch.innerChange(prev, next, { type: Patch.none(prev.type), uri: Patch.outerChange(prev.uri, next.uri) @@ -66,7 +66,7 @@ namespace Material { if (prev && !next) return Patch.outerChange(prev, next); if (!deepNeq(prev.color, next.color)) return Patch.none(prev); - + return Patch.innerChange(prev, next, { type: Patch.none(prev.type), color: Patch.outerChange(prev.color, next.color) @@ -82,7 +82,7 @@ namespace Material { export namespace Texture { export const diff = (prev: Texture, next: Texture): Patch => { if (prev.uri === next.uri) return Patch.none(prev); - + return Patch.innerChange(prev, next, { type: Patch.none(prev.type), uri: Patch.outerChange(prev.uri, next.uri) @@ -119,7 +119,7 @@ namespace Material { export const diff = (prev: Pbr, next: Pbr): Patch => { if (!deepNeq(prev, next)) return Patch.none(prev); - + return Patch.innerChange(prev, next, { type: Patch.none(prev.type), albedo: Source3.diff(prev.albedo, next.albedo), @@ -141,7 +141,7 @@ namespace Material { export const diff = (prev: Basic, next: Basic): Patch => { if (!deepNeq(prev, next)) return Patch.none(prev); - + return Patch.innerChange(prev, next, { type: Patch.none(prev.type), color: Source3.diff(prev.color, next.color) @@ -152,7 +152,7 @@ namespace Material { export const diff = (prev: Material, next: Material): Patch => { if (!deepNeq(prev, next)) return Patch.none(prev); - + if (prev && !next) return Patch.outerChange(prev, next); if (!prev && next) return Patch.outerChange(prev, next); if (prev.type !== next.type) return Patch.outerChange(prev, next); diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index c29d814f..9404ea4f 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -12,33 +12,34 @@ import LocalizedString from '../../util/LocalizedString'; import db from '../../db'; import Selector from '../../db/Selector'; +import jbc0 from "../../simulator/definitions/challenges/jbc0"; import jbc1 from "../../simulator/definitions/challenges/jbc1"; import jbc2 from "../../simulator/definitions/challenges/jbc2"; -import jbc2b from "../../simulator/definitions/challenges/jbc2b"; -import jbc2c from "../../simulator/definitions/challenges/jbc2c"; -import jbc2d from "../../simulator/definitions/challenges/jbc2d"; -import jbc3 from "../../simulator/definitions/challenges/jbc3"; -import jbc4 from "../../simulator/definitions/challenges/jbc4"; -import jbc4b from "../../simulator/definitions/challenges/jbc4b"; +// import jbc2b from "../../simulator/definitions/challenges/archived/jbc2b-Ring-Around-the-Cans-Sr"; +// import jbc2c from "../../simulator/definitions/challenges/archived/jbc2c-Back-It-Up"; +// import jbc2d from "../../simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up"; +import jbc3 from "../../simulator/definitions/challenges/jbc3-Precision-Parking-New"; +import jbc4 from "../../simulator/definitions/challenges/jbc6-Figure-Eight-New"; +// import jbc4b from "../../simulator/definitions/challenges/archived/jbc4b-Barrel-Racing"; import jbc5 from "../../simulator/definitions/challenges/jbc5"; -import jbc6 from "../../simulator/definitions/challenges/jbc6"; -import jbc6c from "../../simulator/definitions/challenges/jbc6c"; -import jbc7 from "../../simulator/definitions/challenges/jbc7"; -import jbc7b from "../../simulator/definitions/challenges/jbc7b"; -import jbc8 from "../../simulator/definitions/challenges/jbc8"; -import jbc8b from "../../simulator/definitions/challenges/jbc8b"; -import jbc10 from "../../simulator/definitions/challenges/jbc10"; -import jbc10b from "../../simulator/definitions/challenges/jbc10b"; -import jbc12 from "../../simulator/definitions/challenges/jbc12"; -import jbc13 from "../../simulator/definitions/challenges/jbc13"; -import jbc15b from "../../simulator/definitions/challenges/jbc15b"; -import jbc17 from "../../simulator/definitions/challenges/jbc17"; -import jbc17b from "../../simulator/definitions/challenges/jbc17b"; -import jbc19 from "../../simulator/definitions/challenges/jbc19"; -import jbc20 from "../../simulator/definitions/challenges/jbc20"; -import jbc21 from "../../simulator/definitions/challenges/jbc21"; -import jbc22 from "../../simulator/definitions/challenges/jbc22"; -import test from '../../simulator/definitions/challenges/test'; +import jbc6 from "../../simulator/definitions/challenges/jbc7-Load-Em-Up-New"; +// import jbc6c from "../../simulator/definitions/challenges/archived/jbc6c-Empty-the-Garage"; +import jbc7 from "../../simulator/definitions/challenges/jbc8-Bulldozer-Mania-New"; +// import jbc7b from "../../simulator/definitions/challenges/archived/jbc7b-Cover-Your-Bases"; +import jbc8 from "../../simulator/definitions/challenges/jbc4-Serpentine-New"; +// import jbc8b from "../../simulator/definitions/challenges/archived/jbc8b-Serpentine-Jr"; +// import jbc10 from "../../simulator/definitions/challenges/archived/jbc10-Solo-Joust"; +// import jbc10b from "../../simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr"; +// import jbc12 from "../../simulator/definitions/challenges/archived/jbc12-Unload-Em"; +// import jbc13 from "../../simulator/definitions/challenges/archived/jbc13-Clean-the-Mat"; +// import jbc15b from "../../simulator/definitions/challenges/archived/jbc15b-Bump-Bump"; +import jbc17 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; +// import jbc17b from "../../simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2"; +import jbc19 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; +// import jbc20 from "../../simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans"; +// import jbc21 from "../../simulator/definitions/challenges/archived/jbc21-Foot-Tall"; +import jbc22 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; +// import test from '../../simulator/definitions/challenges/archived/test'; export namespace ChallengesAction { export interface LoadChallenge { @@ -143,13 +144,17 @@ export type ChallengesAction = ( ); const DEFAULT_CHALLENGES: Challenges = { - 'test': Async.loaded({ - value: test, - brief: ChallengeBrief.fromChallenge(test), - }), - 'jbc6c': Async.loaded({ - value: jbc6c, - brief: ChallengeBrief.fromChallenge(jbc6c), + // 'test': Async.loaded({ + // value: test, + // brief: ChallengeBrief.fromChallenge(test), + // }), + // 'jbc6c': Async.loaded({ + // value: jbc6c, + // brief: ChallengeBrief.fromChallenge(jbc6c), + // }), + 'jbc0': Async.loaded({ + value: jbc0, + brief: ChallengeBrief.fromChallenge(jbc0), }), 'jbc1': Async.loaded({ value: jbc1, @@ -159,33 +164,37 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc2, brief: ChallengeBrief.fromChallenge(jbc2), }), - 'jbc2b': Async.loaded({ - value: jbc2b, - brief: ChallengeBrief.fromChallenge(jbc2b), - }), - 'jbc2c': Async.loaded({ - value: jbc2c, - brief: ChallengeBrief.fromChallenge(jbc2c), - }), - 'jbc2d': Async.loaded({ - value: jbc2d, - brief: ChallengeBrief.fromChallenge(jbc2d), - }), + // 'jbc2b': Async.loaded({ + // value: jbc2b, + // brief: ChallengeBrief.fromChallenge(jbc2b), + // }), + // 'jbc2c': Async.loaded({ + // value: jbc2c, + // brief: ChallengeBrief.fromChallenge(jbc2c), + // }), + // 'jbc2d': Async.loaded({ + // value: jbc2d, + // brief: ChallengeBrief.fromChallenge(jbc2d), + // }), 'jbc3': Async.loaded({ value: jbc3, brief: ChallengeBrief.fromChallenge(jbc3), }), - 'jbc5': Async.loaded({ - value: jbc5, - brief: ChallengeBrief.fromChallenge(jbc5), - }), + // 'jbc5': Async.loaded({ + // value: jbc5, + // brief: ChallengeBrief.fromChallenge(jbc5), + // }), 'jbc4': Async.loaded({ value: jbc4, brief: ChallengeBrief.fromChallenge(jbc4), }), - 'jbc4b': Async.loaded({ - value: jbc4b, - brief: ChallengeBrief.fromChallenge(jbc4b), + // 'jbc4b': Async.loaded({ + // value: jbc4b, + // brief: ChallengeBrief.fromChallenge(jbc4b), + // }), + 'jbc5': Async.loaded({ + value: jbc5, + brief: ChallengeBrief.fromChallenge(jbc5), }), 'jbc6': Async.loaded({ value: jbc6, @@ -195,58 +204,58 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc7, brief: ChallengeBrief.fromChallenge(jbc7), }), - 'jbc7b': Async.loaded({ - value: jbc7b, - brief: ChallengeBrief.fromChallenge(jbc7b), - }), + // 'jbc7b': Async.loaded({ + // value: jbc7b, + // brief: ChallengeBrief.fromChallenge(jbc7b), + // }), 'jbc8': Async.loaded({ value: jbc8, brief: ChallengeBrief.fromChallenge(jbc8), }), - 'jbc8b': Async.loaded({ - value: jbc8b, - brief: ChallengeBrief.fromChallenge(jbc8b), - }), - 'jbc10': Async.loaded({ - value: jbc10, - brief: ChallengeBrief.fromChallenge(jbc10), - }), - 'jbc10b': Async.loaded({ - value: jbc10b, - brief: ChallengeBrief.fromChallenge(jbc10b), - }), - 'jbc12': Async.loaded({ - value: jbc12, - brief: ChallengeBrief.fromChallenge(jbc12), - }), - 'jbc13': Async.loaded({ - value: jbc13, - brief: ChallengeBrief.fromChallenge(jbc13), - }), - 'jbc15b': Async.loaded({ - value: jbc15b, - brief: ChallengeBrief.fromChallenge(jbc15b), - }), + // 'jbc8b': Async.loaded({ + // value: jbc8b, + // brief: ChallengeBrief.fromChallenge(jbc8b), + // }), + // 'jbc10': Async.loaded({ + // value: jbc10, + // brief: ChallengeBrief.fromChallenge(jbc10), + // }), + // 'jbc10b': Async.loaded({ + // value: jbc10b, + // brief: ChallengeBrief.fromChallenge(jbc10b), + // }), + // 'jbc12': Async.loaded({ + // value: jbc12, + // brief: ChallengeBrief.fromChallenge(jbc12), + // }), + // 'jbc13': Async.loaded({ + // value: jbc13, + // brief: ChallengeBrief.fromChallenge(jbc13), + // }), + // 'jbc15b': Async.loaded({ + // value: jbc15b, + // brief: ChallengeBrief.fromChallenge(jbc15b), + // }), 'jbc17': Async.loaded({ value: jbc17, brief: ChallengeBrief.fromChallenge(jbc17), }), - 'jbc17b': Async.loaded({ - value: jbc17b, - brief: ChallengeBrief.fromChallenge(jbc17b), - }), + // 'jbc17b': Async.loaded({ + // value: jbc17b, + // brief: ChallengeBrief.fromChallenge(jbc17b), + // }), 'jbc19': Async.loaded({ value: jbc19, brief: ChallengeBrief.fromChallenge(jbc19), }), - 'jbc20': Async.loaded({ - value: jbc20, - brief: ChallengeBrief.fromChallenge(jbc20), - }), - 'jbc21': Async.loaded({ - value: jbc21, - brief: ChallengeBrief.fromChallenge(jbc21), - }), + // 'jbc20': Async.loaded({ + // value: jbc20, + // brief: ChallengeBrief.fromChallenge(jbc20), + // }), + // 'jbc21': Async.loaded({ + // value: jbc21, + // brief: ChallengeBrief.fromChallenge(jbc21), + // }), 'jbc22': Async.loaded({ value: jbc22, brief: ChallengeBrief.fromChallenge(jbc22), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index ed55c785..32d572bb 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -161,7 +161,7 @@ export namespace ScenesAction { geometryId: string; geometry: Geometry; } - + export const setGeometry = construct('scenes/set-geometry'); export interface SetGeometryBatch { @@ -289,41 +289,42 @@ const DEFAULT_SCENES: Scenes = { moonSandbox: Async.loaded({ value: JBC_SCENES.Moon_Sandbox }), jbcSandboxA: Async.loaded({ value: JBC_SCENES.JBC_Sandbox_A }), jbcSandboxB: Async.loaded({ value: JBC_SCENES.JBC_Sandbox_B }), + jbc0: Async.loaded({ value: JBC_SCENES.JBC_0 }), jbc1: Async.loaded({ value: JBC_SCENES.JBC_1 }), jbc2: Async.loaded({ value: JBC_SCENES.JBC_2 }), - jbc2b: Async.loaded({ value: JBC_SCENES.JBC_2B }), - jbc2c: Async.loaded({ value: JBC_SCENES.JBC_2C }), - jbc2d: Async.loaded({ value: JBC_SCENES.JBC_2D }), + // jbc2b: Async.loaded({ value: JBC_SCENES.JBC_2B }), + // jbc2c: Async.loaded({ value: JBC_SCENES.JBC_2C }), + // jbc2d: Async.loaded({ value: JBC_SCENES.JBC_2D }), jbc3: Async.loaded({ value: JBC_SCENES.JBC_3 }), - jbc3b: Async.loaded({ value: JBC_SCENES.JBC_3B }), - jbc3c: Async.loaded({ value: JBC_SCENES.JBC_3C }), + // jbc3b: Async.loaded({ value: JBC_SCENES.JBC_3B }), + // jbc3c: Async.loaded({ value: JBC_SCENES.JBC_3C }), jbc4: Async.loaded({ value: JBC_SCENES.JBC_4 }), - jbc4b: Async.loaded({ value: JBC_SCENES.JBC_4B }), + // jbc4b: Async.loaded({ value: JBC_SCENES.JBC_4B }), jbc5: Async.loaded({ value: JBC_SCENES.JBC_5 }), - jbc5b: Async.loaded({ value: JBC_SCENES.JBC_5B }), - jbc5c: Async.loaded({ value: JBC_SCENES.JBC_5C }), + // jbc5b: Async.loaded({ value: JBC_SCENES.JBC_5B }), + // jbc5c: Async.loaded({ value: JBC_SCENES.JBC_5C }), jbc6: Async.loaded({ value: JBC_SCENES.JBC_6 }), - jbc6b: Async.loaded({ value: JBC_SCENES.JBC_6B }), - jbc6c: Async.loaded({ value: JBC_SCENES.JBC_6C }), + // jbc6b: Async.loaded({ value: JBC_SCENES.JBC_6B }), + // jbc6c: Async.loaded({ value: JBC_SCENES.JBC_6C }), jbc7: Async.loaded({ value: JBC_SCENES.JBC_7 }), - jbc7b: Async.loaded({ value: JBC_SCENES.JBC_7B }), + // jbc7b: Async.loaded({ value: JBC_SCENES.JBC_7B }), jbc8: Async.loaded({ value: JBC_SCENES.JBC_8 }), - jbc8b: Async.loaded({ value: JBC_SCENES.JBC_8B }), + // jbc8b: Async.loaded({ value: JBC_SCENES.JBC_8B }), jbc9: Async.loaded({ value: JBC_SCENES.JBC_9 }), - jbc9b: Async.loaded({ value: JBC_SCENES.JBC_9B }), - jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), - jbc10b: Async.loaded({ value: JBC_SCENES.JBC_10B }), - jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), - jbc13: Async.loaded({ value: JBC_SCENES.JBC_13 }), - jbc15b: Async.loaded({ value: JBC_SCENES.JBC_15B }), + // jbc9b: Async.loaded({ value: JBC_SCENES.JBC_9B }), + // jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), + // jbc10b: Async.loaded({ value: JBC_SCENES.JBC_10B }), + // jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), + // jbc13: Async.loaded({ value: JBC_SCENES.JBC_13 }), + // jbc15b: Async.loaded({ value: JBC_SCENES.JBC_15B }), jbc17: Async.loaded({ value: JBC_SCENES.JBC_17 }), - jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), + // jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), - jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), - jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), + // jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), + // jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), - scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }), - lightSensorTest: Async.loaded({ value: JBC_SCENES.lightSensorTest }), + // scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }), + // lightSensorTest: Async.loaded({ value: JBC_SCENES.lightSensorTest }), }; const create = async (sceneId: string, next: Async.Creating) => { @@ -450,7 +451,7 @@ export const reduceScenes = (state: Scenes = DEFAULT_SCENES, action: ScenesActio }) }; } - + return state; } case 'scenes/set-scene-partial': { @@ -541,16 +542,16 @@ export const reduceScenes = (state: Scenes = DEFAULT_SCENES, action: ScenesActio if (!scene) return state; - + if (scene.type === Async.Type.Loaded || scene.type === Async.Type.Saveable) { return { ...state, [action.sceneId]: Async.mutate(scene, draft => { for (const nodeId in draft.nodes) { const { origin, startingOrigin } = draft.nodes[nodeId]; - + if (!startingOrigin) continue; - + draft.nodes[nodeId].origin = { position: startingOrigin.position ? startingOrigin.position : undefined, orientation: startingOrigin.orientation ? startingOrigin.orientation : undefined, @@ -560,7 +561,7 @@ export const reduceScenes = (state: Scenes = DEFAULT_SCENES, action: ScenesActio }), }; } - + return state; } case 'scenes/reset-scene': return { From d032840763fb396f85dcdf112da98a8238a58716 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Thu, 17 Oct 2024 23:32:40 -0600 Subject: [PATCH 02/22] Update exports and add JBC 10 and 11 with a couple bugs --- src/simulator/ScriptManager.ts | 27 +-- src/simulator/babylonBindings/RobotBinding.ts | 53 +++--- .../challenges/jbc10-Chopped-New.ts | 79 +++++++++ .../challenges/jbc11-Making-Waves-New.ts | 147 +++++++++++++++++ .../challenges/jbc12-Add-It-Up-New.ts | 10 +- .../challenges/jbc14-Dance-Party.ts | 6 +- .../challenges/jbc17-Mountain-Rescue-New.ts | 14 +- .../challenges/jbc18-Stackerz-New.ts | 12 +- .../challenges/jbc24-Walk-the-Line-New.ts | 8 +- .../challenges/jbc4-Serpentine-New.ts | 10 +- .../challenges/jbc6-Figure-Eight-New.ts | 8 +- .../challenges/jbc7-Load-Em-Up-New.ts | 6 +- .../challenges/jbc8-Bulldozer-Mania-New.ts | 6 +- .../challenges/jbc9-Cover-Your-Bases-New.ts | 6 +- src/simulator/definitions/scenes/index.ts | 28 ++-- src/simulator/definitions/scenes/jbc0.ts | 6 + .../definitions/scenes/jbc10-Chopped-New.ts | 133 +++++++++++++++ .../scenes/jbc11-Making-Waves-New.ts | 156 ++++++++++++++++++ .../definitions/scenes/jbc12-Add-It-Up-New.ts | 108 +++++++++++- .../definitions/scenes/jbc14-Dance-Party.ts | 18 +- .../scenes/jbc17-Mountain-Rescue-New.ts | 6 +- .../definitions/scenes/jbc18-Stackerz-New.ts | 6 +- .../scenes/jbc24-Walk-the-Line-New.ts | 6 +- .../definitions/scenes/jbc4-Serpentine-New.ts | 10 +- .../scenes/jbc6-Figure-Eight-New.ts | 10 +- .../definitions/scenes/jbc7-Load-Em-Up-New.ts | 6 +- .../scenes/jbc8-Bulldozer-Mania-New.ts | 6 +- .../scenes/jbc9-Cover-Your-Bases-New.ts | 6 +- src/state/reducer/challenges.ts | 63 +++++-- src/state/reducer/scenes.ts | 11 +- 30 files changed, 813 insertions(+), 158 deletions(-) create mode 100644 src/simulator/definitions/challenges/jbc10-Chopped-New.ts create mode 100644 src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts create mode 100644 src/simulator/definitions/scenes/jbc10-Chopped-New.ts create mode 100644 src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts diff --git a/src/simulator/ScriptManager.ts b/src/simulator/ScriptManager.ts index 95ec08f5..d01496e1 100644 --- a/src/simulator/ScriptManager.ts +++ b/src/simulator/ScriptManager.ts @@ -32,7 +32,7 @@ export interface ScriptSceneBinding { readonly geometry: Dict; addGeometry(geometry: Geometry, id?: string): string; removeGeometry(id: string): void; - + gravity: Vector3wUnits; camera: Camera; @@ -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())); }; @@ -209,7 +209,7 @@ namespace ScriptManager { } export const collision = construct(Type.Collision); - + export interface IntersectionStart { type: Type.IntersectionStart; nodeId: string; @@ -256,7 +256,7 @@ namespace ScriptManager { } export const render = construct(Type.Render); - + export interface Collision { type: Type.Collision; nodeId: string; @@ -265,7 +265,7 @@ namespace ScriptManager { } export const collision = construct(Type.Collision); - + export interface Intersection { type: Type.Intersection; nodeId: string; @@ -330,7 +330,7 @@ namespace ScriptManager { constructor(script: Script, manager: ScriptManager) { this.script_ = script; this.manager_ = manager; - + this.spawnFunc_({ scene: this, RotationwUnits, @@ -342,6 +342,7 @@ namespace ScriptManager { Distance, Mass, Angle, + Date, }, this.script_.code); } @@ -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. @@ -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; @@ -455,7 +456,7 @@ namespace ScriptManager { onNodeRemove(id); } - + setNode(id: string, node: Node): void { const { onNodeChange } = this.manager_; if (!onNodeChange) return; @@ -496,7 +497,7 @@ namespace ScriptManager { onGeometryRemove(id); } - + get gravity(): Vector3wUnits { return this.manager_.scene.gravity; } @@ -568,7 +569,7 @@ namespace ScriptManager { this.manager_.removeIntersectionRefCounts_(listener); break; } - + delete this.listeners_[handle]; } @@ -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); } } diff --git a/src/simulator/babylonBindings/RobotBinding.ts b/src/simulator/babylonBindings/RobotBinding.ts index fbdc365a..4e279731 100644 --- a/src/simulator/babylonBindings/RobotBinding.ts +++ b/src/simulator/babylonBindings/RobotBinding.ts @@ -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'; @@ -101,7 +102,7 @@ class RobotBinding { private createSensor_ = >(s: { new(parameters: SensorParameters): S }) => (id: string, definition: T): S => { const parent = this.links_[definition.parentId]; - + return new s({ id, definition, @@ -138,7 +139,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`); @@ -184,7 +185,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); @@ -227,7 +228,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; @@ -286,9 +287,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; } @@ -319,11 +320,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]; @@ -353,7 +354,7 @@ 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); @@ -400,7 +401,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; @@ -413,7 +414,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) { @@ -559,10 +560,10 @@ 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.rotationQuaternion = RawQuaternion.toBabylon(RawEuler.toQuaternion(UpdatedEulerOrigin)); for (const link of Object.values(this.links_)) { @@ -618,7 +619,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; @@ -628,7 +629,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_); @@ -639,7 +640,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); @@ -657,10 +658,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; @@ -715,9 +716,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_ ); } diff --git a/src/simulator/definitions/challenges/jbc10-Chopped-New.ts b/src/simulator/definitions/challenges/jbc10-Chopped-New.ts new file mode 100644 index 00000000..f55c9163 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc10-Chopped-New.ts @@ -0,0 +1,79 @@ +import Author from "../../../db/Author"; +import Challenge from "../../../state/State/Challenge"; +import Expr from "../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: "JBC Challenge 10" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 10: Chopped`, + }, + author: { + type: Author.Type.Organization, + id: "kipr", + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: "c", + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + waitedToChop: { + name: { [LocalizedString.EN_US]: "Waited to Chop" }, + description: { [LocalizedString.EN_US]: "Robot waited to chop" }, + }, + can7Upright: { + name: { [LocalizedString.EN_US]: "Can 7 Upright" }, + description: { [LocalizedString.EN_US]: "Can 7 upright" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + //Chop Events + waitedToChop: { + type: Expr.Type.Event, + eventId: "waitedToChop", + }, + can7Upright: { + type: Expr.Type.Event, + eventId: "can7Upright", + }, + can7NotUpright: { + type: Expr.Type.Not, + argId: "can7Upright", + }, + + // Success Logic = Can 7 not upright, waited to chop, and began in start box + completion: { + type: Expr.Type.And, + argIds: [ + "inStartBoxOnce", + "waitedToChop", + "can7NotUpright", + ], + }, + }, + rootId: "completion", + }, + sceneId: "jbc10", +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts b/src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts new file mode 100644 index 00000000..db6c2b32 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts @@ -0,0 +1,147 @@ +import Author from "../../../db/Author"; +import Challenge from "../../../state/State/Challenge"; +import Expr from "../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: "JBC Challenge 11" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 11: Making Waves`, + }, + author: { + type: Author.Type.Organization, + id: "kipr", + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: "c", + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + wave: { + name: { [LocalizedString.EN_US]: "Robot Waved" }, + description: { [LocalizedString.EN_US]: "Robot waved" }, + }, + circle3Touched: { + name: { [LocalizedString.EN_US]: "Circle 3 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 3 touched" }, + }, + circle6Touched: { + name: { [LocalizedString.EN_US]: "Circle 6 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 6 touched" }, + }, + circle9Touched: { + name: { [LocalizedString.EN_US]: "Circle 9 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 9 touched" }, + }, + circle12Touched: { + name: { [LocalizedString.EN_US]: "Circle 12 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 12 touched" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + //Wave Events + wave: { + type: Expr.Type.Event, + eventId: "wave", + }, + + //Circle Events + circle3Touched: { + type: Expr.Type.Event, + eventId: "circle3Touched", + }, + circle3Waved: { + type: Expr.Type.And, + argIds: [ + "circle3Touched", + "wave", + ], + }, + circle3WavedOnce: { + type: Expr.Type.Once, + argId: "circle3Waved", + }, + circle6Touched: { + type: Expr.Type.Event, + eventId: "circle6Touched", + }, + circle6Waved: { + type: Expr.Type.And, + argIds: [ + "circle6Touched", + "wave", + ], + }, + circle6WavedOnce: { + type: Expr.Type.Once, + argId: "circle6Waved", + }, + circle9Touched: { + type: Expr.Type.Event, + eventId: "circle9Touched", + }, + circle9Waved: { + type: Expr.Type.And, + argIds: [ + "circle9Touched", + "wave", + ], + }, + circle9WavedOnce: { + type: Expr.Type.Once, + argId: "circle9Waved", + }, + circle12Touched: { + type: Expr.Type.Event, + eventId: "circle12Touched", + }, + circle12Waved: { + type: Expr.Type.And, + argIds: [ + "circle12Touched", + "wave", + ], + }, + circle12WavedOnce: { + type: Expr.Type.Once, + argId: "circle12Waved", + }, + + // Success Logic = All circles waved at least once and began in start box + completion: { + type: Expr.Type.And, + argIds: [ + "inStartBoxOnce", + "circle3WavedOnce", + "circle6WavedOnce", + "circle9WavedOnce", + "circle12WavedOnce", + ], + }, + }, + rootId: "completion", + }, + sceneId: "jbc11", +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts b/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts index 728a4c7a..5f3d25fc 100644 --- a/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts +++ b/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 12' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Add It Up', + [LocalizedString.EN_US]: 'Junior Botball Challenge 12: Add It Up', }, author: { type: Author.Type.Organization, @@ -135,11 +135,11 @@ export default { type: Expr.Type.Once, argId: 'passed8', }, - + passedSerpentine: { type: Expr.Type.And, - argIds: ["passed1Once", "passed2Once","passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], + argIds: ["passed1Once", "passed2Once", "passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], }, // Success logic @@ -150,5 +150,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc8', + sceneId: 'jbc12', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc14-Dance-Party.ts b/src/simulator/definitions/challenges/jbc14-Dance-Party.ts index 4e2a1123..ec611dd4 100644 --- a/src/simulator/definitions/challenges/jbc14-Dance-Party.ts +++ b/src/simulator/definitions/challenges/jbc14-Dance-Party.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 14' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 5: Dance Party`, + [LocalizedString.EN_US]: `Junior Botball Challenge 14: Dance Party`, }, author: { type: Author.Type.Organization, @@ -129,5 +129,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc5', + sceneId: 'jbc14', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts b/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts index 5f203b61..16efbef9 100644 --- a/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts +++ b/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 19' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 17' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 19: Mountain Rescue`, + [LocalizedString.EN_US]: `Junior Botball Challenge 17: Mountain Rescue`, }, author: { type: Author.Type.Organization, @@ -114,24 +114,24 @@ export default { // Intersecting and Upright IntersectingUpright1: { type: Expr.Type.And, - argIds: ['can1UprightOnce','can1IntersectsOnce'], + argIds: ['can1UprightOnce', 'can1IntersectsOnce'], }, IntersectingUpright2: { type: Expr.Type.And, - argIds: ['can2UprightOnce','can2IntersectsOnce'], + argIds: ['can2UprightOnce', 'can2IntersectsOnce'], }, IntersectingUpright3: { type: Expr.Type.And, - argIds: ['can3UprightOnce','can3IntersectsOnce'], + argIds: ['can3UprightOnce', 'can3IntersectsOnce'], }, completion: { type: Expr.Type.And, - argIds: ['IntersectingUpright1','IntersectingUpright2','IntersectingUpright3'], + argIds: ['IntersectingUpright1', 'IntersectingUpright2', 'IntersectingUpright3'], }, }, rootId: 'completion', }, - sceneId: 'jbc19', + sceneId: 'jbc17', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts b/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts index 09230b55..c6e4dfe0 100644 --- a/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts +++ b/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 22' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 18' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 22: Stackerz`, + [LocalizedString.EN_US]: `Junior Botball Challenge 18: Stackerz`, }, author: { type: Author.Type.Organization, @@ -21,7 +21,7 @@ export default { defaultLanguage: 'c', events: { - + leaveStartBox: { name: { [LocalizedString.EN_US]: 'Robot Left Start' }, description: { [LocalizedString.EN_US]: 'Robot left starting box' }, @@ -31,7 +31,7 @@ export default { name: { [LocalizedString.EN_US]: 'One Can Stacked' }, description: { [LocalizedString.EN_US]: 'One can is stacked on another' }, }, - + robotTouchCan: { name: { [LocalizedString.EN_US]: 'Robot Touching Can' }, description: { [LocalizedString.EN_US]: 'Robot is touching a can' }, @@ -66,7 +66,7 @@ export default { argId: 'robotTouchCan', }, - + completion: { type: Expr.Type.And, argIds: ['leaveStartBoxOnce', 'canStacked', 'robotTouchCanNot'], @@ -74,5 +74,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc22', + sceneId: 'jbc18', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts b/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts index 648c2220..85f7e80a 100644 --- a/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts +++ b/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 17' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 24' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 17: Walk the Line`, + [LocalizedString.EN_US]: `Junior Botball Challenge 24: Walk the Line`, }, author: { type: Author.Type.Organization, @@ -35,7 +35,7 @@ export default { type: Expr.Type.Event, eventId: 'lineFollow', }, - + completion: { type: Expr.Type.And, @@ -46,5 +46,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc17', + sceneId: 'jbc24', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts b/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts index 27346a77..fc187aec 100644 --- a/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts +++ b/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 8' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 4' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 8: Serpentine', + [LocalizedString.EN_US]: 'Junior Botball Challenge 4: Serpentine', }, author: { type: Author.Type.Organization, @@ -135,11 +135,11 @@ export default { type: Expr.Type.Once, argId: 'passed8', }, - + passedSerpentine: { type: Expr.Type.And, - argIds: ["passed1Once", "passed2Once","passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], + argIds: ["passed1Once", "passed2Once", "passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], }, // Success logic @@ -150,5 +150,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc8', + sceneId: 'jbc4', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts b/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts index b39ec0ad..e4dcaa56 100644 --- a/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts +++ b/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts @@ -5,9 +5,9 @@ import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: "JBC Challenge 4" }, + name: { [LocalizedString.EN_US]: "JBC Challenge 6" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 4: Figure Eight`, + [LocalizedString.EN_US]: `Junior Botball Challenge 6: Figure Eight`, }, author: { type: Author.Type.Organization, @@ -122,10 +122,10 @@ export default { // Success Logic = Can A upright, intersects and touched completion: { type: Expr.Type.And, - argIds: ["IntersectsUpright4", "IntersectsUpright9", "startingBox","figureEightOnce"], + argIds: ["IntersectsUpright4", "IntersectsUpright9", "startingBox", "figureEightOnce"], }, }, rootId: "completion", }, - sceneId: "jbc4", + sceneId: "jbc6", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts b/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts index 935907aa..94d0a953 100644 --- a/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts +++ b/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts @@ -5,9 +5,9 @@ import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: "JBC Challenge 6" }, + name: { [LocalizedString.EN_US]: "JBC Challenge 7" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 6: Load 'Em Up`, + [LocalizedString.EN_US]: `Junior Botball Challenge 7: Load 'Em Up`, }, author: { type: Author.Type.Organization, @@ -94,5 +94,5 @@ export default { }, rootId: "completion", }, - sceneId: "jbc6", + sceneId: "jbc7", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts b/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts index cf79b231..3bcf1d61 100644 --- a/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts +++ b/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts @@ -5,9 +5,9 @@ import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: "JBC Challenge 7" }, + name: { [LocalizedString.EN_US]: "JBC Challenge 8" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7: Bulldozer Mania`, + [LocalizedString.EN_US]: `Junior Botball Challenge 8: Bulldozer Mania`, }, author: { type: Author.Type.Organization, @@ -143,5 +143,5 @@ export default { }, rootId: "completion", }, - sceneId: "jbc7", + sceneId: "jbc8", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts b/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts index ee145b12..891c61cb 100644 --- a/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts +++ b/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 7B' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 9' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7B: Cover Your Bases`, + [LocalizedString.EN_US]: `Junior Botball Challenge 9: Cover Your Bases`, }, author: { type: Author.Type.Organization, @@ -198,5 +198,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc7b', + sceneId: 'jbc9', } as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 62295fa6..6c3af999 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -3,38 +3,42 @@ export * from './jbcSandboxB'; export * from './jbc0'; export * from './jbc1'; export * from './jbc2'; +export * from './jbc3-Precision-Parking-New'; +export * from './jbc4-Serpentine-New'; +export * from './jbc5'; +export * from './jbc6-Figure-Eight-New'; +export * from './jbc7-Load-Em-Up-New'; +export * from './jbc8-Bulldozer-Mania-New'; +export * from './jbc9-Cover-Your-Bases-New'; +export * from './jbc10-Chopped-New'; +export * from './jbc11-Making-Waves-New'; +export * from './jbc12-Add-It-Up-New'; +export * from './jbc14-Dance-Party'; +export * from './jbc17-Mountain-Rescue-New'; +export * from './jbc18-Stackerz-New'; +export * from './jbc24-Walk-the-Line-New'; +export * from './moonSandbox'; // export * from './jbc2b-Ring-Around-the-Cans-Sr'; // export * from './jbc2c-Back-It-Up'; // export * from './jbc2d-Ring-Around-the-Can-and-Back-It-Up'; -export * from './jbc3-Precision-Parking-New'; // export * from './jbc3b-Parallel-Parking'; // export * from './jbc3c-Quick-Get-Away'; -export * from './jbc5'; -export * from './jbc6-Figure-Eight-New'; // export * from './jbc4b-Barrel-Racing'; // export * from './jbc14-Dance-Party'; // export * from './jbc5b-Line-Dance'; // export * from './jbc5c-Synchronized-Dancing'; -export * from './jbc7-Load-Em-Up-New'; // export * from './jbc6b-Pick-Em-Up'; // export * from './jbc6c-Empty-the-Garage'; -export * from './jbc8-Bulldozer-Mania-New'; // export * from './jbc7b-Cover-Your-Bases'; -export * from './jbc4-Serpentine-New'; // export * from './jbc8b-Serpentine-Jr'; -export * from './jbc12-Add-It-Up-New'; // export * from './jbc9b-Balancing-Act'; // export * from './jbc10-Solo-Joust'; // export * from './jbc10b-Solo-Joust-Jr'; // export * from './jbc12-Unload-Em'; // export * from './jbc13-Clean-the-Mat'; // export * from './jbc15b-Bump-Bump'; -export * from './jbc24-Walk-the-Line-New'; // export * from './jbc17b-Walk-the-Line-2'; -export * from './jbc17-Mountain-Rescue-New'; // export * from './jbc20-Rescue-the-Cans'; // export * from './jbc21-Foot-Tall'; -export * from './jbc18-Stackerz-New'; // export * from './scriptPlayground'; -// export * from './lightSensorTest'; -export * from './moonSandbox'; \ No newline at end of file +// export * from './lightSensorTest'; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0.ts index 5e56246f..31ebeda3 100644 --- a/src/simulator/definitions/scenes/jbc0.ts +++ b/src/simulator/definitions/scenes/jbc0.ts @@ -5,6 +5,8 @@ import LocalizedString from '../../../util/LocalizedString'; import Script from '../../../state/State/Scene/Script'; import { createBaseSceneSurfaceB, createCanNode } from './jbcBase'; import { Color } from '../../../state/State/Scene/Color'; +import Robot from 'state/State/Robot'; +import Node from 'state/State/Scene/Node'; const baseScene = createBaseSceneSurfaceB(); @@ -96,6 +98,10 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { }, }; +const robotNode: Node.Robot = baseScene.nodes['robot'] as Node.Robot; + + + export const JBC_0: Scene = { ...baseScene, name: { [LocalizedString.EN_US]: 'JBC 0' }, diff --git a/src/simulator/definitions/scenes/jbc10-Chopped-New.ts b/src/simulator/definitions/scenes/jbc10-Chopped-New.ts new file mode 100644 index 00000000..0f12f285 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc10-Chopped-New.ts @@ -0,0 +1,133 @@ +import Scene from "../../../state/State/Scene"; +import LocalizedString from "../../../util/LocalizedString"; +import { createBaseSceneSurfaceA, createCanNode } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; +import Script from "../../../state/State/Scene/Script"; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const waitToChop = ` +// Need to wait 5 seconds before the can can be chopped +let currentDate; +let stopTime = 0; +scene.addOnRenderListener(() => { + const robotNode = scene.nodes['robot']; + if (robotNode.state.getMotor(0).speedGoal <= 15 && robotNode.state.getMotor(3).speedGoal <= 15) { + if (stopTime == 0) { + currentDate = new Date(); + stopTime = currentDate.getTime(); + console.log('Waiting at ', stopTime); + } + else { + currentDate = new Date(); + if (currentDate.getTime() - stopTime > 5000) { + scene.setChallengeEventValue('waitedToChop', true); + console.log("Waited 5 seconds"); + } + } + } + else { + stopTime = 0; + } +}); +`; + +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)); + + +scene.addOnRenderListener(() => { + const upright7 = yAngle('can7') > 5; + scene.setChallengeEventValue('can7Upright', upright7); +}); +`; + +export const JBC_10: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: "JBC 10" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 10: Chopped`, + }, + scripts: { + inStartBox: Script.ecmaScript("In Start Box", notInStartBox), + waitToChop: Script.ecmaScript("Wait to Chop", waitToChop), + uprightCan: Script.ecmaScript("Upright Can", uprightCan), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + can7: createCanNode(7), + }, +}; + diff --git a/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts b/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts new file mode 100644 index 00000000..0620806a --- /dev/null +++ b/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts @@ -0,0 +1,156 @@ +import Scene from "../../../state/State/Scene"; +import LocalizedString from "../../../util/LocalizedString"; +import { createBaseSceneSurfaceA, createCanNode, createCircleNode } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; +import Script from "../../../state/State/Scene/Script"; +import Node from "state/State/Scene/Node"; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const wave = ` + // Check if robot waves + let waveStart = -1; + let waveMax = 0; + + scene.addOnRenderListener(() => { + const robotNode = scene.nodes['robot']; + + if (scene.programStatus === 'running') { + if (robotNode.state.getMotor(0).speedGoal == 0 && robotNode.state.getMotor(3).speedGoal == 0) { + console.log('Robot stopped, motors at: ', robotNode.state.getMotor(0).speedGoal, ' ', robotNode.state.getMotor(3).speedGoal); + if (waveStart == -1) { + waveStart = robotNode.state.getServo(0).position; + console.log('Wave start at ', waveStart); + } + else { + console.log('Wave diff at ', Math.abs(robotNode.state.getServo(0).position - waveStart)); + if (Math.abs(robotNode.state.getServo(0).position - waveStart) >= waveMax) { + waveMax = Math.abs(robotNode.state.getServo(0).position - waveStart); + console.log('Wave max at ', waveMax, 'Wave start at ', waveStart); + } + else { + if (waveMax != 0) { + scene.setChallengeEventValue('wave', true); + console.log('Robot waved!'); + } + } + } + } + else { + console.log('Robot moving, motors at: ', robotNode.state.getMotor(0).pwm, ' ', robotNode.state.getMotor(3).pwm); + waveStart =-1; + waveMax = 0; + scene.setChallengeEventValue('wave', false); + } + } + else { + waveStart =-1; + waveMax = 0; + } + }); +`; + +const circleIntersects = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + +let circles = new Set(['circle3', 'circle6', 'circle9', 'circle12']); + +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot intersects!', type, otherNodeId); + scene.setChallengeEventValue(otherNodeId + 'Touched', true); + setNodeVisible(otherNodeId, true); +}, ...circles); +`; + +export const JBC_11: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: "JBC 11" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 11: Making Waves`, + }, + scripts: { + inStartBox: Script.ecmaScript("In Start Box", notInStartBox), + waitToChop: Script.ecmaScript("Wave", wave), + circleIntersects: Script.ecmaScript("Circle Intersects", circleIntersects), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + circle3: createCircleNode(3, undefined, false, false), + circle6: createCircleNode(6, undefined, false, false), + circle9: createCircleNode(9, undefined, false, false), + circle12: createCircleNode(12, undefined, false, false), + }, +}; + diff --git a/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts b/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts index de5b748d..daf116f3 100644 --- a/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts +++ b/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts @@ -1,14 +1,110 @@ import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; - -import { createBaseSceneSurfaceA } from './jbcBase'; +import LocalizedString from "../../../util/LocalizedString"; +import { createBaseSceneSurfaceA, createCanNode, createCircleNode } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; +import Script from "../../../state/State/Scene/Script"; +import Node from "state/State/Scene/Node"; import tr from '@i18n'; const baseScene = createBaseSceneSurfaceA(); -export const JBC_9: Scene = { +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +// const addItUp = { +// scene.addOnIntersectionListener('robot', (type, otherNodeId) => { +// } + + + + +export const JBC_12: Scene = { ...baseScene, - name: tr('JBC 9'), - description: tr('Junior Botball Challenge 9: Add It Up'), + name: tr('JBC 12'), + description: tr('Junior Botball Challenge 12: Add It Up'), + scripts: { + inStartBox: Script.ecmaScript("In Start Box", notInStartBox), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + circle1: createCircleNode(1, undefined, false, false), + circle2: createCircleNode(2, undefined, false, false), + circle3: createCircleNode(3, undefined, false, false), + circle4: createCircleNode(4, undefined, false, false), + circle5: createCircleNode(5, undefined, false, false), + circle6: createCircleNode(6, undefined, false, false), + circle7: createCircleNode(7, undefined, false, false), + circle8: createCircleNode(8, undefined, false, false), + circle9: createCircleNode(9, undefined, false, false), + circle10: createCircleNode(10, undefined, false, false), + circle11: createCircleNode(11, undefined, false, false), + circle12: createCircleNode(12, undefined, false, false), + }, }; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbc14-Dance-Party.ts b/src/simulator/definitions/scenes/jbc14-Dance-Party.ts index 7126dbe9..b6461e3b 100644 --- a/src/simulator/definitions/scenes/jbc14-Dance-Party.ts +++ b/src/simulator/definitions/scenes/jbc14-Dance-Party.ts @@ -1,9 +1,9 @@ -import Scene from '../../../../state/State/Scene'; -import LocalizedString from '../../../../util/LocalizedString'; -import Script from '../../../../state/State/Scene/Script'; -import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; -import { Color } from '../../../../state/State/Scene/Color'; -import { Distance } from '../../../../util'; +import Scene from '../../../state/State/Scene'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; +import { Distance } from '../../../util'; const baseScene = createBaseSceneSurfaceA(); @@ -51,11 +51,11 @@ scene.addOnRenderListener(() => { `; -export const JBC_5: Scene = { +export const JBC_14: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 5' }, + name: { [LocalizedString.EN_US]: 'JBC 14' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Dance Party', + [LocalizedString.EN_US]: 'Junior Botball Challenge 14: Dance Party', }, scripts: { goingBackwards: Script.ecmaScript('Going Backwards', goingBackwards), diff --git a/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts b/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts index b91a078a..b3a1f0df 100644 --- a/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts +++ b/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts @@ -54,11 +54,11 @@ const REAM_ORIGIN: ReferenceFramewUnits = { }), }; -export const JBC_19: Scene = { +export const JBC_17: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 19' }, + name: { [LocalizedString.EN_US]: 'JBC 17' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 19: Mountain Rescue`, + [LocalizedString.EN_US]: `Junior Botball Challenge 17: Mountain Rescue`, }, scripts: { uprightCans: Script.ecmaScript('Upright Cans', uprightCans), diff --git a/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts b/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts index 4fc5252a..18c316f7 100644 --- a/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts +++ b/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts @@ -63,11 +63,11 @@ scene.onBind = nodeId => { }; `; -export const JBC_22: Scene = { +export const JBC_18: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 22' }, + name: { [LocalizedString.EN_US]: 'JBC 18' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 22: Stackerz`, + [LocalizedString.EN_US]: `Junior Botball Challenge 18: Stackerz`, }, scripts: { leftStartBox: Script.ecmaScript('Robot Left Start', leftStartBox), diff --git a/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts b/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts index f2794375..22b15f0c 100644 --- a/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts +++ b/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts @@ -52,11 +52,11 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { x: Distance.centimeters(-15), }, }; -export const JBC_17: Scene = { +export const JBC_24: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 17' }, + name: { [LocalizedString.EN_US]: 'JBC 24' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 17: Walk the Line', + [LocalizedString.EN_US]: 'Junior Botball Challenge 24: Walk the Line', }, scripts: { lineFollow: Script.ecmaScript('Line Follow', lineFollow), diff --git a/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts b/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts index 08db3a07..f41a8e26 100644 --- a/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts +++ b/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts @@ -109,12 +109,12 @@ scene.onBind = nodeId => { }; `; -// 'n2','n3','n4','n5','n6','n7','n8' -export const JBC_8: Scene = { + +export const JBC_4: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 8' }, + name: { [LocalizedString.EN_US]: 'JBC 4' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 8: Serpentine', + [LocalizedString.EN_US]: 'Junior Botball Challenge 4: Serpentine', }, scripts: { passedSide: Script.ecmaScript('Passed Side', passedSide), @@ -516,7 +516,7 @@ export const JBC_8: Scene = { x: Distance.centimeters(-26), // can 8 y: Distance.centimeters(-6.9), z: Distance.centimeters(65.5), - },false,false), + }, false, false), scriptIds: ['passedSide'], }, }, diff --git a/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts b/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts index 766ad535..8a63e20f 100644 --- a/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts +++ b/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts @@ -117,11 +117,11 @@ scene.addOnRenderListener(() => { }); `; -export const JBC_4: Scene = { +export const JBC_6: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: "JBC 4" }, + name: { [LocalizedString.EN_US]: "JBC 6" }, description: { - [LocalizedString.EN_US]: "Junior Botball Challenge 4: Figure Eight", + [LocalizedString.EN_US]: "Junior Botball Challenge 6: Figure Eight", }, scripts: { circleIntersects: Script.ecmaScript("Circle Intersects", circleIntersects), @@ -305,7 +305,7 @@ export const JBC_4: Scene = { }, }, }, - + n2: { type: "object", geometryId: "topCan9_geom", @@ -327,7 +327,7 @@ export const JBC_4: Scene = { }, }, - + can4: { ...createCanNode(4) }, can9: { ...createCanNode(9), scriptIds: ["passedSide"] }, }, diff --git a/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts b/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts index 3528862f..422c2f5f 100644 --- a/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts +++ b/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts @@ -68,11 +68,11 @@ scene.addOnRenderListener(() => { }); `; -export const JBC_6: Scene = { +export const JBC_7: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: "JBC 6" }, + name: { [LocalizedString.EN_US]: "JBC 7" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 6: Load 'Em Up`, + [LocalizedString.EN_US]: `Junior Botball Challenge 7: Load 'Em Up`, }, scripts: { uprightCans: Script.ecmaScript("Upright Cans", uprightCans), diff --git a/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts b/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts index 57cd7c3e..0258a2e3 100644 --- a/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts +++ b/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts @@ -138,11 +138,11 @@ scene.onBind = nodeId => { }; `; -export const JBC_7: Scene = { +export const JBC_8: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: "JBC 7" }, + name: { [LocalizedString.EN_US]: "JBC 8" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7: Bulldozer Mania`, + [LocalizedString.EN_US]: `Junior Botball Challenge 8: Bulldozer Mania`, }, scripts: { startBoxIntersects: Script.ecmaScript( diff --git a/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts b/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts index ebf88a45..082da976 100644 --- a/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts +++ b/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts @@ -200,11 +200,11 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { }, }; -export const JBC_7B: Scene = { +export const JBC_9: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 7B' }, + name: { [LocalizedString.EN_US]: 'JBC 9' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7B: Cover Your Bases`, + [LocalizedString.EN_US]: `Junior Botball Challenge 9: Cover Your Bases`, }, scripts: { startBoxIntersects: Script.ecmaScript( diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 9404ea4f..19656952 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -19,26 +19,29 @@ import jbc2 from "../../simulator/definitions/challenges/jbc2"; // import jbc2c from "../../simulator/definitions/challenges/archived/jbc2c-Back-It-Up"; // import jbc2d from "../../simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up"; import jbc3 from "../../simulator/definitions/challenges/jbc3-Precision-Parking-New"; -import jbc4 from "../../simulator/definitions/challenges/jbc6-Figure-Eight-New"; +import jbc4 from "../../simulator/definitions/challenges/jbc4-Serpentine-New"; // import jbc4b from "../../simulator/definitions/challenges/archived/jbc4b-Barrel-Racing"; import jbc5 from "../../simulator/definitions/challenges/jbc5"; -import jbc6 from "../../simulator/definitions/challenges/jbc7-Load-Em-Up-New"; +import jbc6 from "../../simulator/definitions/challenges/jbc6-Figure-Eight-New"; // import jbc6c from "../../simulator/definitions/challenges/archived/jbc6c-Empty-the-Garage"; -import jbc7 from "../../simulator/definitions/challenges/jbc8-Bulldozer-Mania-New"; +import jbc7 from "../../simulator/definitions/challenges/jbc7-Load-Em-Up-New"; // import jbc7b from "../../simulator/definitions/challenges/archived/jbc7b-Cover-Your-Bases"; -import jbc8 from "../../simulator/definitions/challenges/jbc4-Serpentine-New"; +import jbc8 from "../../simulator/definitions/challenges/jbc8-Bulldozer-Mania-New"; +import jbc9 from "../../simulator/definitions/challenges/jbc9-Cover-Your-Bases-New"; // import jbc8b from "../../simulator/definitions/challenges/archived/jbc8b-Serpentine-Jr"; -// import jbc10 from "../../simulator/definitions/challenges/archived/jbc10-Solo-Joust"; +import jbc10 from "../../simulator/definitions/challenges/jbc10-Chopped-New"; // import jbc10b from "../../simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr"; +import jbc11 from "../../simulator/definitions/challenges/jbc11-Making-Waves-New"; // import jbc12 from "../../simulator/definitions/challenges/archived/jbc12-Unload-Em"; // import jbc13 from "../../simulator/definitions/challenges/archived/jbc13-Clean-the-Mat"; +import jbc14 from "../../simulator/definitions/challenges/jbc14-Dance-Party"; // import jbc15b from "../../simulator/definitions/challenges/archived/jbc15b-Bump-Bump"; -import jbc17 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; +import jbc17 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; // import jbc17b from "../../simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2"; -import jbc19 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; +import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; // import jbc20 from "../../simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans"; // import jbc21 from "../../simulator/definitions/challenges/archived/jbc21-Foot-Tall"; -import jbc22 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; +import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; export namespace ChallengesAction { @@ -216,14 +219,22 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc8b, // brief: ChallengeBrief.fromChallenge(jbc8b), // }), - // 'jbc10': Async.loaded({ - // value: jbc10, - // brief: ChallengeBrief.fromChallenge(jbc10), - // }), + 'jbc9': Async.loaded({ + value: jbc9, + brief: ChallengeBrief.fromChallenge(jbc9), + }), + 'jbc10': Async.loaded({ + value: jbc10, + brief: ChallengeBrief.fromChallenge(jbc10), + }), // 'jbc10b': Async.loaded({ // value: jbc10b, // brief: ChallengeBrief.fromChallenge(jbc10b), // }), + 'jbc11': Async.loaded({ + value: jbc11, + brief: ChallengeBrief.fromChallenge(jbc11), + }), // 'jbc12': Async.loaded({ // value: jbc12, // brief: ChallengeBrief.fromChallenge(jbc12), @@ -232,6 +243,10 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc13, // brief: ChallengeBrief.fromChallenge(jbc13), // }), + 'jbc14': Async.loaded({ + value: jbc14, + brief: ChallengeBrief.fromChallenge(jbc14), + }), // 'jbc15b': Async.loaded({ // value: jbc15b, // brief: ChallengeBrief.fromChallenge(jbc15b), @@ -244,10 +259,14 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc17b, // brief: ChallengeBrief.fromChallenge(jbc17b), // }), - 'jbc19': Async.loaded({ - value: jbc19, - brief: ChallengeBrief.fromChallenge(jbc19), + 'jbc18': Async.loaded({ + value: jbc18, + brief: ChallengeBrief.fromChallenge(jbc18), }), + // 'jbc19': Async.loaded({ + // value: jbc19, + // brief: ChallengeBrief.fromChallenge(jbc19), + // }), // 'jbc20': Async.loaded({ // value: jbc20, // brief: ChallengeBrief.fromChallenge(jbc20), @@ -256,9 +275,17 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc21, // brief: ChallengeBrief.fromChallenge(jbc21), // }), - 'jbc22': Async.loaded({ - value: jbc22, - brief: ChallengeBrief.fromChallenge(jbc22), + // 'jbc22': Async.loaded({ + // value: jbc22, + // brief: ChallengeBrief.fromChallenge(jbc22), + // }), + // 'jbc23': Async.loaded({ + // value: jbc23, + // brief: ChallengeBrief.fromChallenge(jbc23), + // }), + 'jbc24': Async.loaded({ + value: jbc24, + brief: ChallengeBrief.fromChallenge(jbc24), }), }; diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index 32d572bb..3bb18c57 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -312,17 +312,22 @@ const DEFAULT_SCENES: Scenes = { // jbc8b: Async.loaded({ value: JBC_SCENES.JBC_8B }), jbc9: Async.loaded({ value: JBC_SCENES.JBC_9 }), // jbc9b: Async.loaded({ value: JBC_SCENES.JBC_9B }), - // jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), + jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), // jbc10b: Async.loaded({ value: JBC_SCENES.JBC_10B }), + jbc11: Async.loaded({ value: JBC_SCENES.JBC_11 }), // jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), // jbc13: Async.loaded({ value: JBC_SCENES.JBC_13 }), + jbc14: Async.loaded({ value: JBC_SCENES.JBC_14 }), // jbc15b: Async.loaded({ value: JBC_SCENES.JBC_15B }), jbc17: Async.loaded({ value: JBC_SCENES.JBC_17 }), // jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), - jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), + jbc18: Async.loaded({ value: JBC_SCENES.JBC_18 }), + // jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), // jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), // jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), - jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), + // jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), + // 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 }), }; From a50861878159db4a2e3d02ebc3a3fda7279165b1 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 18 Oct 2024 15:46:39 -0700 Subject: [PATCH 03/22] Fix scale and positioning bug --- src/simulator/babylonBindings/SceneBinding.ts | 68 ++++++++++--------- .../createRobotObjects/createLink.ts | 6 +- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index 789f918c..cc4b8380 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -1,9 +1,11 @@ -import { PhysicsShapeType, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsAggregate, - TransformNode, AbstractMesh, PhysicsViewer, ShadowGenerator, Vector3, StandardMaterial, GizmoManager, +import { + PhysicsShapeType, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsAggregate, + TransformNode, AbstractMesh, PhysicsViewer, ShadowGenerator, Vector3, StandardMaterial, GizmoManager, ArcRotateCamera, PointLight, SpotLight, DirectionalLight, PBRMaterial, EngineView, Scene as babylonScene, Node as babylonNode, Camera as babylCamera, Material as babylMaterial, - Observer, BoundingBox } from '@babylonjs/core'; + Observer, BoundingBox +} from '@babylonjs/core'; // eslint-disable-next-line @typescript-eslint/no-duplicate-imports -- Required import for side effects import '@babylonjs/core/Engines/Extensions/engine.views'; @@ -81,7 +83,7 @@ class SceneBinding { this.engineView_ = engine.registerView(this.canvas_); this.bScene_.detachControl(); - engine.inputElement = this.canvas_; + engine.inputElement = this.canvas_ as unknown as HTMLElement; this.camera_.attachControl(this.engineView_.target, true); this.bScene_.attachControl(); @@ -92,7 +94,7 @@ class SceneBinding { * When this is true, the tick() method will exit immediately and return undefined. */ private declineTicks_ = false; - + private materialIdIter_ = 0; constructor(bScene: babylonScene, physics: IPhysicsEnginePluginV2) { @@ -105,7 +107,7 @@ class SceneBinding { // The sub time step is incredibly important for physics realism. 1 seems to work well. this.bScene_.getPhysicsEngine().setSubTimeStep(1); - + // Uncomment this to turn on the physics viewer for objects // this.physicsViewer_ = new PhysicsViewer(this.bScene_); @@ -147,7 +149,7 @@ class SceneBinding { return this.nodes_[id]; }; - + private updateMaterial_ = (bMaterial: babylMaterial, material: Patch) => { switch (material.type) { case Patch.Type.OuterChange: { @@ -189,13 +191,13 @@ class SceneBinding { throw new Error(`Robot by id "${node.robotId}" not found`); } await robotBinding.setRobot(node, robot, id); - robotBinding.linkOrigins = this.robotLinkOrigins_[id] || {}; + // robotBinding.linkOrigins = this.robotLinkOrigins_[id] || {}; robotBinding.visible = true; const observerObj: { observer: Observer } = { observer: null }; - + robotBinding.origin = node.origin; - + this.declineTicks_ = true; observerObj.observer = this.bScene_.onAfterRenderObservable.add((data, state) => { const node = this.scene_.nodes[id]; @@ -208,8 +210,8 @@ class SceneBinding { const { origin, visible } = node; const linkOrigins = this.robotLinkOrigins_[id]; - if (linkOrigins) robotBinding.linkOrigins = linkOrigins; - + // if (linkOrigins) robotBinding.linkOrigins = linkOrigins; + robotBinding.visible = visible ?? false; observerObj.observer.unregisterOnNextCall = true; this.declineTicks_ = false; @@ -262,10 +264,10 @@ class SceneBinding { } if (!ret) return null; - + this.updateNodePosition_(nodeToCreate, ret, id, nextScene); ret.id = id; - + ret.metadata = { id } as SceneMeshMetadata; if (ret instanceof AbstractMesh || ret instanceof TransformNode) { @@ -331,7 +333,7 @@ class SceneBinding { if (children && children.length > 0) { return (children[0] as AbstractMesh).material; } - + return null; }; @@ -361,7 +363,7 @@ class SceneBinding { }); - + // TODO: Handle changes to faceUvs when we fully support it if (node.inner.origin.type === Patch.Type.OuterChange) { this.updateNodePosition_(node.next, bNode, id, nextScene); @@ -419,7 +421,7 @@ class SceneBinding { private updateRobot_ = async (id: string, node: Patch.InnerChange): Promise => { const robotBinding = this.robotBindings_[id]; if (!robotBinding) throw new Error(`Robot binding not found for id "${id}"`); - + if (node.inner.robotId.type === Patch.Type.OuterChange) { this.destroyNode_(id); return this.createRobot_(id, node.next); @@ -437,8 +439,8 @@ class SceneBinding { }; private updateFromTemplate_ = ( - id: string, - node: Patch.InnerChange | Patch.InnerChange | Patch.InnerChange, + id: string, + node: Patch.InnerChange | Patch.InnerChange | Patch.InnerChange, nextScene: Scene ): Promise => { // If the template ID changes, recreate the node entirely @@ -540,7 +542,7 @@ class SceneBinding { }; private updateNode_ = async (id: string, node: Patch, geometryPatches: Dict>, nextScene: Scene): Promise => { - + switch (node.type) { // The node hasn't changed type, but some fields have been changed case Patch.Type.InnerChange: { @@ -743,7 +745,7 @@ class SceneBinding { if (SetOps.intersection(filterIds, Dict.keySet(this.robotBindings_)).size > 0) { throw new Error(`Cannot add a robot to a collision's filter. Please make the robot the primary nodeId.`); } - + this.intersectionFilters_[nodeId] = filterIds; this.syncCollisionFilters_(); }; @@ -777,7 +779,7 @@ class SceneBinding { return { collider, collidedAgainst, point, distance, impulse, normal }; }; - + readonly setScene = async (scene: Scene, robots: Dict) => { this.robots_ = robots; const patch = Scene.diff(this.scene_, scene); @@ -789,7 +791,7 @@ class SceneBinding { const node = patch.nodes[nodeId]; if (node.type !== Patch.Type.Remove) continue; await this.updateNode_(nodeId, node, patch.geometry, scene); - + delete this.nodes_[nodeId]; delete this.shadowGenerators_[nodeId]; delete this.intersectionFilters_[nodeId]; @@ -828,7 +830,7 @@ class SceneBinding { const nodeTemplate = preBuiltTemplates[prevNode.templateId]; if (nodeTemplate?.type === 'object') prevNodeObj = { ...nodeTemplate, ...Node.Base.upcast(prevNode) }; } - + const prevBNode = this.bScene_.getNodeById(prev); if (prevNodeObj && (prevBNode instanceof AbstractMesh || prevBNode instanceof TransformNode)) { prevBNode.metadata = { ...(prevBNode.metadata as SceneMeshMetadata), selected: false }; @@ -866,7 +868,7 @@ class SceneBinding { oldCamera.detachControl(this.bScene_.getEngine().getRenderingCanvas()); this.bScene_.detachControl(); this.bScene_.removeCamera(oldCamera); - + // Creating the camera already added it to the scene, so no need to call bScene_.addCamera() this.bScene_.activeCamera = this.camera_; if (this.engineView_) this.camera_.attachControl(this.engineView_.target, true); @@ -875,7 +877,7 @@ class SceneBinding { } if (patch.gravity.type === Patch.Type.OuterChange) { - const gravity_scalar = new Vector3(1,10,1); // This seems to be somewhat realistic + const gravity_scalar = new Vector3(1, 10, 1); // This seems to be somewhat realistic this.bScene_.getPhysicsEngine().setGravity(Vector3wUnits.toBabylon(patch.gravity.next, 'meters').multiply(gravity_scalar)); } @@ -941,7 +943,7 @@ class SceneBinding { const robotBinding = this.robotBindings_[nodeId]; if (robotBinding) { ret[nodeId] = robotBinding.tick(abstractRobots[nodeId]); - } else { + } else { // throw new Error(`No robot binding for node ${nodeId}`); } } @@ -953,7 +955,7 @@ class SceneBinding { const filterIds = this.intersectionFilters_[nodeId]; for (const filterId of filterIds) { const filterMinMaxes = this.nodeMinMaxes_(filterId); - + let intersection = false; for (const nodeBoundingBox of nodeBoundingBoxes) { for (const filterMinMax of filterMinMaxes) { @@ -962,22 +964,22 @@ class SceneBinding { } if (intersection) break; } - + if (intersection) { if (!this.currentIntersections_[nodeId]) this.currentIntersections_[nodeId] = new Set(); else if (this.currentIntersections_[nodeId].has(filterId)) continue; - + this.currentIntersections_[nodeId].add(filterId); - + this.scriptManager_.trigger(ScriptManager.Event.intersectionStart({ nodeId, otherNodeId: filterId, })); } else { if (!this.currentIntersections_[nodeId] || !this.currentIntersections_[nodeId].has(filterId)) continue; - + this.currentIntersections_[nodeId].delete(filterId); - + this.scriptManager_.trigger(ScriptManager.Event.intersectionEnd({ nodeId, otherNodeId: filterId, diff --git a/src/simulator/babylonBindings/createRobotObjects/createLink.ts b/src/simulator/babylonBindings/createRobotObjects/createLink.ts index 29336b69..dbd85a6f 100644 --- a/src/simulator/babylonBindings/createRobotObjects/createLink.ts +++ b/src/simulator/babylonBindings/createRobotObjects/createLink.ts @@ -106,9 +106,9 @@ export const createLink = async (id: string, link: Node.Link, bScene_: babylonSc case Node.Link.CollisionBody.Type.Cylinder: { myMesh = Mesh.MergeMeshes(meshes, true, true, undefined, false, true); const scale = link.scale ?? 1; - myMesh.scaling.y *= 1 / scale; - myMesh.scaling.y *= 1 / scale; - myMesh.scaling.scaleInPlace(RENDER_SCALE_METERS_MULTIPLIER * scale); + // myMesh.scaling.y *= 1 / scale; + // myMesh.scaling.y *= 1 / scale; + myMesh.scaling.scaleInPlace(RENDER_SCALE_METERS_MULTIPLIER); const aggregate = new PhysicsAggregate(myMesh, PhysicsShapeType.CYLINDER, { mass: Mass.toGramsValue(link.mass || Mass.grams(10)), friction: link.friction ?? 0.5, From 9009ba36b423e16adb38dc70925f70608ef5d659 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Fri, 18 Oct 2024 17:47:42 -0600 Subject: [PATCH 04/22] Remove duplicate line --- .../createRobotObjects/createLink.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/simulator/babylonBindings/createRobotObjects/createLink.ts b/src/simulator/babylonBindings/createRobotObjects/createLink.ts index 29336b69..12596e99 100644 --- a/src/simulator/babylonBindings/createRobotObjects/createLink.ts +++ b/src/simulator/babylonBindings/createRobotObjects/createLink.ts @@ -1,5 +1,6 @@ -import { Scene as babylonScene, Vector3, Mesh, SceneLoader, PhysicsBody, PhysicsMotionType, PhysicsShape, +import { + Scene as babylonScene, Vector3, Mesh, SceneLoader, PhysicsBody, PhysicsMotionType, PhysicsShape, PhysicsAggregate, PhysicsShapeType, PhysicShapeOptions, PhysicsShapeParameters, PhysicsShapeContainer } from '@babylonjs/core'; @@ -34,7 +35,7 @@ const buildGeometry_ = async (name: string, geometry: Geometry, bScene_: babylon const baseName = geometry.uri.substring(0, index + 1); const res = await SceneLoader.ImportMeshAsync(geometry.include ?? '', baseName, fileName, bScene_); - + const nonColliders: Mesh[] = []; const colliders: BuiltGeometry.Collider[] = []; for (const mesh of res.meshes.slice(1) as Mesh[]) { @@ -61,7 +62,7 @@ const buildGeometry_ = async (name: string, geometry: Geometry, bScene_: babylon } } ret = { nonColliders, colliders }; - break; + break; } default: { throw new Error(`Unsupported geometry type: ${geometry.type}`); } } @@ -81,10 +82,10 @@ export const createLink = async (id: string, link: Node.Link, bScene_: babylonSc if (!geometry) throw new Error(`Missing geometry: ${link.geometryId}`); builtGeometry = await buildGeometry_(id, geometry, bScene_); } - + const meshes = builtGeometry.nonColliders; let myMesh: Mesh; - + switch (link.collisionBody.type) { // Notes on Links - the root link should have the highest mass and inertia and it should // scale down further out the tree to prevent wild oscillations. @@ -107,7 +108,6 @@ export const createLink = async (id: string, link: Node.Link, bScene_: babylonSc myMesh = Mesh.MergeMeshes(meshes, true, true, undefined, false, true); const scale = link.scale ?? 1; myMesh.scaling.y *= 1 / scale; - myMesh.scaling.y *= 1 / scale; myMesh.scaling.scaleInPlace(RENDER_SCALE_METERS_MULTIPLIER * scale); const aggregate = new PhysicsAggregate(myMesh, PhysicsShapeType.CYLINDER, { mass: Mass.toGramsValue(link.mass || Mass.grams(10)), @@ -138,17 +138,17 @@ export const createLink = async (id: string, link: Node.Link, bScene_: babylonSc bCollider.visibility = 0; colliders_.add(bCollider); } - + const body = new PhysicsBody(myMesh, PhysicsMotionType.DYNAMIC, false, bScene_); body.shape = parentShape; if (link.inertia) { - body.setMassProperties({ + body.setMassProperties({ mass: Mass.toGramsValue(link.mass), inertia: new Vector3(link.inertia[0], link.inertia[1], link.inertia[2]) // (left/right, twist around, rock forward and backward) - }); + }); } body.setAngularDamping(.5); - + colliders_.add(myMesh); break; } From edb3b11790ead94cd0ebd8e82d4f5342870481dc Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Sat, 19 Oct 2024 22:48:10 -0600 Subject: [PATCH 05/22] Exclude chassis from node min maxes --- src/simulator/babylonBindings/SceneBinding.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index cc4b8380..75de5cec 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -924,8 +924,14 @@ class SceneBinding { if (meshes.length === 0) return []; const ret: { min: Vector3; max: Vector3; }[] = []; - for (const mesh of meshes) ret.push(mesh.getHierarchyBoundingVectors()); - + // for (const mesh of meshes) ret.push(mesh.getHierarchyBoundingVectors()); + for (const mesh of meshes) { + if (mesh.id.includes('Chassis')) { + continue; + } else { + ret.push(mesh.getHierarchyBoundingVectors()); + } + } return ret; }; From 1f7048b76f2d83d68d68cd15baa3b811059dc872 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Mon, 21 Oct 2024 06:45:42 -0600 Subject: [PATCH 06/22] Push JBC 0 and boundingBox tests --- src/simulator/babylonBindings/SceneBinding.ts | 11 +- .../createRobotObjects/createLink.ts | 10 +- src/simulator/definitions/challenges/jbc0.ts | 38 +++-- src/simulator/definitions/scenes/jbc0.ts | 151 +++++++++++------- 4 files changed, 141 insertions(+), 69 deletions(-) diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index 75de5cec..8401abd7 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -4,7 +4,8 @@ import { TransformNode, AbstractMesh, PhysicsViewer, ShadowGenerator, Vector3, StandardMaterial, GizmoManager, ArcRotateCamera, PointLight, SpotLight, DirectionalLight, PBRMaterial, EngineView, Scene as babylonScene, Node as babylonNode, Camera as babylCamera, Material as babylMaterial, - Observer, BoundingBox + Observer, BoundingBox, + Color3 } from '@babylonjs/core'; // eslint-disable-next-line @typescript-eslint/no-duplicate-imports -- Required import for side effects @@ -122,6 +123,8 @@ class SceneBinding { this.gizmoManager_.rotationGizmoEnabled = true; this.gizmoManager_.scaleGizmoEnabled = false; this.gizmoManager_.usePointerToAttachGizmos = false; + this.gizmoManager_.boundingBoxGizmoEnabled = true; + this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); this.scriptManager_.onCollisionFiltersChanged = this.onCollisionFiltersChanged_; this.scriptManager_.onIntersectionFiltersChanged = this.onIntersectionFiltersChanged_; @@ -922,11 +925,11 @@ class SceneBinding { private nodeMinMaxes_ = (id: string): { min: Vector3; max: Vector3; }[] => { const meshes = this.nodeMeshes_(id); if (meshes.length === 0) return []; - const ret: { min: Vector3; max: Vector3; }[] = []; // for (const mesh of meshes) ret.push(mesh.getHierarchyBoundingVectors()); for (const mesh of meshes) { - if (mesh.id.includes('Chassis')) { + this.gizmoManager_.gizmos.boundingBoxGizmo.attachedMesh = mesh; + if (mesh.id.includes('chassis')) { continue; } else { ret.push(mesh.getHierarchyBoundingVectors()); @@ -957,7 +960,7 @@ class SceneBinding { // Update intersections for (const nodeId in this.intersectionFilters_) { try { - const nodeBoundingBoxes = this.nodeBoundingBoxes_(nodeId); // + const nodeBoundingBoxes = this.nodeBoundingBoxes_(nodeId); const filterIds = this.intersectionFilters_[nodeId]; for (const filterId of filterIds) { const filterMinMaxes = this.nodeMinMaxes_(filterId); diff --git a/src/simulator/babylonBindings/createRobotObjects/createLink.ts b/src/simulator/babylonBindings/createRobotObjects/createLink.ts index b0fe73f2..498cd89b 100644 --- a/src/simulator/babylonBindings/createRobotObjects/createLink.ts +++ b/src/simulator/babylonBindings/createRobotObjects/createLink.ts @@ -1,7 +1,9 @@ import { Scene as babylonScene, Vector3, Mesh, SceneLoader, PhysicsBody, PhysicsMotionType, PhysicsShape, - PhysicsAggregate, PhysicsShapeType, PhysicShapeOptions, PhysicsShapeParameters, PhysicsShapeContainer + PhysicsAggregate, PhysicsShapeType, PhysicShapeOptions, PhysicsShapeParameters, PhysicsShapeContainer, + GizmoManager, + Color3 } from '@babylonjs/core'; import Geometry from '../../../state/State/Robot/Geometry'; @@ -38,7 +40,13 @@ const buildGeometry_ = async (name: string, geometry: Geometry, bScene_: babylon const nonColliders: Mesh[] = []; const colliders: BuiltGeometry.Collider[] = []; + const gizmoManager_ = new GizmoManager(bScene_); + gizmoManager_.boundingBoxGizmoEnabled = true; + gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); for (const mesh of res.meshes.slice(1) as Mesh[]) { + // gizmoManager_.gizmos.boundingBoxGizmo.attachedMesh = mesh; + + // The robot mesh includes sub-meshes with the 'collider' name to indicate their use. if (mesh.name.startsWith('collider')) { const parts = mesh.name.split('-'); diff --git a/src/simulator/definitions/challenges/jbc0.ts b/src/simulator/definitions/challenges/jbc0.ts index 922172ef..d46ae722 100644 --- a/src/simulator/definitions/challenges/jbc0.ts +++ b/src/simulator/definitions/challenges/jbc0.ts @@ -20,9 +20,13 @@ export default { }, defaultLanguage: 'c', events: { - leaveStartBox: { - name: { [LocalizedString.EN_US]: 'Robot Left Start' }, - description: { [LocalizedString.EN_US]: 'Robot left starting box' }, + inStartBox: { + name: { [LocalizedString.EN_US]: 'In Start Box' }, + description: { [LocalizedString.EN_US]: 'Robot is in the start box' }, + }, + notInStartBox: { + name: { [LocalizedString.EN_US]: 'Not In Start Box' }, + description: { [LocalizedString.EN_US]: 'Robot is not in the start box' }, }, robotTouchingLine: { name: { [LocalizedString.EN_US]: 'Robot Touching Line B' }, @@ -47,19 +51,33 @@ export default { }, // Start Box Events - leaveStartBox: { + inStartBox: { + type: Expr.Type.Event, + eventId: 'inStartBox', + }, + notInStartBox: { type: Expr.Type.Event, - eventId: 'leaveStartBox', + eventId: 'notInStartBox', }, - leaveStartBoxOnce: { + inStartBoxOnce: { type: Expr.Type.Once, - argId: 'leaveStartBox', + argId: 'inStartBox', + }, + notOutOfStartBox: { + type: Expr.Type.Not, + argId: 'notInStartBox', + }, + notOutOfStartBoxOnce: { + type: Expr.Type.Once, + argId: 'notOutOfStartBox', + }, + startedInStartBox: { + type: Expr.Type.And, + argIds: ['inStartBoxOnce', 'notOutOfStartBoxOnce'], }, - - completion: { type: Expr.Type.And, - argIds: ['leaveStartBoxOnce', 'reachedEnd'], + argIds: ['startedInStartBox', 'reachedEnd'], }, }, rootId: 'completion', diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0.ts index 31ebeda3..54bb529c 100644 --- a/src/simulator/definitions/scenes/jbc0.ts +++ b/src/simulator/definitions/scenes/jbc0.ts @@ -10,77 +10,67 @@ import Node from 'state/State/Scene/Node'; const baseScene = createBaseSceneSurfaceB(); -const leftStartBox = ` +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; +const inStartBox = ` scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot left start box!', type, otherNodeId); + console.log('Robot started in start box!', type, otherNodeId); if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('leaveStartBox', type === 'end'); + scene.setChallengeEventValue('inStartBox', type === 'start'); } - }, 'startBox'); `; const touchingLine = ` // If the robot wheels touch Line B, it fails the challenge -const getYawRotation = (nodeId)=> { - const node = scene.nodes[nodeId]; - - if (!node || !node.origin || !node.origin.orientation) { - // Return 0 if the node, its origin, or its orientation doesn't exist - return 0; - } - - // Extract the quaternion from the node's orientation - const quaternion = RotationwUnits.toRawQuaternion(node.origin.orientation || EULER_IDENTITY); - - // Calculate yaw (rotation around Y-axis) - const siny_cosp = 2 * (quaternion.w * quaternion.y + quaternion.x * quaternion.z); - const cosy_cosp = 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z); - const yaw = 180 / Math.PI * Math.atan2(siny_cosp, cosy_cosp); - - return yaw; -}; - -const getWheelXPosition = (nodeId, wheelXDistance) => { - const node = scene.nodes[nodeId]; - const robotXOrigin = node.startingOrigin.position.x; - const wheelXOrigin = Distance.add(robotXOrigin, wheelXDistance, 'meters'); - - const robotXPosition = node.origin.position.x; - const yawRad = (getYawRotation(nodeId) + 45) * Math.PI / 180; - const wheelXPosition = Distance.add(robotXPosition, Distance.centimeters(Distance.toCentimetersValue(wheelXOrigin) * Math.cos(yawRad)), 'centimeters'); - return wheelXPosition; -}; +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); -scene.addOnRenderListener(() => { - const leftWheelXPosition = getWheelXPosition('robot', Distance.centimeters(-7.492)); - const rightWheelXPosition = getWheelXPosition('robot', Distance.centimeters(7.492)); - console.log('Left: ', leftWheelXPosition.value, 'Right: ', rightWheelXPosition.value); - const leftWheelTouching = leftWheelXPosition.value > 0.5; - const rightWheelTouching = rightWheelXPosition.value < -0.5; - const robotTouchingLine = leftWheelTouching || rightWheelTouching; +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot touching line!', type, otherNodeId); if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('robotTouchingLine', robotTouchingLine); + scene.setChallengeEventValue('robotTouchingLine', type === 'start'); + setNodeVisible('lineB', true); } -}); +}, 'lineB'); `; const reachedEnd = ` // If the robot reaches the end, it completes the challenge +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + scene.addOnIntersectionListener('robot', (type, otherNodeId) => { console.log('Robot reached end!', type, otherNodeId); + const visible = type === 'start'; if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('reachedEnd', type === 'start'); + scene.setChallengeEventValue('reachedEnd', visible); + setNodeVisible('endBox', visible); } - }, 'endBox'); `; const offMat = ` // If the robot leaves the mat, it fails the challenge + +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + scene.addOnIntersectionListener('robot', (type, otherNodeId) => { console.log('Robot off mat!', type, otherNodeId); const visible = type === 'start'; @@ -98,10 +88,6 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { }, }; -const robotNode: Node.Robot = baseScene.nodes['robot'] as Node.Robot; - - - export const JBC_0: Scene = { ...baseScene, name: { [LocalizedString.EN_US]: 'JBC 0' }, @@ -109,7 +95,8 @@ export const JBC_0: Scene = { [LocalizedString.EN_US]: 'Junior Botball Challenge 0: Drive Straight', }, scripts: { - leftStartBox: Script.ecmaScript('Robot Left Start', leftStartBox), + notInStartBox: Script.ecmaScript("Not In Start Box", notInStartBox), + inStartBox: Script.ecmaScript("In Start Box", inStartBox), touchingLine: Script.ecmaScript('Robot Touching Line', touchingLine), reachedEnd: Script.ecmaScript('Robot Reached End', reachedEnd), offMat: Script.ecmaScript('Robot Off Mat', offMat), @@ -124,27 +111,43 @@ export const JBC_0: Scene = { z: Distance.meters(3.54), }, }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, startBox_geom: { type: 'box', size: { - x: Distance.meters(1.77), + x: Distance.centimeters(30), y: Distance.centimeters(0.1), z: Distance.centimeters(30), }, }, + lineB_geom: { + type: 'box', + size: { + x: Distance.centimeters(0.5), + y: Distance.centimeters(0.1), + z: Distance.inches(48), + }, + }, endBox_geom: { type: 'box', size: { x: Distance.inches(24), y: Distance.centimeters(15), - z: Distance.centimeters(0), + z: Distance.centimeters(1), }, }, endOfMat_geom: { type: 'box', size: { x: Distance.meters(3.54), - y: Distance.centimeters(0.1), + y: Distance.centimeters(4), z: Distance.inches(24), }, }, @@ -176,6 +179,26 @@ export const JBC_0: Scene = { }, }, }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.223), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, startBox: { type: 'object', geometryId: 'startBox_geom', @@ -188,11 +211,31 @@ export const JBC_0: Scene = { z: Distance.centimeters(0.685), }, }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 0, 255), + }, + }, + }, + lineB: { + type: 'object', + geometryId: 'lineB_geom', + name: { [LocalizedString.EN_US]: 'Line B' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(-0.5), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.685), // 24 for half the mat and 19.685 for the mat's origin + }, + }, material: { type: 'pbr', emissive: { type: 'color3', - color: Color.rgb(0, 0, 255), + color: Color.rgb(255, 0, 0), }, }, }, @@ -224,7 +267,7 @@ export const JBC_0: Scene = { origin: { position: { x: Distance.centimeters(0), - y: Distance.centimeters(-6.89), + y: Distance.centimeters(-4.90), z: Distance.inches(59.2), }, }, From ca3a58f8b431d4f26e6b2f9c906f97e18e305140 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Mon, 21 Oct 2024 14:00:38 -0600 Subject: [PATCH 07/22] Fix circle issue in challenge 11 --- .../definitions/scenes/jbc11-Making-Waves-New.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts b/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts index 0620806a..621880c7 100644 --- a/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts +++ b/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts @@ -27,16 +27,16 @@ const wave = ` if (scene.programStatus === 'running') { if (robotNode.state.getMotor(0).speedGoal == 0 && robotNode.state.getMotor(3).speedGoal == 0) { - console.log('Robot stopped, motors at: ', robotNode.state.getMotor(0).speedGoal, ' ', robotNode.state.getMotor(3).speedGoal); + // console.log('Robot stopped, motors at: ', robotNode.state.getMotor(0).speedGoal, ' ', robotNode.state.getMotor(3).speedGoal); if (waveStart == -1) { waveStart = robotNode.state.getServo(0).position; - console.log('Wave start at ', waveStart); + // console.log('Wave start at ', waveStart); } else { - console.log('Wave diff at ', Math.abs(robotNode.state.getServo(0).position - waveStart)); - if (Math.abs(robotNode.state.getServo(0).position - waveStart) >= waveMax) { + console.log('Wave diff at ', Math.abs(Math.abs(robotNode.state.getServo(0).position - waveStart) - waveMax)); + if (Math.abs(Math.abs(robotNode.state.getServo(0).position - waveStart) - waveMax) > 1) { waveMax = Math.abs(robotNode.state.getServo(0).position - waveStart); - console.log('Wave max at ', waveMax, 'Wave start at ', waveStart); + // console.log('Wave max at ', waveMax, 'Wave start at ', waveStart); } else { if (waveMax != 0) { @@ -66,13 +66,11 @@ const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { visible }); -let circles = new Set(['circle3', 'circle6', 'circle9', 'circle12']); - scene.addOnIntersectionListener('robot', (type, otherNodeId) => { console.log('Robot intersects!', type, otherNodeId); scene.setChallengeEventValue(otherNodeId + 'Touched', true); setNodeVisible(otherNodeId, true); -}, ...circles); +}, [ 'circle3', 'circle6', 'circle9', 'circle12' ]); `; export const JBC_11: Scene = { From 03ea7ac4643d99b06cb9c6215b7ba08e76b85ead Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Mon, 21 Oct 2024 15:34:59 -0600 Subject: [PATCH 08/22] JBC 15 completion --- .../challenges/jbc15-Go-Fetch-New.ts | 75 +++++++++ src/simulator/definitions/scenes/index.ts | 1 + .../definitions/scenes/jbc15-Go-Fetch-New.ts | 151 ++++++++++++++++++ src/state/reducer/challenges.ts | 5 + src/state/reducer/scenes.ts | 1 + 5 files changed, 233 insertions(+) create mode 100644 src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts create mode 100644 src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts diff --git a/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts new file mode 100644 index 00000000..6075462d --- /dev/null +++ b/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts @@ -0,0 +1,75 @@ +import Author from "../../../db/Author"; +import Challenge from "../../../state/State/Challenge"; +import Expr from "../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: "JBC Challenge 15" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 15: Go Fetch`, + }, + author: { + type: Author.Type.Organization, + id: "kipr", + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: "c", + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + canInStartBox: { + name: { [LocalizedString.EN_US]: "Can in Start Box" }, + description: { [LocalizedString.EN_US]: "Can in start box" }, + }, + can11Upright: { + name: { [LocalizedString.EN_US]: "Can 11 Upright" }, + description: { [LocalizedString.EN_US]: "Can 11 upright" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + //Can Events + canInStartBox: { + type: Expr.Type.Event, + eventId: "canInStartBox", + }, + can7Upright: { + type: Expr.Type.Event, + eventId: "can7Upright", + }, + + // Success Logic = Can 7 not upright, waited to chop, and began in start box + completion: { + type: Expr.Type.And, + argIds: [ + "inStartBoxOnce", + "canInStartBox", + "can11Upright", + ], + }, + }, + rootId: "completion", + }, + sceneId: "jbc15", +} as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 6c3af999..1c070733 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -14,6 +14,7 @@ export * from './jbc10-Chopped-New'; export * from './jbc11-Making-Waves-New'; export * from './jbc12-Add-It-Up-New'; export * from './jbc14-Dance-Party'; +export * from './jbc15-Go-Fetch-New'; export * from './jbc17-Mountain-Rescue-New'; export * from './jbc18-Stackerz-New'; export * from './jbc24-Walk-the-Line-New'; diff --git a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts new file mode 100644 index 00000000..86045ec6 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts @@ -0,0 +1,151 @@ +import Scene from "../../../state/State/Scene"; +import LocalizedString from "../../../util/LocalizedString"; +import Script from "../../../state/State/Scene/Script"; +import { createCanNode, createBaseSceneSurfaceA } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const enterStartBox = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + + +scene.addOnIntersectionListener('can11', (type, otherNodeId) => { + console.log('Robot returned start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('canInStartBox', type === 'start'); + setNodeVisible('startBox', type == 'start'); + } +}, 'startBox'); +`; + +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)); + + +scene.addOnRenderListener(() => { + const upright11 = yAngle('can11') > 5; + scene.setChallengeEventValue('can11Upright', upright11); +}); +`; + +export const JBC_15: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: "JBC 15" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 15: Go Fetch`, + }, + scripts: { + notInStartBox: Script.ecmaScript("Not in Start Box", notInStartBox), + enterStartBox: Script.ecmaScript("Enter Start Box", enterStartBox), + uprightCans: Script.ecmaScript("Upright Can", uprightCan), + + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + startBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.centimeters(30), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + + nodes: { + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + startBox: { + type: "object", + geometryId: "startBox_geom", + name: { [LocalizedString.EN_US]: "Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.centimeters(-3), + }, + }, + material: { + type: "pbr", + emissive: { + type: "color3", + color: Color.rgb(255, 255, 255), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + can11: createCanNode(11), + }, +}; diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 19656952..c080e877 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -35,6 +35,7 @@ import jbc11 from "../../simulator/definitions/challenges/jbc11-Making-Waves-New // import jbc12 from "../../simulator/definitions/challenges/archived/jbc12-Unload-Em"; // import jbc13 from "../../simulator/definitions/challenges/archived/jbc13-Clean-the-Mat"; import jbc14 from "../../simulator/definitions/challenges/jbc14-Dance-Party"; +import jbc15 from "../../simulator/definitions/challenges/jbc15-Go-Fetch-New"; // import jbc15b from "../../simulator/definitions/challenges/archived/jbc15b-Bump-Bump"; import jbc17 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; // import jbc17b from "../../simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2"; @@ -247,6 +248,10 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc14, brief: ChallengeBrief.fromChallenge(jbc14), }), + 'jbc15': Async.loaded({ + value: jbc15, + brief: ChallengeBrief.fromChallenge(jbc15), + }), // 'jbc15b': Async.loaded({ // value: jbc15b, // brief: ChallengeBrief.fromChallenge(jbc15b), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index 3bb18c57..98c58488 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -318,6 +318,7 @@ const DEFAULT_SCENES: Scenes = { // jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), // jbc13: Async.loaded({ value: JBC_SCENES.JBC_13 }), jbc14: Async.loaded({ value: JBC_SCENES.JBC_14 }), + jbc15: Async.loaded({ value: JBC_SCENES.JBC_15 }), // jbc15b: Async.loaded({ value: JBC_SCENES.JBC_15B }), jbc17: Async.loaded({ value: JBC_SCENES.JBC_17 }), // jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), From 98fa7a0823ee6bc04e6523e61a15cdd764826215 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Mon, 21 Oct 2024 15:42:55 -0600 Subject: [PATCH 09/22] Fix missing nodes --- src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts index 86045ec6..bdba086e 100644 --- a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts +++ b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts @@ -86,6 +86,7 @@ export const JBC_15: Scene = { }, nodes: { + ...baseScene.nodes, mainSurface: { type: "object", geometryId: "mainSurface_geom", From 954726d8e3ff63f9c07711acbcd0d011547c166f Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Mon, 21 Oct 2024 16:09:15 -0600 Subject: [PATCH 10/22] Fix upright conditions on JBC 15 --- src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts index 6075462d..396e1264 100644 --- a/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts +++ b/src/simulator/definitions/challenges/jbc15-Go-Fetch-New.ts @@ -54,9 +54,9 @@ export default { type: Expr.Type.Event, eventId: "canInStartBox", }, - can7Upright: { + can11Upright: { type: Expr.Type.Event, - eventId: "can7Upright", + eventId: "can11Upright", }, // Success Logic = Can 7 not upright, waited to chop, and began in start box From f408cef6594c3d9d25f45100bfe0a29e76b84756 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Tue, 22 Oct 2024 10:12:09 -0600 Subject: [PATCH 11/22] Comment out bounding boxes and fixes to JBC 0 --- src/simulator/babylonBindings/SceneBinding.ts | 11 +++++---- .../createRobotObjects/createLink.ts | 10 ++++---- src/simulator/definitions/challenges/jbc0.ts | 24 +++++++++++-------- src/simulator/definitions/scenes/jbc0.ts | 12 +++++----- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index 8401abd7..ef426354 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -123,8 +123,9 @@ class SceneBinding { this.gizmoManager_.rotationGizmoEnabled = true; this.gizmoManager_.scaleGizmoEnabled = false; this.gizmoManager_.usePointerToAttachGizmos = false; - this.gizmoManager_.boundingBoxGizmoEnabled = true; - this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); + // Un comment for boudning boxes in scene + // this.gizmoManager_.boundingBoxGizmoEnabled = true; + // this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); this.scriptManager_.onCollisionFiltersChanged = this.onCollisionFiltersChanged_; this.scriptManager_.onIntersectionFiltersChanged = this.onIntersectionFiltersChanged_; @@ -928,11 +929,11 @@ class SceneBinding { const ret: { min: Vector3; max: Vector3; }[] = []; // for (const mesh of meshes) ret.push(mesh.getHierarchyBoundingVectors()); for (const mesh of meshes) { - this.gizmoManager_.gizmos.boundingBoxGizmo.attachedMesh = mesh; - if (mesh.id.includes('chassis')) { + // this.gizmoManager_.gizmos.boundingBoxGizmo.attachedMesh = mesh; // For viewing meshes on robot + if (mesh.id.includes('Chassis')) { continue; } else { - ret.push(mesh.getHierarchyBoundingVectors()); + ret.push(mesh.getHierarchyBoundingVectors(true, (mesh: AbstractMesh) => !mesh.name.includes('et_sensor'))); } } return ret; diff --git a/src/simulator/babylonBindings/createRobotObjects/createLink.ts b/src/simulator/babylonBindings/createRobotObjects/createLink.ts index 498cd89b..f140af58 100644 --- a/src/simulator/babylonBindings/createRobotObjects/createLink.ts +++ b/src/simulator/babylonBindings/createRobotObjects/createLink.ts @@ -40,13 +40,11 @@ const buildGeometry_ = async (name: string, geometry: Geometry, bScene_: babylon const nonColliders: Mesh[] = []; const colliders: BuiltGeometry.Collider[] = []; - const gizmoManager_ = new GizmoManager(bScene_); - gizmoManager_.boundingBoxGizmoEnabled = true; - gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); + // Comment in to show bounding boxes on robot + // const gizmoManager_ = new GizmoManager(bScene_); + // gizmoManager_.boundingBoxGizmoEnabled = true; + // gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); for (const mesh of res.meshes.slice(1) as Mesh[]) { - // gizmoManager_.gizmos.boundingBoxGizmo.attachedMesh = mesh; - - // The robot mesh includes sub-meshes with the 'collider' name to indicate their use. if (mesh.name.startsWith('collider')) { const parts = mesh.name.split('-'); diff --git a/src/simulator/definitions/challenges/jbc0.ts b/src/simulator/definitions/challenges/jbc0.ts index d46ae722..cf3016a6 100644 --- a/src/simulator/definitions/challenges/jbc0.ts +++ b/src/simulator/definitions/challenges/jbc0.ts @@ -59,25 +59,29 @@ export default { type: Expr.Type.Event, eventId: 'notInStartBox', }, - inStartBoxOnce: { - type: Expr.Type.Once, - argId: 'inStartBox', - }, + // inStartBoxOnce: { + // type: Expr.Type.Once, + // argId: 'inStartBox', + // }, notOutOfStartBox: { type: Expr.Type.Not, argId: 'notInStartBox', }, - notOutOfStartBoxOnce: { - type: Expr.Type.Once, - argId: 'notOutOfStartBox', - }, + // notOutOfStartBoxOnce: { + // type: Expr.Type.Once, + // argId: 'notOutOfStartBox', + // }, startedInStartBox: { type: Expr.Type.And, - argIds: ['inStartBoxOnce', 'notOutOfStartBoxOnce'], + argIds: ['inStartBox', 'notOutOfStartBox'], + }, + startedInStartBoxOnce: { + type: Expr.Type.Once, + argId: 'startedInStartBox', }, completion: { type: Expr.Type.And, - argIds: ['startedInStartBox', 'reachedEnd'], + argIds: ['startedInStartBoxOnce', 'reachedEnd'], }, }, rootId: 'completion', diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0.ts index 54bb529c..72199e5b 100644 --- a/src/simulator/definitions/scenes/jbc0.ts +++ b/src/simulator/definitions/scenes/jbc0.ts @@ -21,9 +21,9 @@ scene.addOnIntersectionListener('robot', (type, otherNodeId) => { const inStartBox = ` scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot started in start box!', type, otherNodeId); + console.log('Robot started in start box!', type, otherNodeId, scene.programStatus); if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('inStartBox', type === 'start'); + scene.setChallengeEventValue('inStartBox', true); } }, 'startBox'); `; @@ -122,9 +122,9 @@ export const JBC_0: Scene = { startBox_geom: { type: 'box', size: { - x: Distance.centimeters(30), + x: Distance.centimeters(16), y: Distance.centimeters(0.1), - z: Distance.centimeters(30), + z: Distance.centimeters(10), }, }, lineB_geom: { @@ -203,12 +203,12 @@ export const JBC_0: Scene = { type: 'object', geometryId: 'startBox_geom', name: { [LocalizedString.EN_US]: 'Start Box' }, - visible: false, + visible: true, origin: { position: { x: Distance.centimeters(0), y: Distance.centimeters(-6.89), - z: Distance.centimeters(0.685), + z: Distance.centimeters(10.685), }, }, material: { From 182d937ede99e30a83b6e343ff099d72028fbbce Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Wed, 23 Oct 2024 02:23:32 -0600 Subject: [PATCH 12/22] Add JBC 19 and 20. New chassis with lever sensor collider. Mats not movable anymore. --- .../definitions/challenges/jbc19-Bump-New.ts | 68 +++++ .../challenges/jbc20-Amazing-New.ts | 101 ++++++++ src/simulator/definitions/scenes/index.ts | 2 + src/simulator/definitions/scenes/jbc0.ts | 2 +- .../definitions/scenes/jbc19-Bump-New.ts | 125 +++++++++ .../definitions/scenes/jbc20-Amazing-New.ts | 244 ++++++++++++++++++ src/simulator/definitions/scenes/jbcBase.ts | 4 +- src/state/reducer/challenges.ts | 19 +- src/state/reducer/scenes.ts | 4 +- static/object_binaries/chassis.glb | 4 +- 10 files changed, 557 insertions(+), 16 deletions(-) create mode 100644 src/simulator/definitions/challenges/jbc19-Bump-New.ts create mode 100644 src/simulator/definitions/challenges/jbc20-Amazing-New.ts create mode 100644 src/simulator/definitions/scenes/jbc19-Bump-New.ts create mode 100644 src/simulator/definitions/scenes/jbc20-Amazing-New.ts diff --git a/src/simulator/definitions/challenges/jbc19-Bump-New.ts b/src/simulator/definitions/challenges/jbc19-Bump-New.ts new file mode 100644 index 00000000..6ada0a6f --- /dev/null +++ b/src/simulator/definitions/challenges/jbc19-Bump-New.ts @@ -0,0 +1,68 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 19' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 19: Bump`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + driveForwardTouch: { + name: { [LocalizedString.EN_US]: 'Robot Forward Touch' }, + description: { + [LocalizedString.EN_US]: + 'Robot drove forward and touched ream of paper', + }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + // Ream Touching Events + driveForwardTouch: { + type: Expr.Type.Event, + eventId: 'driveForwardTouch', + }, + + completion: { + type: Expr.Type.And, + argIds: [ + 'inStartBoxOnce', + 'driveForwardTouch', + ], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc19', +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc20-Amazing-New.ts b/src/simulator/definitions/challenges/jbc20-Amazing-New.ts new file mode 100644 index 00000000..bc8377bb --- /dev/null +++ b/src/simulator/definitions/challenges/jbc20-Amazing-New.ts @@ -0,0 +1,101 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 20' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 20: A'mazing`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + inStartBox: { + name: { [LocalizedString.EN_US]: "In Start Box" }, + description: { [LocalizedString.EN_US]: "Robot in start box" }, + }, + ream1Touched: { + name: { [LocalizedString.EN_US]: "Ream 1 Touched" }, + description: { [LocalizedString.EN_US]: "Robot touched ream 1" }, + }, + ream2Touched: { + name: { [LocalizedString.EN_US]: "Ream 2 Touched" }, + description: { [LocalizedString.EN_US]: "Robot touched ream 2" }, + }, + ream3Touched: { + name: { [LocalizedString.EN_US]: "Ream 3 Touched" }, + description: { [LocalizedString.EN_US]: "Robot touched ream 3" }, + }, + ream4Touched: { + name: { [LocalizedString.EN_US]: "Ream 4 Touched" }, + description: { [LocalizedString.EN_US]: "Robot touched ream 4" }, + }, + }, + success: { + exprs: { + inStartBox: { + type: Expr.Type.Event, + eventId: 'inStartBox', + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: 'inStartBox', + }, + ream1Touched: { + type: Expr.Type.Event, + eventId: 'ream1Touched', + }, + ream1TouchedOnce: { + type: Expr.Type.Once, + argId: 'ream1Touched', + }, + ream2Touched: { + type: Expr.Type.Event, + eventId: 'ream2Touched', + }, + ream2TouchedOnce: { + type: Expr.Type.Once, + argId: 'ream2Touched', + }, + ream3Touched: { + type: Expr.Type.Event, + eventId: 'ream3Touched', + }, + ream3TouchedOnce: { + type: Expr.Type.Once, + argId: 'ream3Touched', + }, + ream4Touched: { + type: Expr.Type.Event, + eventId: 'ream4Touched', + }, + ream4TouchedOnce: { + type: Expr.Type.Once, + argId: 'ream4Touched', + }, + + completion: { + type: Expr.Type.And, + argIds: [ + 'inStartBoxOnce', + 'ream1TouchedOnce', + 'ream2TouchedOnce', + 'ream3TouchedOnce', + 'ream4TouchedOnce', + ], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc20', +} as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 1c070733..7d5b64f8 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -17,6 +17,8 @@ export * from './jbc14-Dance-Party'; export * from './jbc15-Go-Fetch-New'; export * from './jbc17-Mountain-Rescue-New'; export * from './jbc18-Stackerz-New'; +export * from './jbc19-Bump-New'; +export * from './jbc20-Amazing-New'; export * from './jbc24-Walk-the-Line-New'; export * from './moonSandbox'; // export * from './jbc2b-Ring-Around-the-Cans-Sr'; diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0.ts index 72199e5b..f535406a 100644 --- a/src/simulator/definitions/scenes/jbc0.ts +++ b/src/simulator/definitions/scenes/jbc0.ts @@ -203,7 +203,7 @@ export const JBC_0: Scene = { type: 'object', geometryId: 'startBox_geom', name: { [LocalizedString.EN_US]: 'Start Box' }, - visible: true, + visible: false, origin: { position: { x: Distance.centimeters(0), diff --git a/src/simulator/definitions/scenes/jbc19-Bump-New.ts b/src/simulator/definitions/scenes/jbc19-Bump-New.ts new file mode 100644 index 00000000..52083f2a --- /dev/null +++ b/src/simulator/definitions/scenes/jbc19-Bump-New.ts @@ -0,0 +1,125 @@ +import Scene from '../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits } from '../../../util/math/unitMath'; +import { Distance } from '../../../util'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +import tr from '@i18n'; +import Node from 'state/State/Scene/Node'; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const bumpReam = ` +console.log('Bump Ream script loaded'); +scene.addOnCollisionListener('ream1', (otherNodeId) => { + //If front bumper is pressed + if(scene.nodes['robot'].state.getDigitalValue(0) == 1) { + scene.setChallengeEventValue('driveForwardTouch', true); + } +}, 'robot'); +`; + +const REAM1_ORIGIN: ReferenceFramewUnits = { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(5), + z: Distance.centimeters(48), + }, + orientation: RotationwUnits.AxisAngle.fromRaw({ + axis: { x: 1, y: 0, z: 0 }, + angle: -Math.PI / 2, + }), +}; + +export const JBC_19: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 19' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 19: Bump`, + }, + scripts: { + notInStartBox: Script.ecmaScript('Not in Start Box', notInStartBox), + bumpReam: Script.ecmaScript('Bump Ream', bumpReam), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + ream1: { + type: 'from-jbc-template', + templateId: 'ream', + name: tr('Paper Ream 1'), + startingOrigin: REAM1_ORIGIN, + origin: REAM1_ORIGIN, + visible: true, + }, + }, +}; diff --git a/src/simulator/definitions/scenes/jbc20-Amazing-New.ts b/src/simulator/definitions/scenes/jbc20-Amazing-New.ts new file mode 100644 index 00000000..df67f1bd --- /dev/null +++ b/src/simulator/definitions/scenes/jbc20-Amazing-New.ts @@ -0,0 +1,244 @@ +import Scene from '../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits } from '../../../util/math/unitMath'; +import { Distance } from '../../../util'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +import tr from '@i18n'; +import Node from 'state/State/Scene/Node'; + +const baseScene = createBaseSceneSurfaceA(); + +const inStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot started in start box!', type, otherNodeId, scene.programStatus); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('inStartBox', true); + } +}, 'startBox'); +`; + +const bumpReams = ` +// Checks if reams are bumped in order + +let reamTouchedList = [false, false, false, false]; + +scene.addOnCollisionListener('ream1', (otherNodeId) => { + //If front bumper is pressed + if(scene.nodes['robot'].state.getDigitalValue(0) == 1) { + scene.setChallengeEventValue('ream1Touched', true); + reamTouchedList[0] = true; + } +}, 'robot'); + +scene.addOnCollisionListener('ream2', (otherNodeId) => { + //If front bumper is pressed + if(scene.nodes['robot'].state.getDigitalValue(0) == 1 && reamTouchedList[0]) { + scene.setChallengeEventValue('ream2Touched', true); + reamTouchedList[1] = true; + } +}, 'robot'); + +scene.addOnCollisionListener('ream3', (otherNodeId) => { + //If front bumper is pressed + if(scene.nodes['robot'].state.getDigitalValue(0) == 1 && reamTouchedList[1]) { + scene.setChallengeEventValue('ream3Touched', true); + reamTouchedList[2] = true; + } +}, 'robot'); + +scene.addOnCollisionListener('ream4', (otherNodeId) => { + //If front bumper is pressed + if(scene.nodes['robot'].state.getDigitalValue(0) == 1 && reamTouchedList[2]) { + scene.setChallengeEventValue('ream4Touched', true); + reamTouchedList[3] = true; + } +}, 'robot'); +`; + +const ROBOT_ORIGIN: ReferenceFramewUnits = { + ...baseScene.nodes['robot'].origin, + position: { + ...baseScene.nodes['robot'].origin.position, + x: Distance.inches(9), + }, +}; + +const MATA_ORIGIN: ReferenceFramewUnits = { + ...baseScene.nodes['matA'].origin, + position: { + ...baseScene.nodes['matA'].origin.position, + x: Distance.inches(12), + }, +}; + +const MATB_ORIGIN: ReferenceFramewUnits = { + position: { + x: Distance.inches(-12), + y: Distance.centimeters(-7), + z: Distance.centimeters(50), + }, + orientation: RotationwUnits.eulerDegrees(0, 0, 0) +}; + +const REAM1_ORIGIN: ReferenceFramewUnits = { + position: { + x: Distance.inches(18.5), + y: Distance.inches(2), + z: Distance.inches(43), + }, + orientation: RotationwUnits.eulerDegrees(90, 0, 0) +}; + +const REAM2_ORIGIN: ReferenceFramewUnits = { + position: { + x: Distance.inches(-23), + y: Distance.inches(2), + z: Distance.inches(38.5), + }, + orientation: RotationwUnits.eulerDegrees(90, 90, 0) +}; + +const REAM3_ORIGIN: ReferenceFramewUnits = { + position: { + x: Distance.inches(-18.5), + y: Distance.inches(2), + z: Distance.inches(-3), + }, + orientation: RotationwUnits.eulerDegrees(90, 0, 0) +}; + +const REAM4_ORIGIN: ReferenceFramewUnits = { + position: { + x: Distance.inches(23), + y: Distance.inches(2), + z: Distance.inches(1.5), + }, + orientation: RotationwUnits.eulerDegrees(90, 90, 0) +}; + +export const JBC_20: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 20' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 20: A'mazing`, + }, + scripts: { + inStartBox: Script.ecmaScript("In Start Box", inStartBox), + bumpReams: Script.ecmaScript("Bump Reams", bumpReams), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + startBox_geom: { + type: 'box', + size: { + x: Distance.centimeters(16), + y: Distance.centimeters(0.1), + z: Distance.centimeters(10), + }, + }, + }, + nodes: { + ...baseScene.nodes, + robot: { + ...baseScene.nodes.robot, + origin: ROBOT_ORIGIN, + startingOrigin: ROBOT_ORIGIN, + }, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + startBox: { + type: 'object', + geometryId: 'startBox_geom', + name: { [LocalizedString.EN_US]: 'Start Box' }, + visible: false, + origin: { + position: { + x: Distance.inches(17.85), + y: Distance.centimeters(-6.89), + z: Distance.centimeters(10.685), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 0, 255), + }, + }, + }, + matA: { + ...baseScene.nodes.matA, + origin: MATA_ORIGIN, + startingOrigin: MATA_ORIGIN, + }, + matB: { + type: 'from-jbc-template', + templateId: 'matB', + name: tr('JBC Mat B'), + startingOrigin: MATB_ORIGIN, + origin: MATB_ORIGIN, + visible: true, + }, + ream1: { + type: 'from-jbc-template', + templateId: 'ream', + name: tr('Paper Ream 1'), + startingOrigin: REAM1_ORIGIN, + origin: REAM1_ORIGIN, + visible: true, + }, + ream2: { + type: 'from-jbc-template', + templateId: 'ream', + name: tr('Paper Ream 2'), + startingOrigin: REAM2_ORIGIN, + origin: REAM2_ORIGIN, + visible: true, + }, + ream3: { + type: 'from-jbc-template', + templateId: 'ream', + name: tr('Paper Ream 3'), + startingOrigin: REAM3_ORIGIN, + origin: REAM3_ORIGIN, + visible: true, + }, + ream4: { + type: 'from-jbc-template', + templateId: 'ream', + name: tr('Paper Ream 4'), + startingOrigin: REAM4_ORIGIN, + origin: REAM4_ORIGIN, + visible: true, + }, + }, +}; diff --git a/src/simulator/definitions/scenes/jbcBase.ts b/src/simulator/definitions/scenes/jbcBase.ts index 90dd9a6c..ae972191 100644 --- a/src/simulator/definitions/scenes/jbcBase.ts +++ b/src/simulator/definitions/scenes/jbcBase.ts @@ -90,7 +90,7 @@ export function createBaseSceneSurfaceA(): Scene { startingOrigin: JBC_MAT_ORIGIN, origin: JBC_MAT_ORIGIN, visible: true, - editable: true, + editable: false, }, 'ground': { type: 'object', @@ -168,7 +168,7 @@ export function createBaseSceneSurfaceB(): Scene { startingOrigin: JBC_MAT_ORIGIN, origin: JBC_MAT_ORIGIN, visible: true, - editable: true, + editable: false, }, 'ground': { type: 'object', diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index c080e877..0bd765c6 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -40,7 +40,8 @@ import jbc15 from "../../simulator/definitions/challenges/jbc15-Go-Fetch-New"; import jbc17 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; // import jbc17b from "../../simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2"; import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; -// import jbc20 from "../../simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans"; +import jbc19 from "../../simulator/definitions/challenges/jbc19-Bump-New"; +import jbc20 from "../../simulator/definitions/challenges/jbc20-Amazing-New"; // import jbc21 from "../../simulator/definitions/challenges/archived/jbc21-Foot-Tall"; import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; @@ -268,14 +269,14 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc18, brief: ChallengeBrief.fromChallenge(jbc18), }), - // 'jbc19': Async.loaded({ - // value: jbc19, - // brief: ChallengeBrief.fromChallenge(jbc19), - // }), - // 'jbc20': Async.loaded({ - // value: jbc20, - // brief: ChallengeBrief.fromChallenge(jbc20), - // }), + 'jbc19': Async.loaded({ + value: jbc19, + brief: ChallengeBrief.fromChallenge(jbc19), + }), + 'jbc20': Async.loaded({ + value: jbc20, + brief: ChallengeBrief.fromChallenge(jbc20), + }), // 'jbc21': Async.loaded({ // value: jbc21, // brief: ChallengeBrief.fromChallenge(jbc21), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index 98c58488..3c704815 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -323,8 +323,8 @@ const DEFAULT_SCENES: Scenes = { jbc17: Async.loaded({ value: JBC_SCENES.JBC_17 }), // jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), jbc18: Async.loaded({ value: JBC_SCENES.JBC_18 }), - // jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), - // jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), + jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), + 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 }), diff --git a/static/object_binaries/chassis.glb b/static/object_binaries/chassis.glb index 9a27533e..bd0b5f8a 100644 --- a/static/object_binaries/chassis.glb +++ b/static/object_binaries/chassis.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5828874b778bd827d38e9ec89cc79efcbc31ef441d6340d60326509a4a0d82da -size 15930428 +oid sha256:d97786cb789a76b06695f9649b1dee042d22430b69fad608dd787ddbbe3b1c6e +size 6277152 From dc63ff782c3f8bc590056c606af7727c0297630d Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Wed, 23 Oct 2024 05:17:12 -0600 Subject: [PATCH 13/22] JBC 21 finished. Fixed bug where inches was not converting from meters or centimeters correctly. --- .../challenges/jbc21-Proximity-New.ts | 90 +++++++++ src/simulator/definitions/scenes/index.ts | 1 + .../definitions/scenes/jbc21-Proximity-New.ts | 179 ++++++++++++++++++ src/state/reducer/challenges.ts | 10 +- src/state/reducer/scenes.ts | 2 +- src/util/math/Value.ts | 4 +- 6 files changed, 278 insertions(+), 8 deletions(-) create mode 100644 src/simulator/definitions/challenges/jbc21-Proximity-New.ts create mode 100644 src/simulator/definitions/scenes/jbc21-Proximity-New.ts diff --git a/src/simulator/definitions/challenges/jbc21-Proximity-New.ts b/src/simulator/definitions/challenges/jbc21-Proximity-New.ts new file mode 100644 index 00000000..f2daf20f --- /dev/null +++ b/src/simulator/definitions/challenges/jbc21-Proximity-New.ts @@ -0,0 +1,90 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 21' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 21: Proximity`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + stopAtReam: { + name: { [LocalizedString.EN_US]: "Stop at Ream" }, + description: { [LocalizedString.EN_US]: "Robot stops at ream" }, + }, + touchedReam: { + name: { [LocalizedString.EN_US]: "Bump Ream" }, + description: { [LocalizedString.EN_US]: "Robot bumps ream" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + // Ream Touching Events + stopAtReam: { + type: Expr.Type.Event, + eventId: 'stopAtReam', + }, + + completion: { + type: Expr.Type.And, + argIds: [ + 'inStartBoxOnce', + 'stopAtReam', + ], + }, + }, + rootId: 'completion', + }, + failure: { + exprs: { + // Ream Touching Events + touchedReam: { + type: Expr.Type.Event, + eventId: 'touchedReam', + }, + touchedReamOnce: { + type: Expr.Type.Once, + argId: 'touchedReam', + }, + + failure: { + type: Expr.Type.And, + argIds: [ + 'touchedReamOnce', + ], + }, + }, + rootId: 'failure', + }, + sceneId: 'jbc21', +} as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 7d5b64f8..570bb654 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -19,6 +19,7 @@ export * from './jbc17-Mountain-Rescue-New'; export * from './jbc18-Stackerz-New'; export * from './jbc19-Bump-New'; export * from './jbc20-Amazing-New'; +export * from './jbc21-Proximity-New'; export * from './jbc24-Walk-the-Line-New'; export * from './moonSandbox'; // export * from './jbc2b-Ring-Around-the-Cans-Sr'; diff --git a/src/simulator/definitions/scenes/jbc21-Proximity-New.ts b/src/simulator/definitions/scenes/jbc21-Proximity-New.ts new file mode 100644 index 00000000..47e71c32 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc21-Proximity-New.ts @@ -0,0 +1,179 @@ +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 { createCanNode, createBaseSceneSurfaceA, canPositions } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +import tr from '@i18n'; +import Node from 'state/State/Scene/Node'; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const stopAtReam = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot close enough to ream', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('stopAtReam', type === 'start'); + } +}, 'reamFrontBoundary'); +`; + +const bumpReam = ` +console.log('Bump Ream script loaded'); +scene.addOnCollisionListener('ream1', (otherNodeId) => { + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('touchedReam', true); + } +}, 'robot'); +`; + +function randomCircle(): [Vector3wUnits, Vector3wUnits] { + console.log('Get random circle'); + const circles = [3, 5, 8, 10]; + const randomCircle = circles[Math.floor(Math.random() * circles.length)]; + console.log('Random Circle:', randomCircle + 1); + const circle: Vector3wUnits = { + ...canPositions[randomCircle], + y: Distance.centimeters(5), + }; + const boundary: Vector3wUnits = { + ...canPositions[randomCircle], + y: Distance.centimeters(3.825), + z: Distance.subtract(canPositions[randomCircle].z, Distance.inches(3.125), 'inches'), + }; + console.log('Circle Position:', circle); + console.log('Boundary Position:', boundary); + return [circle, boundary]; +} + +const newRandomCircle = randomCircle(); + +const REAM1_ORIGIN: ReferenceFramewUnits = { + position: { + ...newRandomCircle[0], + }, + orientation: RotationwUnits.eulerDegrees(90, 0, 0) +}; + +const REAM_FRONT_BOUNDARY_ORIGIN: ReferenceFramewUnits = { + position: { + ...newRandomCircle[1], + }, + orientation: RotationwUnits.eulerDegrees(90, 0, 0) +}; + +export const JBC_21: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 21' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 21: Proximity`, + }, + scripts: { + notInStartBox: Script.ecmaScript('Not in Start Box', notInStartBox), + stopAtReam: Script.ecmaScript('Stop at Ream', stopAtReam), + bumpReam: Script.ecmaScript('Bump Ream', bumpReam), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + reamFrontBoundary_geom: { + type: 'box', + size: { + x: Distance.inches(11), + y: Distance.inches(4.25), + z: Distance.inches(8.5), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + reamFrontBoundary: { + type: 'object', + geometryId: 'reamFrontBoundary_geom', + name: { [LocalizedString.EN_US]: 'Ream Front Boundary' }, + visible: false, + origin: REAM_FRONT_BOUNDARY_ORIGIN, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(255, 0, 0), + }, + }, + }, + ream1: { + type: 'from-jbc-template', + templateId: 'ream', + name: tr('Paper Ream 1'), + startingOrigin: REAM1_ORIGIN, + origin: REAM1_ORIGIN, + visible: true, + }, + }, +}; diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 0bd765c6..fab3cf0e 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -42,7 +42,7 @@ import jbc17 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue- import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; import jbc19 from "../../simulator/definitions/challenges/jbc19-Bump-New"; import jbc20 from "../../simulator/definitions/challenges/jbc20-Amazing-New"; -// import jbc21 from "../../simulator/definitions/challenges/archived/jbc21-Foot-Tall"; +import jbc21 from "../../simulator/definitions/challenges/jbc21-Proximity-New"; import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; @@ -277,10 +277,10 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc20, brief: ChallengeBrief.fromChallenge(jbc20), }), - // 'jbc21': Async.loaded({ - // value: jbc21, - // brief: ChallengeBrief.fromChallenge(jbc21), - // }), + 'jbc21': Async.loaded({ + value: jbc21, + brief: ChallengeBrief.fromChallenge(jbc21), + }), // 'jbc22': Async.loaded({ // value: jbc22, // brief: ChallengeBrief.fromChallenge(jbc22), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index 3c704815..dbb8d975 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -325,7 +325,7 @@ const DEFAULT_SCENES: Scenes = { jbc18: Async.loaded({ value: JBC_SCENES.JBC_18 }), jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), - // jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), + jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), // jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), // jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }), jbc24: Async.loaded({ value: JBC_SCENES.JBC_24 }), diff --git a/src/util/math/Value.ts b/src/util/math/Value.ts index 081e31a5..7d7bd879 100644 --- a/src/util/math/Value.ts +++ b/src/util/math/Value.ts @@ -166,11 +166,11 @@ export namespace Distance { case 'inches': return distance; case 'centimeters': return { type: 'inches', - value: distance.value * 39.3701 + value: distance.value * 39.3701 / 100 }; case 'meters': return { type: 'inches', - value: distance.value * 39.3701 / 100 + value: distance.value * 39.3701 }; case 'feet': return { type: 'inches', From 269aa524323e5205f3c3315061ca3b3f4318d133 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Wed, 23 Oct 2024 08:59:40 -0600 Subject: [PATCH 14/22] Make demobot show 0 rotation when loaded. Remove extra console logs --- src/simulator/babylonBindings/RobotBinding.ts | 4 ++-- src/simulator/definitions/robots/createbot.ts | 8 ++++---- src/simulator/definitions/scenes/jbc21-Proximity-New.ts | 4 ---- src/simulator/definitions/scenes/jbcBase.ts | 2 +- src/util/LocalizedString.ts | 6 +++++- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/simulator/babylonBindings/RobotBinding.ts b/src/simulator/babylonBindings/RobotBinding.ts index 4e279731..bbb9d0c9 100644 --- a/src/simulator/babylonBindings/RobotBinding.ts +++ b/src/simulator/babylonBindings/RobotBinding.ts @@ -31,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 @@ -531,8 +532,7 @@ 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, diff --git a/src/simulator/definitions/robots/createbot.ts b/src/simulator/definitions/robots/createbot.ts index a8cb9710..a2bf3abb 100644 --- a/src/simulator/definitions/robots/createbot.ts +++ b/src/simulator/definitions/robots/createbot.ts @@ -35,8 +35,8 @@ export const CREATEBOT: Robot = { }), left_wheel: Node.motor({ parentAxis: RawVector3.create(0, 0, 1), - parentPivot: Vector3wUnits.meters(0,0.015,-.1191), - childAxis: RawVector3.Y, + parentPivot: Vector3wUnits.meters(0, 0.015, -.1191), + childAxis: RawVector3.Y, motorPort: 30, parentId: 'create', plug: Node.Motor.Plug.Inverted @@ -52,7 +52,7 @@ export const CREATEBOT: Robot = { }), right_wheel: Node.motor({ parentAxis: RawVector3.create(0, 0, -1), - parentPivot: Vector3wUnits.meters(0,0.015,0.1255), + parentPivot: Vector3wUnits.meters(0, 0.015, 0.1255), childAxis: RawVector3.Y, motorPort: 40, parentId: 'create', @@ -138,6 +138,6 @@ export const CREATEBOT: Robot = { }, origin: { position: Vector3wUnits.meters(0, 0.5, 0), - orientation: RotationwUnits.eulerDegrees(0, 0, 45), + orientation: RotationwUnits.eulerDegrees(0, 0, 0), } }; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbc21-Proximity-New.ts b/src/simulator/definitions/scenes/jbc21-Proximity-New.ts index 47e71c32..e3f6fa4e 100644 --- a/src/simulator/definitions/scenes/jbc21-Proximity-New.ts +++ b/src/simulator/definitions/scenes/jbc21-Proximity-New.ts @@ -39,10 +39,8 @@ scene.addOnCollisionListener('ream1', (otherNodeId) => { `; function randomCircle(): [Vector3wUnits, Vector3wUnits] { - console.log('Get random circle'); const circles = [3, 5, 8, 10]; const randomCircle = circles[Math.floor(Math.random() * circles.length)]; - console.log('Random Circle:', randomCircle + 1); const circle: Vector3wUnits = { ...canPositions[randomCircle], y: Distance.centimeters(5), @@ -52,8 +50,6 @@ function randomCircle(): [Vector3wUnits, Vector3wUnits] { y: Distance.centimeters(3.825), z: Distance.subtract(canPositions[randomCircle].z, Distance.inches(3.125), 'inches'), }; - console.log('Circle Position:', circle); - console.log('Boundary Position:', boundary); return [circle, boundary]; } diff --git a/src/simulator/definitions/scenes/jbcBase.ts b/src/simulator/definitions/scenes/jbcBase.ts index ae972191..b1d9c1e4 100644 --- a/src/simulator/definitions/scenes/jbcBase.ts +++ b/src/simulator/definitions/scenes/jbcBase.ts @@ -13,7 +13,7 @@ import Dict from '../../../util/objectOps/Dict'; const ROBOT_ORIGIN: ReferenceFramewUnits = { position: Vector3wUnits.centimeters(0, 0, 0), - orientation: RotationwUnits.eulerDegrees(0, -45, 0), + orientation: RotationwUnits.eulerDegrees(0, 0, 0), }; const ROBOT: Node.Robot = { diff --git a/src/util/LocalizedString.ts b/src/util/LocalizedString.ts index bf376d0c..da86d9fa 100644 --- a/src/util/LocalizedString.ts +++ b/src/util/LocalizedString.ts @@ -159,6 +159,10 @@ namespace LocalizedString { return localizedString[currentLocale]; }; + export const getOriginal = (localizedString: LocalizedString) => { + return localizedString[EN_US]; + } + export const SUPPORTED_LANGUAGES = [ LocalizedString.AR_SA, LocalizedString.BG_BG, @@ -193,7 +197,7 @@ namespace LocalizedString { LocalizedString.TH_TH, LocalizedString.TR_TR, LocalizedString.UR_PK, - LocalizedString.VI_VN, + LocalizedString.VI_VN, LocalizedString.ZH_CN, LocalizedString.ZH_TW, ]; From 114b529e71ee826b35693b6bbe4faad2ce594f67 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Tue, 29 Oct 2024 12:03:46 -0600 Subject: [PATCH 15/22] Fix robot position bug and add JBC 23 --- src/simulator/babylonBindings/RobotBinding.ts | 9 +- src/simulator/babylonBindings/SceneBinding.ts | 5 +- src/simulator/definitions/scenes/index.ts | 1 + .../definitions/scenes/jbc15-Go-Fetch-New.ts | 2 +- .../scenes/jbc23-Find-the-Black-Line-New.ts | 92 +++++++++++++++++++ src/state/reducer/scenes.ts | 2 +- 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts diff --git a/src/simulator/babylonBindings/RobotBinding.ts b/src/simulator/babylonBindings/RobotBinding.ts index bbb9d0c9..e312a002 100644 --- a/src/simulator/babylonBindings/RobotBinding.ts +++ b/src/simulator/babylonBindings/RobotBinding.ts @@ -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" ); @@ -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)); diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index ef426354..f7b6122d 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -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)); @@ -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]; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 570bb654..878e2ada 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -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'; diff --git a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts index bdba086e..e8ded99f 100644 --- a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts +++ b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts @@ -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(() => { diff --git a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts new file mode 100644 index 00000000..ead91e73 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts @@ -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), + }, + }, + }, + }, +}; diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index dbb8d975..cbd5312a 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -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 }), From 69b7c7f85f4d474eaa2ddca429db20dc4144f771 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Tue, 29 Oct 2024 14:14:04 -0600 Subject: [PATCH 16/22] Add challenge part of JBC 23, change some logic --- .../jbc23-Find-the-Black-Line-New.ts | 59 +++++++++++++ .../scenes/jbc23-Find-the-Black-Line-New.ts | 86 ++++++++++++------- src/state/reducer/challenges.ts | 9 +- 3 files changed, 119 insertions(+), 35 deletions(-) create mode 100644 src/simulator/definitions/challenges/jbc23-Find-the-Black-Line-New.ts diff --git a/src/simulator/definitions/challenges/jbc23-Find-the-Black-Line-New.ts b/src/simulator/definitions/challenges/jbc23-Find-the-Black-Line-New.ts new file mode 100644 index 00000000..d09f4498 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc23-Find-the-Black-Line-New.ts @@ -0,0 +1,59 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; +import { on } from 'form-data'; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 23' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 23: Find the Black Line`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + stopAtBlackLine: { + name: { [LocalizedString.EN_US]: "Robot Stops at Black Line" }, + description: { [LocalizedString.EN_US]: "Robot stops at black line" }, + }, + onCircle: { + name: { [LocalizedString.EN_US]: "Robot Over Circle" }, + description: { [LocalizedString.EN_US]: "Robot over selected circle" }, + }, + }, + success: { + exprs: { + onCircle: { + type: Expr.Type.Event, + eventId: "onCircle", + }, + onCircleOnce: { + type: Expr.Type.Once, + argId: "onCircle", + }, + stopAtBlackLine: { + type: Expr.Type.Event, + eventId: 'stopAtBlackLine', + }, + + completion: { + type: Expr.Type.And, + argIds: [ + 'onCircleOnce', + 'stopAtBlackLine', + ], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc23', +} as Challenge; diff --git a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts index ead91e73..2e246f80 100644 --- a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts +++ b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts @@ -3,41 +3,68 @@ import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from '../../../ut import { Distance } from '../../../util'; import LocalizedString from '../../../util/LocalizedString'; import Script from '../../../state/State/Scene/Script'; -import { createBaseSceneSurfaceA, canPositions } from './jbcBase'; +import { createBaseSceneSurfaceA, canPositions, createCircleNode } from './jbcBase'; import { Color } from '../../../state/State/Scene/Color'; +import { createCamera } from 'simulator/babylonBindings/createSceneObjects/createCameras'; 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); +scene.addOnRenderListener(() => { if(scene.programStatus === 'running'){ - if(scene.nodes['robot'].state.getAnalogValue(1) > 2000) { - scene.setChallengeEventValue('stopAtBlackLine', type === 'start'); - setNodeVisible('otherNodeId', true); + if(scene.nodes['robot'].state.getAnalogValue(1) > 3500) { + console.log('Robot crossing black line', scene.nodes['robot'].state.getAnalogValue(1)); + scene.setChallengeEventValue('stopAtBlackLine', true); + } + } +}); +`; + +const onCircle = ` +let startTime = 0; +let currentTime = 0; +let overTime = false; +scene.addOnRenderListener(() => { + if (scene.programStatus === 'running') { + if (currentTime - startTime > 500 && !overTime) { + overTime = true; + } + if (startTime === 0) { + startTime = new Date().getTime(); + } + else { + currentTime = new Date().getTime(); + if (!overTime) { + const robotPosition = scene.nodes['robot'].origin.position; + const circlePosition = scene.nodes['circle'].origin.position; + const distance = Math.sqrt( + Math.pow(robotPosition.x.value - circlePosition.x.value, 2) + + Math.pow(robotPosition.z.value - circlePosition.z.value, 2) + ); + if (distance < 1.5) { + console.log('Robot over selected circle', robotPosition, circlePosition, distance); + scene.setChallengeEventValue('onCircle', 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); + console.log('randomCircle', randomCircle); const circle: Vector3wUnits = { ...canPositions[randomCircle - 1], }; - console.log('circle: ', circle); return circle; } +const selectedCircle = randomCircle(); + const ROBOT_ORIGIN: ReferenceFramewUnits = { - position: { ...randomCircle() }, + position: { ...selectedCircle }, orientation: RotationwUnits.eulerDegrees(0, 180, 0) }; @@ -49,17 +76,15 @@ export const JBC_23: Scene = { }, scripts: { foundBlack: Script.ecmaScript('Found Black Line', foundBlack), + onCircle: Script.ecmaScript('On Circle', onCircle), }, geometry: { ...baseScene.geometry, - blackLine_geom: { - type: "box", - size: { - x: Distance.inches(24), - y: Distance.centimeters(10), - z: Distance.inches(0.65), - }, - }, + circle_geom: { + type: "cylinder", + radius: Distance.centimeters(3), + height: Distance.centimeters(10), + } }, nodes: { ...baseScene.nodes, @@ -68,16 +93,14 @@ export const JBC_23: Scene = { origin: ROBOT_ORIGIN, startingOrigin: ROBOT_ORIGIN, }, - blackLine: { + circle: { type: "object", - geometryId: "blackLine_geom", - name: { [LocalizedString.EN_US]: "Black Line" }, + geometryId: "circle_geom", + name: { [LocalizedString.EN_US]: "Circle" }, visible: true, origin: { position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-1.9), - z: Distance.inches(5.95), + ...selectedCircle, }, }, material: { @@ -87,6 +110,7 @@ export const JBC_23: Scene = { color: Color.rgb(255, 255, 255), }, }, - }, - }, + } + + } }; diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index fab3cf0e..16a885a2 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -43,6 +43,7 @@ import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; import jbc19 from "../../simulator/definitions/challenges/jbc19-Bump-New"; import jbc20 from "../../simulator/definitions/challenges/jbc20-Amazing-New"; import jbc21 from "../../simulator/definitions/challenges/jbc21-Proximity-New"; +import jbc23 from "../../simulator/definitions/challenges/jbc23-Find-the-Black-Line-New"; import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; @@ -285,10 +286,10 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc22, // brief: ChallengeBrief.fromChallenge(jbc22), // }), - // 'jbc23': Async.loaded({ - // value: jbc23, - // brief: ChallengeBrief.fromChallenge(jbc23), - // }), + 'jbc23': Async.loaded({ + value: jbc23, + brief: ChallengeBrief.fromChallenge(jbc23), + }), 'jbc24': Async.loaded({ value: jbc24, brief: ChallengeBrief.fromChallenge(jbc24), From 266e9f8110be46f7bc6a7d6763d634a9279830f1 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Tue, 29 Oct 2024 14:42:35 -0600 Subject: [PATCH 17/22] Include ET sensor fix that is on master --- src/simulator/babylonBindings/sensors/EtSensor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulator/babylonBindings/sensors/EtSensor.ts b/src/simulator/babylonBindings/sensors/EtSensor.ts index 3c2f5583..e031eea1 100644 --- a/src/simulator/babylonBindings/sensors/EtSensor.ts +++ b/src/simulator/babylonBindings/sensors/EtSensor.ts @@ -60,7 +60,7 @@ class EtSensor extends SensorObject { mesh !== this.trace_ && !links.has(mesh as Mesh) && !colliders.has(mesh as Mesh) && - (!!mesh.physicsImpostor || metadata.selected) + (!!mesh.physicsImpostor || !metadata.selected) ); }); From b36cdd693d9ec90a38d541db0c2d6aa1b1bda9f6 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 29 Oct 2024 16:04:02 -0500 Subject: [PATCH 18/22] Now using Babylon intersectsMesh function to see if two meshes intersect --- src/simulator/babylonBindings/SceneBinding.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index f7b6122d..1c952ae3 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -5,7 +5,9 @@ import { ArcRotateCamera, PointLight, SpotLight, DirectionalLight, PBRMaterial, EngineView, Scene as babylonScene, Node as babylonNode, Camera as babylCamera, Material as babylMaterial, Observer, BoundingBox, - Color3 + Color3, BoundingBoxGizmo, + MeshBuilder, + BoundingInfo } from '@babylonjs/core'; // eslint-disable-next-line @typescript-eslint/no-duplicate-imports -- Required import for side effects @@ -123,12 +125,15 @@ class SceneBinding { this.gizmoManager_.rotationGizmoEnabled = true; this.gizmoManager_.scaleGizmoEnabled = false; this.gizmoManager_.usePointerToAttachGizmos = false; - // Uncomment for bounding boxes in scene - // this.gizmoManager_.boundingBoxGizmoEnabled = true; - // this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); + this.gizmoManager_.boundingBoxGizmoEnabled = true; + this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(1, 0, 0)); + this.scriptManager_.onCollisionFiltersChanged = this.onCollisionFiltersChanged_; this.scriptManager_.onIntersectionFiltersChanged = this.onIntersectionFiltersChanged_; + + + } private robotLinkOrigins_: Dict> = {}; @@ -251,6 +256,7 @@ class SceneBinding { switch (nodeToCreate.type) { case 'object': { const parent = this.findBNode_(nodeToCreate.parentId, true); + ret = await createObject(nodeToCreate, nextScene, parent, this.bScene_); break; } case 'empty': { @@ -288,6 +294,7 @@ class SceneBinding { // if (node.origin && bNode instanceof TransformNode || bNode instanceof AbstractMesh) { if (node.origin && bNode instanceof AbstractMesh) { this.removePhysicsFromObject(bNode); + const origin = node.origin || {}; const position: Vector3wUnits = origin.position ?? Vector3wUnits.zero(); const orientation: RotationwUnits = origin.orientation ?? RotationwUnits.EulerwUnits.identity(); @@ -303,12 +310,15 @@ class SceneBinding { bNode.position.z = Distance.toCentimetersValue(position.z || Distance.centimeters(0)); bNode.rotationQuaternion = RawQuaternion.toBabylon(RotationwUnits.toRawQuaternion(orientation)); + bNode.scaling.set(scale.x, scale.y, scale.z); this.restorePhysicsToObject(bNode, node as Node.Obj, nodeId, scene); } }; + + private updateEmpty_ = (id: string, node: Patch.InnerChange): TransformNode => { const bNode = this.findBNode_(id) as TransformNode; @@ -964,19 +974,11 @@ class SceneBinding { if (nodeMeshes.length === 0) continue; try { - const nodeBoundingBoxes = this.nodeBoundingBoxes_(nodeId); + const filterIds = this.intersectionFilters_[nodeId]; for (const filterId of filterIds) { - const filterMinMaxes = this.nodeMinMaxes_(filterId); - let intersection = false; - for (const nodeBoundingBox of nodeBoundingBoxes) { - for (const filterMinMax of filterMinMaxes) { - intersection = nodeBoundingBox.intersectsMinMax(filterMinMax.min, filterMinMax.max); - if (intersection) break; - } - if (intersection) break; - } + const intersection = this.nodeMeshes_(nodeId)[0].intersectsMesh(this.nodeMeshes_(filterId)[0], true); if (intersection) { if (!this.currentIntersections_[nodeId]) this.currentIntersections_[nodeId] = new Set(); From bfd90c3d8c0b18306a1e2a553992e448200a5036 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 29 Oct 2024 16:04:45 -0500 Subject: [PATCH 19/22] Added JBC16-Pick-Em-Up-New scene and challenge --- .../challenges/jbc16-Pick-Em-Up-New.ts | 133 +++++++ src/simulator/definitions/scenes/index.ts | 1 + .../scenes/jbc16-Pick-Em-Up-New.ts | 366 ++++++++++++++++++ 3 files changed, 500 insertions(+) create mode 100644 src/simulator/definitions/challenges/jbc16-Pick-Em-Up-New.ts create mode 100644 src/simulator/definitions/scenes/jbc16-Pick-Em-Up-New.ts diff --git a/src/simulator/definitions/challenges/jbc16-Pick-Em-Up-New.ts b/src/simulator/definitions/challenges/jbc16-Pick-Em-Up-New.ts new file mode 100644 index 00000000..5f03fa5a --- /dev/null +++ b/src/simulator/definitions/challenges/jbc16-Pick-Em-Up-New.ts @@ -0,0 +1,133 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 16' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 16: Pick 'Em Up`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + + leaveStartBox: { + name: { [LocalizedString.EN_US]: 'Robot Left Start' }, + description: { [LocalizedString.EN_US]: 'Robot left starting box' }, + }, + + can2Upright: { + name: { [LocalizedString.EN_US]: 'Can 2 Upright' }, + description: { [LocalizedString.EN_US]: 'Can 2 upright' }, + }, + can9Upright: { + name: { [LocalizedString.EN_US]: 'Can 9 Upright' }, + description: { [LocalizedString.EN_US]: 'Can 9 upright' }, + }, + can10Upright: { + name: { [LocalizedString.EN_US]: 'Can 10 Upright' }, + description: { [LocalizedString.EN_US]: 'Can 10 upright' }, + }, + + can2Intersects: { + name: { [LocalizedString.EN_US]: 'Can 2 Intersects Green Garage' }, + description: { [LocalizedString.EN_US]: 'Can 2 intersects Green Garage' }, + }, + can9Intersects: { + name: { [LocalizedString.EN_US]: 'Can 9 Intersects Blue Garage' }, + description: { [LocalizedString.EN_US]: 'Can 9 intersects Blue Garage' }, + }, + can9IntersectsPurple: { + name: { [LocalizedString.EN_US]: 'Can 9 Intersects Purple Garage' }, + description: { [LocalizedString.EN_US]: 'Can 9 intersects Purple Garage' }, + }, + can10Intersects: { + name: { [LocalizedString.EN_US]: 'Can 10 Intersects Yellow Garage' }, + description: { [LocalizedString.EN_US]: 'Can 10 intersects Yellow Garage' }, + }, + + }, + success: { + exprs: { + // Start Box Events + leaveStartBox: { + type: Expr.Type.Event, + eventId: 'leaveStartBox', + }, + leaveStartBoxOnce: { + type: Expr.Type.Once, + argId: 'leaveStartBox', + }, + + + // Upright Events + can2Upright: { + type: Expr.Type.Event, + eventId: 'can2Upright', + }, + can9Upright: { + type: Expr.Type.Event, + eventId: 'can9Upright', + }, + can10Upright: { + type: Expr.Type.Event, + eventId: 'can10Upright', + }, + + // Intersects Events + can2Intersects: { + type: Expr.Type.Event, + eventId: 'can2Intersects', + }, + can9Intersects: { + type: Expr.Type.Event, + eventId: 'can9Intersects', + }, + can10Intersects: { + type: Expr.Type.Event, + eventId: 'can10Intersects', + }, + + // Upright and Intersects logic + can2UprightAndIntersects: { + type: Expr.Type.And, + argIds: ['can2Upright', 'can2Intersects'], + }, + can9UprightAndIntersects: { + type: Expr.Type.And, + argIds: ['can9Upright', 'can9Intersects'], + }, + can10UprightAndIntersects: { + type: Expr.Type.And, + argIds: ['can10Upright', 'can10Intersects'], + }, + + // Final And Logic + cansUprightAndIntersects: { + type: Expr.Type.And, + argIds: ['can2UprightAndIntersects', 'can9UprightAndIntersects', 'can10UprightAndIntersects',], + }, + + + + // Success logic + completion: { + type: Expr.Type.And, + argIds: ['leaveStartBoxOnce', 'cansUprightAndIntersects'], + }, + }, + rootId: 'completion', + }, + + sceneId: 'jbc16', +} as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 878e2ada..da5c2692 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -15,6 +15,7 @@ export * from './jbc11-Making-Waves-New'; export * from './jbc12-Add-It-Up-New'; export * from './jbc14-Dance-Party'; export * from './jbc15-Go-Fetch-New'; +export * from './jbc16-Pick-Em-Up-New'; export * from './jbc17-Mountain-Rescue-New'; export * from './jbc18-Stackerz-New'; export * from './jbc19-Bump-New'; diff --git a/src/simulator/definitions/scenes/jbc16-Pick-Em-Up-New.ts b/src/simulator/definitions/scenes/jbc16-Pick-Em-Up-New.ts new file mode 100644 index 00000000..ebf7d3d1 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc16-Pick-Em-Up-New.ts @@ -0,0 +1,366 @@ +import Scene from '../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits } from '../../../util/math/unitMath'; +import { Distance, Angle } from '../../../util'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { canPositions, createBaseSceneSurfaceA, createBaseSceneSurfaceB, createCanNode } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; +import Robot from 'state/State/Robot'; +import Node from 'state/State/Scene/Node'; + +const baseScene = createBaseSceneSurfaceA(); + + + +const leftStartBox = ` + +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot left start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('leaveStartBox', type === 'end'); + } + +}, 'startBox'); +`; + + +const canIntersectsGarage = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + + +// When the can (can2) is intersecting the green garage, the garage glows +scene.addOnIntersectionListener('can2', (type, otherNodeId) => { + console.log('Can 2 placed!', type, otherNodeId); + const visible = type === 'start'; + scene.setChallengeEventValue('can2Intersects', visible); + setNodeVisible('greenGarage', visible); +}, 'greenGarage'); + +// When the can (can9) is intersecting the blue garage, the garage glows +scene.addOnIntersectionListener('can9', (type, otherNodeId) => { + console.log('Can 9 intersects blue!', type, otherNodeId); + const visible = type === 'start'; + scene.setChallengeEventValue('can9Intersects', visible); + setNodeVisible('blueGarage', visible); +}, 'blueGarage'); + + + + +scene.addOnIntersectionListener('can10', (type, otherNodeId) => { + console.log('Can 10 placed!', type, otherNodeId); + const visible = type === 'start'; + scene.setChallengeEventValue('can10Intersects', visible); + setNodeVisible('yellowGarage', visible); +}, 'yellowGarage'); + + +`; + + +const uprightCans = ` +// When a can is standing upright, the upright condition is met. + +// let startTime = Date.now(); +const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); +// const startingOrientationInv = (nodeId) => Quaternion.inverse(RotationwUnits.toRawQuaternion(scene.nodes[nodeId].startingOrigin.orientation || EULER_IDENTITY)); +const yAngle = (nodeId) => -180 / Math.PI * Math.asin(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y)); + + +scene.addOnRenderListener(() => { + const upright2 = yAngle('can2') > 5; + //console.log('can2 angle: ', yAngle('can2')); + scene.setChallengeEventValue('can2Upright', upright2); + +}); +scene.addOnRenderListener(() => { + const upright9 = yAngle('can9') > 5; + // console.log('can9 angle: ', yAngle('can9')); + scene.setChallengeEventValue('can9Upright', upright9); + +}); +scene.addOnRenderListener(() => { + const upright10 = yAngle('can10') > 5; + // console.log('can10 angle: ', yAngle('can10')); + scene.setChallengeEventValue('can10Upright', upright10); + +}); +`; + + + +const ROBOT_ORIGIN: ReferenceFramewUnits = { + ...baseScene.nodes['robot'].origin, + position: { + ...baseScene.nodes['robot'].origin.position, + + }, +}; + +export const JBC_16: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 16' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 16: Pick 'Em Up`, + }, + scripts: { + uprightCans: Script.ecmaScript('Upright Cans', uprightCans), + canIntersectsGarage: Script.ecmaScript('Can Intersects Garage', canIntersectsGarage), + leftStartBox: Script.ecmaScript('Left Start Box', leftStartBox), + }, + geometry: { + ...baseScene.geometry, + circle_geom: { + type: 'cylinder', + radius: Distance.centimeters(3), + height: Distance.centimeters(0.1), + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + startBox_geom: { + type: 'box', + size: { + x: Distance.centimeters(59), + y: Distance.centimeters(0.1), + z: Distance.centimeters(30), + }, + }, + greenGarage_geom: { + type: 'box', + size: { + x: Distance.centimeters(23), + y: Distance.centimeters(0.1), + z: Distance.centimeters(23), + }, + }, + yellowGarage_geom: { + type: 'box', + size: { + x: Distance.centimeters(19), + y: Distance.centimeters(0.1), + z: Distance.centimeters(19), + }, + }, + blueGarage_geom: { + type: 'box', + size: { + x: Distance.centimeters(20.5), + y: Distance.centimeters(0.1), + z: Distance.centimeters(21), + }, + }, + + + endBox_geom: { + type: 'box', + size: { + x: Distance.inches(24), + y: Distance.centimeters(15), + z: Distance.centimeters(1), + }, + }, + + }, + nodes: { + ...baseScene.nodes, + robot: { + ...baseScene.nodes['robot'], + startingOrigin: ROBOT_ORIGIN, + origin: ROBOT_ORIGIN, + }, + startBox: { + type: 'object', + geometryId: 'startBox_geom', + name: { [LocalizedString.EN_US]: 'Start Box' }, + visible: true, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.89), + z: Distance.centimeters(0.6), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 0, 255), + }, + }, + }, + greenGarage: { + type: 'object', + geometryId: 'greenGarage_geom', + name: { [LocalizedString.EN_US]: 'Green Garage' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0.1), + y: Distance.centimeters(-6.89), + z: Distance.centimeters(53), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 255, 0), + }, + }, + }, + yellowGarage: { + type: 'object', + geometryId: 'yellowGarage_geom', + name: { [LocalizedString.EN_US]: 'Yellow Garage' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(18.8), + y: Distance.centimeters(-6.89), + z: Distance.centimeters(78.2), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(255, 0, 0), + }, + }, + }, + + blueGarage: { + type: 'object', + geometryId: 'blueGarage_geom', + name: { [LocalizedString.EN_US]: 'Blue Garage' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(-12.6), + y: Distance.centimeters(-6.89), + z: Distance.centimeters(94.1), + }, + orientation: { + type: 'euler', + x: Angle.degrees(0), + y: Angle.degrees(45), + z: Angle.degrees(0), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(0, 0, 255), + }, + }, + editable: true, + + }, + + endBox: { + type: 'object', + geometryId: 'endBox_geom', + name: { [LocalizedString.EN_US]: 'End Box' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(0), + z: Distance.inches(43.685), // 24 for half the mat and 19.685 for the mat's origin + }, + }, + material: { + type: 'pbr', + emissive: { + type: 'color3', + color: Color.rgb(0, 255, 0), + }, + }, + }, + + circle2: { + type: 'object', + geometryId: 'circle_geom', + name: { [LocalizedString.EN_US]: 'Circle 2' }, + visible: true, + origin: { + position: { + ...canPositions[1], + y: Distance.centimeters(-6.9), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(25, 29, 95), + }, + + }, + }, + + circle9: { + type: 'object', + geometryId: 'circle_geom', + name: { [LocalizedString.EN_US]: 'Circle 9' }, + visible: true, + origin: { + position: { + ...canPositions[8], + y: Distance.centimeters(-6.9), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(25, 29, 95), + }, + + }, + }, + + circle10: { + type: 'object', + geometryId: 'circle_geom', + name: { [LocalizedString.EN_US]: 'Circle 10' }, + visible: true, + origin: { + position: { + ...canPositions[9], + y: Distance.centimeters(-6.9), + }, + }, + material: { + type: 'basic', + color: { + type: 'color3', + color: Color.rgb(25, 29, 95), + }, + + }, + }, + + + can2: { + ...createCanNode(2, { x: Distance.centimeters(0), y: Distance.centimeters(0), z: Distance.centimeters(28.8) }), + }, + + can9: { + ...createCanNode(9, { x: Distance.centimeters(0), y: Distance.centimeters(0), z: Distance.centimeters(85.4) }, true), + }, + can10: { + ...createCanNode(10, { x: Distance.centimeters(19.3), y: Distance.centimeters(0), z: Distance.centimeters(96.9) }, false), + } + }, +}; From 9d0b6bc261e8936afe57a6019605c8fc7e81d4d5 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 29 Oct 2024 16:05:20 -0500 Subject: [PATCH 20/22] Added JBC16 to state reducer in challenges.ts and scenes.ts --- src/state/reducer/challenges.ts | 15 ++++++++++----- src/state/reducer/scenes.ts | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 16a885a2..6384d086 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -32,11 +32,12 @@ import jbc9 from "../../simulator/definitions/challenges/jbc9-Cover-Your-Bases-N import jbc10 from "../../simulator/definitions/challenges/jbc10-Chopped-New"; // import jbc10b from "../../simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr"; import jbc11 from "../../simulator/definitions/challenges/jbc11-Making-Waves-New"; -// import jbc12 from "../../simulator/definitions/challenges/archived/jbc12-Unload-Em"; +import jbc12 from "../../simulator/definitions/challenges/jbc12-Add-It-Up-New"; // import jbc13 from "../../simulator/definitions/challenges/archived/jbc13-Clean-the-Mat"; import jbc14 from "../../simulator/definitions/challenges/jbc14-Dance-Party"; import jbc15 from "../../simulator/definitions/challenges/jbc15-Go-Fetch-New"; // import jbc15b from "../../simulator/definitions/challenges/archived/jbc15b-Bump-Bump"; +import jbc16 from "../../simulator/definitions/challenges/jbc16-Pick-Em-Up-New"; import jbc17 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; // import jbc17b from "../../simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2"; import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; @@ -238,10 +239,10 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc11, brief: ChallengeBrief.fromChallenge(jbc11), }), - // 'jbc12': Async.loaded({ - // value: jbc12, - // brief: ChallengeBrief.fromChallenge(jbc12), - // }), + 'jbc12': Async.loaded({ + value: jbc12, + brief: ChallengeBrief.fromChallenge(jbc12), + }), // 'jbc13': Async.loaded({ // value: jbc13, // brief: ChallengeBrief.fromChallenge(jbc13), @@ -258,6 +259,10 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc15b, // brief: ChallengeBrief.fromChallenge(jbc15b), // }), + 'jbc16': Async.loaded({ + value: jbc16, + brief: ChallengeBrief.fromChallenge(jbc16), + }), 'jbc17': Async.loaded({ value: jbc17, brief: ChallengeBrief.fromChallenge(jbc17), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index cbd5312a..df35a661 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -315,11 +315,12 @@ const DEFAULT_SCENES: Scenes = { jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), // jbc10b: Async.loaded({ value: JBC_SCENES.JBC_10B }), jbc11: Async.loaded({ value: JBC_SCENES.JBC_11 }), - // jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), + jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), // jbc13: Async.loaded({ value: JBC_SCENES.JBC_13 }), jbc14: Async.loaded({ value: JBC_SCENES.JBC_14 }), jbc15: Async.loaded({ value: JBC_SCENES.JBC_15 }), // jbc15b: Async.loaded({ value: JBC_SCENES.JBC_15B }), + jbc16: Async.loaded({ value: JBC_SCENES.JBC_16 }), jbc17: Async.loaded({ value: JBC_SCENES.JBC_17 }), // jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), jbc18: Async.loaded({ value: JBC_SCENES.JBC_18 }), From 730f72c8f7c63ad90d560438c3823afc6e5f6267 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Wed, 30 Oct 2024 04:18:33 -0600 Subject: [PATCH 21/22] Complete JBC 22. Cleanup in 15 and 23 --- .../challenges/jbc22-Search-and-Rescue-New.ts | 74 ++++++++++ src/simulator/definitions/scenes/index.ts | 1 + .../definitions/scenes/jbc15-Go-Fetch-New.ts | 28 ---- .../scenes/jbc22-Search-and-Rescue-New.ts | 132 ++++++++++++++++++ .../scenes/jbc23-Find-the-Black-Line-New.ts | 1 - src/state/reducer/challenges.ts | 9 +- src/state/reducer/scenes.ts | 2 +- 7 files changed, 213 insertions(+), 34 deletions(-) create mode 100644 src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts create mode 100644 src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts diff --git a/src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts b/src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts new file mode 100644 index 00000000..df40f7a6 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc22-Search-and-Rescue-New.ts @@ -0,0 +1,74 @@ +import Author from '../../../db/Author'; +import Challenge from '../../../state/State/Challenge'; +import Expr from '../../../state/State/Challenge/Expr'; +import LocalizedString from '../../../util/LocalizedString'; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: 'JBC Challenge 22' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 22: Search and Rescue`, + }, + author: { + type: Author.Type.Organization, + id: 'kipr', + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: 'c', + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + canInStartBox: { + name: { [LocalizedString.EN_US]: "Can in Start Box" }, + description: { [LocalizedString.EN_US]: "Can in start box" }, + }, + canUpright: { + name: { [LocalizedString.EN_US]: "Can Upright" }, + description: { [LocalizedString.EN_US]: "Can is upright" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + // Can Events + canInStartBox: { + type: Expr.Type.Event, + eventId: "canInStartBox", + }, + canUpright: { + type: Expr.Type.Event, + eventId: "canUpright", + }, + + completion: { + type: Expr.Type.And, + argIds: [ + 'inStartBoxOnce', + 'canInStartBox', + 'canUpright', + ], + }, + }, + rootId: 'completion', + }, + sceneId: 'jbc22', +} as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index da5c2692..2bc68f0e 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -21,6 +21,7 @@ export * from './jbc18-Stackerz-New'; export * from './jbc19-Bump-New'; export * from './jbc20-Amazing-New'; export * from './jbc21-Proximity-New'; +export * from './jbc22-Search-and-Rescue-New'; export * from './jbc23-Find-the-Black-Line-New'; export * from './jbc24-Walk-the-Line-New'; export * from './moonSandbox'; diff --git a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts index e8ded99f..1348314e 100644 --- a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts +++ b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts @@ -59,14 +59,6 @@ export const JBC_15: Scene = { }, geometry: { ...baseScene.geometry, - mainSurface_geom: { - type: "box", - size: { - x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.meters(3.54), - }, - }, startBox_geom: { type: "box", size: { @@ -87,26 +79,6 @@ export const JBC_15: Scene = { nodes: { ...baseScene.nodes, - mainSurface: { - type: "object", - geometryId: "mainSurface_geom", - name: { [LocalizedString.EN_US]: "Mat Surface" }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.inches(19.75), - }, - }, - material: { - type: "basic", - color: { - type: "color3", - color: Color.rgb(0, 0, 0), - }, - }, - }, startBox: { type: "object", geometryId: "startBox_geom", diff --git a/src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts b/src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts new file mode 100644 index 00000000..7b2b2272 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc22-Search-and-Rescue-New.ts @@ -0,0 +1,132 @@ +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 { createCanNode, createBaseSceneSurfaceA, canPositions } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +import tr from '@i18n'; +import Node from 'state/State/Scene/Node'; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const enterStartBox = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + + +scene.addOnIntersectionListener('can', (type, otherNodeId) => { + console.log('Robot returned start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('canInStartBox', type === 'start'); + setNodeVisible('startBox', type == 'start'); + } +}, 'startBox'); +`; + +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 * -1 * Math.asin(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y)); + + +scene.addOnRenderListener(() => { + const upright = yAngle('can') > 5; + scene.setChallengeEventValue('canUpright', upright); +}); +`; + +function randomCan(): number { + const cans = [2, 4, 6]; + const randomCan = cans[Math.floor(Math.random() * cans.length)]; + return randomCan; +} + +export const JBC_22: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 22' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 22: Search and Rescue`, + }, + scripts: { + notInStartBox: Script.ecmaScript('Not in Start Box', notInStartBox), + enterStartBox: Script.ecmaScript('Enter Start Box', enterStartBox), + uprightCan: Script.ecmaScript('Upright Can', uprightCan), + }, + geometry: { + ...baseScene.geometry, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + startBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.centimeters(30), + }, + }, + }, + nodes: { + ...baseScene.nodes, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + startBox: { + type: "object", + geometryId: "startBox_geom", + name: { [LocalizedString.EN_US]: "Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.centimeters(-3), + }, + }, + material: { + type: "pbr", + emissive: { + type: "color3", + color: Color.rgb(255, 255, 255), + }, + }, + }, + can: createCanNode(randomCan()), + }, +}; diff --git a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts index 2e246f80..cb0bcb21 100644 --- a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts +++ b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts @@ -54,7 +54,6 @@ scene.addOnRenderListener(() => { 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], }; diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 6384d086..17eb2993 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -44,6 +44,7 @@ import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; import jbc19 from "../../simulator/definitions/challenges/jbc19-Bump-New"; import jbc20 from "../../simulator/definitions/challenges/jbc20-Amazing-New"; import jbc21 from "../../simulator/definitions/challenges/jbc21-Proximity-New"; +import jbc22 from "../../simulator/definitions/challenges/jbc22-Search-and-Rescue-New"; import jbc23 from "../../simulator/definitions/challenges/jbc23-Find-the-Black-Line-New"; import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; @@ -287,10 +288,10 @@ const DEFAULT_CHALLENGES: Challenges = { value: jbc21, brief: ChallengeBrief.fromChallenge(jbc21), }), - // 'jbc22': Async.loaded({ - // value: jbc22, - // brief: ChallengeBrief.fromChallenge(jbc22), - // }), + 'jbc22': Async.loaded({ + value: jbc22, + brief: ChallengeBrief.fromChallenge(jbc22), + }), 'jbc23': Async.loaded({ value: jbc23, brief: ChallengeBrief.fromChallenge(jbc23), diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index df35a661..3c36ed1d 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -327,7 +327,7 @@ const DEFAULT_SCENES: Scenes = { jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), - // jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), + jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }), jbc24: Async.loaded({ value: JBC_SCENES.JBC_24 }), // scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }), From 463fea734404ebf6c47e13867ef4d771128e8588 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Wed, 30 Oct 2024 05:22:23 -0600 Subject: [PATCH 22/22] Cleanup JBC 0-2 --- .../{jbc0.ts => jbc0-Drive-Straight.ts} | 8 - .../{jbc1.ts => jbc1-Tag-Youre-It.ts} | 80 ++++---- .../{jbc2.ts => jbc2-Ring-Around-the-Can.ts} | 99 +++++----- src/simulator/definitions/scenes/index.ts | 6 +- .../{jbc0.ts => jbc0-Drive-Straight.ts} | 50 +---- .../definitions/scenes/jbc1-Tag-Youre-It.ts | 138 +++++++++++++ src/simulator/definitions/scenes/jbc1.ts | 183 ------------------ .../{jbc2.ts => jbc2-Ring-Around-the-Can.ts} | 126 ++++-------- src/simulator/definitions/scenes/jbcBase.ts | 2 +- src/state/reducer/challenges.ts | 6 +- 10 files changed, 276 insertions(+), 422 deletions(-) rename src/simulator/definitions/challenges/{jbc0.ts => jbc0-Drive-Straight.ts} (92%) rename src/simulator/definitions/challenges/{jbc1.ts => jbc1-Tag-Youre-It.ts} (74%) rename src/simulator/definitions/challenges/{jbc2.ts => jbc2-Ring-Around-the-Can.ts} (73%) rename src/simulator/definitions/scenes/{jbc0.ts => jbc0-Drive-Straight.ts} (83%) create mode 100644 src/simulator/definitions/scenes/jbc1-Tag-Youre-It.ts delete mode 100644 src/simulator/definitions/scenes/jbc1.ts rename src/simulator/definitions/scenes/{jbc2.ts => jbc2-Ring-Around-the-Can.ts} (67%) diff --git a/src/simulator/definitions/challenges/jbc0.ts b/src/simulator/definitions/challenges/jbc0-Drive-Straight.ts similarity index 92% rename from src/simulator/definitions/challenges/jbc0.ts rename to src/simulator/definitions/challenges/jbc0-Drive-Straight.ts index cf3016a6..9831d6cf 100644 --- a/src/simulator/definitions/challenges/jbc0.ts +++ b/src/simulator/definitions/challenges/jbc0-Drive-Straight.ts @@ -59,18 +59,10 @@ export default { type: Expr.Type.Event, eventId: 'notInStartBox', }, - // inStartBoxOnce: { - // type: Expr.Type.Once, - // argId: 'inStartBox', - // }, notOutOfStartBox: { type: Expr.Type.Not, argId: 'notInStartBox', }, - // notOutOfStartBoxOnce: { - // type: Expr.Type.Once, - // argId: 'notOutOfStartBox', - // }, startedInStartBox: { type: Expr.Type.And, argIds: ['inStartBox', 'notOutOfStartBox'], diff --git a/src/simulator/definitions/challenges/jbc1.ts b/src/simulator/definitions/challenges/jbc1-Tag-Youre-It.ts similarity index 74% rename from src/simulator/definitions/challenges/jbc1.ts rename to src/simulator/definitions/challenges/jbc1-Tag-Youre-It.ts index ef413d09..5c3725b1 100644 --- a/src/simulator/definitions/challenges/jbc1.ts +++ b/src/simulator/definitions/challenges/jbc1-Tag-Youre-It.ts @@ -18,11 +18,15 @@ export default { }, defaultLanguage: 'c', events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: 'Robot not in Start Box' }, + description: { [LocalizedString.EN_US]: 'Robot not in start box' }, + }, can9Touched: { name: { [LocalizedString.EN_US]: 'Can 9 Touched' }, description: { [LocalizedString.EN_US]: 'Can A touched' }, }, - + can9Intersects: { name: { [LocalizedString.EN_US]: 'Can 9 Intersects' }, description: { [LocalizedString.EN_US]: 'Can 9 intersects circle 9' }, @@ -32,11 +36,7 @@ export default { name: { [LocalizedString.EN_US]: 'Can 9 Upright' }, description: { [LocalizedString.EN_US]: 'Can 9 upright on circle 9' }, }, - - leaveStartBox: { - name: { [LocalizedString.EN_US]: 'Robot Left Start' }, - description: { [LocalizedString.EN_US]: 'Robot left starting box' }, - }, + returnStartBox: { name: { [LocalizedString.EN_US]: 'Robot Rentered Start' }, description: { [LocalizedString.EN_US]: 'Robot reentered starting box' }, @@ -50,26 +50,18 @@ export default { eventId: 'can9Touched', }, - // Intersects Events - can9Intersects: { - type: Expr.Type.Event, - eventId: 'can9Intersects', - }, - - // Upright Events - can9Upright: { - type: Expr.Type.Event, - eventId: 'can9Upright', - }, - // Start Box Events - leaveStartBox: { + notInStartBox: { type: Expr.Type.Event, - eventId: 'leaveStartBox', + eventId: "notInStartBox", }, - leaveStartBoxOnce: { + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { type: Expr.Type.Once, - argId: 'leaveStartBox', + argId: "inStartBox", }, returnStartBox: { @@ -81,26 +73,42 @@ export default { argId: 'returnStartBox', }, - - - startingBox:{ - type:Expr.Type.And, - argIds:['leaveStartBoxOnce', 'returnStartBoxOnce'], - }, - - // Intersects and upright logic - can9IntersectsUpright: { - type: Expr.Type.And, - argIds: ['can9Intersects', 'can9Upright'], - }, - // Success Logic = Can A upright, intersects and touched completion: { type: Expr.Type.And, - argIds: ['can9Touched', 'can9IntersectsUpright', 'startingBox'], + argIds: ['can9Touched', 'inStartBoxOnce', 'returnStartBoxOnce'], }, }, rootId: 'completion', }, + failure: { + exprs: { + // Intersects Events + can9Intersects: { + type: Expr.Type.Event, + eventId: 'can9Intersects', + }, + can9NotIntersects: { + type: Expr.Type.Not, + argId: 'can9Intersects', + }, + + // Upright Events + can9Upright: { + type: Expr.Type.Event, + eventId: 'can9Upright', + }, + can9NotUpright: { + type: Expr.Type.Not, + argId: 'can9Upright', + }, + + failure: { + type: Expr.Type.Or, + argIds: ['can9NotIntersects', 'can9NotUpright'], + }, + }, + rootId: 'failure', + }, sceneId: 'jbc1', } as Challenge; \ No newline at end of file diff --git a/src/simulator/definitions/challenges/jbc2.ts b/src/simulator/definitions/challenges/jbc2-Ring-Around-the-Can.ts similarity index 73% rename from src/simulator/definitions/challenges/jbc2.ts rename to src/simulator/definitions/challenges/jbc2-Ring-Around-the-Can.ts index 979c9860..3ea1a014 100644 --- a/src/simulator/definitions/challenges/jbc2.ts +++ b/src/simulator/definitions/challenges/jbc2-Ring-Around-the-Can.ts @@ -20,24 +20,20 @@ export default { }, defaultLanguage: "c", events: { - can6Touched: { - name: { [LocalizedString.EN_US]: "Can 6 Touched" }, - description: { [LocalizedString.EN_US]: "Can 6 touched" }, + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, }, + can6Intersects: { name: { [LocalizedString.EN_US]: "Can 6 Intersects" }, description: { [LocalizedString.EN_US]: "Can 6 intersects circle 6" }, }, - can6Upright: { name: { [LocalizedString.EN_US]: "Can 6 Upright" }, description: { [LocalizedString.EN_US]: "Can 6 upright on circle 6" }, }, - leaveStartBox: { - name: { [LocalizedString.EN_US]: "Robot Left Start" }, - description: { [LocalizedString.EN_US]: "Robot left starting box" }, - }, returnStartBox: { name: { [LocalizedString.EN_US]: "Robot Rentered Start" }, description: { [LocalizedString.EN_US]: "Robot reentered starting box" }, @@ -66,14 +62,18 @@ export default { }, success: { exprs: { - // Touch Events - can6Touched: { + // Start Box Events + notInStartBox: { type: Expr.Type.Event, - eventId: "can6Touched", + eventId: "notInStartBox", }, - can6NotTouched: { + inStartBox: { type: Expr.Type.Not, - argId: "can6Touched", + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", }, // Passing side events @@ -85,6 +85,7 @@ export default { type: Expr.Type.Once, argId: "rightSide", }, + topSide: { type: Expr.Type.Event, eventId: "topSide", @@ -93,6 +94,7 @@ export default { type: Expr.Type.Once, argId: "topSide", }, + leftSide: { type: Expr.Type.Event, eventId: "leftSide", @@ -102,54 +104,16 @@ export default { argId: "leftSide", }, - // Intersects Events - can6Intersects: { - type: Expr.Type.Event, - eventId: "can6Intersects", - }, - - // Upright Events - can6Upright: { - type: Expr.Type.Event, - eventId: "can6Upright", - }, - - // Start Box Events - leaveStartBox: { - type: Expr.Type.Event, - eventId: "leaveStartBox", - }, - leaveStartBoxOnce: { - type: Expr.Type.Once, - argId: "leaveStartBox", - }, - returnStartBox: { type: Expr.Type.Event, eventId: "returnStartBox", }, - returnStartBoxOnce: { - type: Expr.Type.Once, - argId: "returnStartBox", - }, - startingBox: { - type: Expr.Type.And, - argIds: ["leaveStartBoxOnce", "returnStartBoxOnce"], - }, - - // Intersects and upright logic - intersectsUpright: { - type: Expr.Type.And, - argIds: ["can6Intersects", "can6Upright"], - }, - // Success Logic = Can A upright, intersects and touched completion: { type: Expr.Type.And, argIds: [ - "can6NotTouched", - "intersectsUpright", - "startingBox", + "inStartBoxOnce", + "returnStartBox", "rightSideOnce", "topSideOnce", "leftSideOnce" @@ -158,5 +122,34 @@ export default { }, rootId: "completion", }, + failure: { + exprs: { + // Intersects Events + can6Intersects: { + type: Expr.Type.Event, + eventId: 'can6Intersects', + }, + can6NotIntersects: { + type: Expr.Type.Not, + argId: 'can6Intersects', + }, + + // Upright Events + can6Upright: { + type: Expr.Type.Event, + eventId: 'can6Upright', + }, + can6NotUpright: { + type: Expr.Type.Not, + argId: 'can6Upright', + }, + + failure: { + type: Expr.Type.Or, + argIds: ['can6NotIntersects', 'can6NotUpright'], + }, + }, + rootId: 'failure', + }, sceneId: "jbc2", } as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 2bc68f0e..cb7b55ea 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -1,8 +1,8 @@ export * from './jbcSandboxA'; export * from './jbcSandboxB'; -export * from './jbc0'; -export * from './jbc1'; -export * from './jbc2'; +export * from './jbc0-Drive-Straight'; +export * from './jbc1-Tag-Youre-It'; +export * from './jbc2-Ring-Around-the-Can'; export * from './jbc3-Precision-Parking-New'; export * from './jbc4-Serpentine-New'; export * from './jbc5'; diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0-Drive-Straight.ts similarity index 83% rename from src/simulator/definitions/scenes/jbc0.ts rename to src/simulator/definitions/scenes/jbc0-Drive-Straight.ts index f535406a..145fb783 100644 --- a/src/simulator/definitions/scenes/jbc0.ts +++ b/src/simulator/definitions/scenes/jbc0-Drive-Straight.ts @@ -12,7 +12,7 @@ const baseScene = createBaseSceneSurfaceB(); const notInStartBox = ` scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot not in start box!', type, otherNodeId); + // console.log('Robot not in start box!', type, otherNodeId); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('notInStartBox', type === 'start'); } @@ -21,7 +21,7 @@ scene.addOnIntersectionListener('robot', (type, otherNodeId) => { const inStartBox = ` scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot started in start box!', type, otherNodeId, scene.programStatus); + // console.log('Robot started in start box!', type, otherNodeId, scene.programStatus); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('inStartBox', true); } @@ -37,7 +37,7 @@ const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { }); scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot touching line!', type, otherNodeId); + // console.log('Robot touching line!', type, otherNodeId); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('robotTouchingLine', type === 'start'); setNodeVisible('lineB', true); @@ -54,7 +54,7 @@ const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { }); scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot reached end!', type, otherNodeId); + // console.log('Robot reached end!', type, otherNodeId); const visible = type === 'start'; if(scene.programStatus === 'running'){ scene.setChallengeEventValue('reachedEnd', visible); @@ -72,7 +72,7 @@ const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { }); scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot off mat!', type, otherNodeId); + // console.log('Robot off mat!', type, otherNodeId); const visible = type === 'start'; if(scene.programStatus === 'running'){ scene.setChallengeEventValue('offMat', visible); @@ -81,13 +81,6 @@ scene.addOnIntersectionListener('robot', (type, otherNodeId) => { }, 'endOfMat'); `; -const ROBOT_ORIGIN: ReferenceFramewUnits = { - ...baseScene.nodes['robot'].origin, - position: { - ...baseScene.nodes['robot'].origin.position, - }, -}; - export const JBC_0: Scene = { ...baseScene, name: { [LocalizedString.EN_US]: 'JBC 0' }, @@ -103,14 +96,6 @@ export const JBC_0: Scene = { }, geometry: { ...baseScene.geometry, - mainSurface_geom: { - type: 'box', - size: { - x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.meters(3.54), - }, - }, notStartBox_geom: { type: "box", size: { @@ -154,31 +139,6 @@ export const JBC_0: Scene = { }, nodes: { ...baseScene.nodes, - robot: { - ...baseScene.nodes['robot'], - startingOrigin: ROBOT_ORIGIN, - origin: ROBOT_ORIGIN, - }, - mainSurface: { - type: 'object', - geometryId: 'mainSurface_geom', - name: { [LocalizedString.EN_US]: 'Mat Surface' }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.inches(19.75), - }, - }, - material: { - type: 'basic', - color: { - type: 'color3', - color: Color.rgb(0, 0, 0), - }, - }, - }, notStartBox: { type: "object", geometryId: "notStartBox_geom", diff --git a/src/simulator/definitions/scenes/jbc1-Tag-Youre-It.ts b/src/simulator/definitions/scenes/jbc1-Tag-Youre-It.ts new file mode 100644 index 00000000..0e5de576 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc1-Tag-Youre-It.ts @@ -0,0 +1,138 @@ +import Scene from '../../../state/State/Scene'; +import LocalizedString from '../../../util/LocalizedString'; +import { Distance } from "../../../util"; +import Script from '../../../state/State/Scene/Script'; +import { Color } from '../../../state/State/Scene/Color'; +import { createCanNode, createBaseSceneSurfaceA, createCircleNode } from './jbcBase'; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + // console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const circleIntersects = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + +// When the can is intersecting circle9, the circle glows + +scene.addOnIntersectionListener('can9', (type, otherNodeId) => { + // console.log('Can 9 on circle!', type, otherNodeId); + scene.setChallengeEventValue('can9Intersects', type === 'start'); +}, 'circle9'); + +`; + +const enterStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + // console.log('Robot returned start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('returnStartBox', type === 'start'); + } +}, 'startBox'); +`; + +const robotTouches = ` +scene.addOnCollisionListener('can9', (otherNodeId) => { + // console.log('Robot touched Can 9!'); + scene.setChallengeEventValue('can9Touched', true); +}, 'robot'); +`; + +const uprightCans = ` +// Upright Condition +const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); +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(() => { + const upright9 = yAngle('can9') > 5; + scene.setChallengeEventValue('can9Upright', upright9); +}); +`; + +export const JBC_1: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 1' }, + description: { [LocalizedString.EN_US]: `Junior Botball Challenge 1: Tag, You're It!` }, + scripts: { + 'notInStartBox': Script.ecmaScript('Not In Start Box', notInStartBox), + 'circleIntersects': Script.ecmaScript('Circle Intersects', circleIntersects), + 'uprightCans': Script.ecmaScript('Upright Cans', uprightCans), + 'robotTouches': Script.ecmaScript('Robot Touches', robotTouches), + 'enterStartBox': Script.ecmaScript('Robot Reentered Start', enterStartBox), + }, + geometry: { + ...baseScene.geometry, + startBox_geom: { + type: 'box', + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.inches(10), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + + nodes: { + ...baseScene.nodes, + 'startBox': { + type: 'object', + geometryId: 'startBox_geom', + name: { [LocalizedString.EN_US]: 'Start Box' }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.centimeters(2), + }, + }, + material: { + type: 'pbr', + emissive: { + type: 'color3', + color: Color.rgb(0, 255, 255), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + can9: createCanNode(9), + circle9: createCircleNode(9), + } + +}; diff --git a/src/simulator/definitions/scenes/jbc1.ts b/src/simulator/definitions/scenes/jbc1.ts deleted file mode 100644 index e70de8df..00000000 --- a/src/simulator/definitions/scenes/jbc1.ts +++ /dev/null @@ -1,183 +0,0 @@ -import Scene from '../../../state/State/Scene'; -import LocalizedString from '../../../util/LocalizedString'; -import { Distance } from "../../../util"; -import Script from '../../../state/State/Scene/Script'; -import { Color } from '../../../state/State/Scene/Color'; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; - -const baseScene = createBaseSceneSurfaceA(); - -const circleIntersects = ` -const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { - ...scene.nodes[nodeId], - visible -}); - -// When the can (can9) is intersecting circle9, the circle glows - -scene.addOnIntersectionListener('can9', (type, otherNodeId) => { - console.log('Can 9 placed!', type, otherNodeId); - const visible = type === 'start'; - scene.setChallengeEventValue('can9Intersects', visible); - setNodeVisible('circle9', visible); -}, 'circle9'); - -`; - -const leftStartBox = ` - -scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot left start box!', type, otherNodeId); - if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('leaveStartBox', type === 'end'); - } - -}, 'startBox'); -`; - -const enterStartBox = ` - -scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot returned start box!', type, otherNodeId); - if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('returnStartBox', type === 'start'); - } -}, 'startBox'); -`; - -const robotTouches = ` -// scene.onBind = nodeId => { -// scene.addOnCollisionListener(nodeId, (otherNodeId, point)=> { -// console.log('Can 9 touched!', otherNodeId, point); -// scene.setChallengeEventValue(nodeId + 'Touched', true); -// }, 'robot'); -// }; -scene.addOnCollisionListener('can9', (otherNodeId) => { - console.log('Robot touched Can 9!'); - scene.setChallengeEventValue('can9Touched', true); -}, 'robot'); -`; - -const uprightCans = ` -// When a can is standing upright, the upright condition is met. - -// let startTime = Date.now(); -const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); -// const startingOrientationInv = (nodeId) => Quaternion.inverse(RotationwUnits.toRawQuaternion(scene.nodes[nodeId].startingOrigin.orientation || EULER_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)); - - -scene.addOnRenderListener(() => { - const upright9 = yAngle('can9') > 5; - // console.log('can9 angle: ', yAngle('can9')); - scene.setChallengeEventValue('can9Upright', upright9); - -}); -`; - -export const JBC_1: Scene = { - ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 1' }, - description: { [LocalizedString.EN_US]: `Junior Botball Challenge 1: Tag, You're It!` }, - scripts: { - 'circleIntersects': Script.ecmaScript('Circle Intersects', circleIntersects), - 'uprightCans': Script.ecmaScript('Upright Cans', uprightCans), - 'robotTouches': Script.ecmaScript('Robot Touches', robotTouches), - 'leftStartBox': Script.ecmaScript('Robot Left Start', leftStartBox), - 'enterStartBox': Script.ecmaScript('Robot Reentered Start',enterStartBox), - }, - geometry: { - ...baseScene.geometry, - 'circle9_geom': { - type: 'cylinder', - radius: Distance.centimeters(3), - height: Distance.centimeters(0.1), - }, - 'mainSurface_geom': { - type: 'box', - size: { - x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.meters(3.54), - }, - }, - 'startBox_geom': { - type: 'box', - size: { - x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.inches(10), - }, - }, - }, - - nodes: { - ...baseScene.nodes, - 'mainSurface': { - type: 'object', - geometryId: 'mainSurface_geom', - name: { [LocalizedString.EN_US]: 'Mat Surface' }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.inches(19.75), - }, - }, - material: { - type: 'basic', - color: { - type: 'color3', - color: Color.rgb(0, 0, 0) - } - }, - }, - 'circle9': { - type: 'object', - geometryId: 'circle9_geom', - name: { [LocalizedString.EN_US]: 'Circle 9' }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.centimeters(85.4), - }, - }, - material: { - type: 'pbr', - emissive: { - type: 'color3', - color: Color.rgb(255, 255, 255), - }, - }, - }, - 'startBox': { - type: 'object', - geometryId: 'startBox_geom', - name: { [LocalizedString.EN_US]: 'Start Box' }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.centimeters(2), - }, - }, - material: { - type: 'pbr', - emissive: { - type: 'color3', - color: Color.rgb(0, 255, 255), - }, - }, - }, - 'can9': { - ...createCanNode(9, { x: Distance.centimeters(0), y: Distance.centimeters(0), z: Distance.centimeters(85.4) }), - scriptIds: ['robotTouches'] - } - - } - -}; diff --git a/src/simulator/definitions/scenes/jbc2.ts b/src/simulator/definitions/scenes/jbc2-Ring-Around-the-Can.ts similarity index 67% rename from src/simulator/definitions/scenes/jbc2.ts rename to src/simulator/definitions/scenes/jbc2-Ring-Around-the-Can.ts index f2b50e06..13c20f61 100644 --- a/src/simulator/definitions/scenes/jbc2.ts +++ b/src/simulator/definitions/scenes/jbc2-Ring-Around-the-Can.ts @@ -1,12 +1,21 @@ import Scene from "../../../state/State/Scene"; import LocalizedString from '../../../util/LocalizedString'; import Script from "../../../state/State/Scene/Script"; -import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; +import { createCanNode, createBaseSceneSurfaceA, createCircleNode } from './jbcBase'; import { Color } from "../../../state/State/Scene/Color"; import { Distance } from "../../../util"; const baseScene = createBaseSceneSurfaceA(); +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + // console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + const circleIntersects = ` const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { ...scene.nodes[nodeId], @@ -16,7 +25,7 @@ const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { // When the can (can6) is intersecting circle6, the circle glows scene.addOnIntersectionListener('can6', (type, otherNodeId) => { - console.log('Can 6 placed!', type, otherNodeId); + // console.log('Can 6 placed!', type, otherNodeId); const visible = type === 'start'; scene.setChallengeEventValue('can6Intersects', visible); setNodeVisible('circle6', visible); @@ -24,28 +33,10 @@ scene.addOnIntersectionListener('can6', (type, otherNodeId) => { `; -const leftStartBox = ` - -scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot left start box!', type, otherNodeId); - if(scene.programStatus === 'running'){ - scene.setChallengeEventValue('leaveStartBox', type === 'end'); - } - -}, 'startBox'); -`; -const robotTouches = ` -scene.onBind = nodeId => { - scene.addOnCollisionListener(nodeId, (otherNodeId, point)=> { - console.log('Can 6 touched!', otherNodeId, point); - scene.setChallengeEventValue(nodeId + 'Touched', true); - }, 'robot'); -}; -`; const enterStartBox = ` scene.addOnIntersectionListener('robot', (type, otherNodeId) => { - console.log('Robot returned start box!', type, otherNodeId); + // console.log('Robot returned start box!', type, otherNodeId); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('returnStartBox', type === 'start'); } @@ -56,19 +47,19 @@ const passedSide = ` scene.addOnIntersectionListener('robot', (type, otherNodeId) => { switch(otherNodeId){ case 'rightSideCan': - console.log('Robot passed the right side of the can!', type, otherNodeId); + // console.log('Robot passed the right side of the can!', type, otherNodeId); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('rightSide', type === 'start'); } break; case 'topSideCan': - console.log('Robot passed the top side of the can!', type, otherNodeId); + // console.log('Robot passed the top side of the can!', type, otherNodeId); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('topSide', type === 'start'); } break; case 'leftSideCan': - console.log('Robot passed the left side of the can!', type, otherNodeId); + // console.log('Robot passed the left side of the can!', type, otherNodeId); if(scene.programStatus === 'running'){ scene.setChallengeEventValue('leftSide', type === 'start'); } @@ -79,19 +70,13 @@ scene.addOnIntersectionListener('robot', (type, otherNodeId) => { `; const uprightCans = ` -// When a can is standing upright, the upright condition is met. - -// let startTime = Date.now(); const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); -// const startingOrientationInv = (nodeId) => Quaternion.inverse(RotationwUnits.toRawQuaternion(scene.nodes[nodeId].startingOrigin.orientation || EULER_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(() => { const upright6 = yAngle('can6') > 5; - // console.log('can6 angle: ', yAngle('can6')); scene.setChallengeEventValue('can6Upright', upright6); - }); `; @@ -102,38 +87,31 @@ export const JBC_2: Scene = { [LocalizedString.EN_US]: "Junior Botball Challenge 2: Ring Around the Can", }, scripts: { + notInStartBox: Script.ecmaScript("Not in Start Box", notInStartBox), circleIntersects: Script.ecmaScript("Circle Intersects", circleIntersects), uprightCans: Script.ecmaScript("Upright Cans", uprightCans), - robotTouches: Script.ecmaScript("Robot Touches", robotTouches), passedSide: Script.ecmaScript("Passed Side", passedSide), - leftStartBox: Script.ecmaScript("Robot Left Start", leftStartBox), enterStartBox: Script.ecmaScript("Robot Reentered Start", enterStartBox), }, geometry: { ...baseScene.geometry, - circle6_geom: { - type: "cylinder", - radius: Distance.centimeters(3), - height: Distance.centimeters(0.1), - }, - mainSurface_geom: { + startBox_geom: { type: "box", size: { x: Distance.meters(3.54), y: Distance.centimeters(0.1), - z: Distance.meters(3.54), + z: Distance.centimeters(0), }, }, - startBox_geom: { + notStartBox_geom: { type: "box", size: { x: Distance.meters(3.54), - y: Distance.centimeters(0.1), - z: Distance.centimeters(0), + y: Distance.centimeters(10), + z: Distance.meters(2.13), }, }, - rightSideCan_geom: { type: "box", size: { @@ -142,7 +120,6 @@ export const JBC_2: Scene = { z: Distance.meters(0.05), }, }, - topSideCan_geom: { type: "box", size: { @@ -151,7 +128,6 @@ export const JBC_2: Scene = { z: Distance.meters(1.77), }, }, - leftSideCan_geom: { type: "box", size: { @@ -164,36 +140,16 @@ export const JBC_2: Scene = { nodes: { ...baseScene.nodes, - mainSurface: { - type: "object", - geometryId: "mainSurface_geom", - name: { [LocalizedString.EN_US]: "Mat Surface" }, - visible: false, - origin: { - position: { - x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.inches(19.75), - }, - }, - material: { - type: "basic", - color: { - type: "color3", - color: Color.rgb(0, 0, 0), - }, - }, - }, - circle6: { + startBox: { type: "object", - geometryId: "circle6_geom", - name: { [LocalizedString.EN_US]: "Circle 6" }, + geometryId: "startBox_geom", + name: { [LocalizedString.EN_US]: "Start Box" }, visible: false, origin: { position: { x: Distance.centimeters(0), y: Distance.centimeters(-6.9), - z: Distance.centimeters(57.2), + z: Distance.centimeters(0), }, }, material: { @@ -204,28 +160,26 @@ export const JBC_2: Scene = { }, }, }, - - startBox: { + notStartBox: { type: "object", - geometryId: "startBox_geom", - name: { [LocalizedString.EN_US]: "Start Box" }, + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, visible: false, origin: { position: { x: Distance.centimeters(0), - y: Distance.centimeters(-6.9), - z: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), }, }, material: { - type: "pbr", - emissive: { + type: "basic", + color: { type: "color3", - color: Color.rgb(255, 255, 255), + color: Color.rgb(255, 0, 0), }, }, }, - rightSideCan: { type: "object", geometryId: "rightSideCan_geom", @@ -246,7 +200,6 @@ export const JBC_2: Scene = { }, }, }, - topSideCan: { type: "object", geometryId: "topSideCan_geom", @@ -287,14 +240,7 @@ export const JBC_2: Scene = { }, }, }, - - can6: { - ...createCanNode(6, { - x: Distance.centimeters(0), - y: Distance.centimeters(0), - z: Distance.centimeters(57), - }), - scriptIds: ["robotTouches"], - }, + can6: createCanNode(6), + circle6: createCircleNode(6), }, }; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbcBase.ts b/src/simulator/definitions/scenes/jbcBase.ts index b1d9c1e4..efd2b1cd 100644 --- a/src/simulator/definitions/scenes/jbcBase.ts +++ b/src/simulator/definitions/scenes/jbcBase.ts @@ -253,7 +253,7 @@ export function createCanNode(canNumber: number, canPosition?: Vector3wUnits, ed * @param visible Whether the circle is visible * @returns A circle Node that can be inserted into a Scene */ -export function createCircleNode(circleNumber: number, circlePosition: Vector3wUnits, editable?: boolean, visible?: boolean): Node { +export function createCircleNode(circleNumber: number, circlePosition?: Vector3wUnits, editable?: boolean, visible?: boolean): Node { const position: Vector3wUnits = { x: canPositions[circleNumber - 1].x, y: Distance.centimeters(-6.9), diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 17eb2993..b2e16d26 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -12,9 +12,9 @@ import LocalizedString from '../../util/LocalizedString'; import db from '../../db'; import Selector from '../../db/Selector'; -import jbc0 from "../../simulator/definitions/challenges/jbc0"; -import jbc1 from "../../simulator/definitions/challenges/jbc1"; -import jbc2 from "../../simulator/definitions/challenges/jbc2"; +import jbc0 from "../../simulator/definitions/challenges/jbc0-Drive-Straight"; +import jbc1 from "../../simulator/definitions/challenges/jbc1-Tag-Youre-It"; +import jbc2 from "../../simulator/definitions/challenges/jbc2-Ring-Around-the-Can"; // import jbc2b from "../../simulator/definitions/challenges/archived/jbc2b-Ring-Around-the-Cans-Sr"; // import jbc2c from "../../simulator/definitions/challenges/archived/jbc2c-Back-It-Up"; // import jbc2d from "../../simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up";