swerve package

Submodules

swerve.swerve_drive module

Implements a full swerve drive.

class swerve.swerve_drive.SwerveDrive(length, width, config_tuples)[source]

Bases: object

drive(forward, strafe, rotate_cw, max_wheel_speed=370)[source]

Compute and apply module angles and speeds to achieve a given linear / angular velocity.

All control inputs (arguments) are assumed to be in a robot oriented reference frame. In addition, all values are (for now) assumed to fall within the range [0, 1].

Parameters:
  • forward (number) – The desired, relative forward motion of the robot.
  • strafe (number) – The desired, relative sideways motion of the robot.
  • rotate_cw (number) – The desired rotational speed of the robot.
drive_angle_distance(angle_rad, dist_ticks)[source]
get_closed_loop_error()[source]
get_module_distances()[source]
load_config_values()[source]

Load configuration values for all modules within this swerve drive.

reset_drive_position()[source]
save_config_values()[source]

Save configuration values for all modules within this swerve drive.

set_all_module_angles(angle_rad)[source]
set_all_module_dist_ticks(dist_ticks)[source]
set_all_module_speeds(speed, direct=False)[source]
turn_to_angle(imu, target_angle)[source]
update_smart_dashboard()[source]

Update Smart Dashboard for all modules within this swerve drive.

swerve.swerve_module module

Implements common logic for swerve modules.

class swerve.swerve_module.SwerveModule(name, steer_id, drive_id)[source]

Bases: object

apply_control_values(angle_radians, speed, direct=False)[source]

Set a steering angle and a drive speed simultaneously.

Parameters:
  • angle_radians (number) – The desired angle to steer towards.
  • percent_speed (number) – The desired percentage speed to drive at.
get_steer_angle()[source]

Get the current angular position of the swerve module in radians.

load_config_values()[source]

Load saved configuration values for this module via WPILib’s Preferences interface.

The key names are derived from the name passed to the constructor.

reset_drive_position()[source]
save_config_values()[source]

Save configuration values for this module via WPILib’s Preferences interface.

set_drive_distance(ticks)[source]
set_drive_speed(speed, direct=False)[source]

Drive the swerve module wheels at a given percentage of maximum power or speed.

Parameters:percent_speed (number) – The speed to drive the module at, expressed as a percentage of maximum speed. Negative values drive in reverse.
set_steer_angle(angle_radians)[source]

Steer the swerve module to the given angle in radians. angle_radians should be within \([-2\pi, 2\pi]\). This method attempts to find the shortest path to the given steering angle; thus, it may in actuality servo to the position opposite the passed angle and reverse the drive direction. :param angle_radians: The angle to steer towards in radians,

where 0 points in the chassis forward direction.
update_smart_dashboard()[source]

Push various pieces of info to the Smart Dashboard.

This method calls to NetworkTables (eventually), thus it may be _slow_.

As of right now, this displays the current raw absolute encoder reading from the steer Talon, and the current target steer position.

Module contents