add "pause on run" flag to disable waiting after command (#663)
* add "pause on run" flag to disable waiting after command * refactor * fixing build
This commit is contained in:
parent
a8249e94c5
commit
c288242b9c
@ -132,6 +132,7 @@ namespace motors {
|
|||||||
protected _port: Output;
|
protected _port: Output;
|
||||||
protected _portName: string;
|
protected _portName: string;
|
||||||
protected _brake: boolean;
|
protected _brake: boolean;
|
||||||
|
private _pauseOnRun: boolean;
|
||||||
private _initialized: boolean;
|
private _initialized: boolean;
|
||||||
private _init: () => void;
|
private _init: () => void;
|
||||||
private _run: (speed: number) => void;
|
private _run: (speed: number) => void;
|
||||||
@ -142,6 +143,7 @@ namespace motors {
|
|||||||
this._port = port;
|
this._port = port;
|
||||||
this._portName = outputToName(this._port);
|
this._portName = outputToName(this._port);
|
||||||
this._brake = false;
|
this._brake = false;
|
||||||
|
this._pauseOnRun = true;
|
||||||
this._initialized = false;
|
this._initialized = false;
|
||||||
this._init = init;
|
this._init = init;
|
||||||
this._run = run;
|
this._run = run;
|
||||||
@ -172,6 +174,19 @@ namespace motors {
|
|||||||
this._brake = brake;
|
this._brake = brake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates to pause while a motor moves for a given distance or duration.
|
||||||
|
* @param value true to pause; false to continue the program execution
|
||||||
|
*/
|
||||||
|
//% blockId=outputMotorSetPauseMode block="set %motor|pause on run %brake=toggleOnOff"
|
||||||
|
//% motor.fieldEditor="motors"
|
||||||
|
//% weight=60 blockGap=8
|
||||||
|
//% group="Properties"
|
||||||
|
setPauseOnRun(value: boolean) {
|
||||||
|
this.init();
|
||||||
|
this._pauseOnRun = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inverts the motor polarity
|
* Inverts the motor polarity
|
||||||
*/
|
*/
|
||||||
@ -201,13 +216,22 @@ namespace motors {
|
|||||||
this.settle();
|
this.settle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private settle() {
|
protected settle() {
|
||||||
// if we've recently completed a motor command with brake
|
// if we've recently completed a motor command with brake
|
||||||
// allow 500ms for robot to settle
|
// allow 500ms for robot to settle
|
||||||
if(this._brake)
|
if (this._brake)
|
||||||
pause(500);
|
pause(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected pauseOnRun(stepsOrTime: number) {
|
||||||
|
if (stepsOrTime && this._pauseOnRun) {
|
||||||
|
// wait till motor is done with this work
|
||||||
|
this.pauseUntilReady();
|
||||||
|
// allow robot to settle
|
||||||
|
this.settle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the motor(s).
|
* Resets the motor(s).
|
||||||
*/
|
*/
|
||||||
@ -269,10 +293,7 @@ namespace motors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._move(useSteps, stepsOrTime, speed);
|
this._move(useSteps, stepsOrTime, speed);
|
||||||
// wait till motor is done with this work
|
this.pauseOnRun(stepsOrTime);
|
||||||
this.pauseUntilReady();
|
|
||||||
// allow robot to settle
|
|
||||||
this.settle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -572,6 +593,8 @@ namespace motors {
|
|||||||
stepsOrTime: stepsOrTime,
|
stepsOrTime: stepsOrTime,
|
||||||
useBrake: this._brake
|
useBrake: this._brake
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.pauseOnRun(stepsOrTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user