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

Refactor robot config to use individual module positions #904

Merged
merged 12 commits into from
Nov 11, 2024
Binary file added Writerside/images/app_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Writerside/images/robot_config_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Writerside/images/settings.png
Binary file not shown.
35 changes: 29 additions & 6 deletions Writerside/topics/Robot-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ are accurately limited for the performance of your robot. All of these values ha
robot, determining its maximum velocity, acceleration, etc. Therefore, you should take care to ensure that these options
are configured as accurately as possible.

<img src="robot_config_settings.png" alt="robot config" border-effect="rounded"/>

## Robot Config Options

Robot Mass
Expand Down Expand Up @@ -41,11 +43,26 @@ $$

However, this will likely lead to an inaccurate estimate as it assumes a uniform distribution of mass.

Wheelbase
: The distance between the front and back of the drivebase, in meters. Only relevant in holonomic mode.

Trackwidth
: The distance between the left and right sides of the drivebase, in meters.
: The distance between the left and right sides of the drivebase, in meters. Only available for non-holonomic robots.

## Bumper Config Options

The following options are only for visualization purposes in the PathPlanner GUI and are not used in PathPlannerLib.

Bumper Width
: The width of the robot's bumpers, in meters.

Bumper Length
: The length of the robot's bumpers, in meters.

Bumper Offset X
: How far the center of the bumpers are offset from the center of the robot along its X axis, in meters. Positive values
indicate the center of the bumpers is forward of the robot's center.

Bumper Offset Y
: How far the center of the bumpers are offset from the center of the robot along its Y axis, in meters. Positive values
indicate the center of the bumpers is left of the robot's center.

## Module Config Options

Expand All @@ -63,7 +80,8 @@ True Max Drive Speed
> **Note**
>
> It is very important that the True Max Drive Speed is measured for your actual robot. This value is not simply a "max
> velocity" limit on the robot. It encodes information about how much motor torque can actually be used to accelerate the
> velocity" limit on the robot. It encodes information about how much motor torque can actually be used to accelerate
> the
> robot.
>
> This can be easily measured by driving the robot in a straight line as fast as possible on a charged battery, and
Expand All @@ -84,4 +102,9 @@ Drive Motor
: The type of motor used to drive the wheels of the robot.

Drive Current Limit
: The supply current limit applied to the drive motor controllers, in Amps.
: The supply current limit applied to the drive motor controllers, in Amps.

## Module Offsets

The locations of each swerve module relative to the center of the robot, in meters. These should be the same offsets
used to create your kinematics in code. Only available for swerve drive robots.
30 changes: 15 additions & 15 deletions Writerside/topics/gui-Settings.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# Settings

The settings menu can be accessed via the [Navigation Menu](gui-Navigation-Menu.md)
The settings menu can be accessed via the [](gui-Navigation-Menu.md)

<img src="settings.png" alt="settings" border-effect="rounded"/>
## Robot Config

## Robot Config & Module Config
<img src="robot_config_settings.png" alt="robot config" border-effect="rounded"/>

Bumper Width
: The width of the robot, including bumpers, in meters. Used for visualization.
See [](Robot-Config.md) for Robot/Module Configuration options and how to find them.

Bumper Length
: The length of the robot, including bumpers, in meters. Used for visualization.
## App Settings

See [](Robot-Config.md) for Robot/Module Configuration options and how to find them.
<img src="app_settings.png" alt="robot config" border-effect="rounded"/>

## Default Constraints
### Default Constraints

These values will be used as the default global constraints when creating new paths. Updating these values will also
update the constraints of any paths set to use the defaults.
Expand All @@ -35,6 +33,10 @@ Max Angular Velocity
Max Angular Accel
: Max rotational acceleration in degrees per second squared.

Nominal Voltage
: Nominal voltage in Volts. This is what you expect the voltage to be during auto, which may be lower than 12V due to
other systems running, such as an intake or shooter.

## Field Image

Select the field image used as the background of the editor. This contains options for official field images and the
Expand All @@ -46,16 +48,14 @@ Change the UI theme color.

## PPLib Telemetry

Host
: The host address of the robot for use in telemetry and hot reload. If running simulation, this should be `localhost`.
If connected to a robot, this should be the IP address of the roboRIO: `10.TE.AM.2` where TEAM is replaced by your team
number, i.e. `10.30.15.2`.
roboRIO IP
: The IP address of the roboRIO, this should be `10.TE.AM.2` where TEAM is replaced by your team number, i.e.
`10.30.15.2`.

## Additional Options

Holonomic Mode
: Enable or disable holonomic mode. This is on by default. This must be enabled to access special features for holonomic
drive trains.
: Enable or disable holonomic mode.

Hot Reload
: Enable or disable hot reload for paths and autos. This is off by default. When connected to the robot, hot reload will
Expand Down
109 changes: 63 additions & 46 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@
Future<void> _loadProjectSettingsFromFile(Directory projectDir) async {
File settingsFile = fs.file(join(_pathplannerDir.path, _settingsDir));

var json = {};
var json = <String, dynamic>{};

Check warning on line 515 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L515

Added line #L515 was not covered by tests

if (await settingsFile.exists()) {
try {
Expand All @@ -524,10 +524,8 @@
}
}

widget.prefs.setDouble(PrefsKeys.robotWidth,
json[PrefsKeys.robotWidth]?.toDouble() ?? Defaults.robotWidth);
widget.prefs.setDouble(PrefsKeys.robotLength,
json[PrefsKeys.robotLength]?.toDouble() ?? Defaults.robotLength);
_setPrefDoubleFromJSON(json, PrefsKeys.robotWidth, Defaults.robotWidth);
_setPrefDoubleFromJSON(json, PrefsKeys.robotLength, Defaults.robotLength);

Check warning on line 528 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L527-L528

Added lines #L527 - L528 were not covered by tests
widget.prefs.setBool(PrefsKeys.holonomicMode,
json[PrefsKeys.holonomicMode] ?? Defaults.holonomicMode);
widget.prefs.setStringList(
Expand All @@ -542,46 +540,46 @@
?.map((e) => e as String)
.toList() ??
Defaults.autoFolders);
widget.prefs.setDouble(PrefsKeys.defaultMaxVel,
json[PrefsKeys.defaultMaxVel]?.toDouble() ?? Defaults.defaultMaxVel);
widget.prefs.setDouble(
PrefsKeys.defaultMaxAccel,
json[PrefsKeys.defaultMaxAccel]?.toDouble() ??
Defaults.defaultMaxAccel);
widget.prefs.setDouble(
PrefsKeys.defaultMaxAngVel,
json[PrefsKeys.defaultMaxAngVel]?.toDouble() ??
Defaults.defaultMaxAngVel);
widget.prefs.setDouble(
PrefsKeys.defaultMaxAngAccel,
json[PrefsKeys.defaultMaxAngAccel]?.toDouble() ??
Defaults.defaultMaxAngAccel);
widget.prefs.setDouble(PrefsKeys.robotMass,
json[PrefsKeys.robotMass]?.toDouble() ?? Defaults.robotMass);
widget.prefs.setDouble(PrefsKeys.robotMOI,
json[PrefsKeys.robotMOI]?.toDouble() ?? Defaults.robotMOI);
widget.prefs.setDouble(PrefsKeys.robotWheelbase,
json[PrefsKeys.robotWheelbase]?.toDouble() ?? Defaults.robotWheelbase);
widget.prefs.setDouble(
PrefsKeys.robotTrackwidth,
json[PrefsKeys.robotTrackwidth]?.toDouble() ??
Defaults.robotTrackwidth);
widget.prefs.setDouble(
PrefsKeys.driveWheelRadius,
json[PrefsKeys.driveWheelRadius]?.toDouble() ??
Defaults.driveWheelRadius);
widget.prefs.setDouble(PrefsKeys.driveGearing,
json[PrefsKeys.driveGearing]?.toDouble() ?? Defaults.driveGearing);
widget.prefs.setDouble(PrefsKeys.maxDriveSpeed,
json[PrefsKeys.maxDriveSpeed]?.toDouble() ?? Defaults.maxDriveSpeed);
_setPrefDoubleFromJSON(

Check warning on line 543 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L543

Added line #L543 was not covered by tests
json, PrefsKeys.defaultMaxVel, Defaults.defaultMaxVel);
_setPrefDoubleFromJSON(

Check warning on line 545 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L545

Added line #L545 was not covered by tests
json, PrefsKeys.defaultMaxAccel, Defaults.defaultMaxAccel);
_setPrefDoubleFromJSON(

Check warning on line 547 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L547

Added line #L547 was not covered by tests
json, PrefsKeys.defaultMaxAngVel, Defaults.defaultMaxAngVel);
_setPrefDoubleFromJSON(

Check warning on line 549 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L549

Added line #L549 was not covered by tests
json, PrefsKeys.defaultMaxAngAccel, Defaults.defaultMaxAngAccel);
_setPrefDoubleFromJSON(json, PrefsKeys.robotMass, Defaults.robotMass);
_setPrefDoubleFromJSON(json, PrefsKeys.robotMOI, Defaults.robotMOI);
_setPrefDoubleFromJSON(

Check warning on line 553 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L551-L553

Added lines #L551 - L553 were not covered by tests
json, PrefsKeys.robotTrackwidth, Defaults.robotTrackwidth);
_setPrefDoubleFromJSON(

Check warning on line 555 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L555

Added line #L555 was not covered by tests
json, PrefsKeys.driveWheelRadius, Defaults.driveWheelRadius);
_setPrefDoubleFromJSON(json, PrefsKeys.driveGearing, Defaults.driveGearing);
_setPrefDoubleFromJSON(

Check warning on line 558 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L557-L558

Added lines #L557 - L558 were not covered by tests
json, PrefsKeys.maxDriveSpeed, Defaults.maxDriveSpeed);
widget.prefs.setString(PrefsKeys.driveMotor,
json[PrefsKeys.driveMotor] ?? Defaults.driveMotor);
widget.prefs.setDouble(
PrefsKeys.driveCurrentLimit,
json[PrefsKeys.driveCurrentLimit]?.toDouble() ??
Defaults.driveCurrentLimit);
widget.prefs.setDouble(PrefsKeys.wheelCOF,
json[PrefsKeys.wheelCOF]?.toDouble() ?? Defaults.wheelCOF);
_setPrefDoubleFromJSON(

Check warning on line 562 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L562

Added line #L562 was not covered by tests
json, PrefsKeys.driveCurrentLimit, Defaults.driveCurrentLimit);
_setPrefDoubleFromJSON(json, PrefsKeys.wheelCOF, Defaults.wheelCOF);
_setPrefDoubleFromJSON(json, PrefsKeys.flModuleX, Defaults.flModuleX);
_setPrefDoubleFromJSON(json, PrefsKeys.flModuleY, Defaults.flModuleY);
_setPrefDoubleFromJSON(json, PrefsKeys.frModuleX, Defaults.frModuleX);
_setPrefDoubleFromJSON(json, PrefsKeys.frModuleY, Defaults.frModuleY);
_setPrefDoubleFromJSON(json, PrefsKeys.blModuleX, Defaults.blModuleX);
_setPrefDoubleFromJSON(json, PrefsKeys.blModuleY, Defaults.blModuleY);
_setPrefDoubleFromJSON(json, PrefsKeys.brModuleX, Defaults.brModuleX);
_setPrefDoubleFromJSON(json, PrefsKeys.brModuleY, Defaults.brModuleY);
_setPrefDoubleFromJSON(

Check warning on line 573 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L564-L573

Added lines #L564 - L573 were not covered by tests
json, PrefsKeys.bumperOffsetX, Defaults.bumperOffsetX);
_setPrefDoubleFromJSON(

Check warning on line 575 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L575

Added line #L575 was not covered by tests
json, PrefsKeys.bumperOffsetY, Defaults.bumperOffsetY);
}

void _setPrefDoubleFromJSON(

Check warning on line 579 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L579

Added line #L579 was not covered by tests
Map<String, dynamic> json, String prefsKey, double defaultValue) {
widget.prefs
.setDouble(prefsKey, json[prefsKey]?.toDouble() ?? defaultValue);

Check warning on line 582 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L581-L582

Added lines #L581 - L582 were not covered by tests
}

void _saveProjectSettingsToFile(Directory projectDir) {
Expand Down Expand Up @@ -622,9 +620,6 @@
widget.prefs.getDouble(PrefsKeys.robotMass) ?? Defaults.robotMass,
PrefsKeys.robotMOI:
widget.prefs.getDouble(PrefsKeys.robotMOI) ?? Defaults.robotMOI,
PrefsKeys.robotWheelbase:
widget.prefs.getDouble(PrefsKeys.robotWheelbase) ??
Defaults.robotWheelbase,
PrefsKeys.robotTrackwidth:
widget.prefs.getDouble(PrefsKeys.robotTrackwidth) ??
Defaults.robotTrackwidth,
Expand All @@ -643,6 +638,28 @@
Defaults.driveCurrentLimit,
PrefsKeys.wheelCOF:
widget.prefs.getDouble(PrefsKeys.wheelCOF) ?? Defaults.wheelCOF,
PrefsKeys.flModuleX:
widget.prefs.getDouble(PrefsKeys.flModuleX) ?? Defaults.flModuleX,

Check warning on line 642 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L642

Added line #L642 was not covered by tests
PrefsKeys.flModuleY:
widget.prefs.getDouble(PrefsKeys.flModuleY) ?? Defaults.flModuleY,

Check warning on line 644 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L644

Added line #L644 was not covered by tests
PrefsKeys.frModuleX:
widget.prefs.getDouble(PrefsKeys.frModuleX) ?? Defaults.frModuleX,

Check warning on line 646 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L646

Added line #L646 was not covered by tests
PrefsKeys.frModuleY:
widget.prefs.getDouble(PrefsKeys.frModuleY) ?? Defaults.frModuleY,

Check warning on line 648 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L648

Added line #L648 was not covered by tests
PrefsKeys.blModuleX:
widget.prefs.getDouble(PrefsKeys.blModuleX) ?? Defaults.blModuleX,

Check warning on line 650 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L650

Added line #L650 was not covered by tests
PrefsKeys.blModuleY:
widget.prefs.getDouble(PrefsKeys.blModuleY) ?? Defaults.blModuleY,

Check warning on line 652 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L652

Added line #L652 was not covered by tests
PrefsKeys.brModuleX:
widget.prefs.getDouble(PrefsKeys.brModuleX) ?? Defaults.brModuleX,

Check warning on line 654 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L654

Added line #L654 was not covered by tests
PrefsKeys.brModuleY:
widget.prefs.getDouble(PrefsKeys.brModuleY) ?? Defaults.brModuleY,

Check warning on line 656 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L656

Added line #L656 was not covered by tests
PrefsKeys.bumperOffsetX:
widget.prefs.getDouble(PrefsKeys.bumperOffsetX) ??

Check warning on line 658 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L658

Added line #L658 was not covered by tests
Defaults.bumperOffsetX,
PrefsKeys.bumperOffsetY:
widget.prefs.getDouble(PrefsKeys.bumperOffsetY) ??

Check warning on line 661 in lib/pages/home_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/home_page.dart#L661

Added line #L661 was not covered by tests
Defaults.bumperOffsetY,
};

settingsFile.writeAsString(encoder.convert(settings)).then((_) {
Expand Down
22 changes: 20 additions & 2 deletions lib/pages/telemetry_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _TelemetryPageState extends State<TelemetryPage> {
Pose2d? _currentPose;
Pose2d? _targetPose;
late final Size _robotSize;
late final Translation2d _bumperOffset;
late bool _useSim;

bool _gotCurrentPose = false;
Expand All @@ -52,6 +53,12 @@ class _TelemetryPageState extends State<TelemetryPage> {
widget.prefs.getDouble(PrefsKeys.robotLength) ?? Defaults.robotLength;
_robotSize = Size(width, length);

_bumperOffset = Translation2d(
widget.prefs.getDouble(PrefsKeys.bumperOffsetX) ??
Defaults.bumperOffsetX,
widget.prefs.getDouble(PrefsKeys.bumperOffsetY) ??
Defaults.bumperOffsetY);

_useSim = widget.prefs.getBool(PrefsKeys.telemetryUseSim) ??
Defaults.telemetryUseSim;

Expand Down Expand Up @@ -220,6 +227,7 @@ class _TelemetryPageState extends State<TelemetryPage> {
painter: TelemetryPainter(
fieldImage: widget.fieldImage,
robotSize: _robotSize,
bumperOffset: _bumperOffset,
currentPose: _currentPose,
targetPose: _targetPose,
currentPath: _currentPath,
Expand Down Expand Up @@ -564,6 +572,7 @@ class _TelemetryPageState extends State<TelemetryPage> {
class TelemetryPainter extends CustomPainter {
final FieldImage fieldImage;
final Size robotSize;
final Translation2d bumperOffset;
final Pose2d? currentPose;
final Pose2d? targetPose;
final List<Pose2d>? currentPath;
Expand All @@ -574,6 +583,7 @@ class TelemetryPainter extends CustomPainter {
const TelemetryPainter({
required this.fieldImage,
required this.robotSize,
required this.bumperOffset,
this.currentPose,
this.targetPose,
this.currentPath,
Expand Down Expand Up @@ -609,15 +619,23 @@ class TelemetryPainter extends CustomPainter {
targetPose!,
fieldImage,
robotSize,
bumperOffset,
scale,
canvas,
Colors.grey[600]!.withOpacity(0.75),
colorScheme.surfaceContainer);
}

if (currentPose != null) {
PathPainterUtil.paintRobotOutline(currentPose!, fieldImage, robotSize,
scale, canvas, colorScheme.primary, colorScheme.surfaceContainer);
PathPainterUtil.paintRobotOutline(
currentPose!,
fieldImage,
robotSize,
bumperOffset,
scale,
canvas,
colorScheme.primary,
colorScheme.surfaceContainer);
}
}

Expand Down
Loading
Loading