RoboCatz.com

Program 4 (Fall 2025) - Amir2.js


The code below is a set of functions, variables, constants, and algorithms that are the work of RoboCatz for the Fall 2025 season.

// Program name: Amir2.js
const pi = 3.141592653589793238462643382
let gearRatio = 28/20
wheelDiameter = 8.8
let degreesPerCentimeter = 360/(wheelDiameter*pi)
distanceBetweenWheels = 13.5
wheelCircumference = wheelDiameter * pi       
      

pointTurnCircumference=distanceBetweenWheels*pi




function getRocks(){
	//gearRatio = 20/14
	//degreesPerCentimeter = 24
	setMotor( D, 100 )
	sleep( 100 )
	resetEncoder( D )
	waitHereUntil abs(encoderValue( D )) > 1050
	or isMotorStalled(D)
	stopAllMotors()
}

function moveBackward (distance) {
    acceleration =gearRatio* degreesPerCentimeter * distance*.1
    atTopSpeed =gearRatio* degreesPerCentimeter * distance*.8
    deceleration = gearRatio* degreesPerCentimeter * distance*.1
   stepMotors( B , C , 80 ,acceleration, atTopSpeed, deceleration)
   waitHereWhile getMotorSpeed(B) == 0
   waitHereUntil getMotorSpeed(B) == 0
   stopAllMotors(true)
}
function moveForward (distance) {
    acceleration =gearRatio* degreesPerCentimeter * distance*.1
    atTopSpeed =gearRatio* degreesPerCentimeter * distance*.8
    deceleration = gearRatio* degreesPerCentimeter * distance*.1
   stepMotors( B , C , -30 ,acceleration, atTopSpeed, deceleration)
   waitHereWhile getMotorSpeed(B) == 0
   waitHereUntil getMotorSpeed(B) == 0
   stopAllMotors(true)
}

function pointTurnRight(degreesRobotShouldTurn = 90) {
  motorDegreesPerRobotDegree = (pointTurnCircumference / wheelCircumference )
  acceleration = 0.15 * gearRatio * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  atTopSpeed   = 0.70 * gearRatio * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  deceleration = 0.15 * gearRatio * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  stepMotor(B, 20, acceleration, atTopSpeed, deceleration)  // Pass the parameters to the stepMotor() function.
  stepMotor(C, -20, acceleration, atTopSpeed, deceleration) // Notice that one of the motors has positive speed and the other negative speed.
  // Now check the speed of the motors to see if the robot has started or completed the maneuver.
  // Because two motors are being used to make the turn, you will need to check the speed of both motors.
  // The stepMotor() function always starts with the speed at zero.
  waitHereWhile getMotorSpeed(B)==0 || getMotorSpeed(C)==0  // Wait here while the robot has not yet started to move.
  waitHereUntil getMotorSpeed(B)==0 && getMotorSpeed(C)==0  // Wait here as the motor is turning and only exit from this line when the speed returns to back to zero.
  stopAllMotors(true) // Apply the brake to the motor(s)
}

moveForward(64)

await stepMotor( C, -40, 120 )


moveForward(5)
getRocks()



moveBackward(5)
await stepMotor( C, 40, 30 )
moveBackward(64)