-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleOP Treads.c
159 lines (142 loc) · 5.22 KB
/
TeleOP Treads.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
#pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, HTMotor)
#pragma config(Sensor, S2, mag1, sensorHiTechnicMagnetic)
#pragma config(Sensor, S3, ir, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S4, mag2, sensorHiTechnicMagnetic)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_1, motorF, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_2, motorG, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C4_1, motorH, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C4_2, motorI, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C3_1, servo1, tServoStandard)
#pragma config(Servo, srvo_S1_C3_2, servo2, tServoStandard)
#pragma config(Servo, srvo_S1_C3_3, servo3, tServoStandard)
#pragma config(Servo, srvo_S1_C3_4, servo4, tServoStandard)
#pragma config(Servo, srvo_S1_C3_5, servo5, tServoStandard)
#pragma config(Servo, srvo_S1_C3_6, servo6, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tele-Operation Mode Code Template
//
// This file contains a template for simplified creation of an tele-op program for an FTC
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// initializeRobot
//
// Prior to the start of tele-op mode, you may want to perform some initialization on your robot
// and the variables within your program.
//
// In most cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
void initializeRobot()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.
return;
}
void detectball()
{
if((SensorValue[mag1] > 660 || SensorValue[mag1] < 654))
{
servo[servo1] = 255;
wait1Msec(500);
motor[motorD] = -100;
wait1Msec(500);
motor[motorD] = 0;
servo[servo1] =100;
wait1Msec(500);
}
}
void rollers()
{
motor[motorD] = -100;
motor[motorA] = -100;
motor[motorB] = -100;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Main Task
//
// The following is the main code for the tele-op robot operation. Customize as appropriate for
// your specific robot.
//
// Game controller / joystick information is sent periodically (about every 50 milliseconds) from
// the FMS (Field Management System) to the robot. Most tele-op programs will follow the following
// logic:
// 1. Loop forever repeating the following actions:
// 2. Get the latest game controller / joystick settings that have been received from the PC.
// 3. Perform appropriate actions based on the joystick + buttons settings. This is usually a
// simple action:
// * Joystick values are usually directly translated into power levels for a motor or
// position of a servo.
// * Buttons are usually used to start/stop a motor or cause a servo to move to a specific
// position.
// 4. Repeat the loop.
//
// Your program needs to continuously loop because you need to continuously respond to changes in
// the game controller settings.
//
// At the end of the tele-op period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
task main()
{
//initializeRobot();
//waitForStart(); // wait for start of tele-op phase
int threshold = 5;
while (true)
{
nxtDisplayTextLine(3, "Value is %d", SensorValue[mag1]);
rollers();
detectball();
getJoystickSettings(joystick);
if(abs(joystick.joy1_y2) > threshold)
{
motor[motorH] = joystick.joy1_y2/2;
}
else
{
motor[motorH] = 0;
}
if(abs(joystick.joy1_y1) > threshold)
{
motor[motorG] = joystick.joy1_y1/2;
}
else
{
motor[motorG] = 0;
}
if(joy1Btn(1))
{
motor[motorI] = 30;
}
else if(joy1Btn(2))
{
motor[motorI] = -30;
}
else
{
motor[motorI] = 0;
}
if(joy1Btn(3))
{
motor[motorF] = 20;
}
else if(joy1Btn(4))
{
motor[motorF] = -20;
}
else
{
motor[motorF] = 0;
}
}
}