Initial commit

This commit is contained in:
Carter committed 2026-07-21 13:45:37 -04:00
commit 2c7628bb9f
381 files changed
+83535

No files matched your search

+299
View File
@@ -0,0 +1,299 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "EZ-Template/util.hpp"
#include "api.h"
namespace ez {
class PID {
public:
/**
* Default constructor.
*/
PID();
/**
* Constructor with constants.
*
* \param p
* kP
* \param i
* ki
* \param d
* kD
* \param p_start_i
* error value that i starts within
* \param name
* std::string of name that prints
*/
PID(double p, double i = 0, double d = 0, double start_i = 0, std::string name = "");
/**
* Set constants for PID.
*
* \param p
* kP
* \param i
* ki
* \param d
* kD
* \param p_start_i
* error value that i starts within
*/
void constants_set(double p, double i = 0, double d = 0, double p_start_i = 0);
/**
* Struct for constants.
*/
struct Constants {
double kp;
double ki;
double kd;
double start_i;
};
/**
* Struct for exit condition.
*/
struct exit_condition_ {
int small_exit_time = 0;
double small_error = 0;
int big_exit_time = 0;
double big_error = 0;
int velocity_exit_time = 0;
int mA_timeout = 0;
};
/**
* Set's constants for exit conditions.
*
* \param p_small_exit_time
* sets small_exit_time, timer for to exit within smalL_error
* \param p_small_error
* sets smalL_error, timer will start when error is within this
* \param p_big_exit_time
* sets big_exit_time, timer for to exit within big_error
* \param p_big_error
* sets big_error, timer will start when error is within this
* \param p_velocity_exit_time
* sets velocity_exit_time, timer will start when velocity is 0
*/
void exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time = 0, double p_big_error = 0, int p_velocity_exit_time = 0, int p_mA_timeout = 0);
/**
* Sets PID target.
*
* \param target
* new target for PID
*/
void target_set(double input);
/**
* Computes PID.
*
* \param current
* current sensor value
*/
double compute(double current);
/**
* Computes PID, but you compute the error yourself.
*
* Current is only used here for calculative derivative to solve derivative kick.
*
* \param err
* error for the PID, you need to calculate this yourself
* \param current
* current sensor value
*/
double compute_error(double err, double current);
/**
* Returns target value.
*/
double target_get();
/**
* Returns constants.
*/
Constants constants_get();
/**
* Returns true if PID constants are set, returns false if they're all 0.
*/
bool constants_set_check();
/**
* Resets all variables to 0. This does not reset constants.
*/
void variables_reset();
/**
* Constants.
*/
Constants constants;
/**
* Exit.
*/
exit_condition_ exit;
/**
* Updates a secondary sensor for velocity exiting. Ideal use is IMU during normal drive motions.
*
* \param secondary_sensor
* secondary sensor value
*/
void velocity_sensor_secondary_set(double secondary_sensor);
/**
* Returns the updated secondary sensor for velocity exiting.
*/
double velocity_sensor_secondary_get();
/**
* Boolean for if the secondary sensor will be updated or not. True uses this sensor, false does not.
*
* \param toggle
* true uses this sensor, false does not
*/
void velocity_sensor_secondary_toggle_set(bool toggle);
/**
* Returns the boolean for if the secondary sensor will be updated or not. True uses this sensor, false does not.
*/
bool velocity_sensor_secondary_toggle_get();
/**
* Sets the threshold that the main sensor will return 0 velocity within.
*
* \param zero
* a small double
*/
void velocity_sensor_main_exit_set(double zero);
/**
* Returns the threshold that the main sensor will return 0 velocity within.
*/
double velocity_sensor_main_exit_get();
/**
* Sets the threshold that the secondary sensor will return 0 velocity within.
*
* \param zero
* a small double
*/
void velocity_sensor_secondary_exit_set(double zero);
/**
* Returns the threshold that the secondary sensor will return 0 velocity within.
*/
double velocity_sensor_secondary_exit_get();
/**
* Iterative exit condition for PID.
*
* \param print = false
* if true, prints when complete
*/
ez::exit_output exit_condition(bool print = false);
/**
* Iterative exit condition for PID.
*
* \param sensor
* a pros motor on your mechanism
* \param print = false
* if true, prints when complete
*/
ez::exit_output exit_condition(pros::Motor sensor, bool print = false);
/**
* Iterative exit condition for PID.
*
* \param sensor
* pros motors on your mechanism
* \param print = false
* if true, prints when complete
*/
ez::exit_output exit_condition(std::vector<pros::Motor> sensor, bool print = false);
/**
* Iterative exit condition for PID.
*
* \param sensor
* pros motor group on your mechanism
* \param print = false
* if true, prints when complete
*/
ez::exit_output exit_condition(pros::MotorGroup sensor, bool print = false);
/**
* Sets the name of the PID that prints during exit conditions.
*
* \param name
* the name of the mechanism for printing
*/
void name_set(std::string name);
/**
* Returns the name of the PID that prints during exit conditions.
*/
std::string name_get();
/**
* Enables / disables i resetting when sgn of error changes.
*
* True resets, false doesn't.
*
* \param toggle
* true resets, false doesn't
*/
void i_reset_toggle(bool toggle);
/**
* Returns if i will reset when sgn of error changes.
*
* True resets, false doesn't.
*/
bool i_reset_get();
/**
* Resets all timers for exit conditions.
*/
void timers_reset();
/**
* PID variables.
*/
double output = 0.0;
double cur = 0.0;
double error = 0.0;
double target = 0.0;
double prev_error = 0.0;
double prev_current = 0.0;
double integral = 0.0;
double derivative = 0.0;
long time = 0;
long prev_time = 0;
private:
double velocity_zero_main = 0.05;
double velocity_zero_secondary = 0.075;
int i = 0, j = 0, k = 0, l = 0, m = 0;
bool is_mA = false;
double second_sensor = 0.0;
std::string name;
bool name_active = false;
void exit_condition_print(ez::exit_output exit_type);
bool reset_i_sgn = true;
double raw_compute();
bool use_second_sensor = false;
};
}; // namespace ez
+17
View File
@@ -0,0 +1,17 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "EZ-Template/PID.hpp"
#include "EZ-Template/auton.hpp"
#include "EZ-Template/auton_selector.hpp"
#include "EZ-Template/drive/drive.hpp"
#include "EZ-Template/piston.hpp"
#include "EZ-Template/sdcard.hpp"
#include "EZ-Template/slew.hpp"
#include "EZ-Template/tracking_wheel.hpp"
#include "EZ-Template/util.hpp"
+21
View File
@@ -0,0 +1,21 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <functional>
#include <iostream>
namespace ez {
class Auton {
public:
Auton();
Auton(std::string, std::function<void()>);
std::string Name;
std::function<void()> auton_call;
private:
};
} // namespace ez
+27
View File
@@ -0,0 +1,27 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <tuple>
#include "EZ-Template/auton.hpp"
using namespace std;
namespace ez {
class AutonSelector {
public:
std::vector<Auton> Autons;
int auton_page_current;
int auton_count;
int last_auton_page_current;
AutonSelector();
AutonSelector(std::vector<Auton> autons);
void selected_auton_call();
void selected_auton_print();
void autons_add(std::vector<Auton> autons);
};
} // namespace ez
File diff suppressed because it is too large. Load diff
+79
View File
@@ -0,0 +1,79 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
namespace ez {
class Piston {
public:
/**
* Piston used throughout.
*/
pros::adi::DigitalOut piston;
/**
* Piston constructor.
*
* The starting position of your piston defaults to false.
*
* \param input_port
* the ports of your pistons
* \param default_state
* starting state of your piston
*/
Piston(int input_port, bool default_state = false);
/**
* Piston constructor in 3 wire expander.
*
* The starting position of your piston defaults to false.
*
* \param input_ports
* the ports of your pistons
* \param default_state
* starting state of your piston
*/
Piston(int input_port, int expander_smart_port, bool default_state = false);
/**
* Sets the piston to the input.
*
* \param input
* true sets to the opposite of the starting position
*/
void set(bool input);
/**
* Returns current piston state.
*/
bool get();
/**
* One button toggle for the piston.
*
* \param toggle
* an input button
*/
void button_toggle(int toggle);
/**
* Two buttons trigger the piston. Active is enabled, deactive is disabled.
*
* \param active
* sets piston to true
* \param active
* sets piston to false
*/
void buttons(int active, int deactive);
private:
bool reversed = false;
bool current = false;
int last_press = 0;
};
}; // namespace ez
+103
View File
@@ -0,0 +1,103 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "EZ-Template/auton_selector.hpp"
#include "api.h"
namespace ez {
namespace as {
extern AutonSelector auton_selector;
/**
* Sets sd card to current page.
*/
void auton_selector_initialize();
/**
* Sets the sd card to current page.
*/
void auto_sd_update();
/**
* Increases the page by 1.
*/
void page_up();
/**
* Decreases the page by 1.
*/
void page_down();
/**
* Initializes LLEMU and sets up callbacks for auton selector.
*/
void initialize();
/**
* Wrapper for pros::lcd::shutdown.
*/
void shutdown();
/**
* Returns true if the auton selector is running.
*/
bool enabled();
inline bool auton_selector_running;
extern bool turn_off;
extern pros::adi::DigitalIn* limit_switch_left;
extern pros::adi::DigitalIn* limit_switch_right;
/**
* Initialize two limit switches to change pages on the lcd.
*
* @param left_limit_port
* port for the left limit switch
* @param right_limit_port
* port for the right limit switch
*/
void limit_switch_lcd_initialize(pros::adi::DigitalIn* right_limit, pros::adi::DigitalIn* left_limit = nullptr);
/**
* pre_auto_task
*/
void limitSwitchTask();
/**
* Returns the current blank page that is on. Negative value means the current page isn't blank.
*/
int page_blank_current();
/**
* Checks if this blank page is open. If this page doesn't exist, this will create it.
*/
bool page_blank_is_on(int page);
/**
* Removes the blank page if it exists, and previous ones.
*/
void page_blank_remove(int page);
/**
* Removes all blank pages.
*/
void page_blank_remove_all();
/**
* Removes the current amount of blank pages.
*/
int page_blank_amount();
/**
* Current amount of blank pages.
*/
extern int amount_of_blank_pages;
} // namespace as
} // namespace ez
+102
View File
@@ -0,0 +1,102 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "EZ-Template/util.hpp"
#include "api.h"
namespace ez {
class slew {
public:
slew();
/**
* Struct for constants.
*/
struct Constants {
double min_speed = 0;
double distance_to_travel = 0;
};
Constants constants;
/**
* Sets constants for slew. Slew ramps up the speed of the robot until the set distance is traveled.
*
* \param distance
* the distance the robot travels before reaching max speed
* \param minimum_speed
* the starting speed for the movement
*/
slew(double distance, int minimum_speed);
/**
* Sets constants for slew. Slew ramps up the speed of the robot until the set distance is traveled.
*
* \param distance
* the distance the robot travels before reaching max speed
* \param minimum_speed
* the starting speed for the movement
*/
void constants_set(double distance, int minimum_speed);
Constants constants_get();
/**
* Initializes slew for the motion.
*
* \param enabled
* true enables slew, false disables slew
* \param maximum_speed
* the target speed the robot will ramp up too
* \param target
* the target position for the motion
* \param current
* the position at the start of the motion
*/
void initialize(bool enabled, double maximum_speed, double target, double current);
/**
* Iterates slew and ramps up speed the farther along the motion the robot gets.
*
* \param current
* current sensor value
*/
double iterate(double current);
/**
* Returns true if slew is enabled, and false if it isn't.
*/
bool enabled();
/**
* Returns the last output of iterate.
*/
double output();
/**
* Sets the max speed the slew can be.
*
* \param speed
* maximum speed
*/
void speed_max_set(double speed);
/**
* Returns the max speed the slew can be.
*/
double speed_max_get();
private:
int sign = 0;
double error = 0;
double x_intercept = 0;
double y_intercept = 0;
double slope = 0;
double last_output = 0;
bool is_enabled = false;
double max_speed = 0;
};
}; // namespace ez
+162
View File
@@ -0,0 +1,162 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "pros/adi.hpp"
#include "pros/rotation.hpp"
namespace ez {
class tracking_wheel {
public:
pros::adi::Encoder adi_encoder;
pros::Rotation smart_encoder;
/**
* Creates a new tracking wheel with an ADI Encoder.
*
* \param ports
* {'A', 'B'}. make the encoder negative if reversed
* \param wheel_diameter
* assumed inches, this is the diameter of your wheel
* \param distance_to_center
* the distance to the center of your robot, this is used for tracking
* \param ratio
* the gear ratio of your tracking wheel. if it's not geared, this should be 1.0
*/
tracking_wheel(std::vector<int> ports, double wheel_diameter, double distance_to_center = 0.0, double ratio = 1.0);
/**
* Creates a new tracking wheel with an ADI Encoder plugged into a 3-wire expander.
*
* \param smart_port
* the smart port your ADI Expander is plugged into
* \param ports
* {'A', 'B'}. make the encoder negative if reversed
* \param wheel_diameter
* assumed inches, this is the diameter of your wheel
* \param distance_to_center
* the distance to the center of your robot, this is used for tracking
* \param ratio
* the gear ratio of your tracking wheel. if it's not geared, this should be 1.0
*/
tracking_wheel(int smart_port, std::vector<int> ports, double wheel_diameter, double distance_to_center = 0.0, double ratio = 1.0);
/**
* Creates a new tracking wheel with a Rotation sensor.
*
* \param port
* the port your Rotation sensor is plugged into, make this negative if reversed
* \param wheel_diameter
* assumed inches, this is the diameter of your wheel
* \param distance_to_center
* the distance to the center of your robot, this is used for tracking
* \param ratio
* the gear ratio of your tracking wheel. if it's not geared, this should be 1.0
*/
tracking_wheel(int port, double wheel_diameter, double distance_to_center = 0.0, double ratio = 1.0);
/**
* Returns how far the wheel has traveled in inches.
*/
double get();
/**
* Returns the raw sensor value.
*/
double get_raw();
/**
* Sets the distance to the center of the robot.
*
* \param input
* distance to the center of your robot in inches
*/
void distance_to_center_set(double input);
/**
* Returns the distance to the center of the robot.
*/
double distance_to_center_get();
/**
* Sets the distance to the center to be flipped to negative or not.
*
* \param input
* flips distance to center to negative. false leaves it alone, true flips it
*/
void distance_to_center_flip_set(bool input);
/**
* Returns if the distance to center is flipped or not. False is not, true is.
*/
bool distance_to_center_flip_get();
/**
* Resets your sensor.
*/
void reset();
/**
* Returns the constant for how many ticks is 1 inch.
*/
double ticks_per_inch();
/**
* Sets the amount of ticks per revolution of your sensor.
*
* This is useful for custom encoders.
*
* \param input
* ticks per revolution
*/
void ticks_per_rev_set(double input);
/**
* Returns the amount of ticks per revolution of your sensor.
*/
double ticks_per_rev_get();
/**
* Sets the gear ratio for your tracking wheel.
*
* \param input
* gear ratio of tracking wheel
*/
void ratio_set(double input);
/**
* Returns the gear ratio for your tracking wheel.
*/
double ratio_get();
/**
* Sets the diameter of your wheel.
*
* \param input
* wheel diameter
*/
void wheel_diameter_set(double input);
/**
* Returns the diameter of your wheel.
*/
double wheel_diameter_get();
private:
#define DRIVE_ADI_ENCODER 2
#define DRIVE_ROTATION 3
int IS_TRACKER = 0;
bool IS_FLIPPED = false;
double DISTANCE_TO_CENTER = 0.0;
double WHEEL_DIAMETER = 0.0;
double RATIO = 1.0;
double ENCODER_TICKS_PER_REV = 0.0;
double WHEEL_TICK_PER_REV = 0.0;
};
}; // namespace ez
+333
View File
@@ -0,0 +1,333 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include "api.h"
#include "okapi/api/units/QAngle.hpp"
#include "okapi/api/units/QLength.hpp"
#include "okapi/api/units/QTime.hpp"
#include "util.hpp"
using namespace okapi::literals;
/**
* Controller.
*/
extern pros::Controller master;
namespace ez {
/**
* Prints our branding all over your pros terminal.
*/
void ez_template_print();
/**
* Prints to the brain screen in one string.
*
* Splits input between lines with '\n' or when text longer then 32 characters.
*
* \param text
* input string
* \param line
* starting line to print on, defaults to 0
*/
void screen_print(std::string text, int line = 0);
/////
//
// Public Variables
//
/////
/**
* Enum for split and single stick arcade.
*/
enum e_type { SINGLE = 0,
SPLIT = 1 };
/**
* Enum for split and single stick arcade.
*/
enum e_swing { LEFT_SWING = 0,
RIGHT_SWING = 1 };
/**
* Enum for PID::exit_condition outputs.
*/
enum exit_output { RUNNING = 1,
SMALL_EXIT = 2,
BIG_EXIT = 3,
VELOCITY_EXIT = 4,
mA_EXIT = 5,
ERROR_NO_CONSTANTS = 6 };
/**
* Enum for split and single stick arcade.
*/
enum e_mode { DISABLE = 0,
SWING = 1,
TURN = 2,
TURN_TO_POINT = 3,
DRIVE = 4,
POINT_TO_POINT = 5,
PURE_PURSUIT = 6 };
/**
* Enum for drive directions.
*/
enum drive_directions { FWD = 0,
FORWARD = FWD,
fwd = FWD,
forward = FWD,
REV = 1,
REVERSE = REV,
rev = REV,
reverse = REV };
/**
* Enum for turn types.
*/
enum e_angle_behavior { raw = 0,
left_turn = 1,
LEFT_TURN = 1,
counterclockwise = 1,
ccw = 1,
right_turn = 2,
RIGHT_TURN = 2,
clockwise = 2,
cw = 2,
shortest = 3,
longest = 4 };
const double ANGLE_NOT_SET = 0.0000000000000000000001;
const okapi::QAngle p_ANGLE_NOT_SET = 0.0000000000000000000001_deg;
/**
* Struct for coordinates.
*/
typedef struct pose {
double x;
double y;
double theta = ANGLE_NOT_SET;
} pose;
/**
* Struct for united coordinates.
*/
typedef struct united_pose {
okapi::QLength x;
okapi::QLength y;
okapi::QAngle theta = p_ANGLE_NOT_SET;
} united_pose;
/**
* Struct for odom movements.
*/
typedef struct odom {
pose target;
drive_directions drive_direction;
int max_xy_speed;
e_angle_behavior turn_behavior = shortest;
} odom;
/**
* Struct for united odom movements.
*/
typedef struct united_odom {
united_pose target;
drive_directions drive_direction;
int max_xy_speed;
e_angle_behavior turn_behavior = shortest;
} united_odom;
/**
* Outputs string for exit_condition enum.
*/
std::string exit_to_string(exit_output input);
namespace util {
extern bool AUTON_RAN;
/**
* Returns the amount of places after a decimal, maxing out at 6.
*
* \param input
* your input value with decimals
* \param min
* minimum number of decimal places to print, this is defaulted to 0
*/
int places_after_decimal(double input, int min = 0);
/**
* Returns a string with a specific number of decimal points.
*
* \param input
* your input value
* \param n
* the amount of decimals you want to display
*/
std::string to_string_with_precision(double input, int n = 2);
/**
* Returns 1 if input is positive and -1 if input is negative.
*
* \param input
* your input value
*/
int sgn(double input);
/**
* Returns true if the input is < 0.
*
* \param input
* your input value
*/
bool reversed_active(double input);
/**
* Returns input restricted to min-max threshold.
*
* \param input
* your input value
* \param max
* the maximum input can be
* \param min
* the minimum input can be
*/
double clamp(double input, double max, double min);
/**
* Returns input restricted to min-max threshold.
*
* The minimum used is negative max.
*
* \param input
* your input value
* \param max
* the absolute value maximum input can be
*/
double clamp(double input, double max);
/**
* Is the SD card plugged in?
*/
const bool SD_CARD_ACTIVE = pros::usd::is_installed();
/**
* Delay time for tasks, this is set to 10 ms.
*/
const int DELAY_TIME = 10;
/**
* Converts radians to degrees.
*
* \param input
* your input radian
*/
double to_deg(double input);
/**
* Converts degrees to radians.
*
* \param input
* your input degree
*/
double to_rad(double input);
/**
* Returns the angle between two points.
*
* \param itarget
* target position
* \param icurrent
* current position
*/
double absolute_angle_to_point(pose itarget, pose icurrent);
/**
* Returns the distance between two points.
*
* \param itarget
* target position
* \param icurrent
* current position
*/
double distance_to_point(pose itarget, pose icurrent);
/**
* Constrains an angle between 180 and -180.
*
* \param theta
* input angle in degrees
*/
double wrap_angle(double theta);
/**
* Returns a new pose that is projected off of the current pose.
*
* \param added
* how far to project a new point
* \param icurrent
* point to project off of
*/
pose vector_off_point(double added, pose icurrent);
/**
* Returns the shortest angle for the robot to turn to in order to get to target.
*
* \param target
* target value in degrees
* \param current
* current value in degrees
* \param print = false
* will print the new value if this is true, defaults to false
*/
double turn_shortest(double target, double current, bool print = false);
/**
* Returns the farthest away angle for the robot to turn to in order to get to target.
*
* \param target
* target value in degrees
* \param current
* current value in degrees
* \param print = false
* will print the new value if this is true, defaults to false
*/
double turn_longest(double target, double current, bool print = false);
/**
* Converts pose with okapi units to a pose without okapi units.
*
* \param input
* a pose with units
*/
pose united_pose_to_pose(united_pose input);
/**
* Converts vector of poses with okapi units to a vector of poses without okapi units.
*
* \param inputs
* poses with units
*/
std::vector<odom> united_odoms_to_odoms(std::vector<united_odom> inputs);
/**
* Converts odom movement with united pose to an odom movement without united pose.
*
* \param input
* odom movement with units
*/
odom united_odom_to_odom(united_odom input);
} // namespace util
} // namespace ez