Spam

// bool = boolean; booleans are any whole numbers
// 690 is 360 turn without inertial(Inertial21 acts as a gyro but in vrc)

1. include "vex.h"

using namespace vex;

void onwards(int distance) {
while (frontL.position(degrees) < distance) {
frontL.spin(forward, 30, percent);
frontR.spin(forward, 30, percent);
backL.spin(forward, 30, percent);
backR.spin(forward, 30, percent);
}
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}
void backwards(int distance) {
while (frontL.position(degrees) < distance) {
frontL.spin(reverse, 30, percent);
frontR.spin(reverse, 30, percent);
backL.spin(reverse, 30, percent);
backR.spin(reverse, 30, percent);
}
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}
void turner(int turns) {
while (frontL.position(degrees) < turns) {
frontL.spin(forward, 30, percent);
frontR.spin(reverse, 30, percent);
backL.spin(forward, 30, percent);
backR.spin(reverse, 30, percent);
}
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}

void turni(int degs) {
turnthing.setHeading(0, degrees);
while (turnthing.heading(degrees) < degs) {
frontL.spin(forward, 30, percent);
frontR.spin(reverse, 30, percent);
backL.spin(forward, 30, percent);
backR.spin(reverse, 30, percent);
wait(0.1, sec);
}
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}

void isnottouching() {
while (BumperA.pressing() == 0) {
frontL.spin(forward, 30, percent);
frontR.spin(forward, 30, percent);
backL.spin(forward, 30, percent);
backR.spin(forward, 30, percent);
}
frontL.spin(reverse, 30, percent);
frontR.spin(reverse, 30, percent);
backL.spin(reverse, 30, percent);
backR.spin(reverse, 30, percent);
wait(2, seconds);
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}

void ihavemoved() {
while (counter.objectDistance(mm)) {
Brain.Screen.printAt(15, 15, "distance: %f",
counter.objectDistance(distanceUnits::mm));
}
Brain.Screen.print("distance: %d", counter.objectDistance(distanceUnits::mm));
}
void stopnow() {
while (counter.objectDistance(mm) > 80) {
Brain.Screen.printAt(15, 15, "distance: %f",
counter.objectDistance(distanceUnits::mm));
frontL.spin(forward, 30, percent);
frontR.spin(forward, 30, percent);
backL.spin(forward, 30, percent);
backR.spin(forward, 30, percent);
}
Brain.Screen.print("distance: %d", counter.objectDistance(distanceUnits::mm));
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}
void colourdisplay() {
while (true) {
Brain.Screen.drawRectangle(120, 60, 240, 120, THINGTHATSEES.color());
wait(.2, seconds);
Brain.Screen.clearScreen();
}
}

void ifyouseeorange() {
while (counter.objectDistance(inches) > 3) {
Brain.Screen.drawRectangle(120, 60, 240, 120, THINGTHATSEES.color());
frontL.spin(forward, 10, pct);
frontR.spin(forward, 10, pct);
backL.spin(forward, 10, pct);
backR.spin(forward, 10, pct);
wait(0.1, sec);
}
if (THINGTHATSEES.hue() > 10 && THINGTHATSEES.hue() < 40) {
Brain.Screen.drawRectangle(120, 60, 240, 120, THINGTHATSEES.color());
turni(90);
} else {
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
}
}

void PID(int setpoint) {
int error = setpoint - frontL.position(degrees);
int power;
int i = 0;
double kP = 400000;
while (abs(error) > i) {
error = setpoint - frontL.position(degrees);
power = error \* kP;
Brain.Screen.printAt(15, 15, "%f", frontL.position(degrees));
frontL.spin(forward, power, pct);
frontR.spin(forward, power, pct);
backL.spin(forward, power, pct);
backR.spin(forward, power, pct);
}
frontL.stop();
frontR.stop();
backL.stop();
backR.stop();
Brain.Screen.printAt(15, 15, "%f", frontL.position(degrees));
}
// obj: make it so that it stops when speed is 5+
// while axis 3 is more than the deadzone but less than the neg deadzone
void tankdrive() {
int deadzone1 = -10;
int deadzone3 = 10;
while (true) {
Controller1.Axis2.position() < deadzone1)) {
Brain.Screen.printAt(15, 15, "%d", Controller1.Axis2.position(percent));
Brain.Screen.printAt(50, 50, "%d", Controller1.Axis3.position(percent));
frontL.spin(forward, Controller1.Axis3.position(), percent);
frontR.spin(forward, Controller1.Axis2.position(), percent);
backL.spin(forward, Controller1.Axis3.position(), percent);
backR.spin(forward, Controller1.Axis2.position(), percent);
} else {
(frontL.stop(), frontR.stop(), backL.stop(), backR.stop());
}
}
}
void splitdrive() {
while (true) {
Brain.Screen.printAt(15, 15, "%d", Controller1.Axis1.position(percent));
Brain.Screen.printAt(50, 50, "%d", Controller1.Axis2.position(percent));
frontL.spin(forward,
Controller1.Axis3.position() + (Controller1.Axis1.position()),
percent);
frontR.spin(forward,
Controller1.Axis3.position() - (Controller1.Axis1.position()),
percent);
backL.spin(forward,
Controller1.Axis3.position() + (Controller1.Axis1.position()),
percent);
backR.spin(forward,
Controller1.Axis3.position() - (Controller1.Axis1.position()),
percent);
}
}

int mylift() {
while (true) {
if (Controller1.ButtonA.pressing()) {
thingthatgoup.spin(forward,50,pct);
}
else if (Controller1.ButtonB.pressing()) {
thingthatgoup.spin(forward,50,pct);
}
else {
thingthatgoup.stop();
}
}
}

int main() {
turnthing.calibrate();
tankdrive();
}

// int ex = 240;
// int x = 120;
// int why = 120;
// int y = 60;
// Brain.Screen.drawRectangle
// (120,60,240,120,1);
// while (true) {
// if (Brain.Screen.pressing()){
// if(ex>Brain.Screen.xPosition() && x<Brain.Screen.xPosition() &&
// why>Brain.Screen.yPosition() && y<Brain.Screen.yPosition())
// Brain.Screen.drawRectangle
// (120,60,240,120,orange);

// }

/\*----------------------------------------------------------------------------\*/
/\* \*/
/\* Module: main.cpp \*/
/\* Author: C:\Users\eleri \*/
/\* Created: Sun Oct 09 2022 \*/
/\* Description: V5 project \*/
/\* \*/
/\*----------------------------------------------------------------------------\*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// frontleft motor 20
// frontright motor 8
// backleft motor 12
// backright motor 1
// Controller1 controller
// flywheel motor 7
// CoolerGyro inertial 18
// intake motor 9
// kicker motor 3
// string motor 19
// ---- END VEXCODE CONFIGURED DEVICES ----

// i am giong crazye

1. include "vex.h"

// define your global instances of motors and other devices here

competition Competition;

void pre\_auton(void) {
frontleft.setStopping(hold);
frontright.setStopping(hold);
backleft.setStopping(hold);
backright.setStopping(hold);
vexcodeInit();
CoolerGyro.calibrate();
}

// competition auton

void autonomous(void) {
CoolerGyro.calibrate();
frontleft.spin(reverse,40,pct);
frontright.spin(forward,40,pct);
backleft.spin(reverse,40,pct);
backright.spin(forward,40,pct);
intake.spin(forward,100,pct);
wait(.3,seconds);
frontleft.stop();
frontright.stop();
backleft.stop();
backright.stop();
wait(.1,seconds);
frontleft.spin(reverse,40,pct);
frontright.spin(reverse,40,pct);
backleft.spin(reverse,40,pct);
backright.spin(reverse,40,pct);
intake.spin(reverse,70,pct);
wait(.25,seconds);
frontleft.stop();
frontright.stop();
backleft.stop();
backright.stop();
intake.stop();
wait(.25,seconds);
intake.stop();
frontleft.spin(forward,30,pct);
frontright.spin(forward,30,pct);
backleft.spin(forward,30,pct);
backright.spin(forward,30,pct);
wait(.3,seconds);
frontleft.stop();
frontright.stop();
backleft.stop();
backright.stop();
frontleft.spin(reverse,30,pct);
frontright.spin(forward,30,pct);
backleft.spin(reverse,30,pct);
backright.spin(forward,30,pct);
wait(.7,seconds);
frontleft.stop();
frontright.stop();
backleft.stop();
backright.stop();
frontleft.spin(forward,90,pct);
frontright.spin(forward,90,pct);
backleft.spin(forward,90,pct);
backright.spin(forward,90,pct);
wait(1,seconds);
frontleft.stop();
frontright.stop();
backleft.stop();
backright.stop();
}

void usercontrol(void) {
while (1) {
wait(20, msec);
frontleft.setStopping(coast);
frontright.setStopping(coast);
backleft.setStopping(coast);
backright.setStopping(coast);
intake.setStopping(hold);
int deadzone1 = -10;
int deadzone3 = 10;
float speedcontrol = 1;
while (true) {
Brain.Screen.printAt(15, 25, "POSITIONS");
Brain.Screen.printAt(30, 45, "%f", frontleft.position(degrees));
Brain.Screen.printAt(30, 65, "%f", frontright.position(degrees));
Brain.Screen.printAt(30, 85, "%f", backleft.position(degrees));
Brain.Screen.printAt(30, 105, "%f", backright.position(degrees));
Brain.Screen.printAt(150, 65, "You are on the match code.");
Brain.Screen.printAt(150, 85, "Are you sure you're at a comp?");
Brain.Screen.drawRectangle(25, 120, 100, 100, color());
Brain.Screen.printAt(150, 175, "IF FOUND PLEASE RETURN TO 4610F");
speedcontrol = 1;
if (Controller1.ButtonLeft.pressing()) {
speedcontrol = .5;
}
wait(50,msec);
Brain.Screen.clearScreen();

Controller1.Axis2.position() < deadzone1)) {
frontleft.spin(reverse, speedcontrol \* Controller1.Axis3.position(), percent);
frontright.spin(reverse, speedcontrol \* Controller1.Axis2.position(), percent);
backleft.spin(reverse, speedcontrol \* Controller1.Axis3.position(), percent);
backright.spin(reverse, speedcontrol \* Controller1.Axis2.position(), percent);
} else {
(frontleft.stop(), frontright.stop(), backleft.stop(), backright.stop());
}
if (Controller1.ButtonL1.pressing()) {
(flywheel.spin(forward, 55, pct));
}
if (Controller1.ButtonL2.pressing()) {
flywheel.stop();
}
if (Controller1.ButtonUp.pressing()) {
(kicker.spin(forward, 75, pct));
} else if (Controller1.ButtonDown.pressing()) {
(kicker.spin(reverse, 75, pct));
} else {
kicker.stop();
}
if (Controller1.ButtonR1.pressing()) {
intake.spin(forward, 100, pct);
} else if (Controller1.ButtonR2.pressing()) {
intake.spin(reverse, 100, pct);
} else {
intake.stop();
}
if (Controller1.ButtonY.pressing()) {
frontleft.setStopping(hold);
frontright.setStopping(hold);
backleft.setStopping(hold);
backright.setStopping(hold);
} else if (Controller1.ButtonA.pressing()) {
frontleft.setStopping(coast);
frontright.setStopping(coast);
backleft.setStopping(coast);
backright.setStopping(coast);
}
if (Controller1.ButtonB.pressing()) {
string.spin(forward,100,pct);
} else {
string.stop();
}
}
}
}
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
pre\_auton();

while (true) {
wait(100, msec);
}
}

using namespace vex;

void tankdrive() {
int deadzone1 = -10;
int deadzone3 = 10;
while (true) {
Controller1.Axis2.position() < deadzone1)) {
Brain.Screen.printAt(15, 15, "%d", Controller1.Axis2.position(percent));
Brain.Screen.printAt(50, 50, "%d", Controller1.Axis3.position(percent));
frontleft.spin(reverse, Controller1.Axis3.position(), percent);
frontright.spin(reverse, Controller1.Axis2.position(), percent);
backleft.spin(reverse, Controller1.Axis3.position(), percent);
backright.spin(reverse, Controller1.Axis2.position(), percent);
} else {
(frontleft.stop(), frontright.stop(), backleft.stop(), backright.stop());
}
if (Controller1.ButtonL1.pressing()) {
(flywheel.spin(forward, 100, pct));
} else if (Controller1.ButtonL2.pressing()) {
flywheel.stop();
}
if (Controller1.ButtonUp.pressing()) {
(kicker.spin(forward, 100, pct));
} else if (Controller1.ButtonDown.pressing()) {
(kicker.spin(reverse, 100, pct));
} else {
kicker.stop();
}
if (Controller1.ButtonR1.pressing()) {
intake.spin(forward, 100, pct);
} else if (Controller1.ButtonR2.pressing()) {
intake.spin(reverse, 100, pct);
} else {
intake.stop();
}
}
}
void MOVEBITCH(int setpoint) {
int error = setpoint - frontleft.position(degrees);
int power;
int i = 0;
double kP = 0.66;
while (abs(error) > i) {
error = setpoint - frontleft.position(degrees);
power = error \* kP;
Brain.Screen.printAt(15, 15, "%f", frontleft.position(degrees));
frontleft.spin(forward, power, pct);
frontright.spin(forward, power, pct);
backleft.spin(forward, power, pct);
backright.spin(forward, power, pct);
}
frontleft.stop();
frontright.stop();
backleft.stop();
backright.stop();
Brain.Screen.printAt(15, 15, "%f", frontleft.position(degrees));
}

// frontleft 12
// frontright 20
// backleft 4
// backright 10
// flywheel 13
// kicker 14
// cooler gyro 3
// intake 7
// stringmech 9

// int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
// }

/\*----------------------------------------------------------------------------\*/
/\* \*/
/\* Module: main.cpp \*/
/\* Author: C:\Users\Student \*/
/\* Created: Wed Apr 19 2023 \*/
/\* Description: V5 project \*/
/\* \*/
/\*----------------------------------------------------------------------------\*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// frontleft motor 1
// frontright motor 2
// ---- END VEXCODE CONFIGURED DEVICES ----

// note: (class name) :: (name of function you want to create) is the syntax when importing a class.

1. include "vex.h"
2. include "pid.h"

using namespace vex;

PID::PID(float kp, float ki, float kd) {
PID::\_kp = kp;
PID::\_ki = ki;
PID::\_kd = kd;

}

float PID::calculate(float error) {

float kp = 1;
float ki = 0;
float kd = 0;
float dt = 0.2;
float prevError = 0.0;
float integral = 0.0;

float p = error \* kp;
if (error < 60 && error > 10) {
integral += error \* dt;
} else {
integral = 0;
}

float i = integral \* ki;

float d = (error - prevError) \* kd;
d /= dt;

wait(dt, msec);
return p;
return i;
return d;
return 0;
}