Program 6 (Fall 2023)
The code below is a set of functions, variables, constants, and algorithms that are the work of RoboCatz for the Fall 2023 season.
const pi = 3.14159
wheelDiameter = 5.6
wheelCircumference = wheelDiameter * pi
distanceBetweenWheels = 90
gearRatio = 28/20
degreesPerCentimeter =360/wheelCircumference
function moveForward (distance) {
acceleration = degreesPerCentimeter * gearRatio * distance*.1 //20.571 is degrees per centimeter
atTopSpeed = degreesPerCentimeter * gearRatio * distance*.8
deceleration = degreesPerCentimeter * gearRatio * distance*.1
//beep()
print(`${acceleration} ${atTopSpeed} ${deceleration}`)
stepMotors( B , C , 50 ,acceleration, atTopSpeed, deceleration)
waitHereWhile getMotorSpeed(B) == 0
waitHereUntil getMotorSpeed(B) == 0
stopAllMotors(true)
beep(100,8000,1000)
}
function moveBackward(distance) {
if (distance*1 > 0) {
acceleration = degreesPerCentimeter * gearRatio * distance*.05
atTopSpeed = degreesPerCentimeter * gearRatio * distance*.9
deceleration = degreesPerCentimeter * gearRatio *distance*.05
if ( acceleration == 0 ) alert('sorry. try again.')
stepMotors( B , C , -50 ,acceleration, atTopSpeed, deceleration)
waitHereWhile getMotorSpeed(B) == 0
sleep(100)
waitHereUntil getMotorSpeed(B) == 0
stopAllMotors(true)
} else {
syncMotors( B, C, -25)
}
}
function liftDaLever(power=55){
setMotor(A,power)
setMotor(D,power)
sleep(1000)
waitHereUntil isMotorStalled(A) and isMotorStalled(D)
beep(100,800,10)
stopAllMotors()
resetEncoder(A)
resetEncoder(D)
}
function lowerDaLever(power=-55){
setMotor(A,power)
setMotor(D,power)
sleep(1000)
waitHereUntil isMotorStalled(A) and isMotorStalled(D)
beep(100,800,10)
stopAllMotors()
resetEncoder(A)
resetEncoder(D)
}
liftDaLever()
moveForward(25)
lowerDaLever()
moveBackward(25)