autonomous module

Autonomous module.

This module contains classes and functions for autonomous, which is designed as a finite-state automaton updated per tick in autonomousPeriodic.

Autonomous transitions between these states:

  • init: The robot closes the claw, fully lowers the lift, and transitions onto the turn state to angle toward the next waypoint.
  • turn: The swerve modules (not the entire chassis) angle toward the next waypoint, then transitions into the drive state
  • drive: The robot drives over to the next waypoint, then transitions into the turning state or the lifting state if there are no other waypoints.
  • lift: the RD4B lifts to a predetermined height (either the height of the scale or switch), then transitions to the target states.
  • target-turn: Turns the entire chassis towards the target (either the switch or the scale).
  • target-drive: Drives the robot towards the target. This differs slightly from the normal drive state because it uses sensors to be more accurate.
  • drop: The claw opens.
class autonomous.Autonomous(robot, robot_position)[source]

Bases: object

This class implements a finite-state automaton for controlling autonomous. Also, this class includes a way to input waypoint coordinates into a a template to be automatically selected and formatted as necessary.

Parameters:
  • robot – the robot instance.
  • robot_position – the position of the robot on the field.
PATHS = {'1': [(-40, -40), (-20, 10), (20, 0), (40, -10), (0, 0), (40, 40), (30, 30)], '2': [], '3': [], 'default': [(-24, 0), (-24, 24), (-60, 24), (-60, 0), (0, 0)]}

Dictionary of paths (arrays of waypoints). The right one is chosen at runtime.

drive_dist_tolerance = 3

a tolerance range for driving, in inches.

drive_speed = 100

how fast to drive, in native units per 100ms

init_lift_height = 6

initial lift height, in inches above the ground.

lift_height_tolerance = 2

a tolerance range for lifting, in inches.

periodic()[source]

Updates and progresses the autonomous state machine.

state_drive()[source]

Drive toward a waypoint. Calculate the distance, then move the modules that distance.

state_drop()[source]

Open the claw and drop the cube.

state_init()[source]

Perform robot-oriented initializations.

Close the claw and set the lift to its lowest position, then transition into the turning state.

state_lift()[source]

Lift the RD4B to the height needed. Then transition to the target states for final adjustments.

state_table = {'drive': <function Autonomous.state_drive at 0x7fe5f7816b70>, 'drop': <function Autonomous.state_drop at 0x7fe5f7816d90>, 'init': <function Autonomous.state_init at 0x7fe5f7837c80>, 'lift': <function Autonomous.state_lift at 0x7fe5f7816bf8>, 'target-drive': <function Autonomous.state_target_drive at 0x7fe5f7816d08>, 'target-turn': <function Autonomous.state_target_turn at 0x7fe5f7816c80>, 'turn': <function Autonomous.state_turn at 0x7fe5f7816ae8>}

Maps state names to functions.

state_target_drive()[source]

Drive a measured distance towards the target. This should position the claw, with the cube, right over the switch or scale.

state_target_turn()[source]

Complete a targeted, measured turn towards the target, turning the entire chassis this time instead of just each module.

state_turn()[source]

Turn the swerve modules to their desired angle. Then transition into the drive state.

turn_angle_tolerance = 2.5

a tolerance range for turning, in degrees.

update_smart_dashboard()[source]

Periodically call this function to update the smartdashboard with important information about the autonomous class, for troubleshooting/ monitoring purposes.