Skip to content

Commit

Permalink
Merged Current code with fresh copy of EZ-Template and updated to lat…
Browse files Browse the repository at this point in the history
…est kernel version
  • Loading branch information
nikgajjar51 committed Oct 20, 2023
1 parent 4225432 commit 8022703
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 40 deletions.
5 changes: 5 additions & 0 deletions include/Intakes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include "api.h"
#include "main.h"

void intake_control();
4 changes: 4 additions & 0 deletions include/Ports.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "api.h"
#include "pros/adi.hpp"

extern pros::Motor intakeMotor;
6 changes: 6 additions & 0 deletions include/SETTINGS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include "api.h"
#include "main.h"
using namespace pros;

#define intakeMotorPort 16
20 changes: 20 additions & 0 deletions include/autons.hpp
Original file line number Diff line number Diff line change
@@ -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();

11 changes: 9 additions & 2 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/Intakes.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
6 changes: 6 additions & 0 deletions src/Ports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "main.h"
#include "SETTINGS.hpp"
#include "pros/adi.hpp"
#include "pros/motors.h"

pros::Motor intakeMotor(intakeMotorPort);
250 changes: 250 additions & 0 deletions src/autons.cpp
Original file line number Diff line number Diff line change
@@ -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<attempts-1; i++) {
// Attempt to drive backwards
printf("i - %i", i);
chassis.set_drive_pid(-12, 127);
chassis.wait_drive();

// If failsafed...
if (chassis.interfered) {
chassis.reset_drive_sensor();
chassis.set_drive_pid(-2, 20);
pros::delay(1000);
}
// If robot successfully drove back, return
else {
return;
}
}
}

// If there is no interference, robot will drive forward and turn 90 degrees.
// If interfered, robot will drive forward and then attempt to drive backwards.
void interfered_example() {
chassis.set_drive_pid(24, DRIVE_SPEED, true);
chassis.wait_drive();

if (chassis.interfered) {
tug(3);
return;
}

chassis.set_turn_pid(90, TURN_SPEED);
chassis.wait_drive();
}



// . . .
// Make your own autonomous functions here!
// . . .
Loading

0 comments on commit 8022703

Please sign in to comment.