diff --git a/shared/examplecheck.gradle b/shared/examplecheck.gradle index 89106cb158..a071660b76 100644 --- a/shared/examplecheck.gradle +++ b/shared/examplecheck.gradle @@ -66,7 +66,9 @@ def tagList = [ /* --- Misc --- */ /* (try to keep this section minimal) */ - "EventLoop", "Mechanism2d", "Preferences", "Skeleton" + "EventLoop", "Mechanism2d", "Preferences", "Skeleton", + + "FTC", "ExpansionHub", "OpModes" ] task checkTemplates(type: Task) { diff --git a/wpilibjExamples/example_projects.bzl b/wpilibjExamples/example_projects.bzl index 9a50696f18..bf6d01c9f8 100644 --- a/wpilibjExamples/example_projects.bzl +++ b/wpilibjExamples/example_projects.bzl @@ -11,6 +11,7 @@ EXAMPLE_FOLDERS = [ "elevatorsimulation", "elevatortrapezoidprofile", "encoder", + "expansionhubsample", "gettingstarted", "gyro", "hatchbotcmdv3", diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/examples.json b/wpilibjExamples/src/main/java/org/wpilib/examples/examples.json index 12ddf341c5..4d7839cfde 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/examples.json +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/examples.json @@ -23,6 +23,21 @@ "robotclass": "Robot", "commandversion": 2 }, + { + "name": "Expansion Hub Sample", + "description": "Sample the functionality of the Expansion Hub motors.", + "tags": [ + "Hardware", + "ExpansionHub", + "FTC", + "OpModes", + "SmartDashboard" + ], + "foldername": "expansionhubsample", + "gradlebase": "java", + "robotclass": "Robot", + "commandversion": 2 + }, { "name": "Elevator with trapezoid profiled PID", "description": "Reach elevator position setpoints with trapezoid profiles and smart motor controller PID.", diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/DefaultAutoMode.java b/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/DefaultAutoMode.java new file mode 100644 index 0000000000..b769b570c5 --- /dev/null +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/DefaultAutoMode.java @@ -0,0 +1,37 @@ +// 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. + +package org.wpilib.examples.expansionhubsample; + +import org.wpilib.opmode.PeriodicOpMode; +import org.wpilib.system.Timer; + +public class DefaultAutoMode extends PeriodicOpMode { + private final Robot robot; + private final Timer timer = new Timer(); + + public DefaultAutoMode(Robot robot) { + this.robot = robot; + } + + @Override + public void start() { + timer.reset(); + timer.start(); + } + + @Override + public void periodic() { + if (timer.get() < 2.0) { + robot.motor0.setThrottle(0.5); + robot.motor1.setThrottle(0.5); + } else if (timer.get() < 4.0) { + robot.motor0.setThrottle(0.9); + robot.motor1.setThrottle(0.9); + } else { + robot.motor0.setThrottle(0.0); + robot.motor1.setThrottle(0.0); + } + } +} diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/DefaultTeleMode.java b/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/DefaultTeleMode.java new file mode 100644 index 0000000000..9649835aab --- /dev/null +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/DefaultTeleMode.java @@ -0,0 +1,28 @@ +// 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. + +package org.wpilib.examples.expansionhubsample; + +import org.wpilib.driverstation.DefaultUserControls; +import org.wpilib.opmode.PeriodicOpMode; + +public class DefaultTeleMode extends PeriodicOpMode { + private final Robot robot; + private final DefaultUserControls userControls; + + public DefaultTeleMode(Robot robot, DefaultUserControls userControls) { + this.robot = robot; + this.userControls = userControls; + } + + @Override + public void periodic() { + robot.motor0.setThrottle(-userControls.getGamepad(0).getLeftY()); + robot.motor1.setThrottle(-userControls.getGamepad(0).getRightY()); + robot.motor2.setThrottle(-userControls.getGamepad(0).getLeftX()); + robot.motor3.setThrottle(-userControls.getGamepad(0).getRightX()); + robot.servo0.setPosition(userControls.getGamepad(0).getLeftTriggerAxis()); + robot.servo1.setPosition(userControls.getGamepad(0).getRightTriggerAxis()); + } +} diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/Robot.java new file mode 100644 index 0000000000..90760bd81b --- /dev/null +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/expansionhubsample/Robot.java @@ -0,0 +1,29 @@ +// 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. + +package org.wpilib.examples.expansionhubsample; + +import org.wpilib.driverstation.DefaultUserControls; +import org.wpilib.driverstation.UserControlsInstance; +import org.wpilib.framework.OpModeRobot; +import org.wpilib.hardware.expansionhub.ExpansionHubMotor; +import org.wpilib.hardware.expansionhub.ExpansionHubServo; + +/** + * This is a demo program showing the use of the Expansion Hub motors and servos. The motors and + * servos are driven using the controllers in the telop opmode, and timed in the auto op mode. + */ +@UserControlsInstance(DefaultUserControls.class) +public class Robot extends OpModeRobot { + public final ExpansionHubMotor motor0 = new ExpansionHubMotor(0, 0); + public final ExpansionHubMotor motor1 = new ExpansionHubMotor(0, 1); + public final ExpansionHubMotor motor2 = new ExpansionHubMotor(0, 2); + public final ExpansionHubMotor motor3 = new ExpansionHubMotor(0, 3); + + public final ExpansionHubServo servo0 = new ExpansionHubServo(0, 0); + public final ExpansionHubServo servo1 = new ExpansionHubServo(0, 1); + + /** Called once at the beginning of the robot program. */ + public Robot() {} +}