Skip to content

Commit

Permalink
Added example auton routines doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Dec 13, 2021
1 parent d6beec5 commit 061e785
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 38 deletions.
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
layout: default
title: 404
nav_exclude: true
title: EZ-Template
nav_order: 1
permalink: /
---

# EZ-Template
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)

[![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.


Expand All @@ -15,22 +16,17 @@ Simple plug-and-play PROS template that handles drive base functions for VEX rob

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

## Downloading

Download the latest example project [here](https://github.com/EZ-Robotics/EZ-Template-Example/releases/latest) and open it as a new project in PROS.


## Setup
1) Download the latest example project [here](https://github.com/EZ-Robotics/EZ-Template-Example/releases/latest). Extract it, and open it in PROS.
## Download and Installation
1) Download the latest example project [here](https://github.com/EZ-Robotics/EZ-Template-Example/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 cartrige. Remember that 4" omni wheels 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.

## 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.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).
2) In your terminal, `cd` into the directory you downloaded the file.
3) Run this command from terminal `prosv5 c fetch [email protected]`.
4) `cd` into your pros project directory in your terminal.
Expand All @@ -45,7 +41,7 @@ Note* this only works for 2.0.0 and beyond. You cannot upgrade from 1.X.X to 2.


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


## License
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/activebrake.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: default
title: Active Brake
parent: Tutorials
nav_order: 3
nav_order: 4
---


Expand Down
223 changes: 223 additions & 0 deletions docs/Tutorials/example_autons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
---
layout: default
title: Example Autonomous Routines
parent: Tutorials
nav_order: 2
---


# **Adding Autonomous Routines**
{: .no_toc }

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}


---



## Assumed Constants
```cpp
const int DRIVE_SPEED = 110;
const int TURN_SPEED = 90;
const int SWING_SPEED = 90;
```


---


## Drive
```cpp
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
```cpp
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();
}
```


---


## Drive and Turn
```cpp
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 Speed
```cpp
void wait_until_change_speed() {
// wait_until will wait until the robot gets to a desired position


// When the robot gets to 12 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 12 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 -12 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 12 inches at DRIVE_SPEED, the robot will go the remaining distance at 40 speed
chassis.wait_drive();
}
```


---


## Swing Turns
```cpp
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();
}
```


---


## Combining All Movements
```cpp
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_drive_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
```cpp
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 succesfully 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();
}
```
---
2 changes: 1 addition & 1 deletion docs/Tutorials/joystick_curve.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: default
title: Joystick Curve
parent: Tutorials
nav_order: 2
nav_order: 3
---


Expand Down
5 changes: 2 additions & 3 deletions home.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
layout: default
title: EZ-Template
nav_order: 1
permalink: /
title: 404
nav_exclude: true
---

# EZ-Template
Expand Down
7 changes: 0 additions & 7 deletions src/EZ-Template/sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <filesystem>
#include "main.h"
#include "filesystem"

namespace ez {
namespace as {
Expand All @@ -23,12 +22,6 @@ void update_auto_sd() {
fclose(usd_file_write);
}

bool is_file_exist(const char *fileName)
{
std::ifstream infile(fileName);
return infile.good();
}

void init_auton_selector() {
// If no SD card, return
if (!ez::util::IS_SD_CARD) return;
Expand Down
18 changes: 6 additions & 12 deletions src/autons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ void two_mogo_constants() {
///
// Drive Example
///
void
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
Expand All @@ -77,8 +76,7 @@ drive_example() {
///
// Turn Example
///
void
turn_example() {
void turn_example() {
// The first parameter is target degrees
// The second parameter is max speed the robot will drive at

Expand All @@ -98,8 +96,7 @@ turn_example() {
///
// Combining Turn + Drive
///
void
drive_and_turn() {
void drive_and_turn() {
chassis.set_drive_pid(24, DRIVE_SPEED, true);
chassis.wait_drive();

Expand All @@ -121,8 +118,7 @@ drive_and_turn() {
///
// Wait Until and Changing Max Speed
///
void
wait_until_change_speed() {
void wait_until_change_speed() {
// wait_until will wait until the robot gets to a desired position


Expand Down Expand Up @@ -153,8 +149,7 @@ wait_until_change_speed() {
///
// Swing Example
///
void
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
Expand All @@ -175,8 +170,7 @@ swing_example() {
///
// Auto that tests everything
///
void
combining_movements() {
void combining_movements() {
chassis.set_drive_pid(24, DRIVE_SPEED, true);
chassis.wait_drive();

Expand Down

0 comments on commit 061e785

Please sign in to comment.