2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2017-09-28 23:30:00 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/drive/RobotDriveBase.h"
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
2019-11-08 22:53:20 -08:00
|
|
|
#include <hal/FRCUsageReporting.h>
|
2017-09-28 23:30:00 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Base.h"
|
|
|
|
|
#include "frc/SpeedController.h"
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
using namespace frc;
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
RobotDriveBase::RobotDriveBase() {
|
|
|
|
|
SetSafetyEnabled(true);
|
|
|
|
|
}
|
2017-09-28 23:30:00 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void RobotDriveBase::SetDeadband(double deadband) {
|
|
|
|
|
m_deadband = deadband;
|
|
|
|
|
}
|
2017-09-28 23:30:00 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void RobotDriveBase::SetMaxOutput(double maxOutput) {
|
|
|
|
|
m_maxOutput = maxOutput;
|
|
|
|
|
}
|
2017-09-28 23:30:00 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void RobotDriveBase::FeedWatchdog() {
|
|
|
|
|
Feed();
|
|
|
|
|
}
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
double RobotDriveBase::ApplyDeadband(double value, double deadband) {
|
|
|
|
|
if (std::abs(value) > deadband) {
|
|
|
|
|
if (value > 0.0) {
|
|
|
|
|
return (value - deadband) / (1.0 - deadband);
|
|
|
|
|
} else {
|
|
|
|
|
return (value + deadband) / (1.0 - deadband);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
void RobotDriveBase::Normalize(wpi::MutableArrayRef<double> wheelSpeeds) {
|
2017-09-28 23:30:00 -07:00
|
|
|
double maxMagnitude = std::abs(wheelSpeeds[0]);
|
|
|
|
|
for (size_t i = 1; i < wheelSpeeds.size(); i++) {
|
|
|
|
|
double temp = std::abs(wheelSpeeds[i]);
|
|
|
|
|
if (maxMagnitude < temp) {
|
|
|
|
|
maxMagnitude = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (maxMagnitude > 1.0) {
|
|
|
|
|
for (size_t i = 0; i < wheelSpeeds.size(); i++) {
|
|
|
|
|
wheelSpeeds[i] = wheelSpeeds[i] / maxMagnitude;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|