2017-09-28 23:30:00 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
2017-09-28 23:30:00 -07:00
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/ArrayRef.h>
|
|
|
|
|
#include <wpi/raw_ostream.h>
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
#include "MotorSafety.h"
|
|
|
|
|
#include "MotorSafetyHelper.h"
|
2017-12-04 23:28:33 -08:00
|
|
|
#include "SmartDashboard/SendableBase.h"
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
|
|
|
|
|
class SpeedController;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Common base class for drive platforms.
|
|
|
|
|
*/
|
2017-12-04 23:28:33 -08:00
|
|
|
class RobotDriveBase : public MotorSafety, public SendableBase {
|
2017-09-28 23:30:00 -07:00
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* The location of a motor on the robot for the purpose of driving.
|
|
|
|
|
*/
|
|
|
|
|
enum MotorType {
|
|
|
|
|
kFrontLeft = 0,
|
|
|
|
|
kFrontRight = 1,
|
|
|
|
|
kRearLeft = 2,
|
|
|
|
|
kRearRight = 3,
|
|
|
|
|
kLeft = 0,
|
|
|
|
|
kRight = 1,
|
|
|
|
|
kBack = 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RobotDriveBase();
|
2017-12-04 23:28:33 -08:00
|
|
|
~RobotDriveBase() override = default;
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
RobotDriveBase(const RobotDriveBase&) = delete;
|
|
|
|
|
RobotDriveBase& operator=(const RobotDriveBase&) = delete;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the deadband applied to the drive inputs (e.g., joystick values).
|
|
|
|
|
*
|
|
|
|
|
* The default value is 0.02. Inputs smaller than the deadband are set to 0.0
|
|
|
|
|
* while inputs larger than the deadband are scaled from 0.0 to 1.0. See
|
|
|
|
|
* ApplyDeadband().
|
|
|
|
|
*
|
|
|
|
|
* @param deadband The deadband to set.
|
|
|
|
|
*/
|
2017-09-28 23:30:00 -07:00
|
|
|
void SetDeadband(double deadband);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configure the scaling factor for using RobotDrive with motor controllers in
|
|
|
|
|
* a mode other than PercentVbus or to limit the maximum output.
|
|
|
|
|
*
|
|
|
|
|
* @param maxOutput Multiplied with the output percentage computed by the
|
|
|
|
|
* drive functions.
|
|
|
|
|
*/
|
2017-09-28 23:30:00 -07:00
|
|
|
void SetMaxOutput(double maxOutput);
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Feed the motor safety object. Resets the timer that will stop the motors if
|
|
|
|
|
* it completes.
|
|
|
|
|
*
|
|
|
|
|
* @see MotorSafetyHelper::Feed()
|
|
|
|
|
*/
|
2018-05-09 23:18:55 -04:00
|
|
|
void FeedWatchdog();
|
|
|
|
|
|
2017-09-28 23:30:00 -07:00
|
|
|
void SetExpiration(double timeout) override;
|
|
|
|
|
double GetExpiration() const override;
|
|
|
|
|
bool IsAlive() const override;
|
|
|
|
|
void StopMotor() override = 0;
|
|
|
|
|
bool IsSafetyEnabled() const override;
|
|
|
|
|
void SetSafetyEnabled(bool enabled) override;
|
2018-04-29 23:33:19 -07:00
|
|
|
void GetDescription(wpi::raw_ostream& desc) const override = 0;
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
protected:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Limit motor values to the -1.0 to +1.0 range.
|
|
|
|
|
*/
|
2017-09-28 23:30:00 -07:00
|
|
|
double Limit(double number);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns 0.0 if the given value is within the specified range around zero.
|
|
|
|
|
* The remaining range between the deadband and 1.0 is scaled from 0.0 to 1.0.
|
|
|
|
|
*
|
|
|
|
|
* @param value value to clip
|
|
|
|
|
* @param deadband range around zero
|
|
|
|
|
*/
|
2017-09-28 23:30:00 -07:00
|
|
|
double ApplyDeadband(double number, double deadband);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalize all wheel speeds if the magnitude of any wheel is greater than
|
|
|
|
|
* 1.0.
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
void Normalize(wpi::MutableArrayRef<double> wheelSpeeds);
|
2017-09-28 23:30:00 -07:00
|
|
|
|
|
|
|
|
double m_deadband = 0.02;
|
|
|
|
|
double m_maxOutput = 1.0;
|
|
|
|
|
MotorSafetyHelper m_safetyHelper{this};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace frc
|