mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[examples] Add an ExpansionHubSample example (#8810)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -11,6 +11,7 @@ EXAMPLE_FOLDERS = [
|
||||
"elevatorsimulation",
|
||||
"elevatortrapezoidprofile",
|
||||
"encoder",
|
||||
"expansionhubsample",
|
||||
"gettingstarted",
|
||||
"gyro",
|
||||
"hatchbotcmdv3",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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() {}
|
||||
}
|
||||
Reference in New Issue
Block a user