Maximmasterr set settle (#882)

* Added set settle time

* updated blocks
This commit is contained in:
Peli de Halleux 2019-08-27 14:57:28 -07:00 committed by GitHub
parent 5fb8c0de6e
commit 2b300a4094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,6 +134,7 @@ namespace motors {
protected _brake: boolean;
private _pauseOnRun: boolean;
private _initialized: boolean;
private _brakeSettleTime: number;
private _init: () => void;
private _run: (speed: number) => void;
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
@ -147,6 +148,7 @@ namespace motors {
this._brake = false;
this._pauseOnRun = true;
this._initialized = false;
this._brakeSettleTime = 10;
this._init = init;
this._run = run;
this._move = move;
@ -204,6 +206,20 @@ namespace motors {
writePWM(b)
}
/**
* Set the settle time after braking in milliseconds (default is 10ms).
*/
//% blockId=motorSetBrakeSettleTime block="set %motor|brake settle time %millis|ms"
//% motor.fieldEditor="motors"
//% weight=1 blockGap=8
//% group="Properties"
//% millis.defl=200 millis.min=0 millis.max=500
setBrakeSettleTime(millis: number) {
this.init();
// ensure in [0,500]
this._brakeSettleTime = Math.max(0, Math.min(500, millis | 0))
}
/**
* Stops the motor(s).
*/
@ -221,8 +237,8 @@ namespace motors {
protected settle() {
// if we've recently completed a motor command with brake
// allow 500ms for robot to settle
if (this._brake)
pause(500);
if (this._brake && this._brakeSettleTime > 0)
pause(this._brakeSettleTime);
}
protected pauseOnRun(stepsOrTime: number) {
@ -396,7 +412,7 @@ namespace motors {
*/
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
//% motor.fieldEditor="motors"
//% weight=58
//% weight=58 blockGap=8
//% group="Properties"
//% help=motors/motor/set-regulated
setRegulated(value: boolean) {