Skip to content
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

Add Maple-Sim #251

Merged
merged 14 commits into from
Nov 29, 2024
Merged

Conversation

thenetworkgrinch
Copy link
Contributor

No description provided.

@thenetworkgrinch
Copy link
Contributor Author

I made this PR mainly for an easy feedback for the integration and comparison between current implementation and desired one.

Copy link
Contributor Author

@thenetworkgrinch thenetworkgrinch left a comment

Choose a reason for hiding this comment

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

Thank you for your work on this!

build.gradle Outdated
@@ -100,3 +100,7 @@ wpi.java.configureTestTasks(test)
tasks.withType(JavaCompile) {
options.compilerArgs.add '-XDstringConcat=inline'
}

repositories {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be removed when you're done testing after you've released the latest version of maple sim that works with YAGSL

Choose a reason for hiding this comment

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

yes ur right, that was the plan

src/main/java/frc/robot/RobotContainer.java Show resolved Hide resolved
src/main/java/frc/robot/subsystems/swervedrive/Vision.java Outdated Show resolved Hide resolved
src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
@@ -31,6 +29,8 @@
import java.util.Optional;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import frc.robot.Robot;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

User code should never be imported

Choose a reason for hiding this comment

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

my problem, was trying to use TimedRobot.kDefaultPeriod

src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
@@ -366,7 +366,7 @@ public void setAnglePIDF(PIDFConfig config)
*/
public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop, boolean force)
{
desiredState = SwerveModuleState.optimize(desiredState, Rotation2d.fromDegrees(getAbsolutePosition()));
desiredState = SwerveModuleState.optimize(desiredState, getState().angle);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

getState() is slower than getAbsolutePosition

Choose a reason for hiding this comment

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

this is a little strange

so no doubt your code works on real robot

but in sim (since there are no absolute encoders), the getAbsolutePosition() always return 0, so the state optimization is jittering.

So I think it's better to have a if-else statement to let it use different functions during sim and real

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes total sense, the absolute encoder is fetch is wrapped in a Cache so you could make it reference the maplesim absolute encoder in the constructor instead of the real one.

Choose a reason for hiding this comment

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

Great suggestion, I'll do that

src/main/java/swervelib/SwerveModule.java Show resolved Hide resolved
{
Rotation2d absolutePosition = simModule.getState().angle;
/* The Rotation2d.minus() function wraps the angle to the [0, 360) range. */
return absolutePosition.minus(new Rotation2d()).getDegrees();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an unnecessary memory allocation, i get the need for it but this should be handled in maple-sim or do algorithmic only.

Choose a reason for hiding this comment

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

NP, I'll have the SwerveModuleSimulation return a wrapped Rotation2d

return new SwerveModulePosition(fakePos, state.angle);
if (mapleSimModule.isPresent())
{
return new SwerveModulePosition(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should REALLY be embedded into maple-sim

Choose a reason for hiding this comment

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

Yeah I know, it's stupid to keep checking if it present.

I'll figure out a smarter way to do this.

removed redundant optional sim modules

moved swerve state angle wrap into module simulation
@catr1xLiu
Copy link

the issues mentioned in the code review is fixed here

src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
simgui-ds.json Outdated
@@ -98,7 +98,7 @@
],
"robotJoysticks": [
{
"guid": "Keyboard0"
"guid": "030000004c050000e60c000000000000"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please revert this

Choose a reason for hiding this comment

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

My bad, I was using a joystick instead of the keyboard to test.

src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
src/main/java/swervelib/SwerveDrive.java Show resolved Hide resolved
@thenetworkgrinch thenetworkgrinch merged commit 59806b1 into BroncBotz3481:beta Nov 29, 2024
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.

2 participants