commands.default_swerve_drive

 1# Native imports
 2import math
 3from typing import Callable
 4
 5# Internal imports
 6from constants import SwerveDriveConsts
 7from subsystem.drivetrain.swerve_drivetrain import SwerveDrivetrain
 8
 9# Third-party imports
10import commands2
11
12class DefaultDrive(commands2.Command):
13    """
14    Base command to drive a swerve drive robot using an Xbox controller. This should
15    be given as the default command for the swerve drivetrain subsystem.
16    """
17    def __init__ (
18        self,
19        drivetrain: SwerveDrivetrain,
20        velocity_vector_x: Callable[[], float],
21        velocity_vector_y: Callable[[], float],
22        angular_velocity: Callable[[], float],
23        field: Callable[[], bool]
24    ) -> None:
25        """
26        Store joystick and button inputs within the object, and require the swerve drivetrain
27        subsystem when executing this command.
28
29        Args:
30            drivetrain: the swerve drivetrain subsystem that this command with operate
31            velocity_vector_x: live poll of the percentage of max translation velocity that the
32                drivetrain should go in the X (+ forward-backward -) direction. Has
33                domain [-1, 1]
34            velocity_vector_y: live poll of the percentage of max translation velocity that the
35                drivetrain should go in the Y (+ left-right -) direction. Has
36                domain [-1, 1]
37            angular_velocity: live poll of the percentage of max angular velocity that the drivetrain
38                should go in CCW direction. Has domain [-1, 1]
39            field: live poll. if True, the drivetrain should move in field relative mode. If False,
40                the robot should move in robot relative mode
41
42        Returns:
43            None: class initialization executed upon construction
44        """
45        super().__init__()
46
47        self.drivetrain = drivetrain
48        self.velocity_vector_x = velocity_vector_x
49        self.velocity_vector_y = velocity_vector_y
50        self.angular_velocity = angular_velocity
51        self.field = field
52        self.addRequirements(self.drivetrain)
53
54    def execute(self) -> None:
55        """
56        Take the controller input poll functions and transform them into inputs for the
57        swerve drivetrain's drive interface. Execute drive functionality using those inputs.
58
59        Returns:
60            None: interface eventually passes desired goal states to the swerve modules
61        """
62        self.drivetrain.drive(
63            self.velocity_vector_x() * SwerveDriveConsts.maxTranslationMPS,
64            self.velocity_vector_y() * SwerveDriveConsts.maxTranslationMPS,
65            self.angular_velocity() * math.radians(SwerveDriveConsts.maxAngularDPS),
66            self.field()
67        )
class DefaultDrive(commands2.command.Command):
13class DefaultDrive(commands2.Command):
14    """
15    Base command to drive a swerve drive robot using an Xbox controller. This should
16    be given as the default command for the swerve drivetrain subsystem.
17    """
18    def __init__ (
19        self,
20        drivetrain: SwerveDrivetrain,
21        velocity_vector_x: Callable[[], float],
22        velocity_vector_y: Callable[[], float],
23        angular_velocity: Callable[[], float],
24        field: Callable[[], bool]
25    ) -> None:
26        """
27        Store joystick and button inputs within the object, and require the swerve drivetrain
28        subsystem when executing this command.
29
30        Args:
31            drivetrain: the swerve drivetrain subsystem that this command with operate
32            velocity_vector_x: live poll of the percentage of max translation velocity that the
33                drivetrain should go in the X (+ forward-backward -) direction. Has
34                domain [-1, 1]
35            velocity_vector_y: live poll of the percentage of max translation velocity that the
36                drivetrain should go in the Y (+ left-right -) direction. Has
37                domain [-1, 1]
38            angular_velocity: live poll of the percentage of max angular velocity that the drivetrain
39                should go in CCW direction. Has domain [-1, 1]
40            field: live poll. if True, the drivetrain should move in field relative mode. If False,
41                the robot should move in robot relative mode
42
43        Returns:
44            None: class initialization executed upon construction
45        """
46        super().__init__()
47
48        self.drivetrain = drivetrain
49        self.velocity_vector_x = velocity_vector_x
50        self.velocity_vector_y = velocity_vector_y
51        self.angular_velocity = angular_velocity
52        self.field = field
53        self.addRequirements(self.drivetrain)
54
55    def execute(self) -> None:
56        """
57        Take the controller input poll functions and transform them into inputs for the
58        swerve drivetrain's drive interface. Execute drive functionality using those inputs.
59
60        Returns:
61            None: interface eventually passes desired goal states to the swerve modules
62        """
63        self.drivetrain.drive(
64            self.velocity_vector_x() * SwerveDriveConsts.maxTranslationMPS,
65            self.velocity_vector_y() * SwerveDriveConsts.maxTranslationMPS,
66            self.angular_velocity() * math.radians(SwerveDriveConsts.maxAngularDPS),
67            self.field()
68        )

Base command to drive a swerve drive robot using an Xbox controller. This should be given as the default command for the swerve drivetrain subsystem.

DefaultDrive( drivetrain: subsystem.drivetrain.swerve_drivetrain.SwerveDrivetrain, velocity_vector_x: Callable[[], float], velocity_vector_y: Callable[[], float], angular_velocity: Callable[[], float], field: Callable[[], bool])
18    def __init__ (
19        self,
20        drivetrain: SwerveDrivetrain,
21        velocity_vector_x: Callable[[], float],
22        velocity_vector_y: Callable[[], float],
23        angular_velocity: Callable[[], float],
24        field: Callable[[], bool]
25    ) -> None:
26        """
27        Store joystick and button inputs within the object, and require the swerve drivetrain
28        subsystem when executing this command.
29
30        Args:
31            drivetrain: the swerve drivetrain subsystem that this command with operate
32            velocity_vector_x: live poll of the percentage of max translation velocity that the
33                drivetrain should go in the X (+ forward-backward -) direction. Has
34                domain [-1, 1]
35            velocity_vector_y: live poll of the percentage of max translation velocity that the
36                drivetrain should go in the Y (+ left-right -) direction. Has
37                domain [-1, 1]
38            angular_velocity: live poll of the percentage of max angular velocity that the drivetrain
39                should go in CCW direction. Has domain [-1, 1]
40            field: live poll. if True, the drivetrain should move in field relative mode. If False,
41                the robot should move in robot relative mode
42
43        Returns:
44            None: class initialization executed upon construction
45        """
46        super().__init__()
47
48        self.drivetrain = drivetrain
49        self.velocity_vector_x = velocity_vector_x
50        self.velocity_vector_y = velocity_vector_y
51        self.angular_velocity = angular_velocity
52        self.field = field
53        self.addRequirements(self.drivetrain)

Store joystick and button inputs within the object, and require the swerve drivetrain subsystem when executing this command.

Args: drivetrain: the swerve drivetrain subsystem that this command with operate velocity_vector_x: live poll of the percentage of max translation velocity that the drivetrain should go in the X (+ forward-backward -) direction. Has domain [-1, 1] velocity_vector_y: live poll of the percentage of max translation velocity that the drivetrain should go in the Y (+ left-right -) direction. Has domain [-1, 1] angular_velocity: live poll of the percentage of max angular velocity that the drivetrain should go in CCW direction. Has domain [-1, 1] field: live poll. if True, the drivetrain should move in field relative mode. If False, the robot should move in robot relative mode

Returns: None: class initialization executed upon construction

drivetrain
velocity_vector_x
velocity_vector_y
angular_velocity
field
def execute(self) -> None:
55    def execute(self) -> None:
56        """
57        Take the controller input poll functions and transform them into inputs for the
58        swerve drivetrain's drive interface. Execute drive functionality using those inputs.
59
60        Returns:
61            None: interface eventually passes desired goal states to the swerve modules
62        """
63        self.drivetrain.drive(
64            self.velocity_vector_x() * SwerveDriveConsts.maxTranslationMPS,
65            self.velocity_vector_y() * SwerveDriveConsts.maxTranslationMPS,
66            self.angular_velocity() * math.radians(SwerveDriveConsts.maxAngularDPS),
67            self.field()
68        )

Take the controller input poll functions and transform them into inputs for the swerve drivetrain's drive interface. Execute drive functionality using those inputs.

Returns: None: interface eventually passes desired goal states to the swerve modules