Skip to content

Commit

Permalink
Fixed some names, added get functions #73
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Nov 23, 2023
1 parent 343003b commit 7de75fd
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 47 deletions.
54 changes: 30 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
---
layout: default
title: EZ-Template
nav_order: 1
permalink: /
---

[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
![](https://img.shields.io/github/downloads/EZ-Robotics/EZ-Template/total.svg)
![](https://github.com/EZ-Robotics/EZ-Template/workflows/Build/badge.svg)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)

# EZ-Template
Simple plug-and-play PROS template that handles drive base functions for VEX robots.


[EZ-Template Version](https://github.com/EZ-Robotics/EZ-Template): 2.1.2-RC1
EZ-Template is a simple plug-and-play PROS template that handles drive base functions, autonomous selector, input curves, and active brake with PTO support.

[Autonomous routines that used EZ-Template](https://photos.app.goo.gl/yRwuvmq7hDoM4f6EA)

## Features
- Simple to setup
- PID for driving, turning, and swing turns
- Speed ramp-up for driving
- Asynchronous PID with blocking functions until settled and until a specific position has come
- Joystick input curves
- Live adjustment of input curves
- Basic autonomous selector
- SD card saving of autonomous selector and joystick curves
- "Tug of war" detection for autonomous
- PID exit conditions for when drive motors overheat
- Tank drive, single stick arcade, and dual stick arcade
- Loading animation during IMU calibration
- 3 wire encoder and rotation sensor support
- Add / remove motors from the drive dynamically to allow for PTO use
- Exposed PID class for use with your other subsystems

## Download and Installation
1) Download the latest example project [here](https://github.com/EZ-Robotics/EZ-Template/releases/latest). Extract the zip, and open it in PROS.
1) Download the latest `Example-Project.zip` [here](https://github.com/EZ-Robotics/EZ-Template/releases/latest). Extract the zip, and open it in PROS.
2) In `src/main.cpp`, configure drive and IMU ports to what they are on your robot. Be sure to read the comments!
3) Configure your wheel size and cartridge. Remember that 4" omni wheels are actually 4.125!
3) Configure your wheel size and cartridge. Remember that older 4" omni wheels without mounting holes are actually 4.125!
4) In `src/main.cpp`, at the bottom in `void opcontrol()`, decide how you'd like to control your robot! Any flavor of arcade or tank!
5) Turn the robot on and use it in driver control. Make sure the ports are correct and reversed correctly!
6) To test the test autonomous modes, plug into a competition switch and select the autonomous mode on the brain screen by pressing the left and right buttons! The current page will be the autonomous that runs. For making new autonomous routines, check `src/autons.cpp` for examples on how to use the drive functions.
5) Turn the robot on and use it in driver control. Make sure the ports are correct and reversed correctly.
6) To test the test autonomous modes, plug into a competition switch and select the autonomous mode on the brain screen by pressing the left and right buttons. The current page will be the autonomous that runs. For making new autonomous routines, [click here](https://ez-robotics.github.io/EZ-Template/tutorials/example_autons) for examples on how to use the drive functions.

## Upgrading
*Note: this only works for 2.0.0 and beyond. You cannot upgrade from 1.X.X to 2.X.X.*
1) Download the most recent EZ-Template [here](https://github.com/EZ-Robotics/EZ-Template/releases/latest).
*Note: this only works for 2.x and beyond. You cannot upgrade from 1.x to 2.x, or 2.x to 3.x without changing code.*
1) Download the most recent `EZ-Template@x.x.x.zip` [here](https://github.com/EZ-Robotics/EZ-Template/releases/latest).
2) Move the file to your project.
3) Open terminal or command prompt, and `cd` into your projects directory.
4) Run this command from terminal `prosv5 c fetch EZ-Template@2.1.1.zip`.
4) Run this command from terminal `prosv5 c fetch EZ-Template@x.x.x.zip` replacing `x.x.x` with the version number of your file.
5) Apply the library to the project `prosv5 c apply EZ-Template`.
6) Put `#include "EZ-Template/api.hpp"` in your `include/main.h`.

## Tutorials
[Check out our tutorials here!](https://ez-robotics.github.io/EZ-Template/tutorials)
[Check out our tutorials here!](https://ez-robotics.github.io/EZ-Template/category/tutorials)

## Docs
[Read the docs here!](https://ez-robotics.github.io/EZ-Template/docs)

## Additing Autonomous Routines
[Check out the tutorial on adding new autonomous routines here!](https://ez-robotics.github.io/EZ-Template/docs/Tutorials/autons.html)
[Read the docs here!](https://ez-robotics.github.io/EZ-Template/category/docs)


## License
Expand Down
5 changes: 5 additions & 0 deletions include/EZ-Template/PID.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class PID {
*/
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.
*
Expand Down
139 changes: 130 additions & 9 deletions include/EZ-Template/drive/drive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace ez;
class Drive {
public:
/**
* Joysticks will return 0 when they are within this number. Set with opcontrol_joystick_threshold()
* Joysticks will return 0 when they are within this number. Set with opcontrol_joystick_threshold_set()
*/
int JOYSTICK_THRESHOLD;

Expand Down Expand Up @@ -214,13 +214,13 @@ class Drive {

/**
* Sets the chassis to controller joysticks using tank control. Run is usercontrol.
* This passes the controller through the curve functions, but is disabled by default. Use toggle_controller_curve_modifier() to enable it.
* This passes the controller through the curve functions, but is disabled by default. Use opcontrol_curve_buttons_toggle() to enable it.
*/
void opcontrol_tank();

/**
* Sets the chassis to controller joysticks using standard arcade control. Run is usercontrol.
* This passes the controller through the curve functions, but is disabled by default. Use toggle_controller_curve_modifier() to enable it.
* This passes the controller through the curve functions, but is disabled by default. Use opcontrol_curve_buttons_toggle() to enable it.
*
* \param stick_type
* ez::SINGLE or ez::SPLIT control
Expand All @@ -229,7 +229,7 @@ class Drive {

/**
* Sets the chassis to controller joysticks using flipped arcade control. Run is usercontrol.
* This passes the controller through the curve functions, but is disabled by default. Use toggle_controller_curve_modifier() to enable it.
* This passes the controller through the curve functions, but is disabled by default. Use opcontrol_curve_buttons_toggle() to enable it.
*
* \param stick_type
* ez::SINGLE or ez::SPLIT control
Expand All @@ -251,6 +251,11 @@ class Drive {
*/
void opcontrol_curve_default_set(double left, double right = 0);

/**
* Gets the default joystick curves, in {left, right}
*/
std::vector<double> opcontrol_curve_default_get();

/**
* Runs a P loop on the drive when the joysticks are released.
*
Expand All @@ -259,6 +264,11 @@ class Drive {
*/
void opcontrol_drive_activebrake_set(double kp);

/**
* Returns kP for active brake.
*/
double opcontrol_drive_activebrake_get();

/**
* Enables/disables modifying the joystick input curves with the controller. True enables, false disables.
*
Expand All @@ -267,6 +277,11 @@ class Drive {
*/
void opcontrol_curve_buttons_toggle(bool toggle);

/**
* Gets the current state of the toggle. Enables/disables modifying the joystick input curves with the controller. True enables, false disables.
*/
bool opcontrol_curve_buttons_toggle_get();

/**
* Sets buttons for modifying the left joystick curve.
*
Expand All @@ -275,7 +290,12 @@ class Drive {
* \param increase
* a pros button enumerator
*/
void opcontrol_curve_buttons_left(pros::controller_digital_e_t decrease, pros::controller_digital_e_t increase);
void opcontrol_curve_buttons_left_set(pros::controller_digital_e_t decrease, pros::controller_digital_e_t increase);

/**
* Returns a vector of pros controller buttons user for the left joystick curve, in {decrease, increase}
*/
std::vector<pros::controller_digital_e_t> opcontrol_curve_buttons_left_get();

/**
* Sets buttons for modifying the right joystick curve.
Expand All @@ -285,7 +305,12 @@ class Drive {
* \param increase
* a pros button enumerator
*/
void opcontrol_curve_buttons_right(pros::controller_digital_e_t decrease, pros::controller_digital_e_t increase);
void opcontrol_curve_buttons_right_set(pros::controller_digital_e_t decrease, pros::controller_digital_e_t increase);

/**
* Returns a vector of pros controller buttons user for the right joystick curve, in {decrease, increase}
*/
std::vector<pros::controller_digital_e_t> opcontrol_curve_buttons_right_get();

/**
* Outputs a curve from 5225A In the Zone. This gives more control over the robot at lower speeds. https://www.desmos.com/calculator/rcfjjg83zx
Expand All @@ -309,7 +334,12 @@ class Drive {
* \param threshold
* new threshold
*/
void opcontrol_joystick_threshold(int threshold);
void opcontrol_joystick_threshold_set(int threshold);

/**
* Gets a new threshold for the joystick. The joysticks wil not return a value if they are within this.
*/
int opcontrol_joystick_threshold_get();

/**
* Resets drive sensors at the start of opcontrol.
Expand Down Expand Up @@ -390,6 +420,11 @@ class Drive {
*/
void drive_brake_set(pros::motor_brake_mode_e_t brake_type);

/**
* Returns the brake mode of the drive in pros_brake_mode_e_t_
*/
pros::motor_brake_mode_e_t drive_brake_get();

/**
* Sets the limit for the current on the drive.
*
Expand All @@ -398,16 +433,31 @@ class Drive {
*/
void drive_current_limit_set(int mA);

/**
* Gets the limit for the current on the drive.
*/
int drive_current_limit_get();

/**
* Toggles set drive in autonomous. True enables, false disables.
*/
void pid_drive_toggle(bool toggle);

/**
* Gets the current state of the toggle. This toggles set drive in autonomous. True enables, false disables.
*/
bool pid_drive_toggle_get();

/**
* Toggles printing in autonomous. True enables, false disables.
*/
void pid_print_toggle(bool toggle);

/**
* Gets the current state of the toggle. This toggles printing in autonomous. True enables, false disables.
*/
bool pid_print_toggle_get();

/////
//
// Telemetry
Expand Down Expand Up @@ -502,6 +552,11 @@ class Drive {
*/
void opcontrol_joystick_practicemode_toggle(bool toggle);

/**
* Gets current state of the toggle. Practice mode for driver practice that shuts off the drive if you go max speed.
*/
bool opcontrol_joystick_practicemode_toggle_get();

/////
//
// Autonomous Functions
Expand Down Expand Up @@ -574,7 +629,7 @@ class Drive {
/**
* Sets heading of gyro and target of PID.
*/
void set_angle(okapi::QAngle p_angle);
void drive_angle_set(okapi::QAngle p_angle);

/**
* Lock the code in a while loop until the robot has settled.
Expand Down Expand Up @@ -609,6 +664,7 @@ class Drive {
* ratio of the gears
*/
void drive_ratio_set(double ratio);

/**
* Changes max speed during a drive motion.
*
Expand All @@ -617,6 +673,11 @@ class Drive {
*/
void pid_speed_max_set(int speed);

/**
* Returns max speed of drive during autonomous.
*/
int pid_speed_max_get();

/**
* @brief Set the drive pid constants object
*
Expand All @@ -627,6 +688,16 @@ class Drive {
*/
void pid_drive_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);

/**
* @brief returns PID constants with PID::Constants. Returns -1 if fwd and rev constants aren't the same!
*
* @param p kP
* @param i kI
* @param d kD
* @param p_start_i start_I
*/
PID::Constants pid_drive_constants_get();

/**
* @brief Set the turn pid constants object
*
Expand All @@ -637,6 +708,16 @@ class Drive {
*/
void pid_turn_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);

/**
* @brief returns PID constants with PID::Constants.
*
* @param p kP
* @param i kI
* @param d kD
* @param p_start_i start_I
*/
PID::Constants pid_turn_constants_get();

/**
* @brief Set the swing pid constants object
*
Expand All @@ -647,6 +728,16 @@ class Drive {
*/
void pid_swing_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);

/**
* @brief returns PID constants with PID::Constants.
*
* @param p kP
* @param i kI
* @param d kD
* @param p_start_i start_I
*/
PID::Constants pid_swing_constants_get();

/**
* @brief Set the heading pid constants object
*
Expand All @@ -657,6 +748,16 @@ class Drive {
*/
void pid_heading_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);

/**
* @brief returns PID constants with PID::Constants.
*
* @param p kP
* @param i kI
* @param d kD
* @param p_start_i start_I
*/
PID::Constants pid_heading_constants_get();

/**
* @brief Set the forward pid constants object
*
Expand All @@ -667,6 +768,16 @@ class Drive {
*/
void pid_drive_forward_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);

/**
* @brief returns PID constants with PID::Constants.
*
* @param p kP
* @param i kI
* @param d kD
* @param p_start_i start_I
*/
PID::Constants pid_drive_forward_constants_get();

/**
* @brief Set the backwards pid constants object
*
Expand All @@ -677,6 +788,16 @@ class Drive {
*/
void pid_drive_backward_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);

/**
* @brief returns PID constants with PID::Constants.
*
* @param p kP
* @param i kI
* @param d kD
* @param p_start_i start_I
*/
PID::Constants pid_drive_backward_constants_get();

/**
* Sets minimum power for swings when kI and startI are enabled.
*
Expand All @@ -701,7 +822,7 @@ class Drive {
/**
* Returns minimum power for turns when kI and startI are enabled.
*/
int get_turn_min();
int pid_turn_min_get();

/**
* Sets minimum slew speed constants.
Expand Down
Loading

0 comments on commit 7de75fd

Please sign in to comment.