mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] Remove redundant MotorControl example (#4837)
The MotorControlEncoder had the exact same content, with the addition of an encoder. No point in having both examples.
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
// 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 <numbers>
|
||||
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/motorcontrol/PWMSparkMax.h>
|
||||
#include <frc/smartdashboard/SmartDashboard.h>
|
||||
|
||||
/**
|
||||
* This sample program shows how to control a motor using a joystick. In the
|
||||
@@ -13,14 +17,32 @@
|
||||
*
|
||||
* Joystick analog values range from -1 to 1 and motor controller inputs as
|
||||
* range from -1 to 1 making it easy to work together.
|
||||
*
|
||||
* In addition, the encoder value of an encoder connected to ports 0 and 1 is
|
||||
* consistently sent to the Dashboard.
|
||||
*/
|
||||
class Robot : public frc::TimedRobot {
|
||||
public:
|
||||
void TeleopPeriodic() override { m_motor.Set(m_stick.GetY()); }
|
||||
|
||||
/*
|
||||
* The RobotPeriodic function is called every control packet no matter the
|
||||
* robot mode.
|
||||
*/
|
||||
void RobotPeriodic() override {
|
||||
frc::SmartDashboard::PutNumber("Encoder", m_encoder.GetDistance());
|
||||
}
|
||||
|
||||
void RobotInit() override {
|
||||
// Use SetDistancePerPulse to set the multiplier for GetDistance
|
||||
// This is set up assuming a 6 inch wheel with a 360 CPR encoder.
|
||||
m_encoder.SetDistancePerPulse((std::numbers::pi * 6) / 360.0);
|
||||
}
|
||||
|
||||
private:
|
||||
frc::Joystick m_stick{0};
|
||||
frc::PWMSparkMax m_motor{0};
|
||||
frc::Encoder m_encoder{0, 1};
|
||||
};
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
|
||||
@@ -1,52 +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 <numbers>
|
||||
|
||||
#include <frc/Encoder.h>
|
||||
#include <frc/Joystick.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc/motorcontrol/PWMSparkMax.h>
|
||||
#include <frc/smartdashboard/SmartDashboard.h>
|
||||
|
||||
/**
|
||||
* This sample program shows how to control a motor using a joystick. In the
|
||||
* operator control part of the program, the joystick is read and the value is
|
||||
* written to the motor.
|
||||
*
|
||||
* Joystick analog values range from -1 to 1 and motor controller inputs as
|
||||
* range from -1 to 1 making it easy to work together.
|
||||
*
|
||||
* In addition, the encoder value of an encoder connected to ports 0 and 1 is
|
||||
* consistently sent to the Dashboard.
|
||||
*/
|
||||
class Robot : public frc::TimedRobot {
|
||||
public:
|
||||
void TeleopPeriodic() override { m_motor.Set(m_stick.GetY()); }
|
||||
|
||||
/*
|
||||
* The RobotPeriodic function is called every control packet no matter the
|
||||
* robot mode.
|
||||
*/
|
||||
void RobotPeriodic() override {
|
||||
frc::SmartDashboard::PutNumber("Encoder", m_encoder.GetDistance());
|
||||
}
|
||||
|
||||
void RobotInit() override {
|
||||
// Use SetDistancePerPulse to set the multiplier for GetDistance
|
||||
// This is set up assuming a 6 inch wheel with a 360 CPR encoder.
|
||||
m_encoder.SetDistancePerPulse((std::numbers::pi * 6) / 360.0);
|
||||
}
|
||||
|
||||
private:
|
||||
frc::Joystick m_stick{0};
|
||||
frc::PWMSparkMax m_motor{0};
|
||||
frc::Encoder m_encoder{0, 1};
|
||||
};
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() {
|
||||
return frc::StartRobot<Robot>();
|
||||
}
|
||||
#endif
|
||||
@@ -1,19 +1,6 @@
|
||||
[
|
||||
{
|
||||
"name": "Motor Controller",
|
||||
"description": "Demonstrate controlling a single motor with a Joystick.",
|
||||
"tags": [
|
||||
"Robot and Motor",
|
||||
"Actuators",
|
||||
"Joystick",
|
||||
"Complete List"
|
||||
],
|
||||
"foldername": "MotorControl",
|
||||
"gradlebase": "cpp",
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "Motor Control With Encoder",
|
||||
"name": "Motor Control",
|
||||
"description": "Demonstrate controlling a single motor with a Joystick and displaying the net movement of the motor using an encoder.",
|
||||
"tags": [
|
||||
"Robot and Motor",
|
||||
@@ -23,7 +10,7 @@
|
||||
"Joystick",
|
||||
"Complete List"
|
||||
],
|
||||
"foldername": "MotorControlEncoder",
|
||||
"foldername": "MotorControl",
|
||||
"gradlebase": "cpp",
|
||||
"commandversion": 2
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user