# SoftBank Robotics documentation What's new in NAOqi 2.8?

# ALLeds API

NAOqi Sensors & LEDs - Overview | API

Namespace : AL

    #include <alproxies/alledsproxy.h>

## Method list

As any module, this module inherits methods from ALModule API. It also has the following specific methods:

class `ALLedsProxy`

- `ALLedsProxy::createGroup`
- `ALLedsProxy::earLedsSetAngle`
- `ALLedsProxy::fade`
- `ALLedsProxy::fadeListRGB`
- `ALLedsProxy::fadeRGB`
- `ALLedsProxy::getIntensity`
- `ALLedsProxy::listGroup`
- `ALLedsProxy::listGroups`
- `ALLedsProxy::listLED`
- `ALLedsProxy::listLEDs`
- `ALLedsProxy::off`
- `ALLedsProxy::on`
- `ALLedsProxy::randomEyes`
- `ALLedsProxy::rasta`
- `ALLedsProxy::reset`
- `ALLedsProxy::rotateEyes`
- `ALLedsProxy::setIntensity`

## Methods

void `ALLedsProxy::``createGroup`(const std::string& groupName, const std::vector<std::string>& ledNames)

  Makes a group name for ease of setting multiple LEDs.

  Parameters: | groupName – The name of the group. ledNames – A vector of the names of the LEDs in the group.

### Python:

    # Replace "127.0.0.1" with the IP of your robot
    leds = ALProxy("ALLeds","127.0.0.1",9559)
    # Create a new group
    names = [
    "Face/Led/Red/Left/0Deg/Actuator/Value",
    "Face/Led/Red/Left/90Deg/Actuator/Value",
    "Face/Led/Red/Left/180Deg/Actuator/Value",
    "Face/Led/Red/Left/270Deg/Actuator/Value"]
    leds.createGroup("MyGroup",names)
    # Switch the new group on
    leds.on("MyGroup")

### C++:

    boost::shared_ptr<ALLedsProxy> leds = boost::shared_ptr<ALLedsProxy>(new ALLedsProxy(getParentBroker()));
    // Create a new group
    std::vector<std::string> names;
    names.push_back("Face/Led/Red/Left/0Deg/Actuator/Value");
    names.push_back("Face/Led/Red/Left/90Deg/Actuator/Value");
    names.push_back("Face/Led/Red/Left/180Deg/Actuator/Value");
    names.push_back("Face/Led/Red/Left/270Deg/Actuator/Value");
    leds.createGroup("MyGroup",names);
    // Switch the new group on
    leds.on("MyGroup");

void `ALLedsProxy::``earLedsSetAngle`(const int& degrees, const float& duration, const bool& leaveOnAtEnd)

  An animation to show a direction with the ears.

  Parameters: | degrees – The angle you want to show in degrees (int). 0 is up, 90 is forwards, 180 is down and 270 is back. duration – The duration in seconds of the animation. leaveOnAtEnd – If true the last led is left on at the end of the animation.

void `ALLedsProxy::``fade`(const std::string& name, const float& intensity, const float& duration)

  Sets the intensity of a LED or Group of LEDs within a given time.

  Parameters: | name – The name of the LED or Group. intensity – The intensity of the LED or Group (a value between 0 and 1). duration – The duration of the fade in seconds

  `alleds_fade.cpp`

      #include <iostream>
      #include <alproxies/alledsproxy.h>

      int main(int argc, char **argv)
      {
        if (argc < 2) {
          std::cerr << "Usage: leds_ledsfade pIp" << std::endl;
          return 1;
        }
        const std::string pIp = argv[1];

        // Create a proxy to ALLeds.
        AL::ALLedsProxy leds(pIp);

        // Example showing how to fade the left eye group to mid-intensity
        std::string name = "EarLeds";
        float intensity = 0.5f;
        float duration = 1.0f;
        leds.fade(name, intensity, duration);
        std::cout << "Faded " << name << " to " << intensity << " in " << duration
                  << std::endl;

        return 0;
      }

  `alleds_fade.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use fade Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the fade method.
          """
          # Get the service ALLeds.

          leds_service = session.service("ALLeds")

          # Example showing how to fade the ears group to mid-intensity
          name = 'EarLeds'
          intensity = 0.5
          duration = 1.0
          leds_service.fade(name, intensity, duration)

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALLedsProxy::``fadeListRGB`(const std::string& name, const AL::ALValue& rgbList, const AL::ALValue& timeList)

  Executes a list of color commands for a LED or a group of LEDs (like a timeline for LEDs).

  Parameters: | name – The name of the LED or Group. rgbList – List of RGB led value, RGB as seen in hexa-decimal: 0x00RRGGBB. timeList – List of respective time to reach each RGB value.

void `ALLedsProxy::``fadeRGB`(const std::string& name, const float& red, const float& green, const float& blue, const float& duration)

  There are three overloads of this function:

  - ALLedsProxy::fadeRGB with RGB color code.
  - ALLedsProxy::fadeRGB with color names.
  - ALLedsProxy::fadeRGB with hexadecimal color code.

  Sets the color of an RGB led using RGB color code.

  Parameters: | name – The name of the RGB LED or Group. red – The intensity of red channel (0-1). green – The intensity of green channel (0-1). blue – The intensity of blue channel (0-1). duration – Time used to fade in seconds.

void `ALLedsProxy::``fadeRGB`(const std::string& name, const std::string& colorName, const float& duration)

  Sets the color of an RGB led using color names.

  Parameters: | name – The name of the RGB LED or Group. colorName – The name of the color (supported colors: “white”, “red”, “green”, “blue”, “yellow”, “magenta”, “cyan”). duration – Time used to fade in seconds.

void `ALLedsProxy::``fadeRGB`(const std::string& name, const int& rgb, const float& duration)

  Sets the color of an RGB led using hexadecimal color code.

  Parameters: | name – The name of the RGB LED or Group. rgb – The RGB value led, RGB as seen in hexadecimal: 0x00RRGGBB. duration – Time used to fade in seconds.

AL::ALValue `ALLedsProxy::``getIntensity`(const std::string& name)

  Gets the intensity of a LED.

  Parameters: | name – The name of the LED.
  Returns: | The intensity of the LED.

std::vector<std::string> `ALLedsProxy::``listGroup`(const std::string& groupName)

  Lists the devices in the group.

  Parameters: | groupName – The name of the Group.
  Returns: | A vector of string device names.

### Python:

    # Replace "127.0.0.1" with the IP of your robot
    leds = ALProxy("ALLeds","127.0.0.1",9559)
    # Print the names of all the groups
    print(leds.listGroup("FaceLedsLeftExternal"))

### C++:

    boost::shared_ptr<ALLedsProxy> leds = boost::shared_ptr<ALLedsProxy>(new ALLedsProxy(getParentBroker()));
    //  Print the names of all the devices in the group
    std::vector<std::string> deviceNames = leds.listGroup("FaceLedsLeftExternal");
    for(unsigned int i=0; i < deviceNames.size(); i++) {
    std::cout << deviceNames.at(i) << std::endl;
    }

std::vector<std::string> `ALLedsProxy::``listGroups`()

  Lists available group names.

  Returns: | A vector of group names.

std::vector<std::string> `ALLedsProxy::``listLED`(const std::string& arg1)

  Lists the devices aliased by a short LED name.

  Parameters: | arg1 – arg
  Returns: | A vector of device names.

std::vector<std::string> `ALLedsProxy::``listLEDs`()

  Lists the short LED names.

  Returns: | A vector of LED names.

void `ALLedsProxy::``off`(const std::string& name)

  Switch to a minimum intensity a LED or Group of LEDs.

  Parameters: | name – The name of the LED or Group.

  samples/cpp/alleds/alleds_off.cpp

      #include <iostream>
      #include <alproxies/alledsproxy.h>

      int main(int argc, char **argv)
      {
        if (argc < 2) {
          std::cerr << "Usage: leds_off pIp" << std::endl;
          return 1;
        }
        const std::string pIp = argv[1];

        // Create a proxy to ALLeds.
        AL::ALLedsProxy leds(pIp);

        // Example showing how to switch off a group
        std::string name = "FaceLeds";
        leds.off(name);
        std::cout << "LEDs from " << name << " group are now off" << std::endl;

        return 0;
      }

  samples/python/alleds/alleds_off.py

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use off Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the off method.
          """
          # Get the service ALLeds.

          leds_service = session.service("ALLeds")

          # Example showing how to switch off a group
          name = 'FaceLeds'
          leds_service.off(name)

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALLedsProxy::``on`(const std::string& name)

  Switch to a maximum intensity a LED or Group of LEDs.

  Parameters: | name – The name of the LED or Group.

  `alleds_on.cpp`

      #include <iostream>
      #include <alproxies/alledsproxy.h>

      int main(int argc, char **argv)
      {
        if (argc < 2) {
          std::cerr << "Usage: leds_on pIp" << std::endl;
          return 1;
        }
        const std::string pIp = argv[1];

        // Create a proxy to ALLeds.
        AL::ALLedsProxy leds(pIp);

        // Example showing how to switch on a group
        std::string name = "FaceLeds";
        leds.on(name);

        std::cout << "LEDs from " << name << " group are now on." << std::endl;

        return 0;
      }

  `alleds_on.py`

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use on Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the on method.
          """
          # Get the service ALLeds.

          leds_service = session.service("ALLeds")

          # Example showing how to switch on a group
          name = 'FaceLeds'
          leds_service.on(name)

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALLedsProxy::``randomEyes`(const float& duration)

  Launch a random animation in eyes

  Parameters: | duration – Approximate duration of the animation in seconds.

void `ALLedsProxy::``rasta`(const float& duration)

  Launch a green/yellow/red rasta animation on all body.

  Parameters: | duration – Approximate duration of the animation in seconds.

  samples/cpp/alleds/alleds_rasta.cpp

      #include <iostream>
      #include <alproxies/alledsproxy.h>

      int main(int argc, char **argv)
      {
        if (argc < 2) {
          std::cerr << "Usage 'leds_on pIp" << std::endl;
          return 1;
        }
        const std::string pIp = argv[1];

        // Create a proxy to ALLeds.
        AL::ALLedsProxy leds(pIp);

        // Example showing a two seconds rasta animation
        float duration = 2.0f;
        leds.rasta(duration);
        std::cout << "LED animation complete." << std::endl;

        return 0;
      }

  samples/python/alleds/alleds_rasta.py

      #! /usr/bin/env python
      # -*- encoding: UTF-8 -*-

      """Example: Use rasta Method"""

      import qi
      import argparse
      import sys

      def main(session):
          """
          This example uses the rasta method.
          """
          # Get the service ALLeds.

          leds_service = session.service("ALLeds")

          # Example showing a one second rasta animation
          duration = 1.0
          leds_service.rasta(duration)

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument("--ip", type=str, default="127.0.0.1",
                              help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
          parser.add_argument("--port", type=int, default=9559,
                              help="Naoqi port number")

          args = parser.parse_args()
          session = qi.Session()
          try:
              session.connect("tcp://" + args.ip + ":" + str(args.port))
          except RuntimeError:
              print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
                     "Please check your script arguments. Run with -h option for help.")
              sys.exit(1)
          main(session)

void `ALLedsProxy::``reset`(const std::string& name)

  Set a LED or Group of LEDs to their default state.

  Parameters: | name – The name of the LED or Group.

void `ALLedsProxy::``rotateEyes`(const int& rgb, const float& timeForRotation, const float& totalDuration)

  Launch a rotation using the leds of the eyes.

  Parameters: | rgb – the RGB value led, RGB as seen in hexa-decimal: 0x00RRGGBB. timeForRotation – Approximate time to make one turn. totalDuration – Approximate duration of the animation in seconds.

void `ALLedsProxy::``setIntensity`(const std::string& name, const float& intensity)

  Sets the intensity of a LED or Group of LEDs.

  Parameters: | name – The name of the LED or Group. intensity – The intensity of the LED or Group (a value between 0 and 1).

### Python:

    # Replace "127.0.0.1" with the IP of your robot
    leds = ALProxy("ALLeds","127.0.0.1",9559)
    # Turn the red LED of the left foot half on
    leds.setIntensity("LFoot/Led/Red/Actuator/Value", 0.5)
    # Turn the green face LEDs half on
    leds.setIntensity("LeftFaceLedsGreen", 0.5)

### C++:

    boost::shared_ptr<ALLedsProxy> leds = boost::shared_ptr<ALLedsProxy>(new ALLedsProxy(getParentBroker()));
    // Turn the red LED of the left foot half on
    leds->setIntensity("LFoot/Led/Red/Actuator/Value", 0.5f);
    // Turn the green face LEDs half on
    leds->setIntensity("LeftFaceLedsGreen", 0.5f);

Glossary Site map Index Support Contact Legal Notices