diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index a496592b..45879b14 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -53,6 +53,14 @@ "motors.Motor.clearCount": "Clears the motor count", "motors.Motor.count": "Gets motor step count.", "motors.Motor.move": "Moves the motor by a number of rotations, degress or seconds", + "motors.Motor.moveSteering": "Turns the motor and the follower motor by a number of rotations", + "motors.Motor.moveSteering|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50", + "motors.Motor.moveSteering|param|steering": "the ratio of power sent to the follower motor, from ``-100`` to ``100``", + "motors.Motor.moveSteering|param|unit": "the meaning of the value", + "motors.Motor.moveSteering|param|value": "the move quantity, eg: 2", + "motors.Motor.moveTank": "The Move Tank block can make a robot drive forward, backward, turn, or stop. \nUse the Move Tank block for robot vehicles that have two Large Motors, \nwith one motor driving the left side of the vehicle and the other the right side. \nYou can make the two motors go at different speeds or in different directions \nto make your robot turn.", + "motors.Motor.moveTank|param|unit": "@param speedLeft ", + "motors.Motor.moveTank|param|value": "the amount of movement, eg: 2", "motors.Motor.move|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50", "motors.Motor.move|param|unit": "the meaning of the value", "motors.Motor.move|param|value": "the move quantity, eg: 2", @@ -66,11 +74,6 @@ "motors.Motor.sync": "Synchronizes a follower motor to this motor", "motors.Motor.sync|param|follower": "the motor that follows this motor commands, eg: motors.largeC", "motors.Motor.tachoCount": "Gets motor tacho count.", - "motors.Motor.turn": "Turns the motor and the follower motor by a number of rotations", - "motors.Motor.turn|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50", - "motors.Motor.turn|param|turnRatio": "the ratio of power sent to the follower motor, from ``-200`` to ``200``", - "motors.Motor.turn|param|unit": "the meaning of the value", - "motors.Motor.turn|param|value": "the move quantity, eg: 2", "motors.stopAllMotors": "Stops all motors", "output.createBuffer": "Create a new zero-initialized buffer.", "output.createBuffer|param|size": "number of bytes in the buffer", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index bf557bb5..a2f44b08 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -40,6 +40,8 @@ "control.raiseEvent|block": "raise event|from %src|with value %value", "control|block": "control", "motors.Motor.count|block": "`icons.motorLarge` %motor|count", + "motors.Motor.moveSteering|block": "move steering `icons.motorLarge` %motor|at %speed|%|steer %turnRadio|%|by %value|%unit", + "motors.Motor.moveTank|block": "move tank `icons.motorLarge` %motor|left %speedLeft|%|right %speedRight|%|by %value|%unit", "motors.Motor.move|block": "move `icons.motorLarge` %motor|for %value|%unit|at %speed|%", "motors.Motor.reset|block": "reset `icons.motorLarge` %motor", "motors.Motor.setBrake|block": "set `icons.motorLarge` %motor|brake %brake", @@ -48,7 +50,6 @@ "motors.Motor.speed|block": "`icons.motorLarge` %motor|speed", "motors.Motor.sync|block": "sync `icons.motorLarge` %motor|with `icons.motorLarge` %follower", "motors.Motor.tachoCount|block": "`icons.motorLarge` %motor|tacho count", - "motors.Motor.turn|block": "turn `icons.motorLarge` %motor|by %value|%unit|at %speed|% turn %turnRadio", "motors.largeMotorA|block": "large A", "motors.largeMotorB|block": "large B", "motors.largeMotorC|block": "large C", diff --git a/libs/core/output.ts b/libs/core/output.ts index f95b6a33..1255a52a 100644 --- a/libs/core/output.ts +++ b/libs/core/output.ts @@ -313,15 +313,38 @@ namespace motors { * @param value the move quantity, eg: 2 * @param unit the meaning of the value * @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50 - * @param turnRatio the ratio of power sent to the follower motor, from ``-200`` to ``200`` + * @param steering the ratio of power sent to the follower motor, from ``-100`` to ``100`` */ - //% blockId=motorTurn block="turn `icons.motorLarge` %motor|by %value|%unit|at %speed|% turn %turnRadio" + //% blockId=motorTurn block="move steering `icons.motorLarge` %motor|at %speed|%|steer %turnRadio|%|by %value|%unit" //% weight=9 blockGap=8 - //% turnRatio.min=-200 turnRatio=200 + //% steering.min=-100 steering=100 //% inlineInputMode=inline - turn(value: number, unit: MoveUnit, speed: number, turnRatio: number) { - this.output(value, unit, speed, turnRatio); - } + moveSteering(steering: number, speed: number, value: number, unit: MoveUnit) { + this.output(value, unit, speed, steering + 100); + } + + /** + * The Move Tank block can make a robot drive forward, backward, turn, or stop. + * Use the Move Tank block for robot vehicles that have two Large Motors, + * with one motor driving the left side of the vehicle and the other the right side. + * You can make the two motors go at different speeds or in different directions + * to make your robot turn. + * @param value the amount of movement, eg: 2 + * @param unit + * @param speedLeft the speed on the left motor, eg: 50 + * @param speedRight the speed on the right motor, eg: 50 + */ + //% blockId=motorTank block="move tank `icons.motorLarge` %motor|left %speedLeft|%|right %speedRight|%|by %value|%unit" + //% weight=9 blockGap=8 + //% speedLeft.min=-100 speedLeft=100 + //% speedRight.min=-100 speedRight=100 + //% inlineInputMode=inline + moveTank(speedLeft: number, speedRight: number, value: number, unit: MoveUnit) { + speedLeft = Math.clamp(speedLeft >> 0, -100, 100); + speedRight = Math.clamp(speedRight >> 0, -100, 100); + const steering =(speedRight * 100 / speedLeft) >> 0; + this.moveSteering(speedLeft, steering, value, unit); + } } //% whenUsed fixedInstance block="large A"