Skip to content

Commit f40c7c1

Browse files
Add documentation and proper TalonSRX support.
* Properly document all additions. * Enable use of the TalonSRX CAN library from ctr-electronics. * Reformat some preprocessor stuff. * Fix motor pins for PROTOBOT (and also the competition robot because we don't know where everything will go yet). Compiles (both with PROTOBOT and without), functions (with PROTOBOT -Logan H-D
1 parent fd727d1 commit f40c7c1

File tree

7 files changed

+154
-47
lines changed

7 files changed

+154
-47
lines changed

.vscode/settings.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
".classpath": true,
1212
".project": true
1313
},
14-
"C_Cpp.default.configurationProvider": "vscode-wpilib",
15-
"C_Cpp.intelliSenseEngineFallback": "Disabled"
14+
"C_Cpp.intelliSenseEngineFallback": "Enabled",
15+
"files.associations": {
16+
"*.inc": "cpp"
17+
}
1618
}

src/main/cpp/OI.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
OI::OI() {}
1313

14+
// Return references to either the driver or operator Xbox joystick.
15+
// E.g.: passing the joysticks to the drive subsystem.
1416
frc::XboxController& OI::GetDriverJoystick() { return m_hidDriver; }
15-
1617
frc::XboxController& OI::GetOperatorJoystick() { return m_hidOperator; }

src/main/cpp/commands/TeleOpDrive.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "RobotMap.h"
1111

1212
TeleOpDrive::TeleOpDrive() {
13+
// This command needs the drivetrain subsystem to be available while running.
1314
Requires(&Robot::m_DriveTrain);
1415
}
1516

@@ -21,10 +22,6 @@ void TeleOpDrive::Execute() {
2122

2223
bool TeleOpDrive::IsFinished() { return false; }
2324

24-
void TeleOpDrive::End() {
25-
Robot::m_DriveTrain.Drive(0,0);
26-
}
27-
28-
void TeleOpDrive::Interrupted() {
29-
Robot::m_DriveTrain.Drive(0,0);
30-
}
25+
// Make sure the motors stop moving when they aren't being controlled.
26+
void TeleOpDrive::End() { Robot::m_DriveTrain.Drive(0, 0); }
27+
void TeleOpDrive::Interrupted() { Robot::m_DriveTrain.Drive(0, 0); }

src/main/cpp/subsystems/DriveTrain.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,37 @@
99

1010
#include "commands/TeleOpDrive.h"
1111

12-
DriveTrain::DriveTrain() : frc::Subsystem("DriveTrain") {}
12+
DriveTrain::DriveTrain() : frc::Subsystem("DriveTrain") {
13+
# ifndef PROTOBOT
14+
// Set up TalonSRXs.
15+
m_motorRightFront.ConfigFactoryDefault();
16+
m_motorRightBack.ConfigFactoryDefault();
17+
m_motorLeftFront.ConfigFactoryDefault();
18+
m_motorLeftBack.ConfigFactoryDefault();
19+
20+
// The documentation says to do this, so that both sides get the proper values.
21+
// See https://phoenix-documentation.readthedocs.io/en/latest/ch15_WPIDrive.html?highlight=wpi_talon
22+
m_motorRightFront.SetInverted(true);
23+
m_motorRightBack.SetInverted(true);
24+
m_motorLeftFront.SetInverted(false);
25+
m_motorLeftBack.SetInverted(false);
26+
m_robotDrive.SetRightSideInverted(false);
27+
# endif
28+
}
1329

1430
void DriveTrain::InitDefaultCommand() {
15-
// If no other command is using this subsystem, just drive like in TeleOp.
31+
// If no other command is using this subsystem, just drive like normal.
1632
SetDefaultCommand(new TeleOpDrive());
1733
}
1834

35+
// Manually change the motors' power.
1936
void DriveTrain::Drive(double left, double right) {
2037
m_robotDrive.TankDrive(left, right);
2138
}
2239

40+
// Given a controller object, use it to drive.
2341
void DriveTrain::Drive(frc::XboxController& driver) {
42+
// Get left stick axes values.
2443
double hidX = driver.GetX(frc::XboxController::kLeftHand);
2544
double hidY = driver.GetY(frc::XboxController::kLeftHand);
2645

src/main/include/RobotMap.h

+22-23
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,32 @@
1414
* floating around.
1515
**/
1616

17+
1718
// Only define this macro if you're testing on the 1721 bot.
1819
#define PROTOBOT
1920

21+
2022
// Motor controller pins
2123
#ifdef PROTOBOT
22-
# define kLeftFrontMotor 0
23-
# define kLeftBackMotor 1
24-
# define kRightFrontMotor 2
25-
# define kRightBackMotor 3
26-
27-
# define kLeftEncoderPin0 0
28-
# define kLeftEncoderPin1 1
29-
# define kRightEncoderPin0 2
30-
# define kRightEncoderPin1 3
24+
// pin numbers for PWM motor controllers
25+
# define kRightFrontMotor 0
26+
# define kRightBackMotor 1
27+
# define kLeftFrontMotor 2
28+
# define kLeftBackMotor 3
29+
30+
# define kRightEncoderPin0 0
31+
# define kRightEncoderPin1 1
32+
# define kLeftEncoderPin0 2
33+
# define kLeftEncoderPin1 3
3134
#else
32-
# define kFrontLeftMotor 0
33-
# define kBackLeftMotor 1
34-
# define kFrontRightMotor 2
35-
# define kBackRightMotor 3
36-
37-
# define kLeftEncoderPin0 0
38-
# define kLeftEncoderPin1 1
39-
# define kRightEncoderPin0 2
40-
# define kRightEncoderPin1 3
41-
#endif
35+
// CAN ID numbers for CAN Bus TalonSRXs
36+
# define kRightFrontMotor 0
37+
# define kRightBackMotor 1
38+
# define kLeftFrontMotor 2
39+
# define kLeftBackMotor 3
4240

43-
// If you are using multiple modules, make sure to define both the port
44-
// number and the module. For example you with a rangefinder:
45-
// constexpr int kRangeFinderPort = 1;
46-
// constexpr int kRangeFinderModule = 1;
41+
# define kRightEncoderPin0 0
42+
# define kRightEncoderPin1 1
43+
# define kLeftEncoderPin0 2
44+
# define kLeftEncoderPin1 3
45+
#endif

src/main/include/subsystems/DriveTrain.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@
99

1010
#include "RobotMap.h"
1111

12-
#include <frc/XboxController.h>
1312

1413
#include <frc/ADXRS450_Gyro.h>
1514
#include <frc/Encoder.h>
1615
#include <frc/SpeedControllerGroup.h>
16+
#include <frc/XboxController.h>
1717
#include <frc/commands/Subsystem.h>
1818
#include <frc/drive/DifferentialDrive.h>
1919

2020
#ifdef PROTOBOT
21-
#include <frc/Victor.h>
22-
#define MOTORTYPE frc::Victor
21+
// Our team's prototyping bot just uses regular Victor motor controllers.
22+
# include <frc/Victor.h>
23+
# define MOTORTYPE frc::Victor
2324
#else
24-
#include <ctre/Pheonix.h>
25-
#define MOTORTYPE WPI_TalonSRX
25+
// The WPI_TalonSRX type provides compatibility with WPILib's drivetrain types.
26+
# include <ctre/Phoenix.h>
27+
# define MOTORTYPE WPI_TalonSRX
2628
#endif
2729

2830
#include "RobotMap.h"
@@ -36,18 +38,18 @@ class DriveTrain : public frc::Subsystem {
3638

3739
private:
3840
// Motors
39-
MOTORTYPE m_motorLeftFront {kLeftFrontMotor};
40-
MOTORTYPE m_motorLeftBack {kLeftBackMotor};
4141
MOTORTYPE m_motorRightFront {kRightFrontMotor};
4242
MOTORTYPE m_motorRightBack {kRightBackMotor};
43+
MOTORTYPE m_motorLeftFront {kLeftFrontMotor};
44+
MOTORTYPE m_motorLeftBack {kLeftBackMotor};
4345

44-
// Group the motors into their sides and then combine them
45-
frc::SpeedControllerGroup m_leftMotors {m_motorLeftFront, m_motorLeftBack};
46+
// Group the motors into their sides and then combine them into the drivetrain
4647
frc::SpeedControllerGroup m_rightMotors {m_motorRightFront, m_motorRightBack};
48+
frc::SpeedControllerGroup m_leftMotors {m_motorLeftFront, m_motorLeftBack};
4749
frc::DifferentialDrive m_robotDrive {m_leftMotors, m_rightMotors};
4850

49-
// Encoders (third arg reverses direction)
50-
frc::Encoder m_encoderLeft {kLeftEncoderPin0, kLeftEncoderPin1, false};
51+
// Encoders (reverse the right encoder)
5152
frc::Encoder m_encoderRight {kRightEncoderPin0, kRightEncoderPin1, true};
52-
frc::ADXRS450_Gyro m_gyro {};
53+
frc::Encoder m_encoderLeft {kLeftEncoderPin0, kLeftEncoderPin1, false};
54+
frc::ADXRS450_Gyro m_gyro {}; // onboard RoboRIO gyro
5355
};

vendordeps/Phoenix.json

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"fileName": "Phoenix.json",
3+
"name": "CTRE-Phoenix",
4+
"version": "5.12.1",
5+
"uuid": "ab676553-b602-441f-a38d-f1296eff6537",
6+
"mavenUrls": [
7+
"http://devsite.ctr-electronics.com/maven/release/"
8+
],
9+
"jsonUrl": "http://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/Phoenix-latest.json",
10+
"javaDependencies": [
11+
{
12+
"groupId": "com.ctre.phoenix",
13+
"artifactId": "api-java",
14+
"version": "5.12.1"
15+
},
16+
{
17+
"groupId": "com.ctre.phoenix",
18+
"artifactId": "wpiapi-java",
19+
"version": "5.12.1"
20+
}
21+
],
22+
"jniDependencies": [
23+
{
24+
"groupId": "com.ctre.phoenix",
25+
"artifactId": "cci",
26+
"version": "5.12.1",
27+
"isJar": false,
28+
"skipInvalidPlatforms": true,
29+
"validPlatforms": [
30+
"linuxathena",
31+
"windowsx86-64",
32+
"linuxx86-64"
33+
]
34+
}
35+
],
36+
"cppDependencies": [
37+
{
38+
"groupId": "com.ctre.phoenix",
39+
"artifactId": "wpiapi-cpp",
40+
"version": "5.12.1",
41+
"libName": "CTRE_Phoenix_WPI",
42+
"headerClassifier": "headers",
43+
"sharedLibrary": false,
44+
"skipInvalidPlatforms": true,
45+
"binaryPlatforms": [
46+
"linuxathena",
47+
"windowsx86-64",
48+
"linuxx86-64"
49+
]
50+
},
51+
{
52+
"groupId": "com.ctre.phoenix",
53+
"artifactId": "api-cpp",
54+
"version": "5.12.1",
55+
"libName": "CTRE_Phoenix",
56+
"headerClassifier": "headers",
57+
"sharedLibrary": false,
58+
"skipInvalidPlatforms": true,
59+
"binaryPlatforms": [
60+
"linuxathena",
61+
"windowsx86-64",
62+
"linuxx86-64"
63+
]
64+
},
65+
{
66+
"groupId": "com.ctre.phoenix",
67+
"artifactId": "cci",
68+
"version": "5.12.1",
69+
"libName": "CTRE_PhoenixCCI",
70+
"headerClassifier": "headers",
71+
"sharedLibrary": false,
72+
"skipInvalidPlatforms": true,
73+
"binaryPlatforms": [
74+
"linuxathena",
75+
"windowsx86-64",
76+
"linuxx86-64"
77+
]
78+
},
79+
{
80+
"groupId": "com.ctre.phoenix",
81+
"artifactId": "core",
82+
"version": "5.12.1",
83+
"libName": "CTRE_PhoenixCore",
84+
"headerClassifier": "headers"
85+
}
86+
]
87+
}

0 commit comments

Comments
 (0)