Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better lift variable names #54

Open
wants to merge 62 commits into
base: liftVariableNames
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
fdd79b6
intake and feeder motor -> falcon
AntarcticaByToto Mar 30, 2022
f2b7f2f
turret motor -> falconž
AntarcticaByToto Mar 30, 2022
1761ccf
added all falcons excpet flywheel to second can bus
AntarcticaByToto Mar 30, 2022
b0bced4
Revert "turret motor -> falconž"
mray190 Apr 1, 2022
b9c8681
enabled 10v saturation on volatge compensation on intake and feeder
AntarcticaByToto Apr 1, 2022
32999ed
Moved lift wiring to old can bus
mray190 Apr 2, 2022
059ed8b
adjust LOBF on 2x and 1x zoom. Only 1x implemented. intake and feeder…
AntarcticaByToto Apr 2, 2022
58a39a1
new LoBF constants. swaps between 2x and 1x LoBFs
AntarcticaByToto Apr 3, 2022
fa9a720
tuned autos and lift, fixed dumbassery of Rohit and Andrew
rohitalamgari Apr 5, 2022
2d10448
made 2 ball auto for blue, matched blue to be mirror of red
rohitalamgari Apr 5, 2022
c79fa64
current sensing in auto fixes
rohitalamgari Apr 5, 2022
8fe0270
working code from Tuesday Night, all 3 autos look good
andrewmcalinden Apr 6, 2022
700bce6
Make lower limit 1.46m from the limelight (#60)
mray190 Apr 7, 2022
699870f
changed start up procedure of intake on all autos
rohitalamgari Apr 6, 2022
4664543
day1
AntarcticaByToto Apr 8, 2022
a7427dd
changed to shooterPoop instead of intakeReverse on defensive autos
rohitalamgari Apr 8, 2022
6cd0cf1
final at tournement code
AntarcticaByToto Apr 10, 2022
cb04711
fixed main auto bugs, have to tune points still
rohitalamgari Apr 12, 2022
102c59a
Start working on auto-tracking
mray190 Apr 13, 2022
69786a9
opened up turret range
rohitalamgari Apr 13, 2022
46dae37
disabled wrapAround logic in auto
rohitalamgari Apr 14, 2022
5e649a8
removed wrap around in auto, started tuning 2+2
rohitalamgari Apr 16, 2022
67e2583
added trench point in auto, need to test tomorrow morning
rohitalamgari Apr 16, 2022
8535de8
fixed a copypasta issue
rohitalamgari Apr 16, 2022
f601b36
fixed lift and auto tuning
rohitalamgari Apr 16, 2022
6bf6a0c
auto tuning for 2+2
rohitalamgari Apr 16, 2022
936cc8f
tuned shooter, new LOBF looks good
rohitalamgari Apr 16, 2022
d044007
fixed 2+1 to not go over the line
rohitalamgari Apr 16, 2022
12a717f
all the changes I made during the first hour
rohitalamgari Apr 18, 2022
d99c37d
made better way of enabling & disabling turretWrapAround
rohitalamgari Apr 18, 2022
61152d8
wednesday code
AntarcticaByToto Apr 21, 2022
a9c3095
friday code
AntarcticaByToto Apr 23, 2022
f9c1765
final worlds code
AntarcticaByToto Apr 25, 2022
13b4087
Update Feeder.cpp
janhelgeson Apr 25, 2022
614ddec
feat: Added ValorGamepad class
mray190 Jun 2, 2022
d9f913d
feat: Add new ValorSensor construct
mray190 Jun 2, 2022
fcbbe91
fix: Protect against null lambdas in ValorSensor
mray190 Jun 2, 2022
4836d3d
Fix gamepad bug: Even polynomial on a negative base yields incorrect …
mray190 Aug 26, 2022
b22b2dd
Implement Super Poop
mray190 Aug 26, 2022
cda0464
re-implemented mag encoder start button functionality, made turret li…
CooperNelson16 Aug 30, 2022
49e8c2d
all of new intake code minus position setting in assignoutputs of feeder
CooperNelson16 Sep 7, 2022
8941b2a
mid testing
CooperNelson16 Sep 13, 2022
62a417a
intake rotation ready to test intake retract
CooperNelson16 Sep 14, 2022
f26bab3
ready to test with values inserted intake retraction
CooperNelson16 Sep 14, 2022
fdfcc6e
changed constants values for testing, remove turret rotate encoder li…
CooperNelson16 Sep 14, 2022
85bebfd
set x driver button to clench, behavior for intake retract and deploy…
CooperNelson16 Sep 14, 2022
85d2c57
changed shooter LOBF, changed resting forward intake point to 4 degre…
CooperNelson16 Sep 15, 2022
9ab5f29
changed forward intake retract point to 1 degree
CooperNelson16 Sep 16, 2022
9b31a3c
test quintic holonomic auto. needs testing
AntarcticaByToto Aug 30, 2022
d61c155
working 2ball holonomic. May hit pillar
AntarcticaByToto Sep 7, 2022
1d739a7
3 ball chezy
AntarcticaByToto Sep 7, 2022
4fd2f6e
Holonomic testing
AntarcticaByToto Sep 12, 2022
c494256
hard coded one motor to be not inverted
AntarcticaByToto Sep 13, 2022
4bbb7f8
removed hardcode inversion on one swerve module
CooperNelson16 Sep 16, 2022
8ebf9f5
superPoop changed to 4
AntarcticaByToto Sep 20, 2022
a835297
rough working 3 ball + 1. need blue version
AntarcticaByToto Sep 20, 2022
4b8c950
Blue version of 3ball pick 1 chezy
AntarcticaByToto Sep 20, 2022
a42c44d
added more time to 3 ball hanger kickout
AntarcticaByToto Sep 24, 2022
09b0c0e
moved3ball shoot point towards hanger
AntarcticaByToto Sep 24, 2022
5f45c13
moved 3ball shoot spot in -y
AntarcticaByToto Sep 24, 2022
b15a923
red 2 ball state fix
AntarcticaByToto Sep 27, 2022
77a8f91
changed intake rotation to lead lead set up. halfed rotation accelera…
AntarcticaByToto Sep 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Competition/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "Robot.h"



#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

Expand Down Expand Up @@ -37,7 +39,7 @@ void Robot::DisabledInit() {
m_container.m_drivetrain.robotMode = ValorSubsystem::RobotMode::DISABLED;
m_container.m_shooter.robotMode = ValorSubsystem::RobotMode::DISABLED;
m_container.m_turretTracker.robotMode = ValorSubsystem::RobotMode::DISABLED;
//m_container.m_lift.robotMode = ValorSubsystem::RobotMode::DISABLED; //just added, not tested
m_container.m_lift.robotMode = ValorSubsystem::RobotMode::DISABLED; //just added, not tested

m_container.m_shooter.resetState();
m_container.m_drivetrain.resetState();
Expand Down Expand Up @@ -72,6 +74,7 @@ void Robot::AutonomousInit() {
m_container.m_shooter.robotMode = ValorSubsystem::RobotMode::AUTO;
m_container.m_lift.robotMode = ValorSubsystem::RobotMode::AUTO;
m_container.m_turretTracker.robotMode = ValorSubsystem::RobotMode::AUTO;
m_container.m_turretTracker.disableWrapAround();

m_container.m_drivetrain.pullSwerveModuleZeroReference();
}
Expand All @@ -94,8 +97,13 @@ void Robot::TeleopInit() {
m_container.m_feeder.robotMode = ValorSubsystem::RobotMode::TELEOP;
m_container.m_drivetrain.robotMode = ValorSubsystem::RobotMode::TELEOP;
m_container.m_shooter.robotMode = ValorSubsystem::RobotMode::TELEOP;
m_container.m_shooter.state.turretState = m_container.m_shooter.TURRET_TRACK;
m_container.m_shooter.state.hoodState = m_container.m_shooter.HOOD_TRACK;
m_container.m_shooter.state.flywheelState = m_container.m_shooter.FLYWHEEL_TRACK;

m_container.m_lift.robotMode = ValorSubsystem::RobotMode::TELEOP;
m_container.m_turretTracker.robotMode = ValorSubsystem::RobotMode::TELEOP;
m_container.m_turretTracker.enableWrapAround();

}

Expand Down
2 changes: 1 addition & 1 deletion Competition/src/main/cpp/RobotContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "RobotContainer.h"

RobotContainer::RobotContainer() : m_auto(&m_drivetrain, &m_shooter, &m_feeder) {
RobotContainer::RobotContainer() : m_auto(&m_drivetrain, &m_shooter, &m_feeder, &m_turretTracker) {
ConfigureButtonBindings();
m_shooter.setDrivetrain(&m_drivetrain);
m_turretTracker.setDrivetrain(&m_drivetrain);
Expand Down
1,150 changes: 1,060 additions & 90 deletions Competition/src/main/cpp/ValorAuto.cpp

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions Competition/src/main/cpp/ValorGamepad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "ValorGamepad.h"

#include <math.h>

#define DPAD_UP 0
#define DPAD_DOWN 180
#define DPAD_RIGHT 90
#define DPAD_LEFT 270

#define DEADBAND_X 0.05f
#define DEADBAND_Y 0.1f
#define DEADBAND_TRIGGER 0.05f

ValorGamepad::ValorGamepad(int id) :
frc::XboxController(id),
deadbandX(DEADBAND_X),
deadbandY(DEADBAND_Y)
{
}

void ValorGamepad::setDeadbandX(double deadband)
{
deadbandX = deadband;
}

void ValorGamepad::setDeadbandY(double deadband)
{
deadbandY = deadband;
}

// Get the sign of an input
template <typename T> int sgn(T val) {
return (T(0) < val) - (val < T(0));
}

double ValorGamepad::deadband(double input, double deadband, int polynomial)
{
// If input is negative and polynomial is even, output would be positive which is incorrect
// Therefore if polynomial is even, multiply pow by the sign of the input
return std::fabs(input) > deadband ? ((polynomial % 2 == 0 ? sgn(input) : 1) * std::pow(input, polynomial)) : 0;
}

double ValorGamepad::leftStickX(int polynomial)
{
return -deadband(GetLeftX(), deadbandX, polynomial);
}

bool ValorGamepad::leftStickXActive(int polynomial)
{
return leftStickX(polynomial) != 0;
}

double ValorGamepad::leftStickY(int polynomial)
{
return -deadband(GetLeftY(), deadbandY, polynomial);
}

bool ValorGamepad::leftStickYActive(int polynomial)
{
return leftStickY(polynomial) != 0;
}

double ValorGamepad::rightStickX(int polynomial)
{
return -deadband(GetRightX(), deadbandX, polynomial);
}

bool ValorGamepad::rightStickXActive(int polynomial)
{
return rightStickX(polynomial) != 0;
}

double ValorGamepad::rightStickY(int polynomial)
{
return -deadband(GetRightY(), deadbandY, polynomial);
}

bool ValorGamepad::rightStickYActive(int polynomial)
{
return rightStickY(polynomial) != 0;
}

double ValorGamepad::leftTrigger()
{
return GetLeftTriggerAxis() > DEADBAND_TRIGGER ? GetLeftTriggerAxis() : 0;
}

bool ValorGamepad::leftTriggerActive()
{
return leftTrigger() != 0;
}

double ValorGamepad::rightTrigger()
{
return GetRightTriggerAxis() > DEADBAND_TRIGGER ? GetRightTriggerAxis() : 0;
}

bool ValorGamepad::rightTriggerActive()
{
return rightTrigger() != 0;
}

bool ValorGamepad::DPadUp()
{
return GetPOV() == DPAD_UP;
}
bool ValorGamepad::DPadDown()
{
return GetPOV() == DPAD_DOWN;
}
bool ValorGamepad::DPadLeft()
{
return GetPOV() == DPAD_LEFT;
}
bool ValorGamepad::DPadRight()
{
return GetPOV() == DPAD_RIGHT;
}
2 changes: 1 addition & 1 deletion Competition/src/main/cpp/ValorSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ValorSubsystem& ValorSubsystem::GetInstance() {

void ValorSubsystem::init() {
// init subsystem
std::cout << "init valor subsytem" << std::endl;
//std::cout << "init valor subsytem" << std::endl;
}

void ValorSubsystem::analyzeDashboard() {
Expand Down
42 changes: 42 additions & 0 deletions Competition/src/main/cpp/sensors/ValorCurrentSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "sensors/ValorCurrentSensor.h"

#define CACHE_SIZE 20
#define DEFAULT_SPIKE_VALUE 22

ValorCurrentSensor::ValorCurrentSensor() :
spikedSetpoint(DEFAULT_SPIKE_VALUE)
{
reset();
}

void ValorCurrentSensor::setSpikeSetpoint(double _setpoint)
{
spikedSetpoint = _setpoint;
}

bool ValorCurrentSensor::spiked() {
return currState > spikedSetpoint;
}

void ValorCurrentSensor::reset() {
cache.clear();
for (int i = 0; i < CACHE_SIZE; i++) {
cache.push_back(0);
}
prevState = 0;
currState = 0;
}

void ValorCurrentSensor::calculate() {
cache.pop_front();
cache.push_back(getSensor());

// Calculate average current over the cache size, or circular buffer window
double sum = 0;
for (int i = 0; i < CACHE_SIZE; i++) {
sum += cache.at(i);
}

currState = sum / CACHE_SIZE;
prevState = currState;
}
24 changes: 24 additions & 0 deletions Competition/src/main/cpp/sensors/ValorDebounceSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "sensors/ValorDebounceSensor.h"

ValorDebounceSensor::ValorDebounceSensor()
{
}

void ValorDebounceSensor::reset()
{
prevState = false;
currState = false;
isSpiked = false;
}

bool ValorDebounceSensor::spiked()
{
return isSpiked;
}

void ValorDebounceSensor::calculate()
{
currState = getSensor();
isSpiked = currState != prevState;
prevState = currState;
}
52 changes: 18 additions & 34 deletions Competition/src/main/cpp/subsystems/Drivetrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

Drivetrain::Drivetrain() : ValorSubsystem(),
driverController(NULL),
pigeon(DriveConstants::PIGEON_CAN),
pigeon(DriveConstants::PIGEON_CAN, "baseCAN"),
kinematics(motorLocations[0], motorLocations[1], motorLocations[2], motorLocations[3]),
odometry(kinematics, frc::Rotation2d{units::radian_t{0}}),
config(units::velocity::meters_per_second_t{SwerveConstants::AUTO_MAX_SPEED_MPS}, units::acceleration::meters_per_second_squared_t{SwerveConstants::AUTO_MAX_ACCEL_MPSS}),
Expand All @@ -29,7 +29,7 @@ Drivetrain::Drivetrain() : ValorSubsystem(),

void Drivetrain::setKF(){
azimuthMotors[0]->Config_kF(0, SwerveConstants::KF);
std::cout << "set kf" << std::endl;
//std::cout << "set kf" << std::endl;
}

Drivetrain::~Drivetrain()
Expand All @@ -45,7 +45,7 @@ Drivetrain::~Drivetrain()

void Drivetrain::configSwerveModule(int i)
{
azimuthMotors.push_back(new WPI_TalonFX(DriveConstants::AZIMUTH_CANS[i]));
azimuthMotors.push_back(new WPI_TalonFX(DriveConstants::AZIMUTH_CANS[i], "baseCAN"));
azimuthMotors[i]->ConfigFactoryDefault();
azimuthMotors[i]->SetInverted(false);
azimuthMotors[i]->ConfigSelectedFeedbackSensor(FeedbackDevice::IntegratedSensor, 0, 10);
Expand All @@ -60,9 +60,10 @@ void Drivetrain::configSwerveModule(int i)
azimuthMotors[i]->SetNeutralMode(NeutralMode::Brake);
//azimuthMotors[i]->ConfigSupplyCurrentLimit(SupplyCurrentLimitConfiguration(true, 60, 80, .75));

driveMotors.push_back(new WPI_TalonFX(DriveConstants::DRIVE_CANS[i]));
driveMotors.push_back(new WPI_TalonFX(DriveConstants::DRIVE_CANS[i], "baseCAN"));
driveMotors[i]->ConfigFactoryDefault();
driveMotors[i]->SetInverted(false);

driveMotors[i]->ConfigSelectedFeedbackSensor(FeedbackDevice::IntegratedSensor, 0, 10);
driveMotors[i]->SetNeutralMode(NeutralMode::Coast);
driveMotors[i]->ConfigSupplyCurrentLimit(SupplyCurrentLimitConfiguration(true, 60, 80, .75));
Expand Down Expand Up @@ -97,11 +98,11 @@ void Drivetrain::init()
// }

resetState();
//pullSwerveModuleZeroReference();
std::cout <<"init drivetrain" << std::endl;
// pullSwerveModuleZeroReference();
// std::cout <<"init drivetrain" << std::endl;
}

void Drivetrain::setController(frc::XboxController *controller)
void Drivetrain::setController(ValorGamepad *controller)
{
driverController = controller;
}
Expand Down Expand Up @@ -133,22 +134,9 @@ void Drivetrain::assessInputs()
return;
}

// driver inputs
state.leftStickX = driverController->GetLeftX();
state.leftStickY = driverController->GetLeftY();
state.rightStickX = driverController->GetRightX();
state.rightStickY = driverController->GetRightY();

state.bButtonPressed = driverController->GetBButton();
state.aButtonPressed = driverController->GetAButton();
state.xButtonPressed = driverController->GetXButton();
state.yButtonPressed = driverController->GetYButton();

state.startButtonPressed = driverController->GetStartButtonPressed();

state.stickPressed = std::abs(state.leftStickY) > 0.05 ||
std::abs(state.leftStickX) > 0.05 ||
std::abs(state.rightStickX) > 0.05;
state.stickPressed = driverController->leftStickYActive() ||
driverController->leftStickXActive() ||
driverController->rightStickXActive();

//state.dPadDownPressed = driverController->GetPOV(frc::GenericHID::)

Expand All @@ -157,9 +145,6 @@ void Drivetrain::assessInputs()

void Drivetrain::analyzeDashboard()
{
state.backButtonPressed = driverController->GetBackButtonPressed();


table->PutNumber("Robot X", getPose_m().X().to<double>());
table->PutNumber("Robot Y", getPose_m().Y().to<double>());
table->PutNumber("Robot Theta", getPose_m().Rotation().Degrees().to<double>());
Expand Down Expand Up @@ -206,7 +191,7 @@ void Drivetrain::analyzeDashboard()
swerveModules[2]->getState(),
swerveModules[3]->getState());

if (state.backButtonPressed){
if (driverController->GetBackButtonPressed()) {
resetGyro();
}
}
Expand All @@ -226,33 +211,32 @@ void Drivetrain::assignOutputs()
{
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
double xSpeed = std::abs(state.leftStickY) > OIConstants::kDeadbandY ? fabs(state.leftStickY) * -state.leftStickY : 0 ;
double xSpeed = driverController->leftStickY(2);

// Get the y speed or sideways/strafe speed. We are inverting this because
// we want a positive value when we pull to the left. Xbox controllers
// return positive values when you pull to the right by default.
double ySpeed = std::abs(state.leftStickX) > OIConstants::kDeadbandX ? fabs(state.leftStickX) * -state.leftStickX : 0;
double ySpeed = driverController->leftStickX(2);

// Get the rate of angular rotation. We are inverting this because we want a
// positive value when we pull to the left (remember, CCW is positive in
// mathematics). Xbox controllers return positive values when you pull to
// the right by default.

double rot = std::abs(state.rightStickX) > OIConstants::kDeadbandX ? -1 * state.rightStickX * state.rightStickX * state.rightStickX : 0;
double rot = driverController->rightStickX(3);

units::meters_per_second_t xSpeedMPS = units::meters_per_second_t{xSpeed * SwerveConstants::DRIVE_MAX_SPEED_MPS};
units::meters_per_second_t ySpeedMPS = units::meters_per_second_t{ySpeed * SwerveConstants::DRIVE_MAX_SPEED_MPS};
units::radians_per_second_t rotRPS = units::radians_per_second_t{rot * SwerveConstants::ROTATION_MAX_SPEED_RPS};

if(state.aButtonPressed){
if(driverController->GetAButton()){
double magnitude = std::sqrt(std::pow(xSpeed, 2) + std::pow(ySpeed, 2));
xSpeed /= magnitude;
ySpeed /= magnitude;
xSpeedMPS = units::meters_per_second_t{xSpeed};
ySpeedMPS = units::meters_per_second_t{ySpeed};
if(rot != 0){
int sign = std::signbit(rot) == 0 ? 1 : -1;
rotRPS = units::radians_per_second_t{SwerveConstants::ROTATION_SLOW_SPEED_RPS};
rotRPS = units::radians_per_second_t{rot * SwerveConstants::ROTATION_SLOW_SPEED_RPS};
}
}
// double heading = getPose_m().Rotation().Degrees().to<double>();
Expand All @@ -271,7 +255,7 @@ void Drivetrain::assignOutputs()
rotRPS = units::radians_per_second_t{-limeTable->GetNumber("tx", 0.0) * DriveConstants::LIMELIGHT_KP * limeTable->GetNumber("tv", 0) * SwerveConstants::ROTATION_MAX_SPEED_RPS};
}

if (state.startButtonPressed){
if (driverController->GetStartButtonPressed()) {
// x0y0 = frc::Pose2d(8.514_m, 1.771_m, frc::Rotation2d(182.1_deg));

// goZeroZero = frc::TrajectoryGenerator::GenerateTrajectory(
Expand Down
Loading