Skip to content

2025 - draft #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

2025 - draft #107

wants to merge 28 commits into from

Conversation

FriedLongJohns
Copy link
Contributor

@brettle pls review
also @CoolSpy3 thanks!!

sobbing
sim is still broken
tests are still broken
also I probably broke some functionality somewhere
@FriedLongJohns FriedLongJohns requested a review from a team as a code owner January 15, 2025 01:16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional work probably has to be done here to make sure all types/methods are covered. At a glance, I don't see Faults implemented, but there are probably others. Given all the other changes, it's probably also worthwhile to see if Rev's fixed the crash when controller doesn't exist bug so we can get rid of this class too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can I test this?
as far as I know, sim motors are automatically given controllers and I'm not sure how to remove them.

...or do I have to run the robot and rip out the wires while it's running?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basic test procedure is:

  1. Unplug all Spark Max/Flex devices from the test board
  2. Write some code that attempts to drive a Spark Max/Flex
  3. Deploy and Run

In the past, this caused the code to crash, which is why we created this class. Hopefully, they've fixed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: it appears to work without crash!
Unsure what I'd need to modify to remove this class, however. I'll take a look at it.

Comment on lines +140 to +141
System.err.println("heyy... lib199 doesn't have sim support sorri");
// spark = MockSparkMax.createMockSparkMax(id, SparkLowLevel.MotorType.kBrushless);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that this will probably cause the calling code to throw a NullPointerException if run in sim. It might make more sense to print this warning and still initialize the spar normally. This applies to the other methods as well.

sofiebudman and others added 8 commits February 7, 2025 17:30
1. duplicatestrategy to fail
2. no more CachedSparkMax
2. motorcontrollerfactory now configures sparks!!
3. motorErrors checks for null faults
4. swap from smartMotion to MAXmotion in mockedsparkmaxpidcontroller.java
5. cleaner builder pid configs in sparkvelocitypidcontroller.java
6. change from deprecated calculate(double, double) to calculateWithVelocities() in swervemodule and don't persist configs
@FriedLongJohns
Copy link
Contributor Author

Sim support... is back, perhaps.
And SwerveModule gets its pos/vel conversion constants some love.

Copy link
Member

@CoolSpy3 CoolSpy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good! Still a couple of minor changes. Also you still have to address a few of the above comments 👍

You should also start looking into updating the tests (it looks like 90% of the bugs are just imports). Here's the official migration guide to get you started.


config.idleMode(IdleMode.kBrake);

config.voltageCompensation(12);//FIXME does this need to be different for different motors?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we always assume the nominal voltage is 12V.

}
private static SparkFlexConfig baseSparkFlexConfig(MotorConfig motorConfig){
//typical operating voltage: 12V. ( same as sparkMax )
return (SparkFlexConfig) baseSparkConfig(motorConfig);//criminal casting usage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment kind of sums this up, but to clarify, this will always throw a ClassCastException.

Comment on lines +140 to +142
//what does this even supposed to do??
public static SparkMax createDummySparkMax() {
return Mocks.mock(SparkMax.class, new REVLibErrorAnswer());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was used to create a mocked spark max class when no actual spark was connected (See DummySparkMaxAnswer.java. Now that that class is deleted, I think this can just be removed.

@@ -202,7 +215,10 @@ private static void reportSparkTemp(int port, CANSparkBase spark) {
System.err.println("Port " + port + " spark is operating at " + temp
+ " degrees Celsius! It will be disabled until the robot code is restarted.");
}
spark.setSmartCurrentLimit(1);
spark.configure(
new SparkMaxConfig().smartCurrentLimit(1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will lead to a lot of object allocations if anything overheats. I recommend just pulling this out to a static variable.

@@ -8,11 +8,15 @@

import org.mockito.internal.reporting.SmartPrinter;

import com.ctre.phoenix6.signals.AbsoluteSensorRangeValue;
// import com.ctre.phoenix6.signals.AbsoluteSensorRangeValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to keep stuff like this

Suggested change
// import com.ctre.phoenix6.signals.AbsoluteSensorRangeValue;

enum NEOType {
NEO(DCMotor.getNEO(1)),
NEO550(DCMotor.getNeo550(1)),
Vortex(DCMotor.getNeoVortex(1)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Vortex(DCMotor.getNeoVortex(1)),
VORTEX(DCMotor.getNeoVortex(1)),

* @param countsPerRev the number of counts per revolution of this controller's built-in encoder.
*/
public MockSparkBase(int port, MotorType type, String name, int countsPerRev) {
public MockSparkBase(int port, MotorType type, String name, int countsPerRev, NEOType neoType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neoType should have an @param tag.

Comment on lines +82 to +95
if (neoType != NEOType.Vortex){ //WARNING can't initialize a sparkbase without an actual spark...
this.motor = new SparkMax(port,type);
this.spark = new SparkSim(
this.motor,
neoType.dcMotor
);
} else { //only vortex uses sparkflex
this.motor = new SparkFlex(port,type);
this.spark = new SparkSim(
this.motor,
neoType.dcMotor
);
}

Copy link
Member

@CoolSpy3 CoolSpy3 Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this if condition is backwards

Copy link
Member

@CoolSpy3 CoolSpy3 Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I misread the above :P This is fine, I might swap the blocks and use == though so others don't make the same misreading.

Comment on lines +232 to +235
//simply drop all references for garbage collection (?)
absoluteEncoderImpl=null;
analogSensorImpl=null;
alternateEncoder=null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we have to call the close methods so that the objects can cleanup their internal state before being destroyed. Garbage collection just wipes them.

Say what you will about C++, destructors are useful.

Comment on lines +48 to +52
private SparkAbsoluteEncoderSim absoluteEncoderImpl = null;
private SparkMaxAlternateEncoder alternateEncoder = null;
private SparkMaxAlternateEncoderSim alternateEncoderImpl = null;
private SparkAnalogSensor analogSensor = null;
private MockedEncoder analogSensorImpl = null;
private SparkAnalogSensorSim analogSensorImpl = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother swapping these for the sim classes. I agree that those are the right classes for interfacing with the new stuff, but here, they're being used as mock implementations for the classes, and they aren't designed for that.

@CoolSpy3 CoolSpy3 mentioned this pull request Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants