Skip to content

Commit

Permalink
Clean up C++ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhall-ctre committed Oct 31, 2024
1 parent 1db713d commit 5f5f808
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 53 deletions.
7 changes: 0 additions & 7 deletions cpp/ArcadeDrive/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ void Robot::RobotInit() {
leftFollower.GetConfigurator().Apply(leftConfiguration);
rightLeader.GetConfigurator().Apply(rightConfiguration);
rightFollower.GetConfigurator().Apply(rightConfiguration);

/* Currently in simulation, we do not support FOC, so disable it while simulating */
if (utils::IsSimulation())
{
leftOut.EnableFOC = false;
rightOut.EnableFOC = false;
}

/* Set up followers to follow leaders */
leftFollower.SetControl(controls::Follower{leftLeader.GetDeviceID(), false});
Expand Down
42 changes: 16 additions & 26 deletions cpp/CommandBasedDrive/src/main/cpp/subsystems/DriveSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ DriveSubsystem::DriveSubsystem()
/* Set the update frequency of the main requests to 0 so updates are sent immediately in the arcadeDrive method */
m_leftOut.UpdateFreqHz = 0_Hz;
m_rightOut.UpdateFreqHz = 0_Hz;

/* Currently in simulation, we do not support FOC, so disable it while simulating */
if (utils::IsSimulation()) {
m_leftOut.EnableFOC = false;
m_rightOut.EnableFOC = false;
}

/*
* Set the orientation of the simulated TalonFX devices relative to the robot chassis.
Expand Down Expand Up @@ -170,44 +164,40 @@ void DriveSubsystem::SimulationPeriodic()

units::meter_t DriveSubsystem::rotationsToMeters(units::turn_t rotations)
{
/* Get circumference of wheel */
constexpr auto circumference = kWheelRadiusInches / 1_rad;
/* Every rotation of the wheel travels this many inches */
/* Every radian of rotation, the wheel travels this many inches */
constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad;
/* Now apply gear ratio to input rotations */
auto gearedRotations = rotations / kGearRatio;
/* And multiply geared rotations by meters per rotation */
return gearedRotations * circumference;
return gearedRotations * wheelDistancePerRad;
}

units::turn_t DriveSubsystem::metersToRotations(units::meter_t meters)
{
/* Get circumference of wheel */
constexpr auto circumference = kWheelRadiusInches / 1_rad;
/* Every rotation of the wheel travels this many inches */
/* Now apply wheel rotations to input meters */
auto wheelRotations = meters / circumference;
/* Every radian of rotation, the wheel travels this many inches */
constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad;
/* Now get wheel rotations from input meters */
auto wheelRadians = meters / wheelDistancePerRad;
/* And multiply by gear ratio to get rotor rotations */
return wheelRotations * kGearRatio;
return wheelRadians * kGearRatio;
}

units::meters_per_second_t DriveSubsystem::rotationsToMetersVel(units::turns_per_second_t rotations)
{
/* Get circumference of wheel */
constexpr auto circumference = kWheelRadiusInches / 1_rad;
/* Every rotation of the wheel travels this many inches */
/* Every radian of rotation, the wheel travels this many inches */
constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad;
/* Now apply gear ratio to input rotations */
auto gearedRotations = rotations / kGearRatio;
/* And multiply geared rotations by meters per rotation */
return gearedRotations * circumference;
return gearedRotations * wheelDistancePerRad;
}

units::turns_per_second_t DriveSubsystem::metersToRotationsVel(units::meters_per_second_t meters)
{
/* Get circumference of wheel */
constexpr auto circumference = kWheelRadiusInches / 1_rad;
/* Every rotation of the wheel travels this many inches */
/* Now apply wheel rotations to input meters */
auto wheelRotations = meters / circumference;
/* Every radian of rotation, the wheel travels this many inches */
constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad;
/* Now get wheel rotations from input meters */
auto wheelRadians = meters / wheelDistancePerRad;
/* And multiply by gear ratio to get rotor rotations */
return wheelRotations * kGearRatio;
return wheelRadians * kGearRatio;
}
6 changes: 3 additions & 3 deletions cpp/CurrentLimits/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ using namespace ctre::phoenix6;
void Robot::RobotInit() {
/* Configure the Talon to use a supply limit of 60 amps IF we exceed 80 amps for over 0.1 seconds */
configs::TalonFXConfiguration toConfigure{};
m_currentLimits.SupplyCurrentLimit = 80_A; // Default limit of 80 A
m_currentLimits.SupplyCurrentLowerLimit = 40_A; // This is the limit if we've exceeded 80 A for more than 1 second
m_currentLimits.SupplyCurrentLowerTime = 1_s; // Threshold before activating lower limit
m_currentLimits.SupplyCurrentLimit = 70_A; // Default limit of 70 A
m_currentLimits.SupplyCurrentLowerLimit = 40_A; // Reduce the limit to 40 A if we've limited to 70 A...
m_currentLimits.SupplyCurrentLowerTime = 1_s; // ...for at least 1 second
m_currentLimits.SupplyCurrentLimitEnable = true; // And enable it

m_currentLimits.StatorCurrentLimit = 120_A; // Limit stator to 120 amps
Expand Down
8 changes: 4 additions & 4 deletions cpp/MotionMagic/src/main/cpp/sim/SimProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ units::second_t SimProfile::GetPeriod()
{
// set the start time if not yet running
if (!_running) {
_lastTime = utils::GetCurrentTimeSeconds();
_lastTime = utils::GetCurrentTime();
_running = true;
}

double now = utils::GetCurrentTimeSeconds();
double period = now - _lastTime;
auto now = utils::GetCurrentTime();
auto period = now - _lastTime;
_lastTime = now;

return units::second_t{period};
return period;
}
2 changes: 1 addition & 1 deletion cpp/MotionMagic/src/main/include/sim/SimProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Holds information about a simulated device.
*/
class SimProfile {
double _lastTime;
units::second_t _lastTime;
bool _running = false;

public:
Expand Down
6 changes: 0 additions & 6 deletions java/ArcadeDrive/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public void robotInit() {

leftLeader.setSafetyEnabled(true);
rightLeader.setSafetyEnabled(true);

/* Currently in simulation, we do not support FOC, so disable it while simulating */
if (Utils.isSimulation()){
leftOut.EnableFOC = false;
rightOut.EnableFOC = false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ public DriveSubsystem() {
m_leftOut.UpdateFreqHz = 0;
m_rightOut.UpdateFreqHz = 0;

/* Currently in simulation, we do not support FOC, so disable it while simulating */
if (Utils.isSimulation()) {
m_leftOut.EnableFOC = false;
m_rightOut.EnableFOC = false;
}

/*
* Set the orientation of the simulated TalonFX devices relative to the robot chassis.
* WPILib expects +V to be forward. Specify orientations to match that behavior.
Expand Down

0 comments on commit 5f5f808

Please sign in to comment.