rework port output command handling #159
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Initially I only planned to do some small improvements to prevent my port input commands from clogging up such that they were already outdated when being transmitted. But the whole undertaking got more and more inconsistent and messy, so I ended up doing a large-scale rework for all port output commands.
A large majority of code using the library should be compatible with the changes, but some things would change. Rough overview of most important breaking change without paying attention to detail:
same behavior:
motorA.rotateByDegrees(30).then(motorA.rotateByDegrees(30));
Result: motorA rotates by 60 degrees in total
await motorA.rotateByDegrees(30); await motorA.rotateByDegrees(30);
Result: motorA rotates by 60 degrees in total
motorA.rotateByDegrees(30); motorB.rotateByDegrees(30);
Result: motorA and motorB start rotating at the same time by 30 degrees each
motorA.setAccelerationTime(300); motorA.rotateByDegrees(30);
Result: the acceleration time is set to 300 ms and then motorA rotates by 30 degrees
different behavior:
motorA.rotateByDegrees(30); motorA.rotateByDegrees(30);
Result old: motorA rotates by 30 degrees
Result new: motorA rotates by 60 degrees
motorA.rampPower(0,100,5000).then(res => console.log("feedback is " + res)); motorA.rotateByDegrees(30);
Result old: motorA rotates by 30 degrees
Result new: motorA ramps power from 0 to 100, then prints "feedback is 34", then rotates by 30 degrees
new feature:
motorA.setAccelerationTime(300, true).then(res => console.log("feedback1 is " + res)); motorA.rotateByDegrees(30, 100, true).then(res => console.log("feedback2 is " + res));
Result new: prints "feedback1 is 68" and discards the acceleration time command, then rotates by 30 degrees with speed 100, then prints "feedback2 is 34"
I tested with a technic hub and two motors so far it works great for me and I did not encounter any problems, therefore I decided to put this change up for discussion even though not every device has been tested.