diff --git a/docs/examples/core-set/puppy-labview.md b/docs/examples/core-set/puppy-labview.md index 27951f6a..d45c0504 100644 --- a/docs/examples/core-set/puppy-labview.md +++ b/docs/examples/core-set/puppy-labview.md @@ -300,15 +300,56 @@ function HNG() { } function PPP() { - // TODO + NS = false; + IS(2); + UP(); + loops.pause(100) + motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees); + loops.pause(800); + music.playSoundEffect(sounds.mechanicalHorn1); + loops.pause(1000); + for(let i = 0; i < 3; ++i) { + motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees); + motors.largeA.setSpeed(30, 20, MoveUnit.Degrees); + } + motors.largeA.setSpeed(30, 70, MoveUnit.Degrees); + F_C = 1; + CS(0); } function HPY() { - // TODO + IS(8) + MHT(0); + motors.largeAD.setSpeed(10, 0.8, MoveUnit.Seconds); + for(let i = 0; i < 3; ++i) { + music.playSoundEffect(sounds.animalsDogBark1); + motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds); + loops.pause(300) + motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds) + } + loops.pause(500); + music.stopAllSounds(); + DN(); + RST(); +} + +function STL() { + UP(); + motors.largeAD.setSpeed(-20, 60, MoveUnit.Degrees); + music.playSoundEffect(sounds.animalsDogWhine); + motors.largeAD.setSpeed(20, 60, MoveUnit.Degrees); } function WKU() { - + let stateC = false; + IS(5); + music.playSoundEffect(sounds.animalsDogWhine) + MHT(0) + DN() + STL() + loops.pause(1000); + UP() + CS(0;) } DN(); diff --git a/sim/dalboard.ts b/sim/dalboard.ts index 6111f90d..5cda54b6 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -97,28 +97,21 @@ namespace pxsim { return this.brickNode; } - motorUsed(port: number, large: boolean) { + motorUsed(ports: number, large: boolean): boolean { for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { const p = 1 << i; - if (port & p) { - const motorPort = this.motorMap[p]; - if (!this.outputNodes[motorPort]) - this.outputNodes[motorPort] = new MotorNode(motorPort, large); - } - } - } - - hasMotor(port: number) { - for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { - const p = 1 << i; - if (port & p) { + if (ports & p) { const motorPort = this.motorMap[p]; const outputNode = this.outputNodes[motorPort]; - if (outputNode) - return true; + if (!outputNode) { + this.outputNodes[motorPort] = new MotorNode(motorPort, large); + continue; + } + if (outputNode && outputNode.isLarge() != large) + return false; } } - return false; + return true; } getMotor(port: number, large?: boolean): MotorNode[] { diff --git a/sim/state/input.ts b/sim/state/input.ts index a025e34e..4d99f624 100644 --- a/sim/state/input.ts +++ b/sim/state/input.ts @@ -3,15 +3,23 @@ import lf = pxsim.localization.lf; namespace pxsim.motors { - - export function __motorUsed(port: number, large: boolean) { - //console.log("MOTOR INIT " + port); - if (!ev3board().hasMotor(port)) { - ev3board().motorUsed(port, large); - runtime.queueDisplayUpdate(); - } else { - U.userError(`${lf("Multiple motors are connected to Port")} ${String.fromCharCode('A'.charCodeAt(0) + ev3board().motorMap[port])}`); + function portsToString(out: number): string { + let r = ""; + for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { + if (out & (1 << i)) { + if (r.length > 0) r += "+"; + r += "ABCD"[i]; + } } + return r; + } + + export function __motorUsed(ports: number, large: boolean) { + //console.log("MOTOR INIT " + port); + if (ev3board().motorUsed(ports, large)) + runtime.queueDisplayUpdate(); + else + U.userError(`${lf("Multiple motors are connected to Port")} ${portsToString(ports)}`); } } diff --git a/sim/state/motornode.ts b/sim/state/motornode.ts index 745f046f..7a939f33 100644 --- a/sim/state/motornode.ts +++ b/sim/state/motornode.ts @@ -70,6 +70,10 @@ namespace pxsim { this.rotationsPerMilliSecond = (large ? 170 : 250) / 60000; } + isLarge(): boolean { + return this.id == NodeType.LargeMotor; + } + setPolarity(polarity: number) { // Either 1 or 255 (reverse) /*