RoboCatz.com

Program 7 (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   
degreesPerCentirmeter=360/wheelCircumference
swingTurnDiameter = distanceBetweenWheels * 2
gearRatio=28/20

function moveForward (distance) {
    acceleration =gearRatio* degreesPerCentirmeter * distance*.1
    atTopSpeed =gearRatio* degreesPerCentirmeter * distance*.8
    deceleration = gearRatio* degreesPerCentirmeter * distance*.1
   stepMotors( B , C , 50 ,acceleration, atTopSpeed, deceleration)
   waitHereWhile getMotorSpeed(B) == 0
   waitHereUntil getMotorSpeed(B) == 0
   stopAllMotors(true)
}


function moveBackward(distance) { 
   	if (distance > 0) {
       acceleration = gearRatio* degreesPerCentirmeter * distance*.1
    atTopSpeed = gearRatio* degreesPerCentirmeter * distance*.8
    deceleration = gearRatio* degreesPerCentirmeter * distance*.1
stepMotors( B , C , -50 ,acceleration, atTopSpeed, deceleration)
   waitHereWhile getMotorSpeed(B) == 0
   waitHereUntil getMotorSpeed(B) == 0
   stopAllMotors(true)
   } else {
   syncMotors( B, C, -25)
   } 
} 

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

//function Linefind() {
//	syncMotors( B, C, -30 )              // Start moving
//	while( lightSensorPct() > 20 )   // while the light sensor sees a white ground
//	  drawText(50, 60, lightSensorPct(), 2)                    //   Show the lightSensor Percentage
//	  sleep(100)                        //   sleep for 1/10th of a second
	                                  // repeat the loop   
//}

function swingTurnLeftBackwards(degreesRobotShouldTurn = 90) {
  motorDegreesPerRobotDegree = (swingTurnCircumference / wheelCircumference )
  
  acceleration = 0.25 * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  atTopSpeed   = 0.70 * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  deceleration = 0.15 * degreesRobotShouldTurn * motorDegreesPerRobotDegree
  stepMotor(C, -50, acceleration, atTopSpeed, deceleration) 
  waitHereWhile getMotorSpeed(C)==0 
  waitHereUntil getMotorSpeed(C)==0  
  stopAllMotors(true) 
}
function annaDelivery() { 
	moveBackward(0.5)
	moveForward(70)
	swingTurnLeft(45)//reduced it was 55
	moveForward(35)
//	alert ( ' im on 83')
	moveBackward(60)
	swingTurnLeftBackwards(57)
	moveBackward(45)
}
 function Linefind() {
	syncMotors( B, C, 30 )              // Start moving
	while( lightSensorPct() > 15	  )   // while the light sensor sees a white ground
	  drawText(55, 80, lightSensorPct(), 2)                    //   Show the lightSensor Percentage
	  sleep(100)                        //   sleep for 1/10th of a second
	                                  // repeat the loop
	stopAllMotors()     
}
function popStage() {
	moveBackward(0.15)
	swingTurnRight(40)
	moveForward(30)
	swingTurnRight(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)
} 
moveForward(45)
moveBackward(45)