Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4a73c5d700 | |||
a47a06ac19 | |||
3f598a3eee | |||
ded2e9d82c |
@ -27,7 +27,6 @@ while (true) {
|
|||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||||
}
|
}
|
||||||
pause(1);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -43,6 +42,5 @@ while (true) {
|
|||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||||
}
|
}
|
||||||
pause(1);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
@ -64,6 +64,7 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
|||||||
private _writer: any;
|
private _writer: any;
|
||||||
|
|
||||||
constructor(private port: SerialPort, private options: SerialOptions) {
|
constructor(private port: SerialPort, private options: SerialOptions) {
|
||||||
|
console.log(`serial: new io`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async readSerialAsync() {
|
async readSerialAsync() {
|
||||||
@ -90,17 +91,24 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
|||||||
return !!(<any>navigator).serial;
|
return !!(<any>navigator).serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static portIos: WebSerialPackageIO[] = [];
|
||||||
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
|
static async mkPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
|
||||||
const serial = (<any>navigator).serial;
|
const serial = (<any>navigator).serial;
|
||||||
if (serial) {
|
if (serial) {
|
||||||
try {
|
try {
|
||||||
const requestOptions: SerialPortRequestOptions = {};
|
const requestOptions: SerialPortRequestOptions = {};
|
||||||
const port = await serial.requestPort(requestOptions);
|
const port = await serial.requestPort(requestOptions);
|
||||||
const options: SerialOptions = {
|
|
||||||
baudrate: 460800,
|
let io = WebSerialPackageIO.portIos.filter(i => i.port == port)[0];
|
||||||
buffersize: 4096
|
if (!io) {
|
||||||
};
|
const options: SerialOptions = {
|
||||||
return new WebSerialPackageIO(port, options);
|
baudrate: 460800,
|
||||||
|
buffersize: 4096
|
||||||
|
};
|
||||||
|
io = new WebSerialPackageIO(port, options);
|
||||||
|
WebSerialPackageIO.portIos.push(io);
|
||||||
|
}
|
||||||
|
return io;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`connection error`, e)
|
console.log(`connection error`, e)
|
||||||
}
|
}
|
||||||
@ -125,11 +133,8 @@ class WebSerialPackageIO implements pxt.HF2.PacketIO {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeAsync() {
|
private async closeAsync() {
|
||||||
console.log(`serial: closing port`);
|
// don't close port
|
||||||
this.port.close();
|
|
||||||
this._reader = undefined;
|
|
||||||
this._writer = undefined;
|
|
||||||
return Promise.delay(500);
|
return Promise.delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
libs/core/cooperate.ts
Normal file
11
libs/core/cooperate.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace control {
|
||||||
|
let lastPause = 0;
|
||||||
|
const COOPERATION_INTERVAL = 20
|
||||||
|
export function cooperate() {
|
||||||
|
const now = control.millis()
|
||||||
|
if (now - lastPause > COOPERATION_INTERVAL) {
|
||||||
|
lastPause = now
|
||||||
|
pause(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,8 +21,7 @@ namespace sensors.internal {
|
|||||||
const now = control.millis();
|
const now = control.millis();
|
||||||
if (now - this.lastQuery >= this.interval * 2)
|
if (now - this.lastQuery >= this.interval * 2)
|
||||||
this.queryAndUpdate(); // sensor poller is not allowed to run
|
this.queryAndUpdate(); // sensor poller is not allowed to run
|
||||||
if (now - this.lastPause >= this.interval * 5)
|
control.cooperate(); // allow events to trigger
|
||||||
pause(1); // allow events to trigger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private queryAndUpdate() {
|
private queryAndUpdate() {
|
||||||
|
@ -124,7 +124,7 @@ namespace motors {
|
|||||||
export function stopAll() {
|
export function stopAll() {
|
||||||
const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
|
const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
|
||||||
writePWM(b);
|
writePWM(b);
|
||||||
pause(1);
|
control.cooperate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,7 +136,7 @@ namespace motors {
|
|||||||
//% help=motors/reset-all
|
//% help=motors/reset-all
|
||||||
export function resetAll() {
|
export function resetAll() {
|
||||||
reset(Output.ALL)
|
reset(Output.ALL)
|
||||||
pause(1);
|
control.cooperate();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MoveSchedule {
|
interface MoveSchedule {
|
||||||
@ -269,7 +269,7 @@ namespace motors {
|
|||||||
if (this._brake && this._brakeSettleTime > 0)
|
if (this._brake && this._brakeSettleTime > 0)
|
||||||
pause(this._brakeSettleTime);
|
pause(this._brakeSettleTime);
|
||||||
else {
|
else {
|
||||||
pause(1);
|
control.cooperate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ namespace motors {
|
|||||||
// allow robot to settle
|
// allow robot to settle
|
||||||
this.settle();
|
this.settle();
|
||||||
} else {
|
} else {
|
||||||
pause(1);
|
control.cooperate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +357,7 @@ namespace motors {
|
|||||||
// special: 0 is infinity
|
// special: 0 is infinity
|
||||||
if (schedule.steps[0] + schedule.steps[1] + schedule.steps[2] == 0) {
|
if (schedule.steps[0] + schedule.steps[1] + schedule.steps[2] == 0) {
|
||||||
this._run(schedule.speed);
|
this._run(schedule.speed);
|
||||||
pause(1);
|
control.cooperate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@
|
|||||||
"icons.jres",
|
"icons.jres",
|
||||||
"ns.ts",
|
"ns.ts",
|
||||||
"platform.h",
|
"platform.h",
|
||||||
"integrator.ts"
|
"integrator.ts",
|
||||||
|
"cooperate.ts"
|
||||||
],
|
],
|
||||||
"testFiles": [
|
"testFiles": [
|
||||||
"test.ts"
|
"test.ts"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "1.2.26",
|
"version": "1.2.28",
|
||||||
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
||||||
"private": false,
|
"private": false,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
Reference in New Issue
Block a user