|
| 1 | +#pragma config(I2C_Usage, I2C1, i2cSensors) |
| 2 | +#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign ) |
| 3 | +#pragma config(Motor, port2, frontRight, tmotorVex393_MC29, openLoop, reversed, encoderPort, I2C_1) |
| 4 | +#pragma config(Motor, port3, frontLeft, tmotorVex393_MC29, openLoop, encoderPort, I2C_1) |
| 5 | +#pragma config(Motor, port4, backRight, tmotorVex393_MC29, openLoop, reversed) |
| 6 | +#pragma config(Motor, port5, backLeft, tmotorVex393_MC29, openLoop) |
| 7 | +//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// |
| 8 | + |
| 9 | +task main() { |
| 10 | + // Check this link for encoder help http://www.robotc.net/blog/2012/03/07/programming-with-the-new-vex-integrated-motor-encoders/ |
| 11 | + float diameter = 4; // Change this value to the diameter of the wheel. All of these distances should be in inches. Do not change these values on accident!!! |
| 12 | + float circumference = PI * diameter; // This calculates the circumference of the wheel fast and easy! |
| 13 | + |
| 14 | + // This is the code for the right wheel |
| 15 | + int distanceToGoRight = 17.875; // This is how far we want the robot to go during certain autonomous periods. You can change only this line, nothing else! |
| 16 | + float rotationsRight = distanceToGoRight / circumference; |
| 17 | + int degreesToTurnRight = rotationsRight * 360; |
| 18 | + int encoderCountsRight = degreesToTurnRight * 4; // The encoder counts in quarters of a degree, not a full degree |
| 19 | + |
| 20 | + // This is the code for the left wheel |
| 21 | + int distanceToGoLeft = -17.875; |
| 22 | + float rotationsLeft = distanceToGoLeft / circumference; |
| 23 | + int degreesLeft = rotationsLeft * 360; |
| 24 | + int encoderCountsLeft = degreesLeft * 4; |
| 25 | + |
| 26 | + // Reset all the encoder values so we make sure our robot functions properly |
| 27 | + nMotorEncoder[frontRight] = 0; |
| 28 | + nMotorEncoder[frontLeft] = 0; |
| 29 | + |
| 30 | + // Set the targets for each of the encoders |
| 31 | + nMotorEncoder[frontRight] = encoderCountsRight; |
| 32 | + nMotorEncoder[frontLeft] = encoderCountsLeft; |
| 33 | + |
| 34 | + if (vexRT[Btn5U] == 1) |
| 35 | + { |
| 36 | + // Run the motors until they have reached their values |
| 37 | + if (nMotorEncoder[frontRight] != runStateIdle && nMotorEncoder[frontLeft] != runStateIdle) |
| 38 | + { |
| 39 | + // We are wating for idk |
| 40 | + } |
| 41 | + else |
| 42 | + { |
| 43 | + motor[frontRight] = 127; |
| 44 | + motor[frontLeft] = -127; |
| 45 | + } |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + motor[frontRight] = 0; |
| 50 | + motor[frontLeft] = 0; |
| 51 | + } |
| 52 | +} |
0 commit comments