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

Added slew rate limiter to drive controls #174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Gold872
Copy link
Member

@Gold872 Gold872 commented Oct 9, 2024

  • Adds slew rate limiter (acceleration limiter) to drive
  • Invert right input on bar chart in the drive page

lib/src/models/rover/controls/modern_drive.dart Outdated Show resolved Hide resolved
lib/src/data/settings.dart Outdated Show resolved Hide resolved
Comment on lines +22 to +24
final currentTime = DateTime.now();
final elapsedSeconds = (currentTime.microsecondsSinceEpoch / 1e6) -
(_previousTime.microsecondsSinceEpoch / 1e6);
Copy link
Member

@Levi-Lesches Levi-Lesches Nov 5, 2024

Choose a reason for hiding this comment

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

Suggested change
final currentTime = DateTime.now();
final elapsedSeconds = (currentTime.microsecondsSinceEpoch / 1e6) -
(_previousTime.microsecondsSinceEpoch / 1e6);
final elapsedSeconds = DateTime.now().difference(_previousTime).inMilliseconds;

Copy link
Member Author

Choose a reason for hiding this comment

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

This wouldn't work, since this method would be called every 10 ms the output would always be 0

Copy link
Member

@Levi-Lesches Levi-Lesches Nov 5, 2024

Choose a reason for hiding this comment

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

Oh I just based it off the variable name, now I just changed it to inMilliseconds -- that should be the same as what you were doing already, right?

lib/src/models/rover/controls/slew_rate_limiter.dart Outdated Show resolved Hide resolved
lib/src/models/rover/controls/tank_drive.dart Show resolved Hide resolved
Comment on lines +43 to +50
List<Message> parseInputs(GamepadState state) {
final leftInput = state.normalLeftY;
final rightInput = -state.normalRightY;

return [
DriveCommand(throttle: throttle, setThrottle: true),
DriveCommand(setLeft: true, left: leftLimiter.calculate(leftInput)),
DriveCommand(setRight: true, right: rightLimiter.calculate(rightInput)),
Copy link
Member

Choose a reason for hiding this comment

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

You can probably remove the variables here to keep it shorter again. You can do -state.normalRightY instead of -1 * state.normalRightY though

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