-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotcontainer.py
110 lines (85 loc) · 4.62 KB
/
robotcontainer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import math
import logging
logger = logging.getLogger("project212_robot")
import wpilib
from wpimath.geometry import Translation2d, Rotation2d, Pose2d
from pathplannerlib.path import PathPlannerPath, PathConstraints, GoalEndState
from swervepy import u, SwerveDrive, TrajectoryFollowerParameters
from swervepy.impl import CoaxialSwerveModule
from constants import PHYS, MECH, ELEC, OP, SW
import subsystems.swerveComponents as swerveComponents
import commands2
#import commands2.cmd
import commands2.button
# Constants
import constants
from constants import OP, SW
# Subsystem Imports
import subsystems.shooterSubsystem
import subsystems.intakeSubsystem
import subsystems.armSubsystem
import subsystems.hangSubsystem
import subsystems.photonVisionSubsystem
import subsystems.armSubsystem
import subsystems.hangSubsystem
import subsystems.swerveSubsystem
# Command Imports
from commands.shooterCommand import inwardsShooter, outwardsShooter, stopShooter
from commands.intakeCommand import intake, outake, stopIntake, IntakeLimitCommand
from commands.OuttakeCommand import outtakeCommand, stopBothIntakeAndShooter
from commands.intakeCommand import intake, outake, stopIntake
from commands.visionCommand import takeSnapShot, togglePipeline, doNothing
import commands.armCommand
import commands.hangCommand
#Auto Command Imports
import commands.autonomousCommands.driveForwardCommand
import commands.autonomousCommands.autoShootingCommand
import commands.autonomousCommands.autoDropArmCommand
class RobotContainer:
"""
This example robot container should serve as a demonstration for how to
implement swervepy on your robot. You should not need to edit much of the
code in this module to get a test working. Instead, edit the values and
class choices in constants.py.
"""
def __init__(self):
# The robot's subsystems
self.shooter = subsystems.shooterSubsystem.shooterSubsystem()
self.intake = subsystems.intakeSubsystem.intakeSubsystem()
self.arm = subsystems.armSubsystem.ArmSubsystem()
self.hang = subsystems.hangSubsystem.HangSubsystem()
self.Vision = subsystems.photonVisionSubsystem.visionSub()
self.drivetrain = subsystems.swerveSubsystem.swerveSubsystem()
self.swerve = self.drivetrain.getSwerve()
# The driver's controller
self.DriverController = commands2.button.CommandXboxController(OP.driver_controller)
self.OperatorController = commands2.button.CommandXboxController(OP.operator_controller)
#Autos
self.dropArmAndScore = commands2.SequentialCommandGroup(commands.autonomousCommands.autoDropArmCommand.autoDropArmCommand(self.arm),
commands.autonomousCommands.autoShootingCommand.shootingCommand(self.intake, self.shooter))
self.autoChooser = wpilib.SendableChooser()
self.autoChooser.setDefaultOption("DriveForward", commands.autonomousCommands.driveForwardCommand.getAutoCommand(self.swerve, 5.0))
self.autoChooser.addOption("ScoreOneNote", self.dropArmAndScore)
self.autoChooser.addOption("autoDropArm", commands.autonomousCommands.autoDropArmCommand.autoDropArmCommand(self.arm))
wpilib.SmartDashboard.putData(self.autoChooser)
self.configureButtonBindings()
def get_autonomous_command(self):
return self.autoChooser.getSelected()
def configureButtonBindings(self):
"""
Use this method to define your button->command mappings. Buttons can
be created via the button factories on
commands2.button.CommandGenericHID or one of its subclasses
(commands2.button.CommandJoystick or
command2.button.CommandXboxController).
"""
self.OperatorController.button(1).whileTrue(IntakeLimitCommand(self.intake))
self.OperatorController.leftBumper().whileTrue(intake(self.intake))
self.OperatorController.leftBumper().whileFalse(stopIntake(self.intake))
self.OperatorController.rightBumper().whileTrue(outwardsShooter(self.shooter))
self.OperatorController.rightBumper().whileFalse(stopShooter(self.shooter))
self.OperatorController.button(2).whileTrue(outtakeCommand(self.intake, self.shooter))
self.OperatorController.button(2).whileFalse(stopBothIntakeAndShooter(self.intake, self.shooter))
self.arm.setDefaultCommand(commands.armCommand.ArmWithJoystick(self.arm))
self.hang.setDefaultCommand(commands.hangCommand.HangCommand(self.hang))
self.swerve.setDefaultCommand(self.drivetrain.getSwerveTeleopCommand(self.swerve))