RoboCatz.com

Program 5 (Fall 2024)


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 , 80 ,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 swingTurnRight(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 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)
   
	}
}
moveForward (67)
setMotor( A, -25)
sleep(1000)
moveBackward(67)
alert('i am here')
moveForward (26)
swingTurnLeft(90)
moveForward (28)
swingTurnLeft(90)
moveForward (28)
moveBackward(15)