Skip to content

Commit 333954c

Browse files
authored
Added initial
1 parent d07dfef commit 333954c

8 files changed

+1890
-0
lines changed

180.c

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma config(Motor, port2, frontRight, tmotorVex393_MC29, openLoop, reversed)
2+
#pragma config(Motor, port3, frontLeft, tmotorVex393_MC29, openLoop)
3+
#pragma config(Motor, port4, backRight, tmotorVex393_MC29, openLoop, reversed)
4+
#pragma config(Motor, port5, backLeft, tmotorVex393_MC29, openLoop)
5+
#pragma config(Motor, port6, rightLauncher, tmotorVex393_MC29, openLoop)
6+
#pragma config(Motor, port7, leftLauncher, tmotorVex393_MC29, openLoop)
7+
#pragma config(Motor, port8, topBelt, tmotorVex393_MC29, openLoop)
8+
9+
// Setup for the shaft encoders. All units are in inches, unless otherwise stated.
10+
float diameter = 4;
11+
float circumference = PI * diameter;
12+
13+
// Now we will find out how many times each wheel has to turn to go a specefied distance for the right side.
14+
float distanceRight = 29.875;
15+
int rotationsRight = distanceRight / circumference;
16+
float degreesRight = rotationsRight * 360;
17+
int encoderCountsRight = degreesRight * 4; // The encoder counts in quarter degrees.
18+
19+
// This is so we can find out how many times the left wheels have to turn to go the specefied distance
20+
float distanceLeft = -29.875;
21+
int rotationsLeft = distanceLeft / circumference;
22+
float degreesLeft = rotationsLeft * 360;
23+
int encoderCountsLeft = degreesLeft * 4;
24+
25+
task main() //This will only give us the required number on the encoders for a 180 degree turn
26+
{
27+
28+
if (vexRT[Btn8D] == 1)
29+
{
30+
// We will reset the motor encoder values here so we don't screw anything up
31+
nMotorEncoder[frontRight] = 0;
32+
nMotorEncoder[frontLeft] = 0;
33+
34+
if (nMotorEncoder[frontRight] >= encoderCountsRight && nMotorEncoder[frontLeft] >= encoderCountsLeft)
35+
{
36+
motor[frontRight] = 0;
37+
motor[frontLeft] = 0;
38+
motor[backRight] = 0;
39+
motor[backLeft] = 0;
40+
}
41+
42+
else
43+
{
44+
motor[frontRight] = 127;
45+
motor[frontLeft] = -127;
46+
motor[backRight] = 127;
47+
motor[backLeft] = -127;
48+
}
49+
}
50+
51+
}

180_Degree_Turn.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)