work oiwjwojreow
This commit is contained in:
parent
1f3e2bb685
commit
bed0eb2b0d
@ -7,6 +7,13 @@ bool ptoEnabled = false;
|
|||||||
bool wingsOpen = false;
|
bool wingsOpen = false;
|
||||||
bool intakeEngaged = false;
|
bool intakeEngaged = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
SCALE SPEEDS: Determines what percentage speeds of autonomous movements should move at
|
||||||
|
speedScale -> The scale of how fast the drivetrain goes forward and backwards
|
||||||
|
turnScale -> The scale of how fast the drivetrain turns
|
||||||
|
swingScale -> The scale of fast one side of the chassis moves
|
||||||
|
*/
|
||||||
|
|
||||||
double speedScale = 1.0;
|
double speedScale = 1.0;
|
||||||
double turnScale = 1.0;
|
double turnScale = 1.0;
|
||||||
double swingScale = 1.0;
|
double swingScale = 1.0;
|
||||||
@ -36,12 +43,14 @@ namespace superstruct {
|
|||||||
disableActiveBrake();
|
disableActiveBrake();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust exit conditions to allow for quick movements
|
||||||
void configureExitConditions() {
|
void configureExitConditions() {
|
||||||
chassis.set_exit_condition(chassis.turn_exit, 100, 3, 500, 7, 500, 500);
|
chassis.set_exit_condition(chassis.turn_exit, 100, 3, 500, 7, 500, 500);
|
||||||
chassis.set_exit_condition(chassis.swing_exit, 100, 3, 500, 7, 500, 500);
|
chassis.set_exit_condition(chassis.swing_exit, 100, 3, 500, 7, 500, 500);
|
||||||
chassis.set_exit_condition(chassis.drive_exit, 80, 50, 300, 150, 500, 500);
|
chassis.set_exit_condition(chassis.drive_exit, 80, 50, 300, 150, 500, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust PID constants for accurate movements
|
||||||
void configureConstants() {
|
void configureConstants() {
|
||||||
chassis.set_slew_min_power(80, 80);
|
chassis.set_slew_min_power(80, 80);
|
||||||
chassis.set_slew_distance(7, 7);
|
chassis.set_slew_distance(7, 7);
|
||||||
@ -52,6 +61,7 @@ namespace superstruct {
|
|||||||
chassis.set_pid_constants(&chassis.swingPID, 6, 0, 40, 0);
|
chassis.set_pid_constants(&chassis.swingPID, 6, 0, 40, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare the bot for the autonomous period of a match
|
||||||
void autonomousResets() {
|
void autonomousResets() {
|
||||||
chassis.reset_pid_targets();
|
chassis.reset_pid_targets();
|
||||||
chassis.reset_gyro();
|
chassis.reset_gyro();
|
||||||
@ -74,50 +84,61 @@ namespace superstruct {
|
|||||||
chassis.set_drive_brake(MOTOR_BRAKE_BRAKE);
|
chassis.set_drive_brake(MOTOR_BRAKE_BRAKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The chassis will not apply a constant voltage to prevent it from being moved
|
||||||
void disableActiveBrake() {
|
void disableActiveBrake() {
|
||||||
chassis.set_active_brake(0.0);
|
chassis.set_active_brake(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// motion and stuff
|
// Drives forward, runs next commands WITHOUT waiting for the drive to complete
|
||||||
void driveAsync(double dist, bool useHeadingCorrection) {
|
void driveAsync(double dist, bool useHeadingCorrection) {
|
||||||
//chassis.set_mode(ary::DRIVE);
|
//chassis.set_mode(ary::DRIVE);
|
||||||
chassis.set_drive(dist, DRIVE_SPEED * speedScale, (dist > 14.0) ? true : false, useHeadingCorrection);
|
chassis.set_drive(dist, DRIVE_SPEED * speedScale, (dist > 14.0) ? true : false, useHeadingCorrection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drives forward, runs next commands AFTER waiting for the drive to complete
|
||||||
void driveSync(double dist, bool useHeadingCorrection) {
|
void driveSync(double dist, bool useHeadingCorrection) {
|
||||||
//chassis.set_mode(ary::DRIVE);
|
//chassis.set_mode(ary::DRIVE);
|
||||||
chassis.set_drive(dist, DRIVE_SPEED * speedScale, (dist > 14.0) ? true : false, useHeadingCorrection);
|
chassis.set_drive(dist, DRIVE_SPEED * speedScale, (dist > 14.0) ? true : false, useHeadingCorrection);
|
||||||
chassis.wait_drive();
|
chassis.wait_drive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drives forward, runs next commands AFTER reaching a certain measurement/error along the path
|
||||||
void driveWithMD(double dist, bool useHeadingCorrection, double waitUntilDist) {
|
void driveWithMD(double dist, bool useHeadingCorrection, double waitUntilDist) {
|
||||||
//chassis.set_mode(ary::DRIVE);
|
//chassis.set_mode(ary::DRIVE);
|
||||||
chassis.set_drive(dist, DRIVE_SPEED * speedScale, (dist > 14.0) ? true : false, useHeadingCorrection);
|
chassis.set_drive(dist, DRIVE_SPEED * speedScale, (dist > 14.0) ? true : false, useHeadingCorrection);
|
||||||
chassis.wait_until(waitUntilDist);
|
chassis.wait_until(waitUntilDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turns the chassis, runs other commands after it has run.
|
||||||
void turnSync(double theta) {
|
void turnSync(double theta) {
|
||||||
//chassis.set_mode(ary::TURN);
|
//chassis.set_mode(ary::TURN);
|
||||||
chassis.set_turn(theta, TURN_SPEED * turnScale);
|
chassis.set_turn(theta, TURN_SPEED * turnScale);
|
||||||
chassis.wait_drive();
|
chassis.wait_drive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turns the chassis, runs other commands immediately after call
|
||||||
void turnAsync(double theta) {
|
void turnAsync(double theta) {
|
||||||
//chassis.set_mode(ary::TURN);
|
//chassis.set_mode(ary::TURN);
|
||||||
chassis.set_turn(theta, TURN_SPEED * turnScale);
|
chassis.set_turn(theta, TURN_SPEED * turnScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moves only the right side of the chassis so it can make a left turn
|
||||||
void leftSwing(double theta) {
|
void leftSwing(double theta) {
|
||||||
//chassis.set_mode(SWING);
|
//chassis.set_mode(SWING);
|
||||||
chassis.set_swing(LEFT_SWING, theta, SWING_SPEED * swingScale);
|
chassis.set_swing(LEFT_SWING, theta, SWING_SPEED * swingScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moves only the left side of the chassis so it can make a right turn
|
||||||
void rightSwing(double theta) {
|
void rightSwing(double theta) {
|
||||||
//chassis.set_mode(SWING);
|
//chassis.set_mode(SWING);
|
||||||
chassis.set_swing(RIGHT_SWING, theta, SWING_SPEED * swingScale);
|
chassis.set_swing(RIGHT_SWING, theta, SWING_SPEED * swingScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Each of the scale values must be clamed between 0.1 - 1 (10% to 100%) to avoid saturation of motors.
|
||||||
|
*/
|
||||||
|
|
||||||
void setDriveScale(double val) {
|
void setDriveScale(double val) {
|
||||||
speedScale = std::clamp(val, 0.1, 1.0);
|
speedScale = std::clamp(val, 0.1, 1.0);
|
||||||
}
|
}
|
||||||
@ -145,7 +166,7 @@ namespace superstruct {
|
|||||||
|
|
||||||
void togglePto(bool toggle) {
|
void togglePto(bool toggle) {
|
||||||
ptoEnabled = toggle;
|
ptoEnabled = toggle;
|
||||||
chassis.pto_toggle({cata_left, cata_right}, toggle);
|
chassis.pto_toggle({cata_left, cata_right}, toggle); // Configure the listed PTO motors to whatever value toggle is.
|
||||||
pto_piston.set_value(toggle);
|
pto_piston.set_value(toggle);
|
||||||
|
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
@ -162,8 +183,8 @@ namespace superstruct {
|
|||||||
|
|
||||||
int lock = 0;
|
int lock = 0;
|
||||||
void cataControl(pros::controller_digital_e_t ptoToggleButton, pros::controller_digital_e_t cataRunButton) {
|
void cataControl(pros::controller_digital_e_t ptoToggleButton, pros::controller_digital_e_t cataRunButton) {
|
||||||
if (globals::master.get_digital(ptoToggleButton) && lock == 0) {
|
if (globals::master.get_digital(ptoToggleButton) && lock == 0) { // If the PTO button has been pressed and the PTO is not engaged
|
||||||
togglePto(!ptoEnabled);
|
togglePto(!ptoEnabled); // Toggle the PTO so that cataput is useable
|
||||||
lock = 1;
|
lock = 1;
|
||||||
} else if(!globals::master.get_digital(ptoToggleButton)) {
|
} else if(!globals::master.get_digital(ptoToggleButton)) {
|
||||||
lock = 0;
|
lock = 0;
|
||||||
@ -176,29 +197,19 @@ namespace superstruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wingsControl() {
|
|
||||||
if (globals::master.get_digital_new_press(DIGITAL_L2)) {
|
|
||||||
wings.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globals::master.get_digital_new_press(DIGITAL_L1)) {
|
|
||||||
wings.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wingsControlComplex(pros::controller_analog_e_t leftWingButton, pros::controller_analog_e_t rightWingButton, pros::controller_analog_e_t wingButton)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void wingsControlSingle(pros::controller_digital_e_t wingControlButton) {
|
void wingsControlSingle(pros::controller_digital_e_t wingControlButton) {
|
||||||
if (globals::master.get_digital_new_press(wingControlButton)) {
|
if (globals::master.get_digital_new_press(wingControlButton)) {
|
||||||
if (wings.getState() == 0)
|
if (wings.getState() == 0) // A value of 0 indicates that both wings are closed
|
||||||
wings.open();
|
wings.open();
|
||||||
else if (wings.getState() == 3)
|
else if (wings.getState() == 3) // A value of 3 indicates that both wings are open
|
||||||
wings.close();
|
wings.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Handle respective controls
|
||||||
|
*/
|
||||||
|
|
||||||
void renu_control() {
|
void renu_control() {
|
||||||
cataControl(RENU_PTO_TOGGLE, RENU_CATA_CONTROL);
|
cataControl(RENU_PTO_TOGGLE, RENU_CATA_CONTROL);
|
||||||
wingsControl();
|
wingsControl();
|
||||||
|
|||||||
@ -1,12 +1,21 @@
|
|||||||
|
/*
|
||||||
|
Wings.cpp
|
||||||
|
Controls all of the logic for the wings in autonomous and driver control
|
||||||
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "Wings.h"
|
#include "Wings.h"
|
||||||
|
|
||||||
using namespace globals;
|
using namespace globals;
|
||||||
|
|
||||||
Wings::Wings() {
|
Wings::Wings() {
|
||||||
|
/*
|
||||||
|
The state of each wing needs to be manually tracked due to privitization errors.
|
||||||
|
We cannot read the values of the pistons directly, in order to work around this we need to track the state manually.
|
||||||
|
*/
|
||||||
left_wing_state = 0;
|
left_wing_state = 0;
|
||||||
right_wing_state = 0;
|
right_wing_state = 0;
|
||||||
close();
|
close(); // Force close the wings for safety
|
||||||
};
|
};
|
||||||
|
|
||||||
void Wings::open() {
|
void Wings::open() {
|
||||||
@ -33,6 +42,11 @@ void Wings::toggleRight(int value) {
|
|||||||
right_wing_state = value;
|
right_wing_state = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Opens the wings for a certain amount of time
|
||||||
|
openFor(double duration) -> duration in seconds, converted to milliseconds
|
||||||
|
*/
|
||||||
|
|
||||||
void Wings::openFor(double duration) {
|
void Wings::openFor(double duration) {
|
||||||
open();
|
open();
|
||||||
pros::delay(duration * 1000);
|
pros::delay(duration * 1000);
|
||||||
@ -59,7 +73,4 @@ int Wings::getState() {
|
|||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user