diff --git a/include/Intakes.hpp b/include/Intakes.hpp new file mode 100644 index 0000000..fa8518f --- /dev/null +++ b/include/Intakes.hpp @@ -0,0 +1,5 @@ +#pragma once +#include "api.h" +#include "main.h" + +void intake_control(); \ No newline at end of file diff --git a/include/Ports.hpp b/include/Ports.hpp new file mode 100644 index 0000000..8f61d2e --- /dev/null +++ b/include/Ports.hpp @@ -0,0 +1,4 @@ +#include "api.h" +#include "pros/adi.hpp" + +extern pros::Motor intakeMotor; \ No newline at end of file diff --git a/include/SETTINGS.hpp b/include/SETTINGS.hpp new file mode 100644 index 0000000..5d031b9 --- /dev/null +++ b/include/SETTINGS.hpp @@ -0,0 +1,6 @@ +#pragma once +#include "api.h" +#include "main.h" +using namespace pros; + +#define intakeMotorPort 16 diff --git a/include/autons.hpp b/include/autons.hpp new file mode 100644 index 0000000..3d7ace5 --- /dev/null +++ b/include/autons.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "EZ-Template/drive/drive.hpp" + +extern Drive chassis; + +void drive_example(); +void turn_example(); +void drive_and_turn(); +void wait_until_change_speed(); +void swing_example(); +void combining_movements(); +void interfered_example(); + +void default_constants(); +void one_mogo_constants(); +void two_mogo_constants(); +void exit_condition_defaults(); +void modified_exit_condition(); + diff --git a/include/main.h b/include/main.h index 288056e..abc2398 100644 --- a/include/main.h +++ b/include/main.h @@ -4,7 +4,7 @@ * Contains common definitions and header files used throughout your PROS * project. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * Copyright (c) 2017-2021, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public @@ -22,7 +22,7 @@ * * For instance, E_CONTROLLER_MASTER has a shorter name: CONTROLLER_MASTER. * E_CONTROLLER_MASTER is pedantically correct within the PROS styleguide, but - * not convenient for most student programmers. + * not convienent for most student programmers. */ #define PROS_USE_SIMPLE_NAMES @@ -41,6 +41,13 @@ */ //#include "okapi/api.hpp" //#include "pros/api_legacy.h" +#include "EZ-Template/api.hpp" +#include "autons.hpp" +#include "Intakes.hpp" + +// More includes here... +// +// . . . /** * If you find doing pros::Motor() to be tedious and you'd prefer just to do diff --git a/src/Intakes.cpp b/src/Intakes.cpp new file mode 100644 index 0000000..2ef4447 --- /dev/null +++ b/src/Intakes.cpp @@ -0,0 +1,16 @@ +#include "Intakes.hpp" +#include "api.h" +#include "main.h" +#include "pros/misc.h" +#include "SETTINGS.hpp" +#include "Ports.hpp" + +void intake_control(){ + bool intakeActive = false; + while(intakeActive == true) { + if (master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { + intakeMotor.move_velocity(600); + } + intakeActive = !intakeActive; + } +} \ No newline at end of file diff --git a/src/Ports.cpp b/src/Ports.cpp new file mode 100644 index 0000000..65c884d --- /dev/null +++ b/src/Ports.cpp @@ -0,0 +1,6 @@ +#include "main.h" +#include "SETTINGS.hpp" +#include "pros/adi.hpp" +#include "pros/motors.h" + +pros::Motor intakeMotor(intakeMotorPort); diff --git a/src/autons.cpp b/src/autons.cpp new file mode 100644 index 0000000..c2395db --- /dev/null +++ b/src/autons.cpp @@ -0,0 +1,250 @@ +#include "main.h" + + +///// +// For instalattion, upgrading, documentations and tutorials, check out website! +// https://ez-robotics.github.io/EZ-Template/ +///// + + +const int DRIVE_SPEED = 110; // This is 110/127 (around 87% of max speed). We don't suggest making this 127. + // If this is 127 and the robot tries to heading correct, it's only correcting by + // making one side slower. When this is 87%, it's correcting by making one side + // faster and one side slower, giving better heading correction. +const int TURN_SPEED = 90; +const int SWING_SPEED = 90; + + + +/// +// Constants +/// + +// It's best practice to tune constants when the robot is empty and with heavier game objects, or with lifts up vs down. +// If the objects are light or the cog doesn't change much, then there isn't a concern here. + +void default_constants() { + chassis.set_slew_min_power(80, 80); + chassis.set_slew_distance(7, 7); + chassis.set_pid_constants(&chassis.headingPID, 11, 0, 20, 0); + chassis.set_pid_constants(&chassis.forward_drivePID, 0.45, 0, 5, 0); + chassis.set_pid_constants(&chassis.backward_drivePID, 0.45, 0, 5, 0); + chassis.set_pid_constants(&chassis.turnPID, 5, 0.003, 35, 15); + chassis.set_pid_constants(&chassis.swingPID, 7, 0, 45, 0); +} + +void one_mogo_constants() { + chassis.set_slew_min_power(80, 80); + chassis.set_slew_distance(7, 7); + chassis.set_pid_constants(&chassis.headingPID, 11, 0, 20, 0); + chassis.set_pid_constants(&chassis.forward_drivePID, 0.45, 0, 5, 0); + chassis.set_pid_constants(&chassis.backward_drivePID, 0.45, 0, 5, 0); + chassis.set_pid_constants(&chassis.turnPID, 5, 0.003, 35, 15); + chassis.set_pid_constants(&chassis.swingPID, 7, 0, 45, 0); +} + +void two_mogo_constants() { + chassis.set_slew_min_power(80, 80); + chassis.set_slew_distance(7, 7); + chassis.set_pid_constants(&chassis.headingPID, 11, 0, 20, 0); + chassis.set_pid_constants(&chassis.forward_drivePID, 0.45, 0, 5, 0); + chassis.set_pid_constants(&chassis.backward_drivePID, 0.45, 0, 5, 0); + chassis.set_pid_constants(&chassis.turnPID, 5, 0.003, 35, 15); + chassis.set_pid_constants(&chassis.swingPID, 7, 0, 45, 0); +} + +void exit_condition_defaults() { + chassis.set_exit_condition(chassis.turn_exit, 100, 3, 500, 7, 500, 500); + chassis.set_exit_condition(chassis.swing_exit, 100, 3, 500, 7, 500, 500); + chassis.set_exit_condition(chassis.drive_exit, 80, 50, 300, 150, 500, 500); +} + +void modified_exit_condition() { + chassis.set_exit_condition(chassis.turn_exit, 100, 3, 500, 7, 500, 500); + chassis.set_exit_condition(chassis.swing_exit, 100, 3, 500, 7, 500, 500); + chassis.set_exit_condition(chassis.drive_exit, 80, 50, 300, 150, 500, 500); +} + + + +/// +// Drive Example +/// +void drive_example() { + // The first parameter is target inches + // The second parameter is max speed the robot will drive at + // The third parameter is a boolean (true or false) for enabling/disabling a slew at the start of drive motions + // for slew, only enable it when the drive distance is greater then the slew distance + a few inches + + + chassis.set_drive_pid(24, DRIVE_SPEED, true); + chassis.wait_drive(); + + chassis.set_drive_pid(-12, DRIVE_SPEED); + chassis.wait_drive(); + + chassis.set_drive_pid(-12, DRIVE_SPEED); + chassis.wait_drive(); +} + + + +/// +// Turn Example +/// +void turn_example() { + // The first parameter is target degrees + // The second parameter is max speed the robot will drive at + + + chassis.set_turn_pid(90, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(0, TURN_SPEED); + chassis.wait_drive(); +} + + + +/// +// Combining Turn + Drive +/// +void drive_and_turn() { + chassis.set_drive_pid(24, DRIVE_SPEED, true); + chassis.wait_drive(); + + chassis.set_turn_pid(45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(-45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(0, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_drive_pid(-24, DRIVE_SPEED, true); + chassis.wait_drive(); +} + + + +/// +// Wait Until and Changing Max Speed +/// +void wait_until_change_speed() { + // wait_until will wait until the robot gets to a desired position + + + // When the robot gets to 6 inches, the robot will travel the remaining distance at a max speed of 40 + chassis.set_drive_pid(24, DRIVE_SPEED, true); + chassis.wait_until(6); + chassis.set_max_speed(40); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 40 speed + chassis.wait_drive(); + + chassis.set_turn_pid(45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(-45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(0, TURN_SPEED); + chassis.wait_drive(); + + // When the robot gets to -6 inches, the robot will travel the remaining distance at a max speed of 40 + chassis.set_drive_pid(-24, DRIVE_SPEED, true); + chassis.wait_until(-6); + chassis.set_max_speed(40); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 40 speed + chassis.wait_drive(); +} + + + +/// +// Swing Example +/// +void swing_example() { + // The first parameter is ez::LEFT_SWING or ez::RIGHT_SWING + // The second parameter is target degrees + // The third parameter is speed of the moving side of the drive + + + chassis.set_swing_pid(ez::LEFT_SWING, 45, SWING_SPEED); + chassis.wait_drive(); + + chassis.set_drive_pid(24, DRIVE_SPEED, true); + chassis.wait_until(12); + + chassis.set_swing_pid(ez::RIGHT_SWING, 0, SWING_SPEED); + chassis.wait_drive(); +} + + + +/// +// Auto that tests everything +/// +void combining_movements() { + chassis.set_drive_pid(24, DRIVE_SPEED, true); + chassis.wait_drive(); + + chassis.set_turn_pid(45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_swing_pid(ez::RIGHT_SWING, -45, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_turn_pid(0, TURN_SPEED); + chassis.wait_drive(); + + chassis.set_drive_pid(-24, DRIVE_SPEED, true); + chassis.wait_drive(); +} + + + +/// +// Interference example +/// +void tug (int attempts) { + for (int i=0; i> 2, - (pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1, - (pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0); - int left = master.get_analog(ANALOG_LEFT_Y); - int right = master.get_analog(ANALOG_RIGHT_Y); - - left_mtr = left; - right_mtr = right; - - pros::delay(20); - } -} + // This is preference to what you like to drive on. + chassis.set_drive_brake(MOTOR_BRAKE_COAST); + + while (true) { + + //chassis.tank(); // Tank control + chassis.arcade_standard(ez::SPLIT); // Standard split arcade + // chassis.arcade_standard(ez::SINGLE); // Standard single arcade + // chassis.arcade_flipped(ez::SPLIT); // Flipped split arcade + // chassis.arcade_flipped(ez::SINGLE); // Flipped single arcade + + // . . . + // Put more user control code here! + // . . . + // pros::Task IntakeControlTask(Intake); + pros::Task IntakeControlTask(intake_control); + pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME + } +} \ No newline at end of file