Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wedo2 stop motor when power set to 0 #4207

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tpsnt
Copy link

@tpsnt tpsnt commented Feb 9, 2024

When wedo2 motor power set to 0, the motor stops.

Resolves

When wedo2 motor power set to 0, the motor won't stop. And motorOff() won't stop the motors either.

Proposed Changes

This change adds a judge statement. When a startMotorPower() is invoked, it checks args.POWER. If args.POWER === 0, call a motor.turnOff first, then change the power attribute of the motor.

Reason for Changes

In WeDo2Motor.turnOff(), if this._power === 0, it returns immediately.
In Scratch3WeDo2Blocks.startMotorPower(), if args.POWER === 0, WeDo2Motor.turnOn() returns immediately.
So when you call Scratch3WeDo2Blocks.startMotorPower({POWER:0}), you won't turnOff() the motor, until you set the power to a number other and 0.

Test Coverage

Scratch3WeDo2Blocks.startMotorPower({POWER:0});
WeDo2Motor.turnOff();

When motor power set to 0, the motor stops.
@tpsnt tpsnt changed the title fix: stop motor when power set to 0 fix: wedo2 stop motor when power set to 0 Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant