Support for multiple motors in "used" logic. (#238)

* handle registerion of dual / single motors

* updated puppy
This commit is contained in:
Peli de Halleux 2018-01-15 23:57:21 -08:00 committed by GitHub
parent 3c2be25384
commit 9fadf49b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 27 deletions

View File

@ -300,15 +300,56 @@ function HNG() {
} }
function PPP() { 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() { 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() { function WKU() {
let stateC = false;
IS(5);
music.playSoundEffect(sounds.animalsDogWhine)
MHT(0)
DN()
STL()
loops.pause(1000);
UP()
CS(0;)
} }
DN(); DN();

View File

@ -97,29 +97,22 @@ namespace pxsim {
return this.brickNode; return this.brickNode;
} }
motorUsed(port: number, large: boolean) { motorUsed(ports: number, large: boolean): boolean {
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
const p = 1 << i; const p = 1 << i;
if (port & p) { if (ports & 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) {
const motorPort = this.motorMap[p]; const motorPort = this.motorMap[p];
const outputNode = this.outputNodes[motorPort]; const outputNode = this.outputNodes[motorPort];
if (outputNode) if (!outputNode) {
return true; 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[] { getMotor(port: number, large?: boolean): MotorNode[] {
const r = []; const r = [];

View File

@ -3,16 +3,24 @@
import lf = pxsim.localization.lf; import lf = pxsim.localization.lf;
namespace pxsim.motors { namespace pxsim.motors {
function portsToString(out: number): string {
export function __motorUsed(port: number, large: boolean) { let r = "";
//console.log("MOTOR INIT " + port); for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (!ev3board().hasMotor(port)) { if (out & (1 << i)) {
ev3board().motorUsed(port, large); if (r.length > 0) r += "+";
runtime.queueDisplayUpdate(); r += "ABCD"[i];
} else {
U.userError(`${lf("Multiple motors are connected to Port")} ${String.fromCharCode('A'.charCodeAt(0) + ev3board().motorMap[port])}`);
} }
} }
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)}`);
}
} }
namespace pxsim.sensors { namespace pxsim.sensors {

View File

@ -70,6 +70,10 @@ namespace pxsim {
this.rotationsPerMilliSecond = (large ? 170 : 250) / 60000; this.rotationsPerMilliSecond = (large ? 170 : 250) / 60000;
} }
isLarge(): boolean {
return this.id == NodeType.LargeMotor;
}
setPolarity(polarity: number) { setPolarity(polarity: number) {
// Either 1 or 255 (reverse) // Either 1 or 255 (reverse)
/* /*