data.telemetry
1# Internal imports 2from config import OperatorRobotConfig 3from subsystem.drivetrain.swerve_drivetrain import SwerveDrivetrain 4from subsystem.intakeactions import IntakeSubsystem 5 6# Third-party imports 7import wpilib 8from ntcore import NetworkTableInstance 9from wpimath.geometry import Pose2d, Rotation2d 10from wpimath.kinematics import ChassisSpeeds, SwerveModuleState 11from wpiutil.log import BooleanLogEntry, StringLogEntry, FloatLogEntry, IntegerLogEntry 12 13telemetryButtonEntries = [ 14 ["AButton", BooleanLogEntry, "/button/letter/a"], 15 ["BButton", BooleanLogEntry, "/button/letter/b"], 16 ["XButton", BooleanLogEntry, "/button/letter/x"], 17 ["YButton", BooleanLogEntry, "/button/letter/y"], 18 ["BackButton", BooleanLogEntry, "/button/front/back"], 19 ["StartButton", BooleanLogEntry, "/button/front/start"], 20 ["LeftBumper", BooleanLogEntry, "/button/bumper/left"], 21 ["RightBumper", BooleanLogEntry, "/button/bumper/right"], 22 ["LeftStickButton", BooleanLogEntry, "button/stickbutton/left"], 23 ["RightStickButton", BooleanLogEntry, "button/stickbutton/right"], 24 ["RightTrigger", FloatLogEntry, "button/trigger/right"], 25 ["LeftTrigger", FloatLogEntry, "button/trigger/left"], 26 ["JoystickLeftY", FloatLogEntry, "button/joystick/lefty"], 27 ["JoystickLeftX", FloatLogEntry, "button/joystick/leftx"], 28 ["JoystickRightY", FloatLogEntry, "button/joystick/righty"], 29 ["JoystickRightX", FloatLogEntry, "button/joystick/rightx"], 30 ["DPad", IntegerLogEntry, "button/dpad"], 31] 32 33telemetryOdometryEntries = [ 34 ["robotPose", "robotpose"], 35 ["targetPose", "targetpose"], 36] 37 38telemetryFullSwerveDriveTrainEntries = [ 39 ["moduleStates", SwerveModuleState, True, "swervemodeulestates"], 40 ["drivetrainVelocity", ChassisSpeeds, False, "swervevelocity"], 41 ["drivetrainRotation", Rotation2d, False, "swerverotation"], 42] 43 44telemetryRawSwerveDriveTrainEntries = [] 45for i in range(len(OperatorRobotConfig.swerve_module_channels)): 46 telemetryRawSwerveDriveTrainEntries.extend( 47 [ 48 [f"steerDegree{i + 1}", FloatLogEntry, f"module{i + 1}/steerdegree"], 49 [f"drivePercent{i + 1}", FloatLogEntry, f"module{i + 1}/drivepercent"], 50 [f"moduleVelocity{i + 1}", FloatLogEntry, f"module{i + 1}/velocity"], 51 ] 52 ) 53 54driverStationEntries = [ 55 ["alliance", StringLogEntry, "alliance"], 56 ["autonomous", BooleanLogEntry, "autonomous"], 57 ["teleop", BooleanLogEntry, "teleop"], 58 ["test", BooleanLogEntry, "test"], 59 ["enabled", BooleanLogEntry, "enabled"], 60] 61 62intakeEntries = [ 63 # ["intakeSpeed", "intakespeed"], 64 ["rollerSpeed", "rollerspeed"], 65] 66 67class Telemetry: 68 69 def __init__( 70 self, 71 driverController: wpilib.XboxController = None, 72 mechController: wpilib.XboxController = None, 73 driveTrain: SwerveDrivetrain = None, 74 driverStation: wpilib.DriverStation = None, 75 intake: IntakeSubsystem = None 76 ): 77 self.driverController = driverController 78 self.mechController = mechController 79 self.odometryPosition = driveTrain.pose_estimator 80 self.driveTrain = driveTrain 81 self.swerveModules = driveTrain.swerve_modules 82 self.driverStation = driverStation 83 self.intake = intake 84 85 self.networkTable = NetworkTableInstance.getDefault() 86 for entryname, logname in telemetryOdometryEntries: 87 setattr( 88 self, 89 entryname, 90 self.networkTable.getStructTopic( 91 "odometry/" + logname, Pose2d 92 ).publish(), 93 ) 94 for ( 95 entryname, 96 entrytype, 97 isarraytype, 98 logname, 99 ) in telemetryFullSwerveDriveTrainEntries: 100 if isarraytype: 101 setattr( 102 self, 103 entryname, 104 self.networkTable.getStructArrayTopic( 105 "swervedrivetrain/" + logname, entrytype 106 ).publish(), 107 ) 108 else: 109 setattr( 110 self, 111 entryname, 112 self.networkTable.getStructTopic( 113 "swervedrivetrain/" + logname, entrytype 114 ).publish(), 115 ) 116 for entryname, logname in intakeEntries: 117 setattr( 118 self, 119 entryname, 120 self.networkTable.getStructTopic( 121 "intake/" + logname, entrytype 122 ).publish(), 123 ) 124 125 self.datalog = wpilib.DataLogManager.getLog() 126 for entryname, entrytype, logname in telemetryButtonEntries: 127 setattr( 128 self, "driver" + entryname, entrytype(self.datalog, "driver/" + logname) 129 ) 130 setattr( 131 self, "mech" + entryname, entrytype(self.datalog, "mech/" + logname) 132 ) 133 for entryname, entrytype, logname in telemetryRawSwerveDriveTrainEntries: 134 setattr( 135 self, 136 entryname, 137 entrytype(self.datalog, "rawswervedrivetrain/" + logname), 138 ) 139 for entryname, entrytype, logname in driverStationEntries: 140 setattr( 141 self, entryname, entrytype(self.datalog, "driverstation/" + logname) 142 ) 143 144 if self.driverStation: 145 self.driverStation.startDataLog(self.datalog) 146 147 def getDriverControllerInputs(self): 148 """ 149 Records data for buttons and axis inputs for the first controller 150 """ 151 if self.driverController is not None: 152 self.driverAButton.append(self.driverController.getAButton()) # bool 153 self.driverBButton.append(self.driverController.getBButton()) # bool 154 self.driverXButton.append(self.driverController.getXButton()) # bool 155 self.driverYButton.append(self.driverController.getYButton()) # bool 156 self.driverBackButton.append( 157 self.driverController.getBackButton() 158 ) # left side , bool 159 self.driverStartButton.append( 160 self.driverController.getStartButton() 161 ) # right side , bool 162 self.driverLeftBumper.append(self.driverController.getLeftBumper()) # bool 163 self.driverRightBumper.append(self.driverController.getRightBumper()) # bool 164 self.driverLeftStickButton.append( 165 self.driverController.getLeftStickButton() 166 ) # bool 167 self.driverRightStickButton.append( 168 self.driverController.getRightStickButton() 169 ) # bool 170 self.driverLeftTrigger.append( 171 self.driverController.getLeftTriggerAxis() 172 ) # float 0-1 173 self.driverRightTrigger.append( 174 self.driverController.getRightTriggerAxis() 175 ) # float 0-1 176 self.driverJoystickLeftY.append(self.driverController.getLeftY()) # float -1-1 177 self.driverJoystickLeftX.append(self.driverController.getLeftX()) # float -1-1 178 self.driverJoystickRightY.append( 179 self.driverController.getRightY() 180 ) # float -1-1 181 self.driverJoystickRightX.append( 182 self.driverController.getRightX() 183 ) # float -1-1 184 self.driverDPad.append(self.driverController.getPOV()) # ints 185 186 def getMechControllerInputs(self): 187 """ 188 Records data for buttons and axis inputs for the second controller 189 """ 190 if self.mechController is not None: 191 self.mechAButton.append(self.mechController.getAButton()) # bool 192 self.mechBButton.append(self.mechController.getBButton()) # bool 193 self.mechXButton.append(self.mechController.getXButton()) # bool 194 self.mechYButton.append(self.mechController.getYButton()) # bool 195 self.mechBackButton.append( 196 self.mechController.getBackButton() 197 ) # left side , bool 198 self.mechStartButton.append( 199 self.mechController.getStartButton() 200 ) # right side , bool 201 self.mechLeftBumper.append(self.mechController.getLeftBumper()) # bool 202 self.mechRightBumper.append(self.mechController.getRightBumper()) # bool 203 self.mechLeftStickButton.append( 204 self.mechController.getLeftStickButton() 205 ) # bool 206 self.mechRightStickButton.append( 207 self.mechController.getRightStickButton() 208 ) # bool 209 self.mechLeftTrigger.append( 210 self.mechController.getLeftTriggerAxis() 211 ) # float 0-1 212 self.mechRightTrigger.append( 213 self.mechController.getRightTriggerAxis() 214 ) # float 0-1 215 self.mechJoystickLeftY.append(self.mechController.getLeftY()) # float -1-1 216 self.mechJoystickLeftX.append(self.mechController.getLeftX()) # float -1-1 217 self.mechJoystickRightY.append(self.mechController.getRightY()) # float -1-1 218 self.mechJoystickRightX.append(self.mechController.getRightX()) # float -1-1 219 self.mechDPad.append(self.mechController.getPOV()) # ints 220 221 def getOdometryInputs(self): 222 """ 223 Records the data for the positions of the bot in a field, 224 Gives the x position, y position and rotation 225 """ 226 if self.odometryPosition is not None: 227 pose = self.odometryPosition.getEstimatedPosition() 228 self.robotPose.set(pose) 229 230 def getFullSwerveState(self): 231 """ 232 Retrieves values reflecting the current state of the swerve drive 233 """ 234 if self.driveTrain and self.swerveModules: 235 self.moduleStates.set( 236 [swerveModule.current_state() for swerveModule in self.swerveModules] 237 ) 238 self.drivetrainVelocity.set(self.driveTrain.current_robot_relative_speed()) 239 self.drivetrainRotation.set(self.driveTrain.current_yaw()) 240 241 def getRawSwerveInputs(self): 242 """ 243 Gets the inputs for some swerve drive train inputs 244 it get the steer angle, the drive percent and the velocity 245 """ 246 if self.swerveModules is not None: 247 for i, swerveModule in enumerate(self.swerveModules): 248 getattr(self, f"steerDegree{i + 1}").append( 249 swerveModule.current_raw_absolute_steer_position() 250 ) 251 getattr(self, f"drivePercent{i + 1}").append( 252 swerveModule.drive_motor.getAppliedOutput() 253 ) 254 getattr(self, f"moduleVelocity{i + 1}").append( 255 swerveModule.current_state().speed 256 ) 257 258 def getDriverStationInputs(self): 259 """ 260 Gets the inputs of some match/general robot things, 261 the things being: Alliance color and what mode it is in and 262 if it is enabled 263 """ 264 if self.driverStation is not None: 265 alliance = "No Alliance" 266 if self.driverStation.getAlliance() == wpilib.DriverStation.Alliance.kBlue: 267 alliance = "Blue" 268 if self.driverStation.getAlliance() == wpilib.DriverStation.Alliance.kRed: 269 alliance = "Red" 270 self.alliance.append(alliance) 271 self.autonomous.append(self.driverStation.isAutonomous()) 272 self.teleop.append(self.driverStation.isTeleop()) 273 self.test.append(self.driverStation.isTest()) 274 self.enabled.append(self.driverStation.isEnabled()) 275 276 def getIntakeInputs(self): 277 if self.intake is not None: 278 # self.intake.intakeVelocity = self.intakeSpeed.getEntry(getattr(self, "intakeSpeed")) 279 self.intake.rollerVelocity = self.rollerSpeed.getEntry(getattr(self, "rollerSpeed")) 280 281 282 def runDefaultDataCollections(self): 283 self.getDriverControllerInputs() 284 self.getMechControllerInputs() 285 self.getOdometryInputs() 286 self.getFullSwerveState() 287 self.getRawSwerveInputs() 288 self.getIntakeInputs() 289 self.getDriverStationInputs() 290 291 def logAdditionalOdometry( 292 self, odometer_value: Pose2d, log_entry_name: str 293 ) -> None: 294 getattr(self, log_entry_name).set(odometer_value)
telemetryButtonEntries =
[['AButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/letter/a'], ['BButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/letter/b'], ['XButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/letter/x'], ['YButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/letter/y'], ['BackButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/front/back'], ['StartButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/front/start'], ['LeftBumper', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/bumper/left'], ['RightBumper', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, '/button/bumper/right'], ['LeftStickButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, 'button/stickbutton/left'], ['RightStickButton', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, 'button/stickbutton/right'], ['RightTrigger', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'button/trigger/right'], ['LeftTrigger', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'button/trigger/left'], ['JoystickLeftY', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'button/joystick/lefty'], ['JoystickLeftX', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'button/joystick/leftx'], ['JoystickRightY', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'button/joystick/righty'], ['JoystickRightX', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'button/joystick/rightx'], ['DPad', <class 'wpiutil._wpiutil.log.IntegerLogEntry'>, 'button/dpad']]
telemetryOdometryEntries =
[['robotPose', 'robotpose'], ['targetPose', 'targetpose']]
telemetryFullSwerveDriveTrainEntries =
[['moduleStates', <class 'wpimath.kinematics._kinematics.SwerveModuleState'>, True, 'swervemodeulestates'], ['drivetrainVelocity', <class 'wpimath.kinematics._kinematics.ChassisSpeeds'>, False, 'swervevelocity'], ['drivetrainRotation', <class 'wpimath.geometry._geometry.Rotation2d'>, False, 'swerverotation']]
telemetryRawSwerveDriveTrainEntries =
[['steerDegree1', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module1/steerdegree'], ['drivePercent1', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module1/drivepercent'], ['moduleVelocity1', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module1/velocity'], ['steerDegree2', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module2/steerdegree'], ['drivePercent2', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module2/drivepercent'], ['moduleVelocity2', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module2/velocity'], ['steerDegree3', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module3/steerdegree'], ['drivePercent3', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module3/drivepercent'], ['moduleVelocity3', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module3/velocity'], ['steerDegree4', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module4/steerdegree'], ['drivePercent4', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module4/drivepercent'], ['moduleVelocity4', <class 'wpiutil._wpiutil.log.FloatLogEntry'>, 'module4/velocity']]
driverStationEntries =
[['alliance', <class 'wpiutil._wpiutil.log.StringLogEntry'>, 'alliance'], ['autonomous', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, 'autonomous'], ['teleop', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, 'teleop'], ['test', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, 'test'], ['enabled', <class 'wpiutil._wpiutil.log.BooleanLogEntry'>, 'enabled']]
intakeEntries =
[['rollerSpeed', 'rollerspeed']]
class
Telemetry:
68class Telemetry: 69 70 def __init__( 71 self, 72 driverController: wpilib.XboxController = None, 73 mechController: wpilib.XboxController = None, 74 driveTrain: SwerveDrivetrain = None, 75 driverStation: wpilib.DriverStation = None, 76 intake: IntakeSubsystem = None 77 ): 78 self.driverController = driverController 79 self.mechController = mechController 80 self.odometryPosition = driveTrain.pose_estimator 81 self.driveTrain = driveTrain 82 self.swerveModules = driveTrain.swerve_modules 83 self.driverStation = driverStation 84 self.intake = intake 85 86 self.networkTable = NetworkTableInstance.getDefault() 87 for entryname, logname in telemetryOdometryEntries: 88 setattr( 89 self, 90 entryname, 91 self.networkTable.getStructTopic( 92 "odometry/" + logname, Pose2d 93 ).publish(), 94 ) 95 for ( 96 entryname, 97 entrytype, 98 isarraytype, 99 logname, 100 ) in telemetryFullSwerveDriveTrainEntries: 101 if isarraytype: 102 setattr( 103 self, 104 entryname, 105 self.networkTable.getStructArrayTopic( 106 "swervedrivetrain/" + logname, entrytype 107 ).publish(), 108 ) 109 else: 110 setattr( 111 self, 112 entryname, 113 self.networkTable.getStructTopic( 114 "swervedrivetrain/" + logname, entrytype 115 ).publish(), 116 ) 117 for entryname, logname in intakeEntries: 118 setattr( 119 self, 120 entryname, 121 self.networkTable.getStructTopic( 122 "intake/" + logname, entrytype 123 ).publish(), 124 ) 125 126 self.datalog = wpilib.DataLogManager.getLog() 127 for entryname, entrytype, logname in telemetryButtonEntries: 128 setattr( 129 self, "driver" + entryname, entrytype(self.datalog, "driver/" + logname) 130 ) 131 setattr( 132 self, "mech" + entryname, entrytype(self.datalog, "mech/" + logname) 133 ) 134 for entryname, entrytype, logname in telemetryRawSwerveDriveTrainEntries: 135 setattr( 136 self, 137 entryname, 138 entrytype(self.datalog, "rawswervedrivetrain/" + logname), 139 ) 140 for entryname, entrytype, logname in driverStationEntries: 141 setattr( 142 self, entryname, entrytype(self.datalog, "driverstation/" + logname) 143 ) 144 145 if self.driverStation: 146 self.driverStation.startDataLog(self.datalog) 147 148 def getDriverControllerInputs(self): 149 """ 150 Records data for buttons and axis inputs for the first controller 151 """ 152 if self.driverController is not None: 153 self.driverAButton.append(self.driverController.getAButton()) # bool 154 self.driverBButton.append(self.driverController.getBButton()) # bool 155 self.driverXButton.append(self.driverController.getXButton()) # bool 156 self.driverYButton.append(self.driverController.getYButton()) # bool 157 self.driverBackButton.append( 158 self.driverController.getBackButton() 159 ) # left side , bool 160 self.driverStartButton.append( 161 self.driverController.getStartButton() 162 ) # right side , bool 163 self.driverLeftBumper.append(self.driverController.getLeftBumper()) # bool 164 self.driverRightBumper.append(self.driverController.getRightBumper()) # bool 165 self.driverLeftStickButton.append( 166 self.driverController.getLeftStickButton() 167 ) # bool 168 self.driverRightStickButton.append( 169 self.driverController.getRightStickButton() 170 ) # bool 171 self.driverLeftTrigger.append( 172 self.driverController.getLeftTriggerAxis() 173 ) # float 0-1 174 self.driverRightTrigger.append( 175 self.driverController.getRightTriggerAxis() 176 ) # float 0-1 177 self.driverJoystickLeftY.append(self.driverController.getLeftY()) # float -1-1 178 self.driverJoystickLeftX.append(self.driverController.getLeftX()) # float -1-1 179 self.driverJoystickRightY.append( 180 self.driverController.getRightY() 181 ) # float -1-1 182 self.driverJoystickRightX.append( 183 self.driverController.getRightX() 184 ) # float -1-1 185 self.driverDPad.append(self.driverController.getPOV()) # ints 186 187 def getMechControllerInputs(self): 188 """ 189 Records data for buttons and axis inputs for the second controller 190 """ 191 if self.mechController is not None: 192 self.mechAButton.append(self.mechController.getAButton()) # bool 193 self.mechBButton.append(self.mechController.getBButton()) # bool 194 self.mechXButton.append(self.mechController.getXButton()) # bool 195 self.mechYButton.append(self.mechController.getYButton()) # bool 196 self.mechBackButton.append( 197 self.mechController.getBackButton() 198 ) # left side , bool 199 self.mechStartButton.append( 200 self.mechController.getStartButton() 201 ) # right side , bool 202 self.mechLeftBumper.append(self.mechController.getLeftBumper()) # bool 203 self.mechRightBumper.append(self.mechController.getRightBumper()) # bool 204 self.mechLeftStickButton.append( 205 self.mechController.getLeftStickButton() 206 ) # bool 207 self.mechRightStickButton.append( 208 self.mechController.getRightStickButton() 209 ) # bool 210 self.mechLeftTrigger.append( 211 self.mechController.getLeftTriggerAxis() 212 ) # float 0-1 213 self.mechRightTrigger.append( 214 self.mechController.getRightTriggerAxis() 215 ) # float 0-1 216 self.mechJoystickLeftY.append(self.mechController.getLeftY()) # float -1-1 217 self.mechJoystickLeftX.append(self.mechController.getLeftX()) # float -1-1 218 self.mechJoystickRightY.append(self.mechController.getRightY()) # float -1-1 219 self.mechJoystickRightX.append(self.mechController.getRightX()) # float -1-1 220 self.mechDPad.append(self.mechController.getPOV()) # ints 221 222 def getOdometryInputs(self): 223 """ 224 Records the data for the positions of the bot in a field, 225 Gives the x position, y position and rotation 226 """ 227 if self.odometryPosition is not None: 228 pose = self.odometryPosition.getEstimatedPosition() 229 self.robotPose.set(pose) 230 231 def getFullSwerveState(self): 232 """ 233 Retrieves values reflecting the current state of the swerve drive 234 """ 235 if self.driveTrain and self.swerveModules: 236 self.moduleStates.set( 237 [swerveModule.current_state() for swerveModule in self.swerveModules] 238 ) 239 self.drivetrainVelocity.set(self.driveTrain.current_robot_relative_speed()) 240 self.drivetrainRotation.set(self.driveTrain.current_yaw()) 241 242 def getRawSwerveInputs(self): 243 """ 244 Gets the inputs for some swerve drive train inputs 245 it get the steer angle, the drive percent and the velocity 246 """ 247 if self.swerveModules is not None: 248 for i, swerveModule in enumerate(self.swerveModules): 249 getattr(self, f"steerDegree{i + 1}").append( 250 swerveModule.current_raw_absolute_steer_position() 251 ) 252 getattr(self, f"drivePercent{i + 1}").append( 253 swerveModule.drive_motor.getAppliedOutput() 254 ) 255 getattr(self, f"moduleVelocity{i + 1}").append( 256 swerveModule.current_state().speed 257 ) 258 259 def getDriverStationInputs(self): 260 """ 261 Gets the inputs of some match/general robot things, 262 the things being: Alliance color and what mode it is in and 263 if it is enabled 264 """ 265 if self.driverStation is not None: 266 alliance = "No Alliance" 267 if self.driverStation.getAlliance() == wpilib.DriverStation.Alliance.kBlue: 268 alliance = "Blue" 269 if self.driverStation.getAlliance() == wpilib.DriverStation.Alliance.kRed: 270 alliance = "Red" 271 self.alliance.append(alliance) 272 self.autonomous.append(self.driverStation.isAutonomous()) 273 self.teleop.append(self.driverStation.isTeleop()) 274 self.test.append(self.driverStation.isTest()) 275 self.enabled.append(self.driverStation.isEnabled()) 276 277 def getIntakeInputs(self): 278 if self.intake is not None: 279 # self.intake.intakeVelocity = self.intakeSpeed.getEntry(getattr(self, "intakeSpeed")) 280 self.intake.rollerVelocity = self.rollerSpeed.getEntry(getattr(self, "rollerSpeed")) 281 282 283 def runDefaultDataCollections(self): 284 self.getDriverControllerInputs() 285 self.getMechControllerInputs() 286 self.getOdometryInputs() 287 self.getFullSwerveState() 288 self.getRawSwerveInputs() 289 self.getIntakeInputs() 290 self.getDriverStationInputs() 291 292 def logAdditionalOdometry( 293 self, odometer_value: Pose2d, log_entry_name: str 294 ) -> None: 295 getattr(self, log_entry_name).set(odometer_value)
Telemetry( driverController: wpilib._wpilib.XboxController = None, mechController: wpilib._wpilib.XboxController = None, driveTrain: subsystem.drivetrain.swerve_drivetrain.SwerveDrivetrain = None, driverStation: wpilib._wpilib.DriverStation = None, intake: subsystem.intakeactions.IntakeSubsystem = None)
70 def __init__( 71 self, 72 driverController: wpilib.XboxController = None, 73 mechController: wpilib.XboxController = None, 74 driveTrain: SwerveDrivetrain = None, 75 driverStation: wpilib.DriverStation = None, 76 intake: IntakeSubsystem = None 77 ): 78 self.driverController = driverController 79 self.mechController = mechController 80 self.odometryPosition = driveTrain.pose_estimator 81 self.driveTrain = driveTrain 82 self.swerveModules = driveTrain.swerve_modules 83 self.driverStation = driverStation 84 self.intake = intake 85 86 self.networkTable = NetworkTableInstance.getDefault() 87 for entryname, logname in telemetryOdometryEntries: 88 setattr( 89 self, 90 entryname, 91 self.networkTable.getStructTopic( 92 "odometry/" + logname, Pose2d 93 ).publish(), 94 ) 95 for ( 96 entryname, 97 entrytype, 98 isarraytype, 99 logname, 100 ) in telemetryFullSwerveDriveTrainEntries: 101 if isarraytype: 102 setattr( 103 self, 104 entryname, 105 self.networkTable.getStructArrayTopic( 106 "swervedrivetrain/" + logname, entrytype 107 ).publish(), 108 ) 109 else: 110 setattr( 111 self, 112 entryname, 113 self.networkTable.getStructTopic( 114 "swervedrivetrain/" + logname, entrytype 115 ).publish(), 116 ) 117 for entryname, logname in intakeEntries: 118 setattr( 119 self, 120 entryname, 121 self.networkTable.getStructTopic( 122 "intake/" + logname, entrytype 123 ).publish(), 124 ) 125 126 self.datalog = wpilib.DataLogManager.getLog() 127 for entryname, entrytype, logname in telemetryButtonEntries: 128 setattr( 129 self, "driver" + entryname, entrytype(self.datalog, "driver/" + logname) 130 ) 131 setattr( 132 self, "mech" + entryname, entrytype(self.datalog, "mech/" + logname) 133 ) 134 for entryname, entrytype, logname in telemetryRawSwerveDriveTrainEntries: 135 setattr( 136 self, 137 entryname, 138 entrytype(self.datalog, "rawswervedrivetrain/" + logname), 139 ) 140 for entryname, entrytype, logname in driverStationEntries: 141 setattr( 142 self, entryname, entrytype(self.datalog, "driverstation/" + logname) 143 ) 144 145 if self.driverStation: 146 self.driverStation.startDataLog(self.datalog)
def
getDriverControllerInputs(self):
148 def getDriverControllerInputs(self): 149 """ 150 Records data for buttons and axis inputs for the first controller 151 """ 152 if self.driverController is not None: 153 self.driverAButton.append(self.driverController.getAButton()) # bool 154 self.driverBButton.append(self.driverController.getBButton()) # bool 155 self.driverXButton.append(self.driverController.getXButton()) # bool 156 self.driverYButton.append(self.driverController.getYButton()) # bool 157 self.driverBackButton.append( 158 self.driverController.getBackButton() 159 ) # left side , bool 160 self.driverStartButton.append( 161 self.driverController.getStartButton() 162 ) # right side , bool 163 self.driverLeftBumper.append(self.driverController.getLeftBumper()) # bool 164 self.driverRightBumper.append(self.driverController.getRightBumper()) # bool 165 self.driverLeftStickButton.append( 166 self.driverController.getLeftStickButton() 167 ) # bool 168 self.driverRightStickButton.append( 169 self.driverController.getRightStickButton() 170 ) # bool 171 self.driverLeftTrigger.append( 172 self.driverController.getLeftTriggerAxis() 173 ) # float 0-1 174 self.driverRightTrigger.append( 175 self.driverController.getRightTriggerAxis() 176 ) # float 0-1 177 self.driverJoystickLeftY.append(self.driverController.getLeftY()) # float -1-1 178 self.driverJoystickLeftX.append(self.driverController.getLeftX()) # float -1-1 179 self.driverJoystickRightY.append( 180 self.driverController.getRightY() 181 ) # float -1-1 182 self.driverJoystickRightX.append( 183 self.driverController.getRightX() 184 ) # float -1-1 185 self.driverDPad.append(self.driverController.getPOV()) # ints
Records data for buttons and axis inputs for the first controller
def
getMechControllerInputs(self):
187 def getMechControllerInputs(self): 188 """ 189 Records data for buttons and axis inputs for the second controller 190 """ 191 if self.mechController is not None: 192 self.mechAButton.append(self.mechController.getAButton()) # bool 193 self.mechBButton.append(self.mechController.getBButton()) # bool 194 self.mechXButton.append(self.mechController.getXButton()) # bool 195 self.mechYButton.append(self.mechController.getYButton()) # bool 196 self.mechBackButton.append( 197 self.mechController.getBackButton() 198 ) # left side , bool 199 self.mechStartButton.append( 200 self.mechController.getStartButton() 201 ) # right side , bool 202 self.mechLeftBumper.append(self.mechController.getLeftBumper()) # bool 203 self.mechRightBumper.append(self.mechController.getRightBumper()) # bool 204 self.mechLeftStickButton.append( 205 self.mechController.getLeftStickButton() 206 ) # bool 207 self.mechRightStickButton.append( 208 self.mechController.getRightStickButton() 209 ) # bool 210 self.mechLeftTrigger.append( 211 self.mechController.getLeftTriggerAxis() 212 ) # float 0-1 213 self.mechRightTrigger.append( 214 self.mechController.getRightTriggerAxis() 215 ) # float 0-1 216 self.mechJoystickLeftY.append(self.mechController.getLeftY()) # float -1-1 217 self.mechJoystickLeftX.append(self.mechController.getLeftX()) # float -1-1 218 self.mechJoystickRightY.append(self.mechController.getRightY()) # float -1-1 219 self.mechJoystickRightX.append(self.mechController.getRightX()) # float -1-1 220 self.mechDPad.append(self.mechController.getPOV()) # ints
Records data for buttons and axis inputs for the second controller
def
getOdometryInputs(self):
222 def getOdometryInputs(self): 223 """ 224 Records the data for the positions of the bot in a field, 225 Gives the x position, y position and rotation 226 """ 227 if self.odometryPosition is not None: 228 pose = self.odometryPosition.getEstimatedPosition() 229 self.robotPose.set(pose)
Records the data for the positions of the bot in a field, Gives the x position, y position and rotation
def
getFullSwerveState(self):
231 def getFullSwerveState(self): 232 """ 233 Retrieves values reflecting the current state of the swerve drive 234 """ 235 if self.driveTrain and self.swerveModules: 236 self.moduleStates.set( 237 [swerveModule.current_state() for swerveModule in self.swerveModules] 238 ) 239 self.drivetrainVelocity.set(self.driveTrain.current_robot_relative_speed()) 240 self.drivetrainRotation.set(self.driveTrain.current_yaw())
Retrieves values reflecting the current state of the swerve drive
def
getRawSwerveInputs(self):
242 def getRawSwerveInputs(self): 243 """ 244 Gets the inputs for some swerve drive train inputs 245 it get the steer angle, the drive percent and the velocity 246 """ 247 if self.swerveModules is not None: 248 for i, swerveModule in enumerate(self.swerveModules): 249 getattr(self, f"steerDegree{i + 1}").append( 250 swerveModule.current_raw_absolute_steer_position() 251 ) 252 getattr(self, f"drivePercent{i + 1}").append( 253 swerveModule.drive_motor.getAppliedOutput() 254 ) 255 getattr(self, f"moduleVelocity{i + 1}").append( 256 swerveModule.current_state().speed 257 )
Gets the inputs for some swerve drive train inputs it get the steer angle, the drive percent and the velocity
def
getDriverStationInputs(self):
259 def getDriverStationInputs(self): 260 """ 261 Gets the inputs of some match/general robot things, 262 the things being: Alliance color and what mode it is in and 263 if it is enabled 264 """ 265 if self.driverStation is not None: 266 alliance = "No Alliance" 267 if self.driverStation.getAlliance() == wpilib.DriverStation.Alliance.kBlue: 268 alliance = "Blue" 269 if self.driverStation.getAlliance() == wpilib.DriverStation.Alliance.kRed: 270 alliance = "Red" 271 self.alliance.append(alliance) 272 self.autonomous.append(self.driverStation.isAutonomous()) 273 self.teleop.append(self.driverStation.isTeleop()) 274 self.test.append(self.driverStation.isTest()) 275 self.enabled.append(self.driverStation.isEnabled())
Gets the inputs of some match/general robot things, the things being: Alliance color and what mode it is in and if it is enabled