mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
[python] Fixup python examples / build (#2509)
## Description This fixes up and renables the python examples builds. Main fixes - Test shell script just straight up didn't do what it was intended to do - Replace analog imus (and half refactored sims) with OnboardIMU - Fixes swerve velocities function signature - "regenerates" the default robotpy test ## Meta Merge checklist: - [x] Pull Request title is [short, imperative summary](https://cbea.ms/git-commit/) of proposed changes - [x] The description documents the _what_ and _why_, including events that led to this PR - [ ] If this PR changes behavior or adds a feature, user documentation is updated - [ ] If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly - [ ] If this PR touches configuration, this is backwards compatible with all settings going back to the previous seasons's last release (seasons end after champs ends) - [ ] If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated - [ ] If this PR addresses a bug, a regression test for it is added - [ ] If this PR adds a dependency, the license has been checked for compatibility and steps taken to follow it --------- Co-authored-by: Matt Morley <matthew.morley.ca@gmail.com> Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Speeds ###################################################################################
|
||||
###################################################################################
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) PhotonVision
|
||||
@@ -95,12 +95,16 @@ class SwerveModule:
|
||||
# Simulation Support
|
||||
self.simDriveEncoder = wpilib.simulation.EncoderSim(self.driveEncoder)
|
||||
self.simTurningEncoder = wpilib.simulation.EncoderSim(self.turningEncoder)
|
||||
self.simDrivingMotor = wpilib.simulation.PWMSim(driveMotorChannel)
|
||||
self.simTurningMotor = wpilib.simulation.PWMSim(turningMotorChannel)
|
||||
self.simDrivingMotor = wpilib.simulation.PWMMotorControllerSim(
|
||||
driveMotorChannel
|
||||
)
|
||||
self.simTurningMotor = wpilib.simulation.PWMMotorControllerSim(
|
||||
turningMotorChannel
|
||||
)
|
||||
self.simDrivingMotorFilter = wpimath.LinearFilter.singlePoleIIR(0.1, 0.02)
|
||||
self.simTurningMotorFilter = wpimath.LinearFilter.singlePoleIIR(0.0001, 0.02)
|
||||
self.simTurningEncoderPos = 0
|
||||
self.simDrivingEncoderPos = 0
|
||||
self.simTurningEncoderPos = 0.0
|
||||
self.simDrivingEncoderPos = 0.0
|
||||
|
||||
def getVelocity(self) -> wpimath.SwerveModuleVelocity:
|
||||
"""Returns the current state of the module.
|
||||
@@ -155,6 +159,10 @@ class SwerveModule:
|
||||
self.turningEncoder.getDistance(), self.desiredVelocity.angle.radians()
|
||||
)
|
||||
|
||||
turnFeedforward = self.turnFeedforward.calculate(
|
||||
self.turningPIDController.getSetpoint()
|
||||
)
|
||||
|
||||
self.driveMotor.setVoltage(driveOutput + driveFeedforward)
|
||||
self.turningMotor.setVoltage(turnOutput + turnFeedforward)
|
||||
|
||||
@@ -188,10 +196,12 @@ class SwerveModule:
|
||||
|
||||
def simulationPeriodic(self) -> None:
|
||||
driveVoltage = (
|
||||
self.simDrivingMotor.getSpeed() * wpilib.RobotController.getBatteryVoltage()
|
||||
self.simDrivingMotor.getThrottle()
|
||||
* wpilib.RobotController.getBatteryVoltage()
|
||||
)
|
||||
turnVoltage = (
|
||||
self.simTurningMotor.getSpeed() * wpilib.RobotController.getBatteryVoltage()
|
||||
self.simTurningMotor.getThrottle()
|
||||
* wpilib.RobotController.getBatteryVoltage()
|
||||
)
|
||||
driveSpdRaw = (
|
||||
driveVoltage / 12.0 * self.driveFeedforward.maxAchievableVelocity(12.0, 0)
|
||||
|
||||
Reference in New Issue
Block a user