RoboCatz.com

Program 3 (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 moveBackward (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}`)
    stopAllMotors(true),sleep(200)
   stepMotors( B , C , 50 ,acceleration, atTopSpeed, deceleration)
   waitHereWhile getMotorSpeed(B) == 0
   waitHereUntil getMotorSpeed(B) == 0
   stopAllMotors(true)
   beep(100,8000,1000)
}

function swingTurnRight(degreesRobotShouldTurn = 90) {
	motorDegreesPerRobotDegree = (swingTurnCircumference / wheelCircumference )
	acceleration = 0.25 * degreesRobotShouldTurn * motorDegreesPerRobotDegree
	atTopSpeed   = 0.70 * degreesRobotShouldTurn * motorDegreesPerRobotDegree
	deceleration = 0.15 * degreesRobotShouldTurn * motorDegreesPerRobotDegree
	stepMotor(B, 25, acceleration, atTopSpeed, deceleration) 
	waitHereWhile getMotorSpeed(B)==0
	sleep(100)
	waitHereUntil getMotorSpeed(B)==0  
	stopAllMotors(true) 
}
function moveForward(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 ForwardAccelerationOnly(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)
		waitHereWhile getMotorSpeed(B) == 0
		sleep(100)
		waitHereUntil getMotorSpeed(B) == 0
		stopAllMotors(true)
	} else {
		syncMotors( B, C, -25)
	} 
}

function swingTurnLeft(degreesRobotShouldTurn = 10) {
  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
  sleep(100)
  waitHereUntil getMotorSpeed(B)==0  
  stopAllMotors(true) 
}
function swingTurnLeftThree(degreesRobotShouldTurn = 10) {
	beep()
  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) 
}
//stops motor C and moves motor B backwards
function swingTurnRightTwo(degreesRobotShouldTurn = 10) {
  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 colorTurnerKey(){
	clearScreen()
	resetGyroSensor()
  	//alert('You selected ENTER')
  	syncMotors(B,C,20), sleep(100)
  	moveForward(62)
    swingTurnLeft(87)
	moveBackward(2)
    moveForward(4)
	moveBackward(5)
	moveForward(8)
	moveBackward(5)
    setLED(5)
    sleep(2000)
    //alert('ok')
	    
	//moveBackward(60)
	//swingTurnRightTwo(44)
}

//colorTurnerKey()
//print(`gyro ${gyroSensor()}`)
//swingTurnLeft(80) 
//moveBackward(4)
//setMotor( B, 30 )              // Start moving
//while( lightSensorPct(2) > 30 ) {  // while the light sensor sees a white ground
//  drawText(50, 60, lightSensorPct(2), 2)                    //   Show the lightSensor Percentage
//  sleep(100)                        //   sleep for 1/10th of a second
//}                                   // repeat the loop
//stopAllMotors()                     // line has been detected
//sleep(500)
//print(`gyro ${gyroSensor()}`)TurnR


target = 40
gain = 1.5
resetEncoder( B )

//while abs(encoderValue(B))< 600.00 {
  //drawText(10,10, gain*(lightSensorPct(2)-target)+'  ', 2)
  ////syncMotors(B, C, 20, gain*(lightSensorPct(2)-target))
  //clearRect(0,90, 178, 38)  // clears the bottom of the LCD screen
  //fillRect((90-30*0.5)-(lightSensorPct(2)-target),90, 30, 38)
  //sleep(100)
//}
stopAllMotors()
moveForward(60)
swingTurnLeft(36)
moveBackward(7)
ForwardAccelerationOnly(12)
moveBackward(9)
ForwardAccelerationOnly(14)
moveBackward(12)
swingTurnRight(60)
moveBackward(60)

//swingTurnLeftThree(60)
//moveBackward(40)
//swingTurnLeftThree(90)