1010#from commands2.sysid import SysIdRoutine
1111from generated .tuner_constants import TunerConstants
1212from telemetry import Telemetry
13-
13+ from wpimath . geometry import Pose2d # , Rotation2d
1414from phoenix6 import swerve #, SignalLogger
1515from wpimath .units import rotationsToRadians
1616from lifter import Lifter # Import the Lifter class
1717import wpilib
1818import logging
1919import math
20+ from wpimath .kinematics import ChassisSpeeds
2021
2122# Configure logging
2223logging .basicConfig (level = logging .DEBUG )
2829
2930INTAKE_MOTOR_ID_TOP = 18
3031INTAKE_MOTOR_ID_BOTTOM = 22
32+ DUMMY_POSE = Pose2d (2 , 1 , 1 / 2 )
3133
3234class RobotContainer :
3335 """
@@ -74,6 +76,7 @@ def __init__(self) -> None:
7476 # Setup telemetry
7577 self ._registerTelemetry ()
7678
79+
7780 def calculateJoystick (self ) -> tuple [float , float ]:
7881 x0 , y0 = self ._joystick .getLeftX (), self ._joystick .getLeftY ()
7982 magnitude = self .applyExponential (math .hypot (x0 , y0 ), self ._deadband , self ._exponent ) * self ._max_speed
@@ -84,15 +87,22 @@ def calculateJoystick(self) -> tuple[float, float]:
8487
8588 return x1 , y1
8689
87- def applyRequest (self ) -> swerve .requests .SwerveRequest :
90+ def defaultDriveRequest (self ) -> swerve .requests .SwerveRequest :
8891 (new_vx , new_vy ) = self .calculateJoystick ()
8992
9093 return (self ._drive .with_velocity_x (self ._driveMultiplier * new_vy # Drive left with negative X (left)
9194 ) .with_velocity_y (self ._driveMultiplier * new_vx ) # Drive forward with negative Y (forward)
9295 .with_rotational_rate (
9396 self ._driveMultiplier * self .applyExponential (self ._joystick .getRightX (), self ._deadband , self ._exponent ) * self ._max_angular_rate
9497 )) # Drive counterclockwise with negative X (left)
98+
99+ def create_go_to_coordinate_request (self ):
100+ return self .drivetrain .go_to_coordinate (DUMMY_POSE )
95101
102+ def create_point_at_coordinate_request (self ):
103+ return self .drivetrain .point_at_coordinate (DUMMY_POSE , self .calculateJoystick ())
104+
105+
96106
97107 def configureButtonBindings (self ) -> None :
98108 """
@@ -107,7 +117,7 @@ def configureButtonBindings(self) -> None:
107117
108118 # Note that X is defined as forward according to WPILib convention,
109119 # and Y is defined as to the left according to WPILib convention.
110- self .drivetrain .setDefaultCommand (self .drivetrain .apply_request (self .applyRequest ))
120+ self .drivetrain .setDefaultCommand (self .drivetrain .apply_request (self .defaultDriveRequest ))
111121 # reset the field-centric heading on x button press
112122 self ._joystick .x ().onTrue (
113123 self .drivetrain .runOnce (lambda : self .resetHeading ())
@@ -136,6 +146,14 @@ def configureButtonBindings(self) -> None:
136146 lambda : self .intake .stop ()
137147 ))
138148
149+ self ._joystick .b ().whileTrue (commands2 .cmd .run (
150+ lambda : self .create_point_at_coordinate_request (), self .drivetrain
151+ ))
152+
153+ self ._joystick .start ().whileTrue (commands2 .cmd .run (
154+ lambda : self .create_go_to_coordinate_request (), self .drivetrain
155+ ))
156+
139157 def resetHeading (self ) -> None :
140158 self .drivetrain .seed_field_centric ()
141159
@@ -146,15 +164,26 @@ def getAutonomousCommand(self, selected: str) -> commands2.Command:
146164 selected ,
147165 is_red_alliance = self .isRedAlliance ())
148166
149- def isRedAlliance (self ) -> bool :
150- return wpilib .DriverStation .getAlliance () == wpilib .DriverStation .Alliance .kRed
151-
152167 def _registerTelemetry (self ) -> None :
153168 self .drivetrain .register_telemetry (
154169 lambda state : self ._logger .telemeterize (state )
155170 )
156171
157- def applyExponential (self , input : float , deadband : float , exponent : float ) -> float :
172+
173+ @staticmethod
174+ def compute_heading_to_target (current_pose : Pose2d , target_pose : Pose2d ) -> float :
175+ relative_pose = current_pose .relativeTo (target_pose )
176+ return math .atan2 (relative_pose .Y (), relative_pose .X ())
177+
178+
179+ @staticmethod
180+ def isRedAlliance () -> bool :
181+ return wpilib .DriverStation .getAlliance () == wpilib .DriverStation .Alliance .kRed
182+
183+
184+
185+ @staticmethod
186+ def applyExponential (input : float , deadband : float , exponent : float ) -> float :
158187 """
159188 Apply an exponential response curve with a deadband on the input
160189 such that the final output goes smoothly from 0 -> ±1 without
0 commit comments