support for unregulated motors (#227)
This commit is contained in:
		@@ -61,6 +61,8 @@
 | 
			
		||||
  "control.raiseEvent|param|value": "Component specific code indicating the cause of the event.",
 | 
			
		||||
  "motors.Motor.angle": "Gets motor angle.",
 | 
			
		||||
  "motors.Motor.clearCounts": "Clears the motor count",
 | 
			
		||||
  "motors.Motor.setRegulated": "Indicates if the motor speed should be regulated. Default is true.",
 | 
			
		||||
  "motors.Motor.setRegulated|param|value": "true for regulated motor",
 | 
			
		||||
  "motors.Motor.speed": "Gets motor actual speed.",
 | 
			
		||||
  "motors.Motor.tacho": "Gets motor tachometer count.",
 | 
			
		||||
  "motors.Motor.toString": "Returns the status of the motor",
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,7 @@
 | 
			
		||||
  "control|block": "control",
 | 
			
		||||
  "motors.Motor.angle|block": "%motor|angle",
 | 
			
		||||
  "motors.Motor.clearCounts|block": "%motor|clear counts",
 | 
			
		||||
  "motors.Motor.setRegulated|block": "set %motor|regulated %value",
 | 
			
		||||
  "motors.Motor.speed|block": "%motor|speed",
 | 
			
		||||
  "motors.Motor.tacho|block": "%motor|tacho",
 | 
			
		||||
  "motors.MotorBase.pauseUntilReady|block": "%motor|pause until ready",
 | 
			
		||||
 
 | 
			
		||||
@@ -175,7 +175,7 @@ namespace motors {
 | 
			
		||||
        */
 | 
			
		||||
        //% blockId=motorSetReversed block="set %motor|reversed %reversed"
 | 
			
		||||
        //% reversed.fieldEditor=toggleonoff
 | 
			
		||||
        //% weight=59
 | 
			
		||||
        //% weight=59 blockGap=8
 | 
			
		||||
        //% group="Move"
 | 
			
		||||
        setReversed(reversed: boolean) {
 | 
			
		||||
            this.init();
 | 
			
		||||
@@ -282,10 +282,12 @@ namespace motors {
 | 
			
		||||
    //% fixedInstances
 | 
			
		||||
    export class Motor extends MotorBase {
 | 
			
		||||
        private _large: boolean;
 | 
			
		||||
        private _regulated: boolean;
 | 
			
		||||
 | 
			
		||||
        constructor(port: Output, large: boolean) {
 | 
			
		||||
            super(port, () => this.__init(), (speed) => this.__setSpeed(speed), (steps, stepsOrTime, speed) => this.__move(steps, stepsOrTime, speed));
 | 
			
		||||
            this._large = large;
 | 
			
		||||
            this._regulated = true;
 | 
			
		||||
            this.markUsed();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -301,7 +303,7 @@ namespace motors {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private __setSpeed(speed: number) {
 | 
			
		||||
            const b = mkCmd(this._port, DAL.opOutputSpeed, 1)
 | 
			
		||||
            const b = mkCmd(this._port, this._regulated ? DAL.opOutputPower : DAL.opOutputSpeed, 1)
 | 
			
		||||
            b.setNumber(NumberFormat.Int8LE, 2, speed)
 | 
			
		||||
            writePWM(b)
 | 
			
		||||
            if (speed) {
 | 
			
		||||
@@ -315,11 +317,24 @@ namespace motors {
 | 
			
		||||
                step1: 0,
 | 
			
		||||
                step2: stepsOrTime,
 | 
			
		||||
                step3: 0,
 | 
			
		||||
                speed: speed,
 | 
			
		||||
                speed: this._regulated ? speed : undefined,
 | 
			
		||||
                power: this._regulated ? undefined : speed,
 | 
			
		||||
                useBrake: this._brake
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Indicates if the motor speed should be regulated. Default is true.
 | 
			
		||||
         * @param value true for regulated motor
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=outputMotorSetRegulated block="set %motor|regulated %value"
 | 
			
		||||
        //% value.fieldEditor=toggleonoff
 | 
			
		||||
        //% weight=58
 | 
			
		||||
        //% group="Move"
 | 
			
		||||
        setRegulated(value: boolean) {
 | 
			
		||||
            this._regulated = value;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Gets motor actual speed.
 | 
			
		||||
         * @param motor the port which connects to the motor
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user