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.
- controller Controller1 = controller(primary);
- motor leftMotorA = motor(PORT14, ratio6_1, false);
- motor leftMotorB = motor(PORT11, ratio6_1, false);
- motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB);
- motor rightMotorA = motor(PORT17, ratio6_1, true);
- motor rightMotorB = motor(PORT19, ratio6_1, true);
- motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB);
- drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 219.44, 295, 40, mm, 1);
- motor cataMotorA = motor(PORT8, ratio36_1, false);
- motor cataMotorB = motor(PORT3, ratio36_1, true);
- motor_group cata = motor_group(cataMotorA, cataMotorB);
- motor MotorGroup7MotorA = motor(PORT4, ratio36_1, true);
- motor MotorGroup7MotorB = motor(PORT9, 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
- int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis1.position();
- int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis1.position();
- // 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;
- float myVariable, no;
- // "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;
- while (true) {
- DigitalOutB.set(true);
- cata.setStopping(hold);
- if(Controller1.ButtonDown.pressing()){
- cata.spin(reverse);
- }
- if(Controller1.ButtonUp.pressing()){
- cata.spin(forward);
- }
- if(Controller1.ButtonA.pressing()){
- cata.spinFor(forward, 360, degrees);
- DigitalOutB.set(true);
- wait(250, msec);
- } else{
- DigitalOutB.set(false);
- }
- if(Controller1.ButtonLeft.pressing()){
- wingState = !wingState;
- }
- if (wingState == true){
- DigitalOutD.set(true);
- } else{
- DigitalOutD.set(false);
- }
- wait(5, msec);
- }
- return 0;
- }
- int main() {
- // 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