Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/robot/DSGamepadChooser/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from hal import RobotMode
import wpilib
from wpilib.opmoderobot import OpModeRobot
from wpilib.opmodes import OpModeRobot


class DoNothingTeleop(wpilib.PeriodicOpMode):
Expand Down
33 changes: 33 additions & 0 deletions examples/robot/ExpansionHubSample/opmodes/default_auto_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.

from typing import TYPE_CHECKING

import wpilib

if TYPE_CHECKING:
from robot import Robot


@wpilib.autonomous
class DefaultAutoMode(wpilib.PeriodicOpMode):
def __init__(self, robot: "Robot") -> None:
super().__init__()
self.robot = robot
self.timer = wpilib.Timer()

def start(self) -> None:
self.timer.reset()
self.timer.start()

def periodic(self) -> None:
if self.timer.get() < 2.0:
self.robot.motor0.set_throttle(0.5)
Comment thread
virtuald marked this conversation as resolved.
self.robot.motor1.set_throttle(0.5)
elif self.timer.get() < 4.0:
self.robot.motor0.set_throttle(0.9)
self.robot.motor1.set_throttle(0.9)
else:
self.robot.motor0.set_throttle(0.0)
self.robot.motor1.set_throttle(0.0)
26 changes: 26 additions & 0 deletions examples/robot/ExpansionHubSample/opmodes/default_tele_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

from typing import TYPE_CHECKING

import wpilib

if TYPE_CHECKING:
from robot import Robot


@wpilib.teleop
class DefaultTeleMode(wpilib.PeriodicOpMode):
def __init__(self, robot: "Robot") -> None:
super().__init__()
self.robot = robot
self.gamepad = wpilib.DriverStation.get_gamepad(0)

def periodic(self) -> None:
self.robot.motor0.set_throttle(-self.gamepad.get_left_y())
self.robot.motor1.set_throttle(-self.gamepad.get_right_y())
self.robot.motor2.set_throttle(-self.gamepad.get_left_x())
self.robot.motor3.set_throttle(-self.gamepad.get_right_x())
Comment thread
virtuald marked this conversation as resolved.
self.robot.servo0.set_position(self.gamepad.get_left_trigger())
self.robot.servo1.set_position(self.gamepad.get_right_trigger())
23 changes: 23 additions & 0 deletions examples/robot/ExpansionHubSample/robot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

import wpilib


class Robot(wpilib.OpModeRobot):
"""Demo robot for Expansion Hub motors and servos.

The motors and servos are driven using the controllers in the teleop OpMode
and timed in the autonomous OpMode.
"""

def __init__(self) -> None:
"""Called once at the beginning of the robot program."""
super().__init__()
self.motor0 = wpilib.ExpansionHubMotor(0, 0)
self.motor1 = wpilib.ExpansionHubMotor(0, 1)
self.motor2 = wpilib.ExpansionHubMotor(0, 2)
self.motor3 = wpilib.ExpansionHubMotor(0, 3)
self.servo0 = wpilib.ExpansionHubServo(0, 0)
self.servo1 = wpilib.ExpansionHubServo(0, 1)
1 change: 1 addition & 0 deletions examples/robot/examples.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ base = [
"ElevatorSimulation",
"ElevatorTrapezoidProfile",
"Encoder",
"ExpansionHubSample",
"GettingStarted",
"Gyro",
"DSGamepadChooser",
Expand Down
Loading
Loading