RoboCatz.com

Program 4 (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 = 12   
degreesPerCentirmeter=360/wheelCircumference
swingTurnDiameter = distanceBetweenWheels * 2
swingTurnCircumference = swingTurnDiameter*pi
gearRatio=28/20
 
resetVector(50)

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 *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 = (swingTurnCircumference / 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 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 turnVector(newVector) {
	currentVector=vectorValue()
	diffrince= abs(newVector-currentVector)
	//alert(diffrince)
	if newVector-currentVector > 0 swingTurnLeft(diffrince)
	if newVector-currentVector < 0 swingTurnRight(diffrince)   
}

moveForward (38)
turnVector(0)
moveForward (0)

beep()
// Accessory Motor
setMotor( A,  40 )
sleep( 100 )
resetEncoder( A )
waitHereUntil abs(encoderValue( A )) > 90
stopAllMotors()
sleep(2000)