> For the complete documentation index, see [llms.txt](https://marrow.skeletonarmyftc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://marrow.skeletonarmyftc.com/dev-tools/opmodemanager.md).

# OpModeManager

package com.skeletonarmy.marrow

## Overview

`OpModeManager` provides a simple interface for accessing the internal OpMode manager. It allows your code to read the current OpMode, robot state, hardware map, telemetry, and register lifecycle listeners - without direct access to the SDK internals.

This is useful when you need to interact with OpMode-level information from subsystems or utilities without manually passing references around.

{% hint style="warning" %}
Do not access the current OpMode before it is initialized. The hardware map may also change during initialization, so avoid relying on or caching it early.
{% endhint %}

***

## Usage

#### **getManager()**

Returns the active `OpModeManagerImpl` instance.

```java
OpModeManagerImpl manager = OpModeManager.getManager();
```

***

#### **getActiveOpMode()**

Returns the currently running OpMode, or `null` if none is running.

```java
OpMode active = OpModeManager.getActiveOpMode();
```

***

#### **getActiveOpModeName()**

Returns the name of the active OpMode.

```java
String name = OpModeManager.getActiveOpModeName();
```

***

#### **getRobotState()**

Returns the current `RobotState` enum (e.g., `INIT`, `RUNNING`, `STOPPED`).

```java
RobotState state = OpModeManager.getRobotState();
```

***

#### **getHardwareMap()**

Returns the active `HardwareMap`.

Useful when you need hardware access outside your OpMode.

```java
HardwareMap hardwareMap = OpModeManager.getHardwareMap();
```

***

#### **getTelemetry()**

Returns the active `Telemetry`.

Useful when you need to debug things outside your OpMode.

```java
Telemetry telemetry = OpModeManager.getTelemetry();
```

***

#### **registerListener(listener)**

Registers a listener for OpMode lifecycle changes.

The listener receives callbacks such as:

* `onOpModePreInit`
* `onOpModePreStart`
* `onOpModePostStop`

Returns the active OpMode at the time of registration.

```java
OpModeManager.registerListener(myListener);
```

***

#### **unregisterListener(listener)**

Removes a previously registered listener.

```java
OpModeManager.unregisterListener(myListener);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://marrow.skeletonarmyftc.com/dev-tools/opmodemanager.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
