ALLeds API

NAOqi Sensors - Overview | API


See also

Namespace : AL


#include <alproxies/alledsproxy.h>

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


# -*- encoding: UTF-8 -*-

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python leds_fade.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALLeds", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALLeds"
    print "Error was: ",e
    sys.exit(1)

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

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:

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


# -*- encoding: UTF-8 -*-

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python leds_off.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALLeds", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALLeds"
    print "Error was: ",e
    sys.exit(1)
    
# Example showing how to switch off a group
name = 'FaceLeds'
proxy.off(name)

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


# -*- encoding: UTF-8 -*-

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python leds_on.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALLeds", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALLeds"
    print "Error was: ",e
    sys.exit(1)

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

sys.exit(0)

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


# -*- encoding: UTF-8 -*-

import sys
from naoqi import ALProxy

if (len(sys.argv) < 2):
    print "Usage: 'python leds_rasta.py IP [PORT]'"
    sys.exit(1)

IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
    PORT = sys.argv[2]
try:
    proxy = ALProxy("ALLeds", IP, PORT)
except Exception,e:
    print "Could not create proxy to ALLeds"
    print "Error was: ",e
    sys.exit(1)
    
# Example showing a one second rasta animation
duration = 1.0
proxy.rasta(duration)

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);