3D visionTroubleshooting

Failed to set power state: fix camera option call order

A failed to set power state error on a camera option means the call ran after streams were enabled. Set options between device open and pipeline start.

LumaSpec Vision8 min read Share on LinkedIn

On this page 9 sections
  1. 01The symptom: one error string, every option
  2. 02Why the sensor refuses: power state follows the stream configuration
  3. 03The fix: set options between device open and pipeline start
  4. 04Worked example: contrast 50.0 and exposure on a 30 fps color stream
  5. 05What did not work: power, sleeps and warm-up frames
  6. 06Which cameras this ordering governs
  7. 07If the error still appears
  8. 08A start-up order that prevents it
  9. 09Questions

An rs2_get_option or rs2_set_option call for contrast, exposure or white balance raises rs_error with failed to set power state on a 3D camera that otherwise enumerates and streams without trouble. The value you pass is not being refused, the cable is not at fault, and the port's power budget is not the issue: the call is running in the wrong place in the start-up sequence. This guide gives the mechanism, the exact window in which option calls succeed, a worked exposure budget with the arithmetic shown, and the checks that prove the fix. It applies to any USB depth camera whose SDK hands you one sensor handle per imaging module.

The symptom: one error string, every option

The message reads rs_error was raised when calling rs2_get_option(..., option_id:2): failed to set power state. Two details identify the fault. First, the same string comes back for every option you touch — option_id:2 for contrast here, a different id for a different option — so the refused thing is not the value you passed. Second, the call fails at once rather than timing out: the SDK rejects it because the sensor handle cannot reach the state an option query needs, not because the hardware is slow to answer. Context, device and pipeline all work, frames flow, and this one class of call fails.

Why the sensor refuses: power state follows the stream configuration

A depth camera SDK manages each imaging module — stereo module, color sensor, motion module — as a separately powered sensor. While the device is open and idle, a handle from rs2_create_sensor can bring its module up briefly to answer rs2_get_option or accept rs2_set_option. Once a pipeline has called enable_stream, the stream configuration claims those sensors, and the power transition an option call asks for is no longer the SDK's to grant. Query an option at that point and the request fails before it reaches the sensor.

The failure is positional, not electrical. It depends on where the call sits relative to enable_stream, which is why adding power or waiting changes nothing.

Where the option call runs Result
After the device is open, before the pipeline exists Succeeds
After enable_stream, before the pipeline starts failed to set power state
While the pipeline is streaming failed to set power state
On a handle already freed with rs2_delete_sensor Errors that imitate it

The fix: set options between device open and pipeline start

Move the whole option block — sensor loop, gets, sets — to directly below the device initialization, above the code that creates the pipeline and calls enable_stream.

  1. Create the context and enumerate the device, exactly as you already do.
  2. Query the sensor list with rs2_query_sensors and count it with rs2_get_sensors_count.
  3. Loop with rs2_create_sensor and pick the color module with rs2_is_sensor_extendable_to(sensor, RS2_EXTENSION_COLOR_SENSOR, &e).
  4. Read defaults with rs2_get_option and write targets with rs2_set_option, calling check_error(e) after every call.
  5. Free each sensor with rs2_delete_sensor inside the loop, then the list with rs2_delete_sensor_list.
  6. Only now build the config, create the pipeline, call enable_stream and start.
rs2_error* e = 0;
/* ctx and device are already created at this point */

rs2_sensor_list* sensor_list = rs2_query_sensors(dev, &e);
check_error(e);

int num_sensor = rs2_get_sensors_count(sensor_list, &e);
check_error(e);

for (int i = 0; i < num_sensor; i++) {
    rs2_sensor* sensor = rs2_create_sensor(sensor_list, i, &e);
    check_error(e);

    if (rs2_is_sensor_extendable_to(sensor, RS2_EXTENSION_COLOR_SENSOR, &e) && !e) {
        float def = rs2_get_option(sensor, RS2_OPTION_CONTRAST, &e);
        check_error(e);
        rs2_set_option(sensor, RS2_OPTION_CONTRAST, 50.0, &e);
        check_error(e);
    }
    rs2_delete_sensor(sensor);
}
rs2_delete_sensor_list(sensor_list);

/* pipeline, enable_stream and start come after this block */

The block is the one that was failing; only its position changed.

Worked example: contrast 50.0 and exposure on a 30 fps color stream

Inputs, with units and where each comes from:

  • Contrast target 50.0, the unitless float from the failing rs2_set_option call.
  • Color stream at 30 fps, the rate you pass to enable_stream — an example input, so substitute your own rate in the same formulas.
  • Exposure starting point of one quarter of the frame period, which leaves room for readout and transfer.

Rule in words: every get and set sits between device enumeration and pipeline start, and manual exposure stays under the frame period.

frame period = 1 / frame rate exposure = frame period / 4 margin = frame period - exposure

Arithmetic: 1 / 30 fps = 0.0333 s = 33.3 ms per frame. Exposure = 33.3 ms / 4 = 8.3 ms. Margin left = 33.3 ms - 8.3 ms = 25.0 ms. Both option calls now return with no rs_error, and a read-back with rs2_get_option in the same idle window confirms the value took.

Decision: hold manual exposure under half the frame period — 16.7 ms at 30 fps — and start near a quarter. If you need more light, lower the rate first: at 15 fps the period is 66.7 ms and a 20 ms exposure leaves 46.7 ms of margin. Before picking the number, read the minimum and maximum the option query returns; query the option range before setting exposure or gain shows the pattern.

What did not work: power, sleeps and warm-up frames

Three remedies get tried first, and none touches the cause.

More USB power. The state in the message belongs to the sensor handle inside the SDK, not to the volts at the port. A real power shortfall looks different: the camera disconnects when a stream starts, as in depth camera disconnects when the IR stream starts. The broader lesson — troubleshooting a camera crash from device state instead of the cabling — lands the same way: this fault is software state.

A two-second sleep before the call. A delay changes when the call runs, not which state the handle is in. Once enable_stream has claimed the sensor, waiting leaves it claimed.

Capturing warm-up frames first. Streaming frames moves the sensor deeper into the streaming configuration — the opposite direction from the idle state an option call needs.

Which cameras this ordering governs

Any camera whose SDK exposes one handle per sensor follows the rule: options on an open, idle device, streams afterwards. Across the 3D sensors range the discipline is identical for a time-of-flight unit and a projected structured-light unit:

3D sensorsHikrobot MV-DT01WMU ToF sensing cameraMV-DT01WMU
Type
Depth / ToF camera
Price on requestView and quote
3D sensorsHikrobot MV-DPS200P-02 Projected structured-light 3D cameraMV-DPS200P-02
Type
Stereo / structured light
$8,829.00 · quotedView and quote
Cameras3D sensors

Laser profilers and stereo 3D cameras

170 models · from $699.00

Plain area scan cameras meet the same family of faults in GenICam form: a node refuses to write because the camera's access state or acquisition state does not allow it, which is exactly GenICam node not writable: check camera access state. The parallel habit is to set exposure and gain right after opening the device; setting camera exposure time through a GenICam API in Python works the same open-first ordering. The LS-CMR-0166 is a 12 MP USB3 area scan camera rated at 30 fps:

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

If the error still appears

Reordered and still failing? Work this list in order.

  1. Handle lifetime. A handle used after rs2_delete_sensor, or a fresh handle created once streams are enabled, fails in ways that imitate this fault. Create, use and free handles inside the idle window only.
  2. Option support. Ask for the option list and each option's range before you set anything; the range also tells you the unit the value carries.
  3. SDK and firmware alignment. A viewer that streams while your build fails points at mismatched headers or firmware versions; 3D camera header version mismatch: fix firmware and SDK alignment covers the pairing.
  4. Auto-exposure groups. Options under auto exposure carry a master switch that must be set before the members; depth camera auto exposure options error: set the master option first is that failure.
  5. Values you must change live. For tuning during streaming, the dependable pattern is stop, set, start; runtime camera parameter control: exposure and white balance live covers what belongs in that loop.

If the camera drops off the bus entirely, that is hardware territory: tell us on the contact page what the stream configuration is when it drops.

A start-up order that prevents it

Keep one sequence in the project:

  • Context and device enumeration.
  • Sensor option block: every rs2_get_option and rs2_set_option, each followed by check_error(e).
  • Free the sensor handles and the sensor list.
  • Config, pipeline, enable_stream, start.
  • One read-back in the idle window to prove the values took.

To prove the fix, run the sequence once with the block before the pipeline — the calls succeed — then move a single rs2_set_option below start and watch it raise the same rs_error. That pair of runs settles it.

Choosing hardware rather than fixing code? The camera finder filters the range by interface, resolution and shutter, configure a system walks a camera-led build, and the 3D vision guides collect the rest of the set-up pieces.

Questions

Does failed to set power state mean the USB port lacks power?

No. The power state is the SDK's name for the state of the sensor handle, not the electrical budget of the port. A genuine power shortfall announces itself differently: the camera disconnects or drops frames when a stream starts. If disconnects are what you see, treat it as a power problem; if only option calls fail while frames flow, it is the ordering.

Which options can I set once the calls sit in the right place?

The ones the sensor reports as supported. Ask for the option list and each option's range first, which also tells you the unit each value carries. On the color sensor, contrast, exposure and white-balance style options are the usual targets. The option_id in the error message tells you which option was refused, which keeps the mapping straight while you loop over sensors.

Can I change options while the pipeline is streaming?

Plan on no. The state that produced this error is the streaming one, so the dependable pattern is stop the pipeline, set the value, start again. Some SDKs accept live changes for some options, and auto-exposure groups add their own ordering with a master switch to set before the individual members. Anything you know at start-up belongs in the idle window before enable_stream.

Do I have to free the sensor handles?

Yes. Call rs2_delete_sensor on each handle inside the loop and rs2_delete_sensor_list on the list afterwards. A handle used after it is freed, or a fresh handle created once streams are enabled, fails in ways that imitate the power-state fault and sends debugging after the wrong cause. Create, use and free handles in the same idle window.

Does the same ordering matter on area scan cameras?

Yes, in its GenICam form. A node's writability depends on the camera's access state and acquisition state, so a feature can refuse to write until the camera is in the right one. The parallel habit is identical: open the device, set exposure and gain, then start acquisition. Node-state errors that appear after a sleep or a reconnect belong to the same family.