mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] Make Romi/XRP Examples use appropriate vendordeps (#5665)
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "sensors/RomiGyro.h"
|
||||
|
||||
RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") {
|
||||
if (m_simDevice) {
|
||||
m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
|
||||
m_simRateX =
|
||||
m_simDevice.CreateDouble("rate_x", hal::SimDevice::kInput, 0.0);
|
||||
m_simRateY =
|
||||
m_simDevice.CreateDouble("rate_y", hal::SimDevice::kInput, 0.0);
|
||||
m_simRateZ =
|
||||
m_simDevice.CreateDouble("rate_z", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleX =
|
||||
m_simDevice.CreateDouble("angle_x", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleY =
|
||||
m_simDevice.CreateDouble("angle_y", hal::SimDevice::kInput, 0.0);
|
||||
m_simAngleZ =
|
||||
m_simDevice.CreateDouble("angle_z", hal::SimDevice::kInput, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
double RomiGyro::GetRateX() {
|
||||
if (m_simRateX) {
|
||||
return m_simRateX.Get();
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double RomiGyro::GetRateY() {
|
||||
if (m_simRateY) {
|
||||
return m_simRateY.Get();
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double RomiGyro::GetRateZ() {
|
||||
if (m_simRateZ) {
|
||||
return m_simRateZ.Get();
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double RomiGyro::GetAngleX() {
|
||||
if (m_simAngleX) {
|
||||
return m_simAngleX.Get() - m_angleXOffset;
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double RomiGyro::GetAngleY() {
|
||||
if (m_simAngleY) {
|
||||
return m_simAngleY.Get() - m_angleYOffset;
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double RomiGyro::GetAngleZ() {
|
||||
if (m_simAngleZ) {
|
||||
return m_simAngleZ.Get() - m_angleZOffset;
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void RomiGyro::Reset() {
|
||||
if (m_simAngleX) {
|
||||
m_angleXOffset = m_simAngleX.Get();
|
||||
m_angleYOffset = m_simAngleY.Get();
|
||||
m_angleZOffset = m_simAngleZ.Get();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "subsystems/OnBoardIO.h"
|
||||
|
||||
#include <frc/DigitalInput.h>
|
||||
#include <frc/DigitalOutput.h>
|
||||
#include <frc/Errors.h>
|
||||
#include <frc/Timer.h>
|
||||
|
||||
OnBoardIO::OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2) {
|
||||
if (dio1 == ChannelMode::INPUT) {
|
||||
m_buttonB = std::make_unique<frc::DigitalInput>(1);
|
||||
} else {
|
||||
m_greenLed = std::make_unique<frc::DigitalOutput>(1);
|
||||
}
|
||||
if (dio2 == ChannelMode::INPUT) {
|
||||
m_buttonC = std::make_unique<frc::DigitalInput>(2);
|
||||
} else {
|
||||
m_redLed = std::make_unique<frc::DigitalOutput>(2);
|
||||
}
|
||||
}
|
||||
|
||||
bool OnBoardIO::GetButtonAPressed() {
|
||||
return m_buttonA.Get();
|
||||
}
|
||||
|
||||
bool OnBoardIO::GetButtonBPressed() {
|
||||
if (m_buttonB) {
|
||||
return m_buttonB->Get();
|
||||
}
|
||||
|
||||
auto currentTime = frc::Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
FRC_ReportError(frc::err::Error, "Button {} was not configured", "B");
|
||||
m_nextMessageTime = currentTime + kMessageInterval;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OnBoardIO::GetButtonCPressed() {
|
||||
if (m_buttonC) {
|
||||
return m_buttonC->Get();
|
||||
}
|
||||
|
||||
auto currentTime = frc::Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
FRC_ReportError(frc::err::Error, "Button {} was not configured", "C");
|
||||
m_nextMessageTime = currentTime + kMessageInterval;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnBoardIO::SetGreenLed(bool value) {
|
||||
if (m_greenLed) {
|
||||
m_greenLed->Set(value);
|
||||
} else {
|
||||
auto currentTime = frc::Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
FRC_ReportError(frc::err::Error, "{} LED was not configured", "Green");
|
||||
m_nextMessageTime = currentTime + kMessageInterval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnBoardIO::SetRedLed(bool value) {
|
||||
if (m_redLed) {
|
||||
m_redLed->Set(value);
|
||||
} else {
|
||||
auto currentTime = frc::Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
FRC_ReportError(frc::err::Error, "{} LED was not configured", "Red");
|
||||
m_nextMessageTime = currentTime + kMessageInterval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnBoardIO::SetYellowLed(bool value) {
|
||||
m_yellowLed.Set(value);
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/romi/OnBoardIO.h>
|
||||
#include <frc/smartdashboard/SendableChooser.h>
|
||||
#include <frc2/command/Command.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
@@ -14,7 +15,6 @@
|
||||
#include "commands/AutonomousDistance.h"
|
||||
#include "commands/AutonomousTime.h"
|
||||
#include "subsystems/Drivetrain.h"
|
||||
#include "subsystems/OnBoardIO.h"
|
||||
|
||||
/**
|
||||
* This class is where the bulk of the robot should be declared. Since
|
||||
@@ -47,8 +47,8 @@ class RobotContainer {
|
||||
|
||||
// The robot's subsystems
|
||||
Drivetrain m_drive;
|
||||
OnBoardIO m_onboardIO{OnBoardIO::ChannelMode::INPUT,
|
||||
OnBoardIO::ChannelMode::INPUT};
|
||||
frc::OnBoardIO m_onboardIO{frc::OnBoardIO::ChannelMode::INPUT,
|
||||
frc::OnBoardIO::ChannelMode::INPUT};
|
||||
|
||||
// Example button
|
||||
frc2::Trigger m_onboardButtonA{
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
|
||||
class RomiGyro {
|
||||
public:
|
||||
RomiGyro();
|
||||
|
||||
/**
|
||||
* Gets the rate of turn in degrees-per-second around the X-axis
|
||||
*/
|
||||
double GetRateX();
|
||||
|
||||
/**
|
||||
* Gets the rate of turn in degrees-per-second around the Y-axis
|
||||
*/
|
||||
double GetRateY();
|
||||
|
||||
/**
|
||||
* Gets the rate of turn in degrees-per-second around the Z-axis
|
||||
*/
|
||||
double GetRateZ();
|
||||
|
||||
/**
|
||||
* Gets the currently reported angle around the X-axis
|
||||
*/
|
||||
double GetAngleX();
|
||||
|
||||
/**
|
||||
* Gets the currently reported angle around the X-axis
|
||||
*/
|
||||
double GetAngleY();
|
||||
|
||||
/**
|
||||
* Gets the currently reported angle around the X-axis
|
||||
*/
|
||||
double GetAngleZ();
|
||||
|
||||
/**
|
||||
* Resets the gyro
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
hal::SimDevice m_simDevice;
|
||||
hal::SimDouble m_simRateX;
|
||||
hal::SimDouble m_simRateY;
|
||||
hal::SimDouble m_simRateZ;
|
||||
hal::SimDouble m_simAngleX;
|
||||
hal::SimDouble m_simAngleY;
|
||||
hal::SimDouble m_simAngleZ;
|
||||
|
||||
double m_angleXOffset = 0;
|
||||
double m_angleYOffset = 0;
|
||||
double m_angleZOffset = 0;
|
||||
};
|
||||
@@ -8,11 +8,10 @@
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/drive/DifferentialDrive.h>
|
||||
#include <frc/motorcontrol/Spark.h>
|
||||
#include <frc/romi/RomiGyro.h>
|
||||
#include <frc2/command/SubsystemBase.h>
|
||||
#include <units/length.h>
|
||||
|
||||
#include "sensors/RomiGyro.h"
|
||||
|
||||
class Drivetrain : public frc2::SubsystemBase {
|
||||
public:
|
||||
static constexpr double kCountsPerRevolution = 1440.0;
|
||||
@@ -117,6 +116,6 @@ class Drivetrain : public frc2::SubsystemBase {
|
||||
|
||||
frc::DifferentialDrive m_drive{m_leftMotor, m_rightMotor};
|
||||
|
||||
RomiGyro m_gyro;
|
||||
frc::RomiGyro m_gyro;
|
||||
frc::BuiltInAccelerometer m_accelerometer;
|
||||
};
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <frc/DigitalInput.h>
|
||||
#include <frc/DigitalOutput.h>
|
||||
#include <frc2/command/SubsystemBase.h>
|
||||
|
||||
/**
|
||||
* This class represents the onboard IO of the Romi
|
||||
* reference robot. This includes the pushbuttons and
|
||||
* LEDs.
|
||||
*
|
||||
* <p>DIO 0 - Button A (input only)
|
||||
* DIO 1 - Button B (input) or Green LED (output)
|
||||
* DIO 2 - Button C (input) or Red LED (output)
|
||||
* DIO 3 - Yellow LED (output only)
|
||||
*/
|
||||
class OnBoardIO : public frc2::SubsystemBase {
|
||||
public:
|
||||
enum ChannelMode { INPUT, OUTPUT };
|
||||
OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2);
|
||||
|
||||
static constexpr auto kMessageInterval = 1_s;
|
||||
units::second_t m_nextMessageTime = 0_s;
|
||||
|
||||
/**
|
||||
* Gets if the A button is pressed.
|
||||
*/
|
||||
bool GetButtonAPressed();
|
||||
|
||||
/**
|
||||
* Gets if the B button is pressed.
|
||||
*/
|
||||
bool GetButtonBPressed();
|
||||
|
||||
/**
|
||||
* Gets if the C button is pressed.
|
||||
*/
|
||||
bool GetButtonCPressed();
|
||||
|
||||
/**
|
||||
* Sets the green LED.
|
||||
*/
|
||||
void SetGreenLed(bool value);
|
||||
|
||||
/**
|
||||
* Sets the red LED.
|
||||
*/
|
||||
void SetRedLed(bool value);
|
||||
|
||||
/**
|
||||
* Sets the yellow LED.
|
||||
*/
|
||||
void SetYellowLed(bool value);
|
||||
|
||||
private:
|
||||
frc::DigitalInput m_buttonA{0};
|
||||
frc::DigitalOutput m_yellowLed{3};
|
||||
|
||||
// DIO 1
|
||||
std::unique_ptr<frc::DigitalInput> m_buttonB;
|
||||
std::unique_ptr<frc::DigitalOutput> m_greenLed;
|
||||
|
||||
// DIO 2
|
||||
std::unique_ptr<frc::DigitalInput> m_buttonC;
|
||||
std::unique_ptr<frc::DigitalOutput> m_redLed;
|
||||
};
|
||||
@@ -686,7 +686,10 @@
|
||||
],
|
||||
"foldername": "RomiReference",
|
||||
"gradlebase": "cppromi",
|
||||
"commandversion": 2
|
||||
"commandversion": 2,
|
||||
"extravendordeps": [
|
||||
"romi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StateSpaceFlywheel",
|
||||
|
||||
@@ -82,7 +82,10 @@
|
||||
],
|
||||
"foldername": "commandbased",
|
||||
"gradlebase": "cppromi",
|
||||
"commandversion": 2
|
||||
"commandversion": 2,
|
||||
"extravendordeps": [
|
||||
"romi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Romi - Timed Robot",
|
||||
@@ -93,6 +96,9 @@
|
||||
],
|
||||
"foldername": "timed",
|
||||
"gradlebase": "cppromi",
|
||||
"commandversion": 2
|
||||
"commandversion": 2,
|
||||
"extravendordeps": [
|
||||
"romi"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user