-
Notifications
You must be signed in to change notification settings - Fork 146
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
Add Maple-Sim #251
Conversation
I made this PR mainly for an easy feedback for the integration and comparison between current implementation and desired one. |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -31,6 +29,8 @@ | |||
import java.util.Optional; | |||
import java.util.concurrent.locks.Lock; | |||
import java.util.concurrent.locks.ReentrantLock; | |||
|
|||
import frc.robot.Robot; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
{ | ||
Rotation2d absolutePosition = simModule.getState().angle; | ||
/* The Rotation2d.minus() function wraps the angle to the [0, 360) range. */ | ||
return absolutePosition.minus(new Rotation2d()).getDegrees(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
the issues mentioned in the code review is fixed here |
This reverts commit 7e3ca88.
maple-sim is thread safe now, so we're free to push the simulation rate up for a smoother simulation
and it's all ready!
simgui-ds.json
Outdated
@@ -98,7 +98,7 @@ | |||
], | |||
"robotJoysticks": [ | |||
{ | |||
"guid": "Keyboard0" | |||
"guid": "030000004c050000e60c000000000000" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this
There was a problem hiding this comment.
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.
No description provided.