Last active
November 21, 2017 18:03
-
-
Save anastasiia-kornilova/aa023d07a68295ec47094acc68298e98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var time = 2000; | |
var cpr = [64, 64, 64, 64]; | |
var countTicks = function(motorPort, encoderPort, time) { | |
var motor = brick.motor(motorPort); | |
var encoder = brick.encoder(encoderPort); | |
var encBegin = encoder.readRawData(); | |
motor.setPower(100); | |
script.wait(time); | |
var encEnd = encoder.readRawData(); | |
motor.setPower(0); | |
return Math.abs(encEnd - encBegin); | |
}; | |
var round = function(number, accur) { | |
return Math.round(number * accur) / accur; | |
}; | |
var pixelPerString = 30; | |
var main = function() { | |
var display = brick.display(); | |
display.addLabel("Rotation time: " + time, 10, pixelPerString * 1); | |
print("Rotation time: " + time); | |
display.addLabel("Motor / CPR / Revs", 10, pixelPerString * 2); | |
print("Motor / CPR / Revs"); | |
for (var i = 1; i <= 4; i++) { | |
var ticks = countTicks("M" + i, "E" + i, time); | |
var revs = round(ticks / cpr[i - 1], 10); | |
var infoString = "M" + i + " / " + cpr[i - 1] + " / " + revs; | |
display.addLabel(infoString, 10, pixelPerString * (i + 2)); | |
display.redraw(); | |
print(infoString); | |
} | |
script.wait(60000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment