Skip to content

Commit

Permalink
Changing max speed works, new (old) default constants, new constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Jun 5, 2024
1 parent 2314e7c commit 2c55b63
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 57 deletions.
Binary file added EZ-Template-Example-Project-3.1.0-RC2.zip
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: 19 additions & 1 deletion EZ-Template-Example-Project/include/EZ-Template/drive/drive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Drive {
* \param ratio
* External gear ratio, wheel gear / motor gear.
*/
Drive(std::vector<int> left_motor_ports, std::vector<int> right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio);
Drive(std::vector<int> left_motor_ports, std::vector<int> right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio = 1.0);

/**
* Creates a Drive Controller using encoders plugged into the brain.
Expand Down Expand Up @@ -916,6 +916,24 @@ class Drive {
*/
void drive_ratio_set(double ratio);

/**
* @brief Set the cartridge/wheel rpm of the robot
*
* @param rpm
* rpm of the cartridge or wheel
*/
void drive_rpm_set(double rpm);

/**
* Returns the ratio of the drive.
*/
double drive_ratio_get();

/**
* Returns the current cartridge / wheel rpm.
*/
double drive_rpm_get();

/**
* Changes max speed during a drive motion.
*
Expand Down
13 changes: 13 additions & 0 deletions EZ-Template-Example-Project/include/EZ-Template/slew.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ class slew {
*/
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;
Expand Down
18 changes: 9 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]",
"location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\[email protected]-RC2",
"metadata": {
"origin": "local"
},
"name": "EZ-Template",
"py/object": "pros.conductor.templates.local_template.LocalTemplate",
"supported_kernels": "^4.1.0",
"system_files": [
"include\\EZ-Template\\util.hpp",
"include\\EZ-Template\\PID.hpp",
"include\\EZ-Template\\api.hpp",
"include\\EZ-Template\\auton_selector.hpp",
"include\\EZ-Template\\drive\\drive.hpp",
"include\\EZ-Template\\PID.hpp",
"include\\EZ-Template\\sdcard.hpp",
"firmware\\EZ-Template.a",
"include\\EZ-Template\\piston.hpp",
"include\\EZ-Template\\slew.hpp",
"include\\EZ-Template\\api.hpp",
"include\\EZ-Template\\drive\\drive.hpp",
"include\\EZ-Template\\auton.hpp",
"include\\EZ-Template\\sdcard.hpp"
"include\\EZ-Template\\piston.hpp",
"include\\EZ-Template\\util.hpp",
"include\\EZ-Template\\auton.hpp"
],
"target": "v5",
"user_files": [],
"version": "3.1.0"
"version": "3.1.0-RC2"
},
"kernel": {
"location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\[email protected]",
Expand Down
26 changes: 13 additions & 13 deletions EZ-Template-Example-Project/src/autons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const int SWING_SPEED = 90;
// Constants
///
void default_constants() {
chassis.pid_heading_constants_set(3, 0, 20);
chassis.pid_drive_constants_set(10, 0, 100);
chassis.pid_turn_constants_set(3, 0, 20);
chassis.pid_swing_constants_set(5, 0, 30);
chassis.pid_heading_constants_set(11, 0, 20);
chassis.pid_drive_constants_set(20, 0, 100);
chassis.pid_turn_constants_set(3, 0.05, 20, 15);
chassis.pid_swing_constants_set(6, 0, 65);

chassis.pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
chassis.pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
chassis.pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms);
chassis.pid_turn_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
chassis.pid_swing_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
chassis.pid_drive_exit_condition_set(80_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms);

chassis.pid_turn_chain_constant_set(3_deg);
chassis.pid_swing_chain_constant_set(5_deg);
Expand Down Expand Up @@ -93,9 +93,9 @@ void wait_until_change_speed() {
// pid_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 30
chassis.pid_drive_set(24_in, DRIVE_SPEED, true);
chassis.pid_drive_set(24_in, 30, true);
chassis.pid_wait_until(6_in);
chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed
chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED
chassis.pid_wait();

chassis.pid_turn_set(45_deg, TURN_SPEED);
Expand All @@ -108,9 +108,9 @@ void wait_until_change_speed() {
chassis.pid_wait();

// When the robot gets to -6 inches, the robot will travel the remaining distance at a max speed of 30
chassis.pid_drive_set(-24_in, DRIVE_SPEED, true);
chassis.pid_drive_set(-24_in, 30, true);
chassis.pid_wait_until(-6_in);
chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed
chassis.pid_speed_max_set(30); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED
chassis.pid_wait();
}

Expand All @@ -137,7 +137,7 @@ void swing_example() {
}

///
// Combining Turn + Drive
// Motion Chaining
///
void motion_chaining() {
// Motion chaining is where motions all try to blend together instead of individual movements.
Expand All @@ -153,7 +153,7 @@ void motion_chaining() {
chassis.pid_wait_quick_chain();

chassis.pid_turn_set(0_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_wait();

// Your final motion should still be a normal pid_wait
chassis.pid_drive_set(-24_in, DRIVE_SPEED, true);
Expand Down
7 changes: 1 addition & 6 deletions EZ-Template-Example-Project/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ ez::Drive chassis(

7, // IMU Port
4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!)
600, // Cartridge RPM

// External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / MOTOR GEAR
// eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 84/36 which is 2.333
// eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 36/60 which is 0.6
1.75);
343); // Wheel RPM

/**
* Runs initialization code. This occurs as soon as the program is started.
Expand Down
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
VERSION:=3.1.0-RC2
# 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
20 changes: 19 additions & 1 deletion include/EZ-Template/drive/drive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Drive {
* \param ratio
* External gear ratio, wheel gear / motor gear.
*/
Drive(std::vector<int> left_motor_ports, std::vector<int> right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio);
Drive(std::vector<int> left_motor_ports, std::vector<int> right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio = 1.0);

/**
* Creates a Drive Controller using encoders plugged into the brain.
Expand Down Expand Up @@ -916,6 +916,24 @@ class Drive {
*/
void drive_ratio_set(double ratio);

/**
* @brief Set the cartridge/wheel rpm of the robot
*
* @param rpm
* rpm of the cartridge or wheel
*/
void drive_rpm_set(double rpm);

/**
* Returns the ratio of the drive.
*/
double drive_ratio_get();

/**
* Returns the current cartridge / wheel rpm.
*/
double drive_rpm_get();

/**
* Changes max speed during a drive motion.
*
Expand Down
13 changes: 13 additions & 0 deletions include/EZ-Template/slew.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ class slew {
*/
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;
Expand Down
17 changes: 10 additions & 7 deletions src/EZ-Template/drive/drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ Drive::Drive(std::vector<int> left_motor_ports, std::vector<int> right_motor_por

void Drive::drive_defaults_set() {
// PID Constants
pid_heading_constants_set(3, 0, 20, 0);
pid_drive_constants_set(10, 0, 100, 0);
pid_turn_constants_set(3, 0, 20, 0);
pid_swing_constants_set(5, 0, 30, 0);
pid_heading_constants_set(11, 0, 20, 0);
pid_drive_constants_set(20, 0, 100, 0);
pid_turn_constants_set(3, 0.05, 20, 15);
pid_swing_constants_set(6, 0, 65);
pid_turn_min_set(30);
pid_swing_min_set(30);

// Slew constants
slew_drive_constants_set(7_in, 80);

// Exit condition constants
pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms);
pid_turn_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
pid_swing_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
pid_drive_exit_condition_set(80_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms);

pid_turn_chain_constant_set(3_deg);
pid_swing_chain_constant_set(5_deg);
Expand Down Expand Up @@ -197,6 +197,9 @@ double Drive::drive_tick_per_inch() {
}

void Drive::drive_ratio_set(double ratio) { RATIO = ratio; }
double Drive::drive_ratio_get() { return RATIO; }
void Drive::drive_rpm_set(double rpm) { CARTRIDGE = rpm; }
double Drive::drive_rpm_get() { return CARTRIDGE; }

void Drive::private_drive_set(int left, int right) {
if (pros::millis() < 1500) return;
Expand Down
4 changes: 4 additions & 0 deletions src/EZ-Template/drive/set_pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ PID::Constants Drive::pid_heading_constants_get() {
// Updates max speed
void Drive::pid_speed_max_set(int speed) {
max_speed = abs(util::clamp(speed, 127, -127));
slew_left.speed_max_set(max_speed);
slew_right.speed_max_set(max_speed);
slew_turn.speed_max_set(max_speed);
slew_swing.speed_max_set(max_speed);
}

int Drive::pid_speed_max_get() {
Expand Down
3 changes: 3 additions & 0 deletions src/EZ-Template/slew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ void slew::constants_set(double distance, int minimum_speed) {
constants.distance_to_travel = distance;
}

void slew::speed_max_set(double speed) { max_speed = speed; }
double slew::speed_max_get() { return max_speed; }

bool slew::enabled() { return is_enabled; } // Is slew currently enabled?
double slew::output() { return last_output; } // Returns output
slew::Constants slew::constants_get() { return constants; } // Get constants
Expand Down
26 changes: 13 additions & 13 deletions src/autons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const int SWING_SPEED = 90;
// Constants
///
void default_constants() {
chassis.pid_heading_constants_set(3, 0, 20);
chassis.pid_drive_constants_set(10, 0, 100);
chassis.pid_turn_constants_set(3, 0, 20);
chassis.pid_swing_constants_set(5, 0, 30);
chassis.pid_heading_constants_set(11, 0, 20);
chassis.pid_drive_constants_set(20, 0, 100);
chassis.pid_turn_constants_set(3, 0.05, 20, 15);
chassis.pid_swing_constants_set(6, 0, 65);

chassis.pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
chassis.pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
chassis.pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms);
chassis.pid_turn_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
chassis.pid_swing_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
chassis.pid_drive_exit_condition_set(80_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms);

chassis.pid_turn_chain_constant_set(3_deg);
chassis.pid_swing_chain_constant_set(5_deg);
Expand Down Expand Up @@ -93,9 +93,9 @@ void wait_until_change_speed() {
// pid_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 30
chassis.pid_drive_set(24_in, DRIVE_SPEED, true);
chassis.pid_drive_set(24_in, 30, true);
chassis.pid_wait_until(6_in);
chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed
chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED
chassis.pid_wait();

chassis.pid_turn_set(45_deg, TURN_SPEED);
Expand All @@ -108,9 +108,9 @@ void wait_until_change_speed() {
chassis.pid_wait();

// When the robot gets to -6 inches, the robot will travel the remaining distance at a max speed of 30
chassis.pid_drive_set(-24_in, DRIVE_SPEED, true);
chassis.pid_drive_set(-24_in, 30, true);
chassis.pid_wait_until(-6_in);
chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed
chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED
chassis.pid_wait();
}

Expand All @@ -137,7 +137,7 @@ void swing_example() {
}

///
// Combining Turn + Drive
// Motion Chaining
///
void motion_chaining() {
// Motion chaining is where motions all try to blend together instead of individual movements.
Expand All @@ -153,7 +153,7 @@ void motion_chaining() {
chassis.pid_wait_quick_chain();

chassis.pid_turn_set(0_deg, TURN_SPEED);
chassis.pid_wait_quick_chain();
chassis.pid_wait();

// Your final motion should still be a normal pid_wait
chassis.pid_drive_set(-24_in, DRIVE_SPEED, true);
Expand Down
7 changes: 1 addition & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ ez::Drive chassis(

21, // IMU Port
4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!)
420, // Cartridge RPM

// External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / MOTOR GEAR
// eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 84/36 which is 2.333
// eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 36/60 which is 0.6
1.0);
420); // Wheel RPM

/**
* Runs initialization code. This occurs as soon as the program is started.
Expand Down

0 comments on commit 2c55b63

Please sign in to comment.