Changing the color of the rear LED of the RVR

Using python3, with the latest RVR python SDK (August 20 release), I am unable to change the color of rear LED on the RVR. The problem is I don’t know the attribute of the RvrLedGroups class that references the RVR’s rear LED.

In looking through the examples, I couldn’t find any python code that specifically changes the color of the rear LED. I also couldn’t find any end-user documentation concerning python control of the RVR LEDs. I was finally able to find LED -pecific attributes in rvr_led_groups_enum.py (located in the /sphero_sdk/common/enums directory).

Specifically here is what I found. As an aside, I know that some of the other LED-specific attributes in this program work. For example, I was able to use the “battery_door_front” and the “power_button_front” attributes to control the LEDs on the left-side and right-side of the RVR.

class RvrLedGroups(Enum):
.
.
.

brakelight_left = SpheroRvrLedBitmasks.left_brakelight_red | \
                  SpheroRvrLedBitmasks.left_brakelight_green | \
                  SpheroRvrLedBitmasks.left_brakelight_blue

brakelight_right = SpheroRvrLedBitmasks.right_brakelight_red | \
                   SpheroRvrLedBitmasks.right_brakelight_green | \
                   SpheroRvrLedBitmasks.right_brakelight_blue

Here is a portion of the code I ran to write to the rear LED:

.
.
.
from sphero_sdk import SpheroRvrObserver
from sphero_sdk import RawMotorModesEnum
from sphero_sdk import RvrLedGroups
from sphero_sdk import Colors
.
.
.
rvr.led_control.set_led_rgb(RvrLedGroups.breaklight_left, red=255, green=255, blue=0)**

Here is the error message I received:

Traceback (most recent call last):
__File “LED_test_program.py”, line 168, in
____rvr.led_control.set_led_rgb(RvrLedGroups.breaklight_left, red=255, green=255, blue=0)
__File “/usr/lib/python3.7/enum.py”, line 349, in getattr
____raise AttributeError(name) from None
AttributeError: breaklight_left

Given this, here are my questions:

  1. Where can I find python-specific documentation on how to program the RVR LEDs?
  2. What is the python code for controlling the rear LED of the RVR?

Thanks in advance for any assistance you can provide.

…Gary

You have “breaklight” not “brakelight”.

Rud,
Sometimes an extra pair of eyes helps!
…Gary

I just did a dir() to list the attributes of RvrLedGroups and this is what I got:

dir(RvrLedGroups): [‘class’, ‘doc’, ‘members’, ‘module’, ‘all_lights’, ‘battery_door_front’, ‘battery_door_rear’, ‘brakelight_left’, ‘brakelight_right’, ‘headlight_left’, ‘headlight_right’, ‘power_button_front’, ‘power_button_rear’, ‘status_indication_left’, ‘status_indication_right’, ‘undercarriage_white’]

Obviously, ‘brakelight_left’ and ‘brakelight_right’ are attributes of RvrLedGroups, so something is wrong. For whatever reason getattr in enum.py is failing to obtain the attribute.

…Gary

Are you getting another error? Or the code runs but the LEDs don’t change color?

My C++ code changes all the LEDs so it does work. Best I can tell looking at the Python SDK there is nothing specific about the brake lights that should cause a problem. Maybe post your code again for another set of eyes?

Thanks for the follow-up. When I used the correct attribute (‘brakelight_left’ instead of ‘breaklight_left’), the following code worked:

rvr.led_control.set_led_rgb(RvrLedGroups.brakelight_left, red=255, green=255, blue=0)

I should have caught this one… Anyway, I guess the python developers never gave the interpreter the ability to understand attributes that sound the same, but are spelled differently :wink:

SPHERO Email Marketing -