-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrobotcontainer.py
159 lines (131 loc) · 6.21 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import math
import commands2
import wpimath
import wpilib
from wpilib import SmartDashboard
from commands2 import cmd
from wpimath.controller import HolonomicDriveController
from wpimath.controller import PIDController, ProfiledPIDControllerRadians, HolonomicDriveController
from wpimath.geometry import Pose2d, Rotation2d, Translation2d
from wpimath.trajectory import TrajectoryConfig, TrajectoryGenerator
from commands.auto_align import AutoAlign
from constants import AutoConstants, DriveConstants, OIConstants
from subsystems.drivesubsystem import DriveSubsystem
from subsystems.limelight_subsystem import LimelightSystem
from commands.auto_rotate import AutoRotate
from commands.drivecommand import DriveCommand
from pathplannerlib.auto import AutoBuilder # type: ignore
from pathplannerlib.auto import NamedCommands # type: ignore
from pathplannerlib.auto import PathPlannerAuto # type: ignore
class RobotContainer:
"""
This class is where the bulk of the robot should be declared. Since Command-based is a
"declarative" paradigm, very little robot logic should actually be handled in the :class:`.Robot`
periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
subsystems, commands, and button mappings) should be declared here.
"""
def __init__(self) -> None:
# The robot's subsystems
self.robotDrive = DriveSubsystem()
self.limelight = LimelightSystem()
self.autoChooser = AutoBuilder.buildAutoChooser()
SmartDashboard.putData("Auto Chooser", self.autoChooser)
# The driver's controller
self.driverController = wpilib.XboxController(OIConstants.kDriverControllerPort)
# Configure the button bindings
self.configureButtonBindings()
# Configure default commands
self.robotDrive.setDefaultCommand(
# The left stick controls translation of the robot.
# Turning is controlled by the X axis of the right stick.
DriveCommand(
self.robotDrive,
self.limelight,
lambda:
-wpimath.applyDeadband(
self.driverController.getLeftY(), OIConstants.kDriveDeadband
),
lambda:
-wpimath.applyDeadband(
self.driverController.getLeftX(), OIConstants.kDriveDeadband
),
lambda:
-wpimath.applyDeadband(
self.driverController.getRawAxis(2), OIConstants.kDriveDeadband
),
self.driverController.getAButton
),
)
def configureButtonBindings(self) -> None:
"""
Use this method to define your button->command mappings. Buttons can be created by
instantiating a :GenericHID or one of its subclasses (Joystick or XboxController),
and then passing it to a JoystickButton.
"""
def disablePIDSubsystems(self) -> None:
"""Disables all ProfiledPIDSubsystem and PIDSubsystem instances.
This should be called on robot disable to prevent integral windup."""
def getAutonomousCommand(self) -> commands2.Command:
# """Use this to pass the autonomous command to the main {@link Robot} class.
# :returns: the command to run in autonomous
# """
# # Create config for trajectory
# config = TrajectoryConfig(
# AutoConstants.kMaxSpeedMetersPerSecond,
# AutoConstants.kMaxAccelerationMetersPerSecondSquared,
# )
# # Add kinematics to ensure max speed is actually obeyed
# config.setKinematics(DriveConstants.kDriveKinematics)
# # An example trajectory to follow. All units in meters.
# exampleTrajectory = TrajectoryGenerator.generateTrajectory(
# # Start at the origin facing the +X direction
# Pose2d(0, 0, Rotation2d(0)),
# # Pass through these two interior waypoints, making an 's' curve path
# [Translation2d(1, 1), Translation2d(2, -1)],
# # End 3 meters straight ahead of where we started, facing forward
# Pose2d(3, 0, Rotation2d(0)),
# config,
# )
# exampleTrajectoryTwo = TrajectoryGenerator.generateTrajectory(
# # Start at the origin facing the +X direction
# Pose2d(0, 0, Rotation2d(0)),
# # Pass through these two interior waypoints, making an 's' curve path
# # [Translation2d(1, 1), Translation2d(2, -1)],
# [],
# # End 3 meters straight ahead of where we started, facing forward
# Pose2d(3, 0, Rotation2d(0)),
# config,
# )
# thetaController = ProfiledPIDControllerRadians(
# AutoConstants.kPThetaController,
# 0,
# 0,
# AutoConstants.kThetaControllerConstraints,
# )
# thetaController.enableContinuousInput(-math.pi, math.pi)
# controller = HolonomicDriveController(
# PIDController(AutoConstants.kPXController, 0, 0),
# PIDController(AutoConstants.kPYController, 0, 0),
# thetaController,
# )
# swerveControllerCommand = commands2.SwerveControllerCommand(
# exampleTrajectory,
# self.robotDrive.getPose,
# DriveConstants.kDriveKinematics,
# controller,
# self.robotDrive.setModuleStates,
# (self.robotDrive,),
# )
# # Reset odometry to the starting pose of the trajectory.
# self.robotDrive.resetOdometry(exampleTrajectory.initialPose())
# # Run path following command, then stop at the end.
# return swerveControllerCommand.andThen(
# cmd.run(
# lambda: self.robotDrive.drive(0, 0, 0, False, False),
# self.robotDrive,
# )
# )
# https://github.com/robotpy/robotpy-rev/tree/384ca50b2ede3ab44e09f0c12b8c5db33dff7c9e/examples/maxswerve
# return AutoAlign(self.robotDrive, self.limelight).andThen(AutoRotate(self.robotDrive, self.limelight))
return self.autoChooser.getSelected()
# return PathPlannerAuto('New Auto')