setAlias

Overview

This is a method to send many different timed commands to many actuators.

There are two ways to do that:

  • Time-mixed: you send a specific time to each actuator timed-command
  • Time-separate: you send first the list of all time (for example for times: 10ms, 20ms, 30ms, 40ms) and then all commands for these times (If there is 4 times, always send 4 commands for each actuator). This way is a bit more efficient.

Method

/** * Call this function to send timed-command list to an alias * An alias is used to update many actuator (as with set) at the same time, * just giving the name of the alias, and not the name of actuators. * * @param pCommands ALValue with all data * pCommands[0] Is the Alias name * pCommands[1] Is the kind of update: * "Merge": Just add new timed command. * "ClearAll": Delete all timed command before adding this one. * "ClearAfter": Delete all command that are after the time of the 1st one on the list (the soonest) * "ClearBefore": Delete all command that are before the time of the last one on the list (the oldest) * pCommands[2] Type of command: could be "time-mixed" or "time-separate" * * For pParams[3] there is 2 options: * if it's "time-mixed": * pCommands[3][x] is a list of x actuator. Each x is an actuator member of the alias * pCommands[3][x][y] is a list of y timed-command for this actuator * pCommands[3][x][y][0] is the float command (offset and gain are then used) * pCommands[3][x][y][1] is the DCM Time for the command to be applied * pCommands[3][x][y][2] is the optional importance level. Minimum if not specified * * For pCommands[3] there is 2 options: * if it's "time-separate": * pCommands[3] is the importance level of all these commands * * pCommands[4] is a list of T time. * pCommands[4][0] If the 1st time * pCommands[4][1] If the 2nd time * pCommands[4][2]... * pCommands[4][T] T time * * pCommands[5][x] is a list of x command list. Each x is an actuator member of the alias * pCommands[5][x][0] 1st command for this actuator, and at the 1st time * pCommands[5][x][1] 2nd command for this actuator, and at the 2nd time * pCommands[5][x][2]... * pCommands[5][x][T] T command * * */ void DCM::setAlias(ALValue& pCommands)

Example of use

With time-mixed

Python:

import naoqi from naoqi import ALProxy dcm = ALProxy("DCM","127.0.0.1",9559) dcm.createAlias([ "ChestLeds", [ "ChestBoard/Led/Red/Actuator/Value", "ChestBoard/Led/Green/Actuator/Value", "ChestBoard/Led/Blue/Actuator/Value" ] ]) dcm.setAlias([ "ChestLeds", "ClearAll", "time-mixed", [ [ [1.0, dcm.getTime(4000)], [0.0, dcm.getTime(6000)] ], [ [0.25, dcm.getTime(3000)] ], [ [0.125,dcm.getTime(2000)] ] ] ])

C++

// Program running in a module. Do not forget the #include "dcmproxy.h" try { DCMProxy* dcm = new DCMProxy(pBroker); ALValue commandsAlias; ALValue commands; commandsAlias.arraySetSize(2); commandsAlias[0] = string("ChestLeds"); commandsAlias[1].arraySetSize(3); commandsAlias[1][0] = string("ChestBoard/Led/Red/Actuator/Value"); commandsAlias[1][1] = string("ChestBoard/Led/Green/Actuator/Value"); commandsAlias[1][2] = string("ChestBoard/Led/Blue/Actuator/Value"); dcm->createAlias(commandsAlias); commands.arraySetSize(4); commands[0] = string("ChestLeds"); commands[1] = string("ClearAll"); commands[2] = string("time-mixed"); commands[3].arraySetSize(3); //ChestBoard/Led/Red/Actuator/Value commands[3][0].arraySetSize(2); commands[3][0][0].arraySetSize(2); commands[3][0][0][0] = 1.0; commands[3][0][0][1] = dcm->getTime(4000); commands[3][0][1].arraySetSize(2); commands[3][0][1][0] = 0.0; commands[3][0][1][1] = dcm->getTime(6000); //ChestBoard/Led/Green/Actuator/Value commands[3][1].arraySetSize(1); commands[3][1][0].arraySetSize(2); commands[3][1][0][0] = 0.25; commands[3][1][0][1] = dcm->getTime(3000); //ChestBoard/Led/Blue/Actuator/Value commands[3][2].arraySetSize(1); commands[3][2][0].arraySetSize(2); commands[3][2][0][0] = 0.125; commands[3][2][0][1] = dcm->getTime(2000); dcm->setAlias(commands); } AL_CATCH_ERR(return false;);

Send 2 commands for the red LED (value 1.0 in 4s, and value 0.0 in 6s) and 1 command for the 2 others (value 0.25 in 3s for the green, and value 0.125 in 2s for the blue).

With time-separate:

Python:

import naoqi from naoqi import ALProxy dcm = ALProxy("DCM","127.0.0.1",9559) dcm.createAlias([ "ChestLeds", [ "ChestBoard/Led/Red/Actuator/Value", "ChestBoard/Led/Green/Actuator/Value", "ChestBoard/Led/Blue/Actuator/Value" ] ]) t = dcm.getTime(0) dcm.setAlias([ "ChestLeds", "ClearAll", "time-separate", 0, [t,t+2000, t+3000, t+4000, t+5000,t+6000], [ [1.0,0.0,1.0,0.0,1.0,0.0], [1.0,0.5,1.0,0.25,0.125,0.0], [0.0625,0.125,0.25,0.50,0.75,1.0] ] ])

C++:

// Program running in a module. Do not forget the #include "dcmproxy.h" try { DCMProxy* dcm = new DCMProxy(pBroker); ALValue commandsAlias; ALValue commands; commandsAlias.arraySetSize(2); commandsAlias[0] = string("ChestLeds"); commandsAlias[1].arraySetSize(3); commandsAlias[1][0] = string("ChestBoard/Led/Red/Actuator/Value"); commandsAlias[1][1] = string("ChestBoard/Led/Green/Actuator/Value"); commandsAlias[1][2] = string("ChestBoard/Led/Blue/Actuator/Value"); dcm->createAlias(commandsAlias); commands.arraySetSize(6); commands[0] = string("ChestLeds"); commands[1] = string("ClearAll"); commands[2] = string("time-separate"); commands[3] = 0; commands[4].arraySetSize(6); commands[4][0] = dcm->getTime(10000); commands[4][1] = dcm->getTime(20000); commands[4][2] = dcm->getTime(30000); commands[4][3] = dcm->getTime(40000); commands[4][4] = dcm->getTime(50000); commands[4][5] = dcm->getTime(60000); commands[5].arraySetSize(3); // ChestBoard/Led/Red/Actuator/Value commands[5][0].arraySetSize(6); commands[5][0][0] = 1.0; commands[5][0][1] = 0.0; commands[5][0][2] = 1.0; commands[5][0][3] = 0.0; commands[5][0][4] = 1.0; commands[5][0][5] = 0.0; // ChestBoard/Led/Green/Actuator/Value commands[5][1].arraySetSize(6); commands[5][1][0] = 1.0; commands[5][1][1] = 0.5; commands[5][1][2] = 1.0; commands[5][1][3] = 0.25; commands[5][1][4] = 0.125; commands[5][1][5] = 0.0; // ChestBoard/Led/Blue/Actuator/Value commands[5][2].arraySetSize(6); commands[5][2][0] = 0.0625; commands[5][2][1] = 0.125; commands[5][2][2] = 0.25; commands[5][2][3] = 0.50; commands[5][2][4] = 0.75; commands[5][2][5] = 1.0; dcm->setAlias(commands); } AL_CATCH_ERR(return false;);

Send 6 commands to every LEDs, in 10s, 20s, 30s, 40s, 50s, and 60s.

For the red one, they are 1, 0, 1, 0, 1, 0.

For the green one, they are 1, 0.5, 1.0, 0.25, 0.125, 0.

For the blue one, they are 0.0625, 0.125, 0.25, 0.50, 0.75, 1.0.

Note:

All examples here use dcm.getTime() to get all time for timed-command request. This is just an example, and there are better ways to use it. For example you can just do one dcm.getTime() at startup and after increment the integer value for each ms. Or you can use the CPU clock if you have a module running on the robot

Note:

It's possible to send a "NAN" float number ("Not A Number") to actuator values using C++ (only from the same process). NAN are not taking into account. It may be useful to send a NAN command to an alias of many joints for just some joints, so that they do not move.

Note:

For speed improvement in C++, it's better not to create the AlValue at each request, but to keep it and just change values inside if you send to the same alias. Creating and resizing ALValue are heavy operation, while change an already allocated value is a small one.





Copyright © 2010 Aldebaran-Robotics - All rights reserved