-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maze Program.c
149 lines (116 loc) · 3.61 KB
/
Maze Program.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, leftFollower, sensorLineFollower)
#pragma config(Sensor, in2, rightFollower, sensorLineFollower)
#pragma config(Sensor, dgtl1, leftBumper, sensorTouch)
#pragma config(Sensor, dgtl2, rightBumper, sensorTouch)
#pragma config(Sensor, dgtl3, armBaseEncoder1, sensorQuadEncoder)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port1, leftMotor, tmotorVex269_HBridge, openLoop, reversed, driveLeft, encoderPort, I2C_1)
#pragma config(Motor, port2, armBaseLeft, tmotorServoStandard, openLoop)
#pragma config(Motor, port3, armBaseRight, tmotorServoStandard, openLoop)
#pragma config(Motor, port4, armElbow, tmotorServoStandard, openLoop)
#pragma config(Motor, port5, armWrist, tmotorServoStandard, openLoop)
#pragma config(Motor, port6, armRiser, tmotorServoStandard, openLoop)
#pragma config(Motor, port10, rightMotor, tmotorVex269_HBridge, openLoop, reversed, driveRight, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#define abs(X) ((X < 0) ? -1 * X : X)
#define MAX_SPEED 127
#define MID_SPEED 63
#define ZERO_SPEED 0
/**
* driveStraight(int, int) should be preferred to moving individual motors.
* Note: distance is in tenths of an inch.
*/
void driveMotor(int distance, int speed, short motorName, short encoderName)
{
SensorValue[encoderName] = 0;
int tickGoal = 29 * distance / 10;
int totalTicks = 0;
while (abs(totalTicks) < tickGoal)
{
totalTicks += SensorValue(encoderName);
motor[motorName] = speed;
wait1Msec(100);
}
motor[motorName] = 0;
}
void driveStraight(int distance, int speed)
{
int masterPower = speed;
int slavePower = masterPower - 5;
int tickGoal = 29 * distance;
int totalTicks = 0;
// The difference in speed between the master and slave encoders.
int error = 0;
//'Constant of proportionality' which the error is divided by. Usually this is a number between 1 and 0 the
//error is multiplied by, but we cannot use floating point numbers. Basically, it lets us choose how much
//the difference in encoder values effects the final power change to the motor.
int kp = 5;
SensorValue[I2C_1] = 0;
SensorValue[I2C_2] = 0;
while (abs(totalTicks) < tickGoal) {
motor[leftMotor] = masterPower;
motor[rightMotor] = slavePower;
error = SensorValue[I2C_1] - SensorValue[I2C_2];
slavePower += error / kp;
SensorValue[I2C_1] = 0;
SensorValue[I2C_2] = 0;
wait1Msec(100);
totalTicks += SensorValue[I2C_1];
}
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
void driveStraight(int distance)
{
driveStraight(distance, MAX_SPEED);
}
void turnLeft(int distance, int speed)
{
driveMotor(distance, speed, rightMotor, I2C_2);
}
void turnLeft(int distance)
{
turnLeft(distance, MID_SPEED);
}
void turnRight(int distance, int speed)
{
driveMotor(distance, speed, leftMotor, I2C_1);
}
void turnRight(int distance)
{
turnRight(distance, MID_SPEED);
}
void reset()
{
}
void expandArm()
{
}
void moveArmBase(int distance)
{
}
void moveElbow(int distance)
{
}
task main()
{
wait1Msec(2000);
driveStraight(60);
turnRight(2);
driveStraight(150);
turnRight(2);
driveStraight(150);
turnRight(2);
driveStraight(25);
turnRight(2);
driveStraight(25);
turnLeft(2);
driveStraight(25);
turnLeft(2);
driveStraight(10);
// motor[armBaseLeft] = -127;
// motor[armBaseRight] = -127;
// wait1Msec(10000);
}