Skip to content

Commit

Permalink
Main project updated to example, fixed #122 and #123
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Jun 9, 2024
1 parent e7c6b2a commit 64dd7c1
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 441 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified EZ-Template-Example-Project/firmware/EZ-Template.a
Binary file not shown.
20 changes: 11 additions & 9 deletions EZ-Template-Example-Project/project.pros
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
"target": "v5",
"templates": {
"EZ-Template": {
"location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\[email protected]RC2",
"location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\[email protected]RC3",
"metadata": {
"origin": "local"
},
"name": "EZ-Template",
"py/object": "pros.conductor.templates.local_template.LocalTemplate",
"supported_kernels": "^4.1.0",
"system_files": [
"include\\EZ-Template\\api.hpp",
"include\\EZ-Template\\auton_selector.hpp",
"include\\EZ-Template\\drive\\drive.hpp",
"include\\EZ-Template\\api.hpp",
"include\\EZ-Template\\util.hpp",
"include\\EZ-Template\\slew.hpp",
"include\\EZ-Template\\piston.hpp",
"include\\EZ-Template\\PID.hpp",
"include\\EZ-Template\\sdcard.hpp",
"include\\EZ-Template\\auton.hpp",
"firmware\\EZ-Template.a",
"include\\EZ-Template\\slew.hpp",
"include\\EZ-Template\\piston.hpp",
"include\\EZ-Template\\util.hpp",
"include\\EZ-Template\\auton.hpp"
"include\\EZ-Template\\drive\\drive.hpp"
],
"target": "v5",
"user_files": [],
"version": "3.1.0-RC2"
"version": "3.1.0-RC3"
},
"kernel": {
"location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\[email protected]",
Expand Down Expand Up @@ -420,7 +420,9 @@
"version": "5.0.0"
}
},
"upload_options": {},
"upload_options": {
"description": "making code ez"
},
"use_early_access": false
}
}
Binary file renamed [email protected][email protected]
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ EXCLUDE_COLD_LIBRARIES:=
IS_LIBRARY:=1
# TODO: CHANGE THIS!
LIBNAME:=EZ-Template
VERSION:=3.1.0-RC2
VERSION:=3.1.0-RC3
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
# this line excludes opcontrol.c and similar files
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/autons $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))
Expand Down
2 changes: 2 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

// More includes here...
#include "autons.hpp"
#include "subsystems.hpp"


/**
* If you find doing pros::Motor() to be tedious and you'd prefer just to do
Expand Down
8 changes: 8 additions & 0 deletions include/subsystems.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "api.h"

// Your motors, sensors, etc. should go here. Below are examples

// inline pros::Motor intake(1);
// inline pros::adi::DigitalIn limit_switch('A');
804 changes: 402 additions & 402 deletions project.pros

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/EZ-Template/drive/drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ Drive::Drive(std::vector<int> left_motor_ports, std::vector<int> right_motor_por
}

void Drive::drive_defaults_set() {
std::cout << std::fixed;
std::cout << std::setprecision(2);

// PID Constants
pid_heading_constants_set(11, 0, 20, 0);
pid_drive_constants_set(20, 0, 100, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/EZ-Template/drive/exit_conditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void Drive::wait_until_drive(double target) {
}
// Once we've past target, return
else if (util::sgn(l_error) != l_sgn || util::sgn(r_error) != r_sgn) {
if (print_toggle) printf(" Drive Wait Until Exit Success. Triggered at: L,R(%f, %f) Target: L,R(%f, %f)\n", drive_sensor_left() - l_start, drive_sensor_right() - r_start, l_tar, r_tar);
if (print_toggle) printf(" Drive Wait Until Exit Success. Triggered at: L,R(%.2f, %.2f) Target: L,R(%.2f, %.2f)\n", drive_sensor_left() - l_start, drive_sensor_right() - r_start, l_tar, r_tar);
leftPID.timers_reset();
rightPID.timers_reset();
return;
Expand Down Expand Up @@ -210,7 +210,7 @@ void Drive::wait_until_turn_swing(double target) {
}
// Once we've past target, return
else if (util::sgn(g_error) != g_sgn) {
if (print_toggle) printf(" Turn Wait Until Exit Success, triggered at %f. Target: %f\n", drive_imu_get(), target);
if (print_toggle) printf(" Turn Wait Until Exit Success, triggered at %.2f. Target: %.2f\n", drive_imu_get(), target);
turnPID.timers_reset();
return;
}
Expand All @@ -235,7 +235,7 @@ void Drive::wait_until_turn_swing(double target) {
}
// Once we've past target, return
else if (util::sgn(g_error) != g_sgn) {
if (print_toggle) printf(" Swing Wait Until Exit Success, triggered at %f. Target: %f\n", drive_imu_get(), target);
if (print_toggle) printf(" Swing Wait Until Exit Success, triggered at %.2f. Target: %.2f\n", drive_imu_get(), target);
swingPID.timers_reset();
return;
}
Expand Down Expand Up @@ -327,7 +327,7 @@ void Drive::pid_wait_quick_chain() {
double chain_scale = motion_chain_backward ? drive_backward_motion_chain_scale : drive_forward_motion_chain_scale;
used_motion_chain_scale = chain_scale * util::sgn(chain_target_start);
leftPID.target_set(leftPID.target_get() + used_motion_chain_scale);
rightPID.target_set(leftPID.target_get() + used_motion_chain_scale);
rightPID.target_set(rightPID.target_get() + used_motion_chain_scale);
}
// If turning, add turn_motion_chain_scale to target
else if (mode == TURN) {
Expand Down
6 changes: 3 additions & 3 deletions src/EZ-Template/drive/set_pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void Drive::pid_drive_set(double target, int speed, bool slew_on, bool toggle_he
rightPID.timers_reset();

// Print targets
if (print_toggle) printf("Drive Started... Target Value: %f", target);
if (print_toggle) printf("Drive Started... Target Value: %.2f", target);
if (slew_on && print_toggle) printf(" with slew");
if (print_toggle) printf("\n");
chain_target_start = target;
Expand Down Expand Up @@ -197,7 +197,7 @@ void Drive::pid_turn_set(double target, int speed, bool slew_on) {
turnPID.timers_reset();

// Print targets
if (print_toggle) printf("Turn Started... Target Value: %f\n", target);
if (print_toggle) printf("Turn Started... Target Value: %.2f\n", target);
chain_sensor_start = drive_imu_get();
chain_target_start = target;
used_motion_chain_scale = 0.0;
Expand Down Expand Up @@ -239,7 +239,7 @@ void Drive::pid_swing_set(e_swing type, double target, int speed, int opposite_s
swingPID.timers_reset();

// Print targets
if (print_toggle) printf("Swing Started... Target Value: %f\n", target);
if (print_toggle) printf("Swing Started... Target Value: %.2f\n", target);
current_swing = type;
chain_sensor_start = drive_imu_get();
chain_target_start = target;
Expand Down
17 changes: 10 additions & 7 deletions src/EZ-Template/drive/user_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ void Drive::opcontrol_curve_buttons_iterate() {
button_press(&r_decrease_, master.get_digital(r_decrease_.button), ([this] { this->r_decrease(); }), ([this] { this->save_r_curve_sd(); }));
}

auto sr = std::to_string(right_curve_scale);
auto sl = std::to_string(left_curve_scale);
std::ostringstream short_sl, short_sr;
short_sl << std::fixed << std::setprecision(1) << left_curve_scale;
short_sr << std::fixed << std::setprecision(1) << right_curve_scale;

auto sr = short_sr.str();
auto sl = short_sl.str();
if (!is_tank)
master.set_text(2, 0, sl + " " + sr);
master.set_text(2, 0, sl + " " + sr);
else
master.set_text(2, 0, sl);
}
Expand Down Expand Up @@ -230,11 +234,10 @@ void Drive::opcontrol_joystick_threshold_iterate(int l_stick, int r_stick) {
if (abs(l_stick) > 0 || abs(r_stick) > 0) {
if (practice_mode_is_on && (abs(l_stick) > 120 || abs(r_stick) > 120))
drive_set(0, 0);
else if (is_reversed == true)
drive_set(-r_stick, -l_stick);
else
if(is_reversed == true)
drive_set(-r_stick, -l_stick);
else
drive_set(l_stick, r_stick);
drive_set(l_stick, r_stick);
if (active_brake_kp != 0) drive_sensor_reset();
}
// When joys are released, run active brake (P) on drive
Expand Down
4 changes: 2 additions & 2 deletions src/autons.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "main.h"

/////
// For installation, upgrading, documentations and tutorials, check out our website!
// For installation, upgrading, documentations, and tutorials, check out our website!
// https://ez-robotics.github.io/EZ-Template/
/////

Expand Down Expand Up @@ -144,7 +144,7 @@ void motion_chaining() {
// This works by exiting while the robot is still moving a little bit.
// To use this, replace pid_wait with pid_wait_quick_chain.
chassis.pid_drive_set(24_in, DRIVE_SPEED, true);
chassis.pid_wait_quick_chain();
chassis.pid_wait();

chassis.pid_turn_set(45_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
Expand Down
28 changes: 16 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "main.h"

/////
// For installation, upgrading, documentations and tutorials, check out our website!
// For installation, upgrading, documentations, and tutorials, check out our website!
// https://ez-robotics.github.io/EZ-Template/
/////

Expand Down Expand Up @@ -29,15 +29,15 @@ void initialize() {

// Configure your chassis controls
chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks
chassis.opcontrol_drive_activebrake_set(0); // Sets the active brake kP. We recommend 2.
chassis.opcontrol_drive_activebrake_set(0); // Sets the active brake kP. We recommend ~2. 0 will disable.
chassis.opcontrol_curve_default_set(0, 0); // Defaults for curve. If using tank, only the first parameter is used. (Comment this line out if you have an SD card!)

// Set the drive to your own constants from autons.cpp!
default_constants();

// These are already defaulted to these buttons, but you can change the left/right curve buttons here!
// chassis.opcontrol_curve_buttons_left_set (pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used.
// chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A);
// chassis.opcontrol_curve_buttons_left_set(pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used.
// chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A);

// Autonomous Selector using LLEMU
ez::as::auton_selector.autons_add({
Expand Down Expand Up @@ -114,7 +114,9 @@ void autonomous() {
*/
void opcontrol() {
// This is preference to what you like to drive on
chassis.drive_brake_set(MOTOR_BRAKE_COAST);
pros::motor_brake_mode_e_t driver_preference_brake = MOTOR_BRAKE_COAST;

chassis.drive_brake_set(driver_preference_brake);

while (true) {
// PID Tuner
Expand All @@ -128,22 +130,24 @@ void opcontrol() {
chassis.pid_tuner_toggle();

// Trigger the selected autonomous routine
if (master.get_digital_new_press(DIGITAL_B) && master.get_digital(DIGITAL_DOWN))
if (master.get_digital(DIGITAL_B) && master.get_digital(DIGITAL_DOWN)) {
autonomous();
chassis.drive_brake_set(driver_preference_brake);
}

chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate
}

chassis.opcontrol_tank(); // Tank control
// chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade
// chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade
// chassis.opcontrol_tank(); // Tank control
chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade
// chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade

// . . .
// Put more user control code here!
// . . .

pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME
}
}
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.1.0-RC3

0 comments on commit 64dd7c1

Please sign in to comment.