Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Reformatted master.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjiboy50fonz committed Jun 1, 2021
1 parent 7ee3877 commit f71c184
Show file tree
Hide file tree
Showing 39 changed files with 360 additions and 389 deletions.
11 changes: 7 additions & 4 deletions commands/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ def init():
try:
val = definedAutos[0]
for auto in definedAutos:
if auto[-1] == '0':
if auto[-1] == "0":
val = auto
table.putString("selectedAuto", val)
except(IndexError):
except (IndexError):
table.putString("selectedAuto", "NO AUTO FOUND")


def getAutoProgram():
"""
Returns the first defined auto if none are selected.
"""
try:
return table.getString("selectedAuto", (definedAutos[0]).lower()) # Should never call the default here since default is populated above.
except(IndexError):
return table.getString(
"selectedAuto", (definedAutos[0]).lower()
) # Should never call the default here since default is populated above.
except (IndexError):
raise Exception("You don't have any autos defined!")
4 changes: 2 additions & 2 deletions commands/autonomouscommandgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def __init__(self):
if var.lower() == self.currentAuto:
toRun = var
break

eval("self." + toRun + "()") # Runs the method

def example(self):
"""
Define the function using the name of the autonomous program. It should
then appear on the driverstation. Put a exclamation point in front of the chosen
default one! If there is no default selected, the default will be the auto first
default one! If there is no default selected, the default will be the auto first
in alphabetical order.
"""
pass
Expand Down
14 changes: 6 additions & 8 deletions commands/drivetrain/drivecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from custom import driverhud
import math

logicalaxes.registerAxis('driveX')
logicalaxes.registerAxis('driveY')
logicalaxes.registerAxis('driveRotate')
logicalaxes.registerAxis("driveX")
logicalaxes.registerAxis("driveY")
logicalaxes.registerAxis("driveRotate")


class DriveCommand(CommandBase):
def __init__(self):
Expand All @@ -19,11 +20,10 @@ def __init__(self):
def initialize(self):
robot.drivetrain.stop()
robot.drivetrain.setProfile(0)

self.lastY = None
self.slowed = False


def execute(self):
# Avoid quick changes in direction
y = logicalaxes.driveY.get()
Expand All @@ -46,7 +46,5 @@ def execute(self):
correction = 0

robot.drivetrain.move(
logicalaxes.driveX.get(),
y - correction,
logicalaxes.driveRotate.get()
logicalaxes.driveX.get(), y - correction, logicalaxes.driveRotate.get()
)
4 changes: 2 additions & 2 deletions commands/drivetrain/movecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def __init__(self, distance, angle=0, tolerance=5, slow=False, name=None):
name = "Move %f inches" % distance

super().__init__()

if isinstance(robot.drivetain, SwerveDrive):

self.distance = -distance
self.angle = angle
self.tol = tolerance # Angle tolerance in degrees.
Expand Down
7 changes: 3 additions & 4 deletions commands/drivetrain/pivotcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@


class PivotCommand(TurnCommand):
'''Allows autonomous turning using the drive base encoders.'''
"""Allows autonomous turning using the drive base encoders."""

def __init__(self, degrees, reverse=False, name=None):
if name is None:
name = 'Pivot %f degrees' % degrees
name = "Pivot %f degrees" % degrees

super().__init__(degrees, name)

Expand All @@ -23,9 +23,8 @@ def __init__(self, degrees, reverse=False, name=None):
if reverse:
self.pivotSide = abs(self.pivotSide - 1)


def initialize(self):
'''Calculates new positions by offsetting the current ones.'''
"""Calculates new positions by offsetting the current ones."""

offset = self._calculateDisplacement() * 2
targetPositions = []
Expand Down
10 changes: 3 additions & 7 deletions commands/drivetrain/pivottocommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

import robot


class PivotToCommand(PivotCommand):
'''Pivot to a specified angle using the gyroscope.'''
"""Pivot to a specified angle using the gyroscope."""

def __init__(self, targetDegrees, reverse=False):
super().__init__(
targetDegrees,
reverse,
'Pivot to %f degrees' % targetDegrees
)
super().__init__(targetDegrees, reverse, "Pivot to %f degrees" % targetDegrees)

self.targetDegrees = targetDegrees
self.reversed = reverse


def initialize(self):
self.distance = robot.drivetrain.getAngleTo(self.targetDegrees)

Expand Down
2 changes: 1 addition & 1 deletion commands/drivetrain/resettiltcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import robot

class ResetTiltCommand(InstantCommand):

class ResetTiltCommand(InstantCommand):
def __init__(self):
super().__init__()

Expand Down
4 changes: 2 additions & 2 deletions commands/drivetrain/setspeedcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import robot


class SetSpeedCommand(InstantCommand):
'''Changes the max speed of the drive subsystem.'''
"""Changes the max speed of the drive subsystem."""

def __init__(self, speed):
super().__init__()
self.speed = speed


def initialize(self):
robot.drivetrain.setSpeedLimit(self.speed)
16 changes: 7 additions & 9 deletions commands/drivetrain/turncommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@


class TurnCommand(MoveCommand):
'''Allows autonomous turning using the drive base encoders.'''
"""Allows autonomous turning using the drive base encoders."""

def __init__(self, degrees, name=None):
if name is None:
name = 'Turn %f degrees' % degrees
name = "Turn %f degrees" % degrees

super().__init__(degrees, False, name)


def initialize(self):
'''Calculates new positions by offseting the current ones.'''
"""Calculates new positions by offseting the current ones."""

offset = self._calculateDisplacement()
targetPositions = []
Expand All @@ -26,15 +25,14 @@ def initialize(self):

robot.drivetrain.setPositions(targetPositions)


def _calculateDisplacement(self):
'''
"""
In order to avoid having a separate ticksPerDegree, we calculate it
based on the width of the robot base.
'''
"""

inchesPerDegree = math.pi * Config('DriveTrain/width') / 360
inchesPerDegree = math.pi * Config("DriveTrain/width") / 360
totalDistanceInInches = self.distance * inchesPerDegree
ticks = robot.drivetrain.inchesToTicks(totalDistanceInInches)

return ticks * Config('DriveTrain/slip', 1.2)
return ticks * Config("DriveTrain/slip", 1.2)
9 changes: 3 additions & 6 deletions commands/drivetrain/turntocommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

import robot


class TurnToCommand(TurnCommand):
'''Turn to a specified angle using the gyroscope.'''
"""Turn to a specified angle using the gyroscope."""

def __init__(self, targetDegrees):
super().__init__(
targetDegrees,
'Turn to %f degrees' % targetDegrees
)
super().__init__(targetDegrees, "Turn to %f degrees" % targetDegrees)

self.targetDegrees = targetDegrees


def initialize(self):
self.distance = robot.drivetrain.getAngleTo(self.targetDegrees)

Expand Down
5 changes: 2 additions & 3 deletions commands/drivetrain/zerogyrocommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import robot

class ZeroGyroCommand(InstantCommand):

class ZeroGyroCommand(InstantCommand):
def __init__(self):
super().__init__('Zero Gyro')
super().__init__("Zero Gyro")

self.requires(robot.drivetrain)


def initialize(self):
robot.drivetrain.resetGyro()
12 changes: 6 additions & 6 deletions commands/monitorcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import robot


class MonitorCommand(Command):
'''Runs continually while the robot is powered on.'''
"""Runs continually while the robot is powered on."""

def __init__(self):
super().__init__('MonitorCommand')
super().__init__("MonitorCommand")

'''
"""
Required because this is the default command for the monitor subsystem.
'''
"""
self.requires(robot.monitor)

self.setInterruptible(False)
self.setRunWhenDisabled(True)


def execute(self):
'''Implement watchers here.'''
"""Implement watchers here."""
pass
1 change: 1 addition & 0 deletions commands/network/messagecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from subsystems.cougarsystem import CougarSystem


class MessageCommand(InstantCommand):
def __init__(self, msg):
super().__init__()
Expand Down
7 changes: 4 additions & 3 deletions commands/resetcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import robot


class ResetCommand(InstantCommand):
'''
"""
Disable any running commands for all subsystems, except Monitor. This should
be used to stop any motion and return the commands to a safe state. In
general just requiring a subsystem will stop its current command. Additional
resetting can be handled in the initialize method.
'''
"""

def __init__(self):
super().__init__()

'''Require all subsystems to reset.'''
"""Require all subsystems to reset."""
self.addRequirements(robot.drivetrain)
2 changes: 1 addition & 1 deletion commands/startupcommandgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from .drivetrain.resettiltcommand import ResetTiltCommand

class StartUpCommandGroup(ParallelCommandGroup):

class StartUpCommandGroup(ParallelCommandGroup):
def __init__(self):
super().__init__()

Expand Down
12 changes: 5 additions & 7 deletions commands/tools/calculateerrorcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import robot
from custom.config import Config


class CalculateErrorCommand(MoveCommand):

errors = []
Expand All @@ -12,15 +13,13 @@ def __init__(self, direction=1):
super().__init__(30 * direction)

self.addRequirements(robot.drivetrain)
Config('DriveTrain/wheelDiameter', 8)
self.table = NetworkTables.getTable('DriveTrain/Speed')

Config("DriveTrain/wheelDiameter", 8)
self.table = NetworkTables.getTable("DriveTrain/Speed")

def initialize(self):
self.table.putValue('P', 0)
self.table.putValue("P", 0)
super().initialize()


def isFinished(self):
if not self.isTimedOut():
return False
Expand All @@ -35,9 +34,8 @@ def isFinished(self):

return self.onTarget > 5


def end(self):
self.errors.append(robot.drivetrain.averageError())

avgError = sum(self.errors) / len(self.errors)
self.table.putValue('P', 415 / avgError)
self.table.putValue("P", 415 / avgError)
12 changes: 6 additions & 6 deletions commands/tools/calculatemaxspeedcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import robot


class CalculateMaxSpeedCommand(InstantCommand):

measuredSpeeds = []
Expand All @@ -12,8 +13,7 @@ def __init__(self):
super().__init__()

self.addRequirements(robot.drivetrain)
self.table = NetworkTables.getTable('DriveTrain')

self.table = NetworkTables.getTable("DriveTrain")

def initialize(self):
for speed in robot.drivetrain.getSpeeds():
Expand All @@ -22,8 +22,8 @@ def initialize(self):
# Select the smallest max speed
maxSpeed = min(self.measuredSpeeds)

self.table.putValue('maxSpeed', math.floor(maxSpeed))
self.table.putValue('normalSpeed', round(maxSpeed * 0.7))
self.table.putValue('preciseSpeed', round(maxSpeed * 0.3))
self.table.putValue("maxSpeed", math.floor(maxSpeed))
self.table.putValue("normalSpeed", round(maxSpeed * 0.7))
self.table.putValue("preciseSpeed", round(maxSpeed * 0.3))

self.table.putValue('Speed/F', 1023 / maxSpeed)
self.table.putValue("Speed/F", 1023 / maxSpeed)
Loading

0 comments on commit f71c184

Please sign in to comment.