Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma region VEXcode Generated Robot Configuration
- // Make sure all required headers are included.
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <math.h>
- #include <string.h>
- #include "vex.h"
- using namespace vex;
- // Brain should be defined by default
- brain Brain;
- // START V5 MACROS
- #define waitUntil(condition) \
- do { \
- wait(5, msec); \
- } while (!(condition))
- #define repeat(iterations) \
- for (int iterator = 0; iterator < iterations; iterator++)
- // END V5 MACROS
- // Robot configuration code.
- motor Left1MotorA = motor(PORT4, ratio6_1, false);
- motor Left1MotorB = motor(PORT5, ratio6_1, false);
- motor_group Left1 = motor_group(Left1MotorA, Left1MotorB);
- motor Left2 = motor(PORT21, ratio6_1, false);
- motor Right1MotorA = motor(PORT11, ratio6_1, true);
- motor Right1MotorB = motor(PORT14, ratio6_1, true);
- motor_group Right1 = motor_group(Right1MotorA, Right1MotorB);
- motor Right2 = motor(PORT15, ratio6_1, true);
- motor Intake = motor(PORT10, ratio6_1, false);
- digital_out Wings = digital_out(Brain.ThreeWirePort.G);
- digital_out Intakepnumatic = digital_out(Brain.ThreeWirePort.F);
- controller Controller1 = controller(primary);
- motor Cata = motor(PORT17, ratio36_1, true);
- pot PotentiometerB = pot(Brain.ThreeWirePort.B);
- // Helper to make playing sounds from the V5 in VEXcode easier and
- // keeps the code cleaner by making it clear what is happening.
- void playVexcodeSound(const char *soundName) {
- printf("VEXPlaySound:%s\n", soundName);
- wait(5, msec);
- }
- // define variable for remote controller enable/disable
- bool RemoteControlCodeEnabled = true;
- #pragma endregion VEXcode Generated Robot Configuration
- // Include the V5 Library
- #include "vex.h"
- // Allows for easier use of the VEX Library
- using namespace vex;
- competition Competition;
- float myVariable;
- // "when started" hat block
- int whenStarted1() {
- Left1.setMaxTorque(50.0, percent);
- Left2.setMaxTorque(50.0, percent);
- Right1.setMaxTorque(50.0, percent);
- Right2.setMaxTorque(50.0, percent);
- Intake.setVelocity(50.0, percent);
- Intake.spin(forward);
- Cata.setStopping(brake);
- Cata.setVelocity(100.0, percent);
- Cata.setMaxTorque(100.0, percent);
- return 0;
- }
- // "when Controller1 ButtonR1 pressed" hat block
- void onevent_Controller1ButtonR1_pressed_0() {
- Wings.set(true);
- }
- // "when Controller1 ButtonR1 released" hat block
- void onevent_Controller1ButtonR1_released_0() {
- Wings.set(false);
- }
- // "when driver control" hat block
- int ondriver_drivercontrol_0() {
- float L1 = 0.0;
- float L2 = 0.0;
- float L3 = 0.0;
- float R1 = 0.0;
- float R2 = 0.0;
- float R3 = 0.0;
- float cata = 0.0;
- float intake = 0.0;
- while (true) {
- Left1.spin(forward);
- Left2.spin(forward);
- Right1.spin(forward);
- Right2.spin(forward);
- if ((5.0 > Controller1.Axis3.position() && Controller1.Axis3.position() > -5.0) && (5.0 > Controller1.Axis1.position() && Controller1.Axis1.position() > -5.0)) {
- Left1.setVelocity(0.0, percent);
- Left2.setVelocity(0.0, percent);
- Right1.setVelocity(0.0, percent);
- Right2.setVelocity(0.0, percent);
- }
- else {
- Left1.setVelocity((Controller1.Axis3.position() + Controller1.Axis1.position() * 0.25), percent);
- Left2.setVelocity((Controller1.Axis3.position() + Controller1.Axis1.position() * 0.25), percent);
- Right1.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position() * 0.25) - 5.0), percent);
- Right2.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position() * 0.25) - 5.0), percent);
- }
- if (Controller1.ButtonR1.pressing()) {
- Intake.setVelocity(100.0, percent);
- Intake.spin(forward);
- wait(100, msec);
- } else if(Controller1.ButtonR2.pressing()){
- Intake.setVelocity(-100.0, percent);
- Intake.spin(forward);
- wait(100, msec);
- } else {
- Intake.stop();
- wait(100, msec);
- }
- if(Controller1.ButtonB.pressing()){
- Cata.spin(forward);
- } else {
- Cata.stop();
- }
- if(Controller1.ButtonL1.pressing()){
- Wings.set(true);
- } else {
- Wings.set(false);
- }
- L1 = Left1MotorA.velocity(rpm);
- L2 = Left1MotorB.velocity(rpm);
- L3 = Left2.velocity(rpm);
- R1 = Right1MotorA.velocity(rpm);
- R2 = Right1MotorB.velocity(rpm);
- R3 = Right2.velocity(rpm);
- cata = Cata.velocity(rpm);
- intake = Intake.velocity(rpm);
- printf("%f,\t%f,\t%f,\t%f,\t%f,\t%f,\t%f,\t%f,\n",L1,L2,L3,R1,R2,R3,cata,intake);
- wait(10, msec);
- }
- return 0;
- }
- // "when autonomous" hat block
- int onauton_autonomous_0() {
- float values[] = {0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 30.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, -45.200001,
- 9.000000, 26.400000, 6.600000, 14.200000, 12.600000, 15.600000, -0.000000, 17.799999,
- 24.799999, 17.400000, 30.000000, 17.600000, 19.600000, 33.000000, -0.000000, 21.799999,
- 82.000000, 87.599998, 88.400002, 49.799999, 52.200001, 46.400002, -0.000000, 0.000000,
- 126.400002, 133.800003, 156.800003, 87.800003, 96.800003, 112.000000, -0.000000, 0.000000,
- 135.800003, 147.199997, 142.000000, 103.599998, 80.800003, 85.400002, -0.000000, 0.000000,
- 125.000000, 79.199997, 130.600006, 71.199997, 98.800003, 101.800003, -0.000000, 0.000000,
- 63.400002, 74.800003, 75.599998, 59.799999, 69.800003, 58.000000, -0.000000, 0.000000,
- 29.400000, 31.200001, 25.799999, 26.799999, 30.799999, 36.599998, -0.000000, 0.000000,
- 14.800000, 19.799999, 20.799999, -0.000000, 18.799999, 25.799999, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -9.200000, -0.000000, -16.600000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- -22.200001, -13.600000, 0.000000, -11.400000, -14.400000, -13.000000, -0.000000, 0.000000,
- -46.599998, -45.400002, -39.599998, -51.599998, -53.599998, -65.800003, -0.000000, 0.000000,
- -124.400002, -145.600006, -128.800003, -137.000000, -121.800003, -135.600006, -0.000000, 0.000000,
- -198.399994, -201.399994, -194.199997, -211.800003, -262.200012, -238.600006, -0.000000, 0.000000,
- -174.199997, -201.199997, -183.399994, -220.399994, -231.000000, -267.399994, -0.000000, 0.000000,
- -185.600006, -219.399994, -180.000000, -226.199997, -169.000000, -182.600006, -3.900000, 0.000000,
- -18.000000, 0.000000, -40.799999, -11.200000, -79.000000, -65.000000, -0.000000, 0.000000,
- -7.200000, -21.799999, -18.799999, 11.400000, -0.000000, -0.000000, -0.000000, 0.000000,
- -6.200000, -16.200001, -20.600000, 54.599998, 45.200001, 55.000000, -0.000000, 0.000000,
- -35.799999, -35.799999, -38.599998, 92.800003, 99.800003, 96.599998, -0.000000, 0.000000,
- -62.200001, -20.600000, -18.400000, 105.800003, 35.599998, 34.200001, -0.000000, 0.000000,
- -16.200001, -31.000000, -14.200000, 70.000000, 49.200001, 61.400002, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 31.200001, 32.799999, 33.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, 15.800000, 23.799999, 14.600000, -0.000000, 0.000000,
- -31.799999, -39.799999, -18.400000, 12.200000, 19.600000, 17.400000, -0.000000, 0.000000,
- 0.000000, 14.800000, 6.800000, 32.200001, -0.000000, 33.400002, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 11.800000, 12.600000, 13.200000, -34.599998, -36.400002, -13.600000, -0.000000, 0.000000,
- 22.400000, 19.000000, 24.400000, -45.599998, -54.400002, -44.200001, -0.000000, 0.000000,
- -14.400000, -18.799999, 0.000000, -15.600000, -40.799999, -5.600000, -0.000000, 0.000000,
- 0.000000, 0.000000, 18.799999, -18.200001, -21.200001, -19.200001, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -13.200000, -9.200000, -13.400000, -0.000000, 0.000000,
- 44.200001, 29.799999, 38.599998, -17.200001, -21.799999, -25.799999, -0.000000, 0.000000,
- 15.800000, 7.000000, 18.400000, -31.600000, -34.599998, -29.200001, -0.000000, 0.000000,
- -18.400000, -6.200000, -4.200000, -31.600000, -38.599998, 5.600000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -14.600000, -14.200000, -20.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -9.200000, -15.200000, -13.800000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
- };
- int math1 = -8;
- int math2 = -7;
- int math3 = -6;
- int math4 = -5;
- int math5 = -4;
- int math6 = -3;
- int math7 = -2;
- int math8 = -1;
- while(true){
- Right1.setMaxTorque(100, percent);
- Left1.setMaxTorque(100, percent);
- Right2.setMaxTorque(100, percent);
- Left2.setMaxTorque(100, percent);
- math1 = math1 + 8;
- math2 = math2 + 8;
- math3 = math3 + 8;
- math4 = math4 + 8;
- math5 = math5 + 8;
- math6 = math6 + 8;
- math7 = math7 + 8;
- math8 = math8 + 8;
- Right1MotorA.setVelocity(values[math1], rpm);
- Right1MotorB.setVelocity(values[math2], rpm);
- Right2.setVelocity(values[math3], rpm);
- Left1MotorA.setVelocity(values[math4], rpm);
- Left1MotorB.setVelocity(values[math5], rpm);
- Left2.setVelocity(values[math6], rpm);
- Cata.setVelocity(values[math7], rpm);
- Intake.setVelocity(values[math8], rpm);
- wait(10, msec);
- }
- return 0;
- }
- void VEXcode_driver_task() {
- // Start the driver control tasks....
- vex::task drive0(ondriver_drivercontrol_0);
- while(Competition.isDriverControl() && Competition.isEnabled()) {this_thread::sleep_for(10);}
- drive0.stop();
- return;
- }
- void VEXcode_auton_task() {
- // Start the auton control tasks....
- vex::task auto0(onauton_autonomous_0);
- while(Competition.isAutonomous() && Competition.isEnabled()) {this_thread::sleep_for(10);}
- auto0.stop();
- return;
- }
- int main() {
- vex::competition::bStopTasksBetweenModes = false;
- Competition.autonomous(VEXcode_auton_task);
- Competition.drivercontrol(VEXcode_driver_task);
- // register event handlers
- Controller1.ButtonR1.pressed(onevent_Controller1ButtonR1_pressed_0);
- Controller1.ButtonR1.released(onevent_Controller1ButtonR1_released_0);
- wait(15, msec);
- // post event registration
- // set default print color to black
- printf("\033[30m");
- // wait for rotation sensor to fully initialize
- wait(30, msec);
- whenStarted1();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement