Add an example showing how to use a hid rumbler (#1394)

This commit is contained in:
Austin Shalit
2018-10-29 15:37:30 -04:00
committed by Peter Johnson
parent 761933a164
commit f774e47c80
5 changed files with 115 additions and 0 deletions

View File

@@ -98,6 +98,16 @@
"gradlebase": "java",
"mainclass": "Main"
},
{
"name": "HID Rumble",
"description": "An example program showing how to make human interface devices rumble.",
"tags": [
"Joystick"
],
"foldername": "hidrumble",
"gradlebase": "java",
"mainclass": "Main"
},
{
"name": "Motor Controller",
"description": "Demonstrate controlling a single motor with a joystick",

View File

@@ -0,0 +1,29 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.examples.hidrumble;
import edu.wpi.first.wpilibj.RobotBase;
/**
* Do NOT add any static variables to this class, or any initialization at all.
* Unless you know what you are doing, do not modify this file except to
* change the parameter class to the startRobot call.
*/
public final class Main {
private Main() {
}
/**
* Main initialization function. Do not perform any initialization here.
*
* <p>If you change your main robot class, change the parameter type.
*/
public static void main(String... args) {
RobotBase.startRobot(Robot::new);
}
}

View File

@@ -0,0 +1,33 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.examples.hidrumble;
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.XboxController;
/**
* This is a demo program showing the use of GenericHID's rumble feature.
*/
public class Robot extends TimedRobot {
private final XboxController m_hid = new XboxController(0);
@Override
public void autonomousInit() {
// Turn on rumble at the start of auto
m_hid.setRumble(RumbleType.kLeftRumble, 1.0);
m_hid.setRumble(RumbleType.kRightRumble, 1.0);
}
@Override
public void disabledInit() {
// Stop the rumble when entering disabled
m_hid.setRumble(RumbleType.kLeftRumble, 0.0);
m_hid.setRumble(RumbleType.kRightRumble, 0.0);
}
}