-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleOp.c
112 lines (90 loc) · 2.96 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
#pragma config(Hubs, S2, HTMotor, HTMotor, none, none)
#pragma config(Sensor, S1, limit_switch, sensorTouch)
#pragma config(Sensor, S2, , sensorI2CMuxController)
#pragma config(Motor, motorA, , tmotorNXT, openLoop)
#pragma config(Motor, motorB, , tmotorNXT, openLoop)
#pragma config(Motor, motorC, , tmotorNXT, openLoop)
#pragma config(Motor, mtr_S2_C1_1, arm_tipper, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C1_2, flag_spinner, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C2_1, right_drive, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S2_C2_2, left_drive, tmotorTetrix, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
#include "gearcats_helpers.h"
//disable main tasks in functions from other files
#define MAIN_ROBOT_CODE
const float POWER_LEVEL_1 = 0.50;
const float POWER_LEVEL_2 = 1.00;
float current_power_level;
int forward;
int turn;
//will be run once at start of teleop
void initializeRobot()
{
left_drive_motor = left_drive;
right_drive_motor = right_drive;
current_power_level = POWER_LEVEL_1;
// Place code here to initialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.
return;
}
//zeroes a value if its magnitude is less than a certain value
//used to create a dead zone for the motors
int floor(int input, int min_value){
if (abs(input) < min_value) {
return 0;
} else {
return input;
}
}
task drive() {
while(true){
getJoystickSettings(joystick);
//these have to be floored to create a dead zone, preventing motor drift and noise
forward = floor(joystick.joy1_y1, 10) * current_power_level;
turn = floor(joystick.joy1_x2,10) * current_power_level;
if (abs(forward) < 10){
forward = 0;
}
arcade_drive(forward, turn);
nxtDisplayTextLine(1, "forward: %d", forward);
nxtDisplayTextLine(2, "turn: %d", turn);
}
}
task main()
{
initializeRobot();
waitForStart(); // wait for start of tele-op phase
StartTask(drive);
while (true)
{
getJoystickSettings(joystick);
//power level controls: driver can set motors to always spin at half speed, allowing more precise control
if (joy1Btn(A_BTN) == 1){
current_power_level = POWER_LEVEL_1;
}
if (joy1Btn(B_BTN) == 1) {
current_power_level = POWER_LEVEL_2;
}
int arm_tipper_speed = 0;
//move the arm up if X pressed, down if Y, otherwise brake
if(joy1Btn(X_BTN) == 1) {
arm_tipper_speed = 20;
}
else if(joy1Btn(Y_BTN) == 1) {
arm_tipper_speed = -20;
}
else {
arm_tipper_speed = 0;
}
if (joy1Btn(6)){
arm_tipper_speed /= 2;
}
motor[arm_tipper] = arm_tipper_speed;
if (joy1Btn(5)) {
motor[flag_spinner] = 63;
} else {
motor[flag_spinner] = 0;
}
}
}