mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Move CameraServer and WPILib headers into their own folder
The old headers were moved into folders because doing so avoids polluting the system include directories. Folder names were also normalized to lowercase.
This commit is contained in:
committed by
Peter Johnson
parent
31ced30c1e
commit
d89b7dd412
82
wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp
Normal file
82
wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "frc/drive/RobotDriveBase.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#include "frc/Base.h"
|
||||
#include "frc/SpeedController.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
RobotDriveBase::RobotDriveBase() { m_safetyHelper.SetSafetyEnabled(true); }
|
||||
|
||||
void RobotDriveBase::SetDeadband(double deadband) { m_deadband = deadband; }
|
||||
|
||||
void RobotDriveBase::SetMaxOutput(double maxOutput) { m_maxOutput = maxOutput; }
|
||||
|
||||
void RobotDriveBase::FeedWatchdog() { m_safetyHelper.Feed(); }
|
||||
|
||||
void RobotDriveBase::SetExpiration(double timeout) {
|
||||
m_safetyHelper.SetExpiration(timeout);
|
||||
}
|
||||
|
||||
double RobotDriveBase::GetExpiration() const {
|
||||
return m_safetyHelper.GetExpiration();
|
||||
}
|
||||
|
||||
bool RobotDriveBase::IsAlive() const { return m_safetyHelper.IsAlive(); }
|
||||
|
||||
bool RobotDriveBase::IsSafetyEnabled() const {
|
||||
return m_safetyHelper.IsSafetyEnabled();
|
||||
}
|
||||
|
||||
void RobotDriveBase::SetSafetyEnabled(bool enabled) {
|
||||
m_safetyHelper.SetSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
double RobotDriveBase::Limit(double value) {
|
||||
if (value > 1.0) {
|
||||
return 1.0;
|
||||
}
|
||||
if (value < -1.0) {
|
||||
return -1.0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotDriveBase::Normalize(wpi::MutableArrayRef<double> wheelSpeeds) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user