Skip to content

Unify the driveMode storage and fetching - from ControlsFragment.vehicle.driveMode, instead of ControlsFragment.currentDriveMode. - #498

Closed
yijunwu wants to merge 2 commits into
ob-f:masterfrom
yijunwu:fix/unify_driveMode_storage
Closed

yijunwu wants to merge 2 commits into
ob-f:masterfrom
yijunwu:fix/unify_driveMode_storage

Conversation

@yijunwu

@yijunwu yijunwu commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

Unify the driveMode storage and fetching - from ControlsFragment.vehicle.driveMode, instead of ControlsFragment.currentDriveMode.

There are two places containing drive mode: ControlsFragment.currentDriveMode, and ControlsFragment.vehicle.driveMode. They should be unified. ControlsFragment.vehicle.driveMode is used more widely(as shown below) and is supposed to be the final one.

image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors drive mode state management by eliminating the redundant currentDriveMode field and replacing it with direct calls to vehicle.getDriveMode(). This change improves maintainability by ensuring the vehicle object is the single source of truth for drive mode state.

  • Removes the currentDriveMode field from ControlsFragment base class
  • Updates all references to use vehicle.getDriveMode() instead
  • Affects multiple fragment implementations: FreeRoamFragment, ObjectNavFragment, LoggerFragment, and AutopilotFragment

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
android/robot/src/main/java/org/openbot/common/ControlsFragment.java Removes the currentDriveMode field declaration and updates status reporting to use vehicle.getDriveMode()
android/robot/src/main/java/org/openbot/robot/FreeRoamFragment.java Replaces currentDriveMode references with vehicle.getDriveMode() in controller connection methods
android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java Replaces currentDriveMode references with vehicle.getDriveMode() in controller connection methods
android/robot/src/main/java/org/openbot/logging/LoggerFragment.java Replaces currentDriveMode references with vehicle.getDriveMode() in controller connection methods
android/robot/src/main/java/org/openbot/autopilot/AutopilotFragment.java Replaces currentDriveMode references with vehicle.getDriveMode() in controller connection methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Enums.DriveMode oldDriveMode = currentDriveMode;
Enums.DriveMode oldDriveMode = vehicle.getDriveMode();
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.GAME);

Copilot AI Nov 8, 2025

Copy link

Choose a reason for hiding this comment

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

Inconsistent type reference. This file uses a static import for DriveMode (line 4), so Enums.DriveMode.GAME should be simplified to DriveMode.GAME for consistency with line 267 which uses DriveMode.DUAL.

Suggested change
setDriveMode(Enums.DriveMode.GAME);
setDriveMode(DriveMode.GAME);

Copilot uses AI. Check for mistakes.
@thias15

thias15 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Sorry for taking so long to look at this — thanks for your patience.

  1. Is vehicle.getDriveMode() guaranteed to return a non-null value at every read site? The old currentDriveMode was initialized to Enums.DriveMode.GAME at field declaration, so it was never null. After the refactor, the first handlePhoneControllerEvents() call (status reporting in ControlsFragment) and the connect*Controller() methods rely on the vehicle already having a drive mode set. If Vehicle initializes its driveMode to a sane default, this is fine — could you confirm?
  2. The PR has been open since June 2025 — has it been re-tested against current master? Touching ControlsFragment and four downstream fragments has broad surface area; given the time gap, it'd be worth a quick verification that all four control modes (free roam, object nav, logging, autopilot) still behave correctly with both phone and web controllers.
  3. Minor (optional): while you're touching FreeRoamFragment.java, the file mixes Enums.DriveMode and DriveMode (static import) — Copilot pointed this out. Not a regression from this PR, but a 1-line cleanup if you want it.

….java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@thias15

thias15 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks @yijunwu for finding this! The code has moved a lot since (package rename and the new robot/ folder), so I redid your change on the current code in #561, with you as co-author. Closing this one in favor of #561.

@thias15 thias15 closed this Oct 22, 2026
thias15 added a commit that referenced this pull request Oct 23, 2026
- Drive mode: the app reads the robot's current drive mode, and keeps the
  one you chose when switching to phone or web control (redoes #498)
- Linux robot: updated requirements (pandas, OpenVINO versions),
  test_infer.py finds the repo itself, README setup fixes
- CI: Python 3.12 and JDK 17 for the new Ubuntu runners; firmware builds
  skip Markdown-only changes; controller release APK is ARM-only
- .git-blame-ignore-revs hides the Java formatting commit from blame

Co-authored-by: Jacob Wu <wuyijun1129@hotmail.com>
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.

4 participants