[sim] Add joystick simulation support (#2595)

This adds joystick functions to DriverStationSim, and new GenericHIDSim,
JoystickSim, and XboxControllerSim classes.
This commit is contained in:
Peter Johnson
2020-07-15 00:33:57 -07:00
committed by GitHub
parent b06ddcdd86
commit b9feb81226
19 changed files with 1979 additions and 19 deletions

View File

@@ -0,0 +1,39 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
/* 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. */
/*----------------------------------------------------------------------------*/
#include "frc/Joystick.h" // NOLINT(build/include_order)
#include "frc/simulation/JoystickSim.h"
#include "gtest/gtest.h"
using namespace frc;
TEST(JoystickTests, GetX) {
Joystick joy{1};
sim::JoystickSim joysim{joy};
joysim.SetX(0.25);
joysim.NotifyNewData();
ASSERT_NEAR(joy.GetX(), 0.25, 0.001);
joysim.SetX(0);
joysim.NotifyNewData();
ASSERT_NEAR(joy.GetX(), 0, 0.001);
}
TEST(JoystickTests, GetY) {
Joystick joy{1};
sim::JoystickSim joysim{joy};
joysim.SetY(0.25);
joysim.NotifyNewData();
ASSERT_NEAR(joy.GetY(), 0.25, 0.001);
joysim.SetY(0);
joysim.NotifyNewData();
ASSERT_NEAR(joy.GetY(), 0, 0.001);
}