-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathautonomous.cpp
177 lines (168 loc) · 4.93 KB
/
autonomous.cpp
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
#include "main.h"
#include <stdio.h>
#include "okapi/api.hpp"
using namespace okapi;
/**
* Runs the user autonomous code. This function will be started in its own task
* with the default priority and stack size whenever the robot is enabled via
* the Field Management System or the VEX Competition Switch in the autonomous
* mode. Alternatively, this function may be called in initialize or opcontrol
* for non-competition testing purposes.
*
* If the robot is disabled or communications is lost, the autonomous task
* will be stopped. Re-enabling the robot will restart the task, not re-start it
* from where it left off.
*/
std::vector<int> a = {};
std::vector<int> b = {};
std::vector<int> c = {};
std::vector<int> d = {};
bool red=true;
bool front =false;
bool skills=false;
pros::Motor intake (4);
pros::Motor intake2 (5);
auto chassis = ChassisControllerFactory::create(
{1, -2}, {10, -9},
AbstractMotor::gearset::green,
{4_in, 12.5_in}
);
auto profileController1 = AsyncControllerFactory::motionProfile(
0.20, // Maximum linear velocity of the Chassis in m/s
2.0, // Maximum linear acceleration of the Chassis in m/s/s
10.0, // Maximum linear jerk of the Chassis in m/s/s/s
chassis // Chassis Controller
);
auto profileController2= AsyncControllerFactory::motionProfile(
4.0,
4.0,
4.0,
chassis
);
void autonomous() {
if(skills){
int tick = 0;{
while(tick<a.size()){
pros::Motor(1).move(a[tick]);
pros::Motor(10).move(b[tick]);
pros::Motor(2).move(a[tick]);
pros::Motor(9).move(b[tick]);
pros::Motor(4).move(-c[tick]);
pros::Motor(5).move(c[tick]);
pros::Motor(3).move(d[tick]);
pros::Motor(11).move(-d[tick]);
tick++;
pros::delay(10);
}
}
}
else{
int c = 2*red-1;
if(front){
intake.move(126);
intake2.move(-126);
profileController2.generatePath({
Point{0_ft, 0_ft, 0_deg},
Point{2.5_ft, 0_ft, 0_deg}},
"intake1"
);
printf("g");
profileController2.setTarget("intake1");
profileController2.waitUntilSettled();
profileController2.setTarget("intake1",true);
profileController2.waitUntilSettled();
profileController2.generatePath({
Point{0_ft, 0_ft, 0_deg},
Point{0.1_ft, 0_ft, 0_deg}},
"forward"
);
profileController2.setTarget("forward");
profileController2.waitUntilSettled();
chassis.turnAngle(c*-140);
profileController2.generatePath({
Point{0_ft, 0_ft, 0_deg},
Point{1.1_ft, 0_ft, 0_deg}},
"forward2"
);
profileController2.setTarget("forward2");
profileController2.waitUntilSettled();
intake.move(0);
intake2.move(0);
IntegratedEncoder enc = IntegratedEncoder(pros::Motor(3));//outtake
enc.reset();
intake.move(0);
intake2.move(0);
while(enc.get()<=5600){
pros::Motor(3).move(126);
pros::Motor(11).move(-126);
}
pros::Motor(3).move(0);
pros::Motor(11).move(0);
//backoff
pros::Motor(1).move(-50);
pros::Motor(2).move(-50);
pros::Motor(10).move(-50);
pros::Motor(9).move(-50);
}
else{
chassis.setMaxVelocity(200);
intake.move(126);
intake2.move(-126);
profileController1.generatePath({
Point{0_ft, 0_ft, 0_deg},
Point{1.5_ft, 0_ft, 0_deg}},
"intake1"
);
printf("done");
profileController1.setTarget("intake1");
profileController1.waitUntilSettled();
profileController2.generatePath({
Point{0_ft, c*-0.90_ft, 0_deg},
Point{2.5_ft, 0_ft, 0_deg}},
"back1" // Profile name
);
profileController2.setTarget("back1",true);
profileController1.generatePath({
Point{0_ft, 0_ft, 0_deg},
Point{2.7_ft, 0_ft, 0_deg}},
"intake2" // Profile name
);
profileController1.setTarget("intake2");
profileController1.waitUntilSettled();
//stopintake
//turn 135 degrees
chassis.setMaxVelocity(60);
chassis.turnAngle(c*204);
pros::delay(400);
chassis.setMaxVelocity(200);
profileController2.generatePath({
Point{0_ft, 0_ft, 0_deg},
Point{2.0_ft, 0_ft, 0_deg}},
"scorezone" // Profile name
);
profileController2.setTarget("scorezone");
profileController2.waitUntilSettled();
intake.move(0);
intake2.move(-0);
pros::Motor(1).move(0);
pros::Motor(2).move(0);
pros::Motor(10).move(0);
pros::Motor(9).move(0);
IntegratedEncoder enc = IntegratedEncoder(pros::Motor(3));//outtake
enc.reset();
intake.move(0);
intake2.move(0);
while(enc.get()<=5600){
pros::Motor(3).move(126);
pros::Motor(11).move(-126);
}
pros::Motor(3).move(0);
pros::Motor(11).move(0);
//backoff
pros::Motor(1).move(-50);
pros::Motor(2).move(-50);
pros::Motor(10).move(-50);
pros::Motor(9).move(-50);
}
}
}