RoboCatz.com

Program 5 (Fall 2025) - Voyage1.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: Voyage1.js
const pi = 3.141592653589793238462643382
wheelDiameter = 8.8
wheelCircumference = wheelDiameter * pi       
distanceBetweenWheels = 13.5  
degreesPerCentirmeter=360/wheelCircumference
swingTurnDiameter = distanceBetweenWheels * 2
pointTurnCircumference=distanceBetweenWheels*pi
gearRatio=20/28
// alert(`${pointTurnCircumference}`)

// alert("hlo wrld")
 
function moveBackward (distance) {
    acceleration =gearRatio* degreesPerCentirmeter * distance*.1
    atTopSpeed =gearRatio* degreesPerCentirmeter * distance*.8
    deceleration = gearRatio* degreesPerCentirmeter * distance*.1
   stepMotors( B , C , 80 ,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, 25, acceleration, atTopSpeed, deceleration)  // Pass the parameters to the stepMotor() function.
  stepMotor(C, -25, 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)
}

function swingTurnLeft(degreesRobotShouldTurn = 90) {
  motorDegreesPerRobotDegree = (swingTurnDiameter*pi / wheelCircumference )
  
  acceleration = 0.25 *gearRatio* degreesRobotShouldTurn * motorDegreesPerRobotDegree
  atTopSpeed   = 0.70 *gearRatio* degreesRobotShouldTurn * motorDegreesPerRobotDegree
  deceleration = 0.15 *gearRatio* degreesRobotShouldTurn * motorDegreesPerRobotDegree
  stepMotor(C, 25, acceleration, atTopSpeed, deceleration) //reduced pwr from 50
  waitHereWhile getMotorSpeed(C)==0 
  waitHereUntil getMotorSpeed(C)==0  
  stopAllMotors(true) 
}
function swingTurnRight(degreesRobotShouldTurn = 90) {
  motorDegreesPerRobotDegree = (swingTurnDiameter*pi / wheelCircumference )
  
  acceleration = 0.25 *gearRatio* degreesRobotShouldTurn * motorDegreesPerRobotDegree
  atTopSpeed   = 0.70 *gearRatio* degreesRobotShouldTurn * motorDegreesPerRobotDegree
  deceleration = 0.15 *gearRatio* degreesRobotShouldTurn * motorDegreesPerRobotDegree
  stepMotor(C, -25, acceleration, atTopSpeed, deceleration) //reduced pwr from 50
  waitHereWhile getMotorSpeed(C)==0 
  waitHereUntil getMotorSpeed(C)==0  
  stopAllMotors(true) 
}  
 
function pointTurnLeft(degreesRobotShouldTurn = 90) {

  motorDegreesPerRobotDegree = (pointTurnCircumference / wheelCircumference )
  acceleration = 0.15 * gearRatio * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  atTopSpeed   = 0.70 * gearRatio * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  deceleration = 0.15 * gearRatio * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  // alert(`${motorDegreesPerRobotDegree} ${acceleration} ${atTopSpeed} ${deceleration } `)

  stepMotor(C, 25, acceleration, atTopSpeed, deceleration)  // Pass the parameters to the stepMotor() function.
  stepMotor(B, -25, 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)
 
 
} 
function moveForward() { 
		syncMotors( B , C , -80 , min( 45, max( -45, gyroSensor()*-4)) )
}

//program start
resetGyroSensor()
sleep(100)
while(touchSensorPressed()==false){
moveForward()

}