Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Heightened resonsibility of ConfigurationManager #140

Draft
wants to merge 115 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
0950af8
Major changes to config, switched to .json
cannedlock Mar 28, 2020
423142c
small flake8 changes{
cannedlock Mar 28, 2020
8e1f43e
changed some names
cannedlock Mar 28, 2020
0014c2a
fixed names
cannedlock Mar 28, 2020
97ff22f
renamed config file to 'robot.json'
cannedlock Mar 28, 2020
ab9c71a
fixed minor arg error
cannedlock Mar 29, 2020
b603e4e
fixed some docstrings
cannedlock Mar 29, 2020
0266776
added an error
cannedlock Mar 29, 2020
ebd9a20
added failsafe for uppercase config
cannedlock Mar 29, 2020
6fa4b73
fixed docstring
cannedlock Apr 5, 2020
0c14232
fixed weird dictionary search thing
cannedlock Apr 6, 2020
6fd9cac
small changes
cannedlock Apr 13, 2020
64b1fc3
reworked a new idea for the config file
cannedlock Apr 15, 2020
b5d999e
early progress
cannedlock Apr 15, 2020
50a78c7
more working stuff...
cannedlock Apr 16, 2020
e106e43
temp changes
cannedlock Apr 16, 2020
9718be8
major fixes
cannedlock Apr 17, 2020
7c1dc9a
major improvements; almost ready for review.
cannedlock Apr 17, 2020
1ee73e2
finally working
cannedlock Apr 18, 2020
5e43ec5
removed obsolete config mapper
cannedlock Apr 18, 2020
fb40d5b
added docstrigs
cannedlock Apr 18, 2020
ba5d8a3
finalizing changes
cannedlock Apr 18, 2020
c32a9d9
changed some names
cannedlock Apr 19, 2020
e9334dc
cleaned up a variable
cannedlock Apr 20, 2020
270c9ba
dummy func made to fix flake8
cannedlock Apr 20, 2020
c03c88c
cleaned up some vars
cannedlock Apr 21, 2020
8bc2d21
fixed __main__ err
cannedlock Apr 25, 2020
ceda1d6
major changes, finalizing code
cannedlock Apr 27, 2020
aa51bf3
added some docstrings
cannedlock Apr 27, 2020
d7f590a
small format changes
cannedlock Apr 29, 2020
0cc40dc
fixed docstring
cannedlock Apr 30, 2020
16dbd79
simplified config evaluation
cannedlock May 1, 2020
97c65ee
flake8 changes
cannedlock May 1, 2020
5565ec9
changed container name to something more descriptive
cannedlock May 1, 2020
f57571c
added annotations
cannedlock May 2, 2020
ca3b63b
small changes
cannedlock May 3, 2020
0c05901
small changes:
cannedlock May 4, 2020
10ed7d0
playing with some ideas
cannedlock May 6, 2020
cb19994
added file
cannedlock May 6, 2020
5e48e63
removed file
cannedlock May 6, 2020
3be282a
base finished for new take on config
cannedlock May 6, 2020
cc80f71
added an error
cannedlock May 6, 2020
210a2cd
small changes
cannedlock May 6, 2020
e46f039
simplified some aspects
cannedlock May 6, 2020
d82cc11
flake8 fixes
cannedlock May 6, 2020
32a20dc
added scorption/minibot configs
cannedlock May 7, 2020
001a8bb
fix to injecting vars
cannedlock May 7, 2020
47209bc
fixed some prints
cannedlock May 9, 2020
b1bf604
lots of neat changes
cannedlock May 11, 2020
719cc4a
fixed an error msg
cannedlock May 11, 2020
9dc0009
flake8 fixes
cannedlock May 11, 2020
c8ba8b7
format changes
cannedlock May 12, 2020
a1c8f5d
added docstring
cannedlock May 12, 2020
7c56a6d
made findConfig a staticmethod
cannedlock May 12, 2020
0ab03b9
localized .json factories file
cannedlock May 12, 2020
18aa045
fixed error
cannedlock May 12, 2020
0233c0e
added newline
cannedlock May 13, 2020
5cd8af8
added a lot to FileHandler
cannedlock May 13, 2020
1745bf1
added some restrictions
cannedlock May 13, 2020
574db64
added .yml support
cannedlock May 13, 2020
68343a1
fixed checkCompatiblity
cannedlock May 14, 2020
e94c66d
FINALLY fixed the flake8 thing
cannedlock May 14, 2020
ad719a4
fixed some vars
cannedlock May 14, 2020
080278b
secured config info aquisition
cannedlock May 14, 2020
6d14fc8
added docstring:
cannedlock May 14, 2020
d530db5
created comprehension
cannedlock May 14, 2020
ae0f978
small change
cannedlock May 14, 2020
8f0ea8d
simplified
cannedlock May 14, 2020
cd08969
simplified some things
cannedlock May 15, 2020
9e58557
significantly simplifed config manager
cannedlock May 15, 2020
6f24552
removed if __name__ == '__main__'
cannedlock May 15, 2020
bf89ca9
flake8 fixes
cannedlock May 15, 2020
7c95a68
localized checkCompatibility
cannedlock May 15, 2020
d7cb0ae
removed use_encoding option
cannedlock May 15, 2020
3e53b94
added component check features
cannedlock May 15, 2020
05bae5b
flake8 fixes
cannedlock May 15, 2020
b0bdbb3
fixed comment
cannedlock May 16, 2020
34e7334
small changes
cannedlock May 16, 2020
0481761
small changes
cannedlock May 16, 2020
7a74011
cleanup
cannedlock May 17, 2020
47bdcfb
small changes
cannedlock May 18, 2020
3fa554a
simplified
cannedlock May 18, 2020
957d288
nested findConfig
cannedlock May 19, 2020
f3a6d91
fixed import
cannedlock May 19, 2020
3aec4d5
simplified findConfig
cannedlock May 19, 2020
c32af03
moved FileHandler to own file
cannedlock May 19, 2020
47331ae
flake8 fixes:
cannedlock May 19, 2020
1c7121d
small changes
cannedlock May 20, 2020
acfa8f2
added SafeFileReader
cannedlock May 20, 2020
c18a255
fixed context manager
cannedlock May 21, 2020
0504107
removed context manager
cannedlock May 21, 2020
6ae9b07
flake8 fixes
cannedlock May 22, 2020
b3be3a9
?
cannedlock May 22, 2020
d05c8f6
fixed weird issue
cannedlock May 22, 2020
04423d0
made more pythonic
cannedlock May 23, 2020
f15694f
minor additions to reworked config; added pycodestyle test
cannedlock May 24, 2020
f2cd935
initial changes
cannedlock May 25, 2020
9ed3c44
WIP
cannedlock May 27, 2020
34345c2
basic update threader
cannedlock May 27, 2020
1a82b9c
needs testing
cannedlock May 27, 2020
53b2652
restricted value collection to teleop only
cannedlock May 27, 2020
e30f001
finalized controller config; changed feederMap
cannedlock May 27, 2020
a706751
removed robot map; added delay
cannedlock May 27, 2020
9899883
rough fixes to remove robotMap
cannedlock May 28, 2020
83baed9
moved code out of teleop periodic. Needs testing
cannedlock May 28, 2020
78f04c2
flake8 fixes
cannedlock May 28, 2020
d558a0c
moved math.py
cannedlock May 28, 2020
383bec5
fixed error
cannedlock May 28, 2020
1e0bb55
fixed formatting of axis collection
cannedlock May 28, 2020
b69ed37
nested _Controller class
cannedlock May 28, 2020
30dda67
renamed reworkedConfig.py to robotInitializer.py
cannedlock May 28, 2020
01428d3
changed logging statements
cannedlock May 28, 2020
6de3c0d
small changes:
cannedlock May 29, 2020
ff59276
made constants
cannedlock Jun 1, 2020
4d28dbf
button event additions
cannedlock Jun 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/breakSensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class State:

class Sensors:

compatString = ["doof"]

digitalInput_breaksensors: dict

def on_enable(self):
Expand Down
2 changes: 2 additions & 0 deletions components/buttonManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ButtonManager(object):
use any registered buttons directly.
"""

compatString = ["all"]

def setup(self):
"""
Sets up Button manager.
Expand Down
33 changes: 29 additions & 4 deletions components/driveTrain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import wpilib.drive
from enum import Enum, auto

from magicbot import tunable


class ControlMode(Enum):
"""
Drive Train Control Modes
Expand All @@ -14,8 +15,12 @@ class ControlMode(Enum):
class DriveTrain():
# Note - The way we will want to do this will be to give this component motor description dictionaries from robotmap and then creating the motors with motorhelper. After that, we simply call wpilib' differential drive
motors_driveTrain: dict
controllers: dict
driveMotorsMultiplier = tunable(.5)
gyros_system: dict
sensitivityExponent = tunable(1.8)
#gyros_system: dict

compatString = ["all"]

def setup(self):
self.tankLeftSpeed = 0
Expand All @@ -26,9 +31,24 @@ def setup(self):
self.controlMode = ControlMode.kDisabled
self.leftMotor = self.motors_driveTrain["leftMotor"]
self.rightMotor = self.motors_driveTrain["rightMotor"]
self.drive = self.controllers['drive']
self.driveTrain = wpilib.drive.DifferentialDrive(self.leftMotor, self.rightMotor)
self.logger.info("DriveTrain setup completed")


def expScale(self, initVal, exp):
"""
Applies an exponent exp to a value initVal and returns value.
Will work whether initVal is positive or negative or zero.
"""

val = initVal
if val > 0:
val = val ** exp
if val < 0:
val *= -1
val = val ** exp
val *= -1
return val

def getLeft(self):
return self.leftMotor.get()
Expand Down Expand Up @@ -71,9 +91,14 @@ def getMeasuredSpeed(self):
pass

def execute(self):

driveLeft = self.expScale(self.drive.leftY, self.sensitivityExponent) * self.driveMotorsMultiplier
driveRight = self.expScale(self.drive.rightY, self.sensitivityExponent) * self.driveMotorsMultiplier

self.setTank(driveLeft, driveRight)

if self.controlMode == ControlMode.kTankDrive:
self.driveTrain.tankDrive(self.tankLeftSpeed, self.tankRightSpeed, False)

elif self.controlMode == ControlMode.kArcadeDrive:
self.driveTrain.arcadeDrive(self.arcadeSpeed, self.arcadeRotation, False)

3 changes: 3 additions & 0 deletions components/elevator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from magicbot import tunable

class Elevator:

compatString = ["doof"]

motors_loader: dict
downSpeed = tunable(-.4)
upSpeed = tunable(.4)
Expand Down
28 changes: 16 additions & 12 deletions components/feederMap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from robotMap import XboxMap
#from robotMap import XboxMap
from components.shooterMotors import ShooterMotorCreation, Direction
from enum import Enum, auto
from magicbot import tunable
Expand All @@ -15,38 +15,42 @@ class FeederMap:
compatString = ["doof"]

shooterMotors: ShooterMotorCreation
xboxMap: XboxMap
#xboxMap: XboxMap
logger: logging

controllers: dict

loaderMotorSpeed = tunable(.4)
intakeMotorSpeed = tunable(.7)

def on_enable(self):
pass
# self.logger.setLevel(logging.DEBUG)

self.mech = self.controllers['mech']

self.logger.setLevel(logging.DEBUG)

def run(self, loaderFunc):
"""Called when execution of a feeder element is desired."""
if loaderFunc == Type.kIntake:
if self.xboxMap.getMechRightTrig() > 0 and self.xboxMap.getMechLeftTrig() == 0:
if self.mech.rightTrigger > 0 and self.mech.leftTrigger == 0:
self.shooterMotors.runIntake(self.intakeMotorSpeed, Direction.kForwards)
self.logger.debug("right trig intake", self.xboxMap.getMechRightTrig())
self.logger.debug(f"right trig intake {self.mech.rightTrigger}")

elif self.xboxMap.getMechLeftTrig() > 0 and self.xboxMap.getMechRightTrig() == 0:
elif self.mech.leftTrigger > 0 and self.mech.rightTrigger == 0:
self.shooterMotors.runIntake(self.intakeMotorSpeed, Direction.kBackwards)
self.logger.debug("left trig intake", self.xboxMap.getMechLeftTrig())
self.logger.debug(f"left trig intake {self.mech.leftTrigger}")

else:
self.shooterMotors.stopIntake()

if loaderFunc == Type.kLoader:
if self.xboxMap.getMechRightTrig() > 0 and self.xboxMap.getMechLeftTrig() == 0:
if self.mech.rightTrigger > 0 and self.mech.leftTrigger == 0:
self.shooterMotors.runLoader(self.loaderMotorSpeed, Direction.kForwards)
self.logger.debug("right trig manual", self.xboxMap.getMechRightTrig())
self.logger.debug(f"right trig manual {self.mech.rightTrigger}")

elif self.xboxMap.getMechLeftTrig() > 0 and self.xboxMap.getMechRightTrig() == 0:
elif self.mech.leftTrigger > 0 and self.mech.rightTrigger == 0:
self.shooterMotors.runLoader(self.loaderMotorSpeed, Direction.kBackwards)
self.logger.debug("left trig manual", self.xboxMap.getMechLeftTrig())
self.logger.debug(f"left trig manual {self.mech.leftTrigger}")

else:
self.shooterMotors.stopLoader()
Expand Down
3 changes: 1 addition & 2 deletions components/loaderLogic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from robotMap import XboxMap
from components.shooterMotors import ShooterMotorCreation, Direction
from components.breakSensors import Sensors, State
from components.feederMap import FeederMap, Type
Expand All @@ -7,14 +6,14 @@

class LoaderLogic(StateMachine):
"""StateMachine-based loader. Has both automatic and manual modes."""

compatString = ["doof"]

# Component/module related things
shooterMotors: ShooterMotorCreation
feeder: FeederMap
logger: logging
sensors: Sensors
xboxMap: XboxMap

# Tunable
automaticLoaderSpeed = tunable(.4)
Expand Down
4 changes: 3 additions & 1 deletion components/pneumatics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging

class Pneumatics:

compatString = ["doof"]

compressors_pneumatics: dict
solenoids_pneumatics: dict
Expand All @@ -24,7 +26,7 @@ def getLoaderDeployed(self):
"""
returns the "value" of the solenoid. Boolean, is it on or off?
"""
return True if self.solenloaderSolenoidoid.get() == dsPos.kForward else False
return True if self.loaderSolenoid.get() == dsPos.kForward else False

def deployLoader(self):
"""
Expand Down
15 changes: 11 additions & 4 deletions components/scorpionLoader.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from robotMap import XboxMap
from magicbot import tunable

class ScorpionLoader:

compatString = ["scorpion"]

controllers: dict

motors_shooter: dict
motors_loader: dict
xboxMap: XboxMap
shooterSpeed = tunable(-0.4)


def setup(self):
self.intakeSpeed = 0
self.loaderSpeed = 0
self.shooterSpeed = 0

self.mech = self.controllers['mech']

self.loaderMotor = self.motors_loader["loaderMotor"]
self.intakeMotor = self.motors_loader["intakeMotor"]
Expand All @@ -36,10 +40,13 @@ def isLoaderActive(self):
return self.loader

def checkController(self):
self.runIntake(self.shooterSpeed if self.xboxMap.mechLeft < -.2 else 0)
self.runLoader(self.xboxMap.mechRight)
self.runIntake(self.shooterSpeed if self.mech.leftTrigger < -.2 else 0)
self.runLoader(self.mech.rightTrigger)

def execute(self):

self.checkController()

if self.intake:
self.intakeMotor.set(self.intakeSpeed)
elif self.intake == False:
Expand Down
11 changes: 7 additions & 4 deletions components/shooterLogic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from robotMap import XboxMap
from components.shooterMotors import ShooterMotorCreation, Direction
from components.breakSensors import Sensors, State
from components.feederMap import FeederMap, Type
Expand All @@ -7,16 +6,18 @@

class ShooterLogic(StateMachine):
"""StateMachine-based shooter. Has both manual and automatic modes."""

compatString = ["doof"]

# Component/module related things
shooterMotors: ShooterMotorCreation
feeder: FeederMap
logger: logging
sensors: Sensors
xboxMap: XboxMap
speedTolerance = tunable(50)

controllers: dict

# Tunables
shootingLoaderSpeed = tunable(.4)
autoShootingSpeed = tunable(4800)
Expand All @@ -32,6 +33,8 @@ def on_enable(self):
self.isAutonomous = False
self.isSetup = True

self.mech = self.controllers['mech'].controller

def autonomousEnabled(self):
"""Indicates if the robot is in autonomous mode."""
self.isAutonomous = True
Expand Down Expand Up @@ -64,8 +67,8 @@ def isShooterUpToSpeed(self):
rumble = 0
if atSpeed and not self.isAutonomous:
rumble = .3
self.xboxMap.mech.setRumble(self.xboxMap.mech.RumbleType.kLeftRumble, rumble)
self.xboxMap.mech.setRumble(self.xboxMap.mech.RumbleType.kRightRumble, rumble)
self.mech.setRumble(self.mech.RumbleType.kLeftRumble, rumble)
self.mech.setRumble(self.mech.RumbleType.kRightRumble, rumble)
return atSpeed

@state
Expand Down
1 change: 1 addition & 0 deletions components/shooterMotors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ShooterMotorCreation:
"""
Allows you to run motors in the shooter
"""

compatString = ["doof"]

logger: logging
Expand Down
11 changes: 11 additions & 0 deletions components/winch.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@

class Winch:

compatString = ["doof"]

motors_winch: dict

controllers: dict

def on_enable(self):
"""
Sets up the winch
"""
self.upSpeed = 0
self.winchMotor = self.motors_winch["winchMotor"]
self.mech = self.controllers['mech']

self.logger.info("Lifter Component Created")

Expand All @@ -25,4 +30,10 @@ def stop(self):
self.upSpeed = 0

def execute(self):

if self.mech.pov == 0:
self.setRaise()
else:
self.stop()

self.winchMotor.set(self.upSpeed)
1 change: 0 additions & 1 deletion configs/default

This file was deleted.

Loading