Skip to content

Commit

Permalink
Fix C++ example compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed May 21, 2024
1 parent 043f5d3 commit 6d8611e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
25 changes: 13 additions & 12 deletions wpilibcExamples/src/main/cpp/examples/AprilTagsVision/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
* solution!
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
std::fputs("Vision only available on Linux or Windows.\n", stderr);
std::fflush(stderr);
#endif
}

#if defined(__linux__) || defined(_WIN32)

private:
Expand Down Expand Up @@ -147,18 +160,6 @@ class Robot : public frc::TimedRobot {
}
}
#endif

Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
std::fputs("Vision only available on Linux or Windows.\n", stderr);
std::fflush(stderr);
#endif
}
};

#ifndef RUNNING_FRC_TESTS
Expand Down
8 changes: 3 additions & 5 deletions wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
wpi::SendableRegistry::AddChild(&m_drive, &m_left);
wpi::SendableRegistry::AddChild(&m_drive, &m_right);
}

Robot() {
m_gyro.SetSensitivity(kVoltsPerDegreePerSecond);
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
m_right.SetInverted(true);

wpi::SendableRegistry::AddChild(&m_drive, &m_left);
wpi::SendableRegistry::AddChild(&m_drive, &m_right);
}

/**
Expand Down
15 changes: 8 additions & 7 deletions wpilibcExamples/src/main/cpp/examples/HttpCamera/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
* processing.
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
std::thread visionThread(VisionThread);
visionThread.detach();
}

private:
static void VisionThread() {
// Create an HTTP camera. The address will need to be modified to have the
Expand Down Expand Up @@ -50,13 +58,6 @@ class Robot : public frc::TimedRobot {
outputStream.PutFrame(mat);
}
}

Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
std::thread visionThread(VisionThread);
visionThread.detach();
}
};

#ifndef RUNNING_FRC_TESTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
* processing.
*/
class Robot : public frc::TimedRobot {
public:
Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
std::fputs("Vision only available on Linux or Windows.\n", stderr);
std::fflush(stderr);
#endif
}

#if defined(__linux__) || defined(_WIN32)

private:
Expand Down Expand Up @@ -55,18 +68,6 @@ class Robot : public frc::TimedRobot {
}
}
#endif

Robot() {
// We need to run our vision program in a separate thread. If not, our robot
// program will not run.
#if defined(__linux__) || defined(_WIN32)
std::thread visionThread(VisionThread);
visionThread.detach();
#else
std::fputs("Vision only available on Linux or Windows.\n", stderr);
std::fflush(stderr);
#endif
}
};

#ifndef RUNNING_FRC_TESTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ void Robot::Teleop() {}
void Robot::Test() {}

void Robot::StartCompetition() {
RobotInit();

frc::internal::DriverStationModeThread modeThread;

wpi::Event event{false, false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Robot : public frc::TimesliceRobot {
public:
Robot();

Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down

0 comments on commit 6d8611e

Please sign in to comment.