-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleOp.c
197 lines (179 loc) · 4.7 KB
/
TeleOp.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#pragma config(Hubs, S1, HTServo, HTMotor, HTMotor, HTMotor)
#pragma config(Sensor, S2, HTIRS2, sensorI2CCustom)
#pragma config(Sensor, S3, HTGYRO, sensorAnalogInactive)
#pragma config(Motor, motorA, green, tmotorNormal, openLoop)
#pragma config(Motor, motorB, yellow, tmotorNormal, openLoop)
#pragma config(Motor, motorC, red, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_1, ballArm, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_2, clawArm, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C3_1, intake, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C3_2, spool, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C4_1, right, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C4_2, left, tmotorNormal, openLoop, encoder)
#pragma config(Servo, srvo_S1_C1_1, clawRelease, tServoStandard)
#pragma config(Servo, srvo_S1_C1_2, armRelease, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/* $Id$ */
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
#define SERVO_CHANGE_RATE 10
#define LED_ON 100
#define LED_OFF 0
#define JOYSTICK_THRESHOLD 10
#define INTAKE_POWER 100
#define MOTOR_OFF 0
#define MOTOR_FULL 100
#define SPOOL_SPEED 50
#define GRAB_START 20
#define GRAB_OPEN 100
#define ARM_RELEASE_OPEN 120
#define ARM_RELEASE_CLOSED 239
#define CLAW_RELEASE_OPEN 186
#define CLAW_RELEASE_CLOSED 131
#define CLAW_SPEED 100
/**
* Initialize the robot.
*/
void initializeRobot()
{
bFloatDuringInactiveMotorPWM = false;
motor[green] = LED_ON;
motor[yellow] = LED_ON;
motor[red] = LED_ON;
motor[right] = MOTOR_OFF;
motor[clawArm] = MOTOR_OFF;
motor[left] = MOTOR_OFF;
motor[ballArm] = MOTOR_OFF;
motor[spool] = MOTOR_OFF;
motor[intake] = MOTOR_OFF;
servoChangeRate[armRelease] = 50;
servoTarget[armRelease] = ARM_RELEASE_CLOSED;
servoChangeRate[armRelease] = 10;
servoTarget[clawRelease] = CLAW_RELEASE_CLOSED;
return;
}
/**
*
*/
task main()
{
bool armReleaseOpen = false;
initializeRobot(); // init
waitForStart(); // wait for start of tele-op phase
motor[green] = LED_OFF;
motor[yellow] = LED_OFF;
motor[red] = LED_OFF;
while(true)
{
getJoystickSettings(joystick);
// 100% power
if(abs(joystick.joy1_y1) > JOYSTICK_THRESHOLD)
{
motor[left] = joystick.joy1_y1;
}
else
{
motor[left] = MOTOR_OFF;
}
if(abs(joystick.joy1_y2) > JOYSTICK_THRESHOLD)
{
motor[right] = joystick.joy1_y2;
}
else
{
motor[right] = MOTOR_OFF;
}
if(abs(joystick.joy2_y1) > JOYSTICK_THRESHOLD)
{
motor[ballArm] = joystick.joy2_y1;
}
else
{
motor[ballArm] = MOTOR_OFF;
}
// intake
if(joy2Btn(2))
{
motor[intake] = INTAKE_POWER;
motor[green] = LED_OFF;
motor[red] = LED_ON;
}
else if(joy2Btn(1))
{
motor[intake] = -INTAKE_POWER;
motor[green] = LED_ON;
motor[red] = LED_OFF;
}
else
{
motor[intake] = MOTOR_OFF;
motor[green] = LED_OFF;
motor[red] = LED_OFF;
}
if(joy2Btn(4) && joy2Btn(5))
{
servo[clawRelease] = CLAW_RELEASE_OPEN;
}
else
{
servo[clawRelease] = CLAW_RELEASE_CLOSED;
}
if(joy2Btn(3) && joy2Btn(5))
{
servo[armRelease] = ARM_RELEASE_OPEN;
armReleaseOpen = true;
}
else if(!armReleaseOpen)
{
servo[armRelease] = ARM_RELEASE_CLOSED;
}
if(joy2Btn(6))
{
motor[spool] = SPOOL_SPEED;
}
else if(joy2Btn(8))
{
motor[spool] = -SPOOL_SPEED;
}
else
{
motor[spool] = MOTOR_OFF;
}
if(abs(joystick.joy2_y2) > JOYSTICK_THRESHOLD)
{
if(joystick.joy2_y2 > 0)
{
motor[clawArm] = 20;
}
else
{
motor[clawArm] = -CLAW_SPEED;
}
}
else
{
motor[clawArm] = MOTOR_OFF;
}
/*
if(joy1Btn(6))
{
servo[grab] = GRAB_START;
motor[yellow] = LED_OFF;
}
else if(joy1Btn(8))
{
servo[grab] = GRAB_OPEN;
motor[yellow] = LED_ON;
}
if(joy2Btn(6))
{
servo[hopper1] = HOPPER1_OPEN;
servo[hopper2] = HOPPER2_OPEN;
}
else
{
servo[hopper1] = HOPPER1_CLOSED;
servo[hopper2] = HOPPER2_CLOSED;
}
*/
}
}