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;
- competition Competition;
- // 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.
- controller Controller1 = controller(primary);
- distance Distance1 = distance(PORT7);
- motor leftMotorA = motor(PORT4, ratio6_1, true);
- motor leftMotorB = motor(PORT8, ratio6_1, true);
- motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB);
- motor rightMotorA = motor(PORT2, ratio6_1, false);
- motor rightMotorB = motor(PORT7, ratio6_1, false);
- motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB);
- drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 219.44, 295, 40, mm, 1);
- motor cataMotorA = motor(PORT1, ratio36_1, false);
- motor cataMotorB = motor(PORT10, ratio36_1, true);
- motor_group cata = motor_group(cataMotorA, cataMotorB);
- //Should say that port 13 is unplugged, this is by design cause im lazy
- motor MotorGroup7MotorA = motor(PORT12, ratio36_1, true);
- motor MotorGroup7MotorB = motor(PORT13, ratio36_1, false);
- motor_group MotorGroup7 = motor_group(MotorGroup7MotorA, MotorGroup7MotorB);
- digital_out DigitalOutB = digital_out(Brain.ThreeWirePort.B);
- digital_out DigitalOutD = digital_out(Brain.ThreeWirePort.D);
- // define variable for remote controller enable/disable
- bool RemoteControlCodeEnabled = true;
- // define variables used for controlling motors based on controller inputs
- bool DrivetrainLNeedsToBeStopped_Controller1 = true;
- bool DrivetrainRNeedsToBeStopped_Controller1 = true;
- // define a task that will handle monitoring inputs from Controller1
- int rc_auto_loop_function_Controller1() {
- // process the controller input every 20 milliseconds
- // update the motors based on the input values
- while(true) {
- if(RemoteControlCodeEnabled) {
- // calculate the drivetrain motor velocities from the controller joystick axies
- // left = Axis3 + Axis1
- // right = Axis3 - Axis1
- double y = 0;
- double x = Controller1.Axis3.position();
- x = x * 1.28;
- x = fabs(x);
- if(0<=x&&x<60){
- y = pow(1.04029, x * 1.284467);
- }else if(60<=x&&x<80){
- y = 0.75 * x -25;
- }else if(80<=x&&x<=108){
- y = 1.0357 * x - 47.85714857;
- }else if(x > 108){
- y = 63 + pow(1.232099, x - 108);
- }
- y = y/1.28;
- if(Controller1.Axis3.position() < 0){
- y = -y;
- }
- double sy = 0;
- double sx = Controller1.Axis1.position();
- sx = sx * 1.28;
- sx = fabs(sx);
- if(0<=sx&&sx<60){
- sy = pow(1.04029, sx * 1.284467);
- }else if(60<=sx&&sx<80){
- sy = 0.75 * sx -25;
- }else if(80<=sx&&sx<=108){
- sy = 1.0357 * sx - 47.85714857;
- }else if(sx > 108){
- sy = 63 + pow(1.232099, sx - 108);
- }
- sy = sy/1.28;
- if(Controller1.Axis1.position() < 0){
- sy = -sy;
- }
- int drivetrainLeftSideSpeed = y + sy;
- int drivetrainRightSideSpeed = y - sy;
- // check if the value is inside of the deadband range
- if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
- // check if the left motor has already been stopped
- if (DrivetrainLNeedsToBeStopped_Controller1) {
- // stop the left drive motor
- LeftDriveSmart.stop();
- // tell the code that the left motor has been stopped
- DrivetrainLNeedsToBeStopped_Controller1 = false;
- }
- } else {
- // reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
- DrivetrainLNeedsToBeStopped_Controller1 = true;
- }
- // check if the value is inside of the deadband range
- if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
- // check if the right motor has already been stopped
- if (DrivetrainRNeedsToBeStopped_Controller1) {
- // stop the right drive motor
- RightDriveSmart.stop();
- // tell the code that the right motor has been stopped
- DrivetrainRNeedsToBeStopped_Controller1 = false;
- }
- } else {
- // reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
- DrivetrainRNeedsToBeStopped_Controller1 = true;
- }
- // only tell the left drive motor to spin if the values are not in the deadband range
- if (DrivetrainLNeedsToBeStopped_Controller1) {
- LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
- LeftDriveSmart.spin(forward);
- }
- // only tell the right drive motor to spin if the values are not in the deadband range
- if (DrivetrainRNeedsToBeStopped_Controller1) {
- RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
- RightDriveSmart.spin(forward);
- }
- }
- // wait before repeating the process
- wait(20, msec);
- }
- return 0;
- }
- task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);
- #pragma endregion VEXcode Generated Robot Configuration
- // Include the V5 Library
- #include "vex.h"
- // Allows for easier use of the VEX Library
- using namespace vex;
- // "when started" hat block
- int whenStarted1() {
- Drivetrain.setDriveVelocity(600.0, rpm);
- Drivetrain.setTurnVelocity(100.0, percent);
- MotorGroup7.setMaxTorque(100, percent);
- MotorGroup7.setVelocity(100, percent);
- cata.setMaxTorque(100, percent);
- cata.setVelocity(100, percent);
- bool wingState = false;
- bool digitalB1 = false;
- bool digitalB2 = false;
- bool pl = false;
- bool ytoggle = false;
- float catapos = 0;
- int turng = 0;
- bool matchload = false;
- int i = 0;
- int c = 0;
- while (true) {
- cata.setStopping(hold);
- cata.stop();
- if(Controller1.ButtonR1.pressing()){
- if(Controller1.Axis3.position() < -15.0){
- MotorGroup7.spin(reverse);
- } else {
- MotorGroup7.spin(forward);
- }
- } else {
- MotorGroup7.spin(forward);
- }
- turng = floor(cata.position(turns));
- if(Controller1.ButtonDown.pressing()){
- cata.spin(reverse);
- }
- if(Controller1.ButtonUp.pressing()){
- cata.spin(forward);
- }
- if(catapos <= 60 || catapos >= 330){
- digitalB2 = false;
- } else {
- digitalB2 = true;
- }
- if(Controller1.ButtonL1.pressing()){
- wingState = !wingState;
- }
- if (Controller1.ButtonL1.pressing()){
- DigitalOutD.set(true);
- wait(150, msec);
- } else{
- DigitalOutD.set(false);
- wait(150, msec);
- }
- if(Controller1.ButtonLeft.pressing()){
- pl = !pl;
- wait(150, msec);
- }
- catapos = cata.position(degrees) - (turng * 360);
- //if(pl == true){
- //DigitalOutB.set(true);
- //} else if((digitalB1 == true || digitalB2 == true)||(digitalB1 == true & digitalB2 == true)){
- //DigitalOutB.set(true);
- //} else {
- //DigitalOutB.set(false);
- //}
- if(Controller1.ButtonY.pressing()){
- ytoggle = !ytoggle;
- }
- if(ytoggle == true){
- //DigitalOutB.set(true);
- }else{
- //DigitalOutB.set(false);
- }
- if(Controller1.ButtonA.pressing()){
- matchload = !matchload;
- wait(350, msec);
- }
- if(matchload == true){
- DigitalOutB.set(true);
- MotorGroup7.stop();
- printf("%.1f\n", (Distance1.objectDistance(inches)));
- if(i == 0){
- cata.spinFor(forward, 355, degrees);
- c = c + 355;
- ++i;
- }
- if(Distance1.objectDistance(inches) < 2.5){
- wait(25, msec);
- cata.spinFor(forward, 30, degrees);
- c = c + 30;
- if(Distance1.objectDistance(inches) > 2.5){
- c = c + 330;
- cata.setposition(c, degrees);
- }
- }
- } else{
- DigitalOutB.set(false);
- MotorGroup7.setVelocity(100, percent);
- if(i == 1){
- cata.spinFor(reverse, 355, degrees);
- c = c - 355;
- }
- i = 0;
- }
- wait(5, msec);
- }
- return 0;
- }
- int onauton_autonomous_0() {
- MotorGroup7.setvelocity(100, percent);
- MotorGroup7.spin(forward);
- Drivetrain.forward();
- wait(500, msec);
- Drivetrain.reverse();
- wait(75, msec);
- Drivetrain.stop();
- return 0;
- }
- int ondriver_drivercontrol_0() {
- whenStarted1();
- 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() {
- // post event registration
- // set default print color to black
- printf("\033[30m");
- vex::competition::bStopTasksBetweenModes = false;
- Competition.autonomous(VEXcode_auton_task);
- Competition.drivercontrol(VEXcode_driver_task);
- // wait for rotation sensor to fully initialize
- wait(30, msec);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement