Create Alias
Alias
Aliases are a way to send faster commands to many actuators at the same time.
They are defined dynamically by a "createAlias" to the DCM They also could be changed.
Every Alias has a name, and is a list of actuator names.
Then, with a "setAlias" method, you can ask for an update of all actuator with different timed command, with only one method, and without giving back all actuators names.
Warning: |
Be careful, right now alias changes are not thread safe. |
---|
Warning: |
Right now, the DCM is not optimized for a huge number of alias. |
---|
"createAlias" method
/** * Create or change the alias * An alias is create to update many actuator (as with set) at the same time * * @param pParams ALValue with all data * pParams[0] Is the alias name (a new one or an already created one) * Then there is a list of x actuator name * pParams[1][0] The name of the 1st actuator * pParams[1][1] The name of the 2nd actuator * pParams[1][2]... * * @result Same as param, but with the name removed if the actuator is not found * */ ALValue DCM::createAlias(ALValue& pParams)
The result is a copy of the input param, but where not found actuators names are changed to by "". You can use this return to know if one or more actuator names are wrong.
The most useful method to send commands to alias is the "setAlias". But you can also use a "set", with the same commands sent to every actuator. See example below.
Example of use
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" ] ])
C++
// Program running in a module. Do not forget the #include "dcmproxy.h" try { DCMProxy* dcm = new DCMProxy(pBroker); ALValue commands; commands.arraySetSize(2); commands[0] = string("ChestLeds"); commands[1].arraySetSize(3); commands[1][0] = string("ChestBoard/Led/Red/Actuator/Value"); commands[1][1] = string("ChestBoard/Led/Green/Actuator/Value"); commands[1][2] = string("ChestBoard/Led/Blue/Actuator/Value"); ALValue result = dcm->createAlias(commands); cout << result.toString() << endl; } AL_CATCH_ERR(return false;);
Define a new alias name "ChestLeds" with 3 actuator (3 LEDs), in this order: red, green, blue.
Here is a "set" example: All LEDs are smoothly set on and set off, 2 times
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.set([ "ChestLeds", "ClearAll", [ [1.0, dcm.getTime(1000)], [0.0, dcm.getTime(2000)], [1.0, dcm.getTime(3000)], [0.0, dcm.getTime(4000)] ] ])
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(3); commands[0] = string("ChestLeds"); commands[1] = string("ClearAll"); commands[2].arraySetSize(4); commands[2][0].arraySetSize(2); commands[2][0][0] = 1.0; commands[2][0][1] = dcm->getTime(1000); commands[2][1].arraySetSize(2); commands[2][1][0] = 0.0; commands[2][1][1] = dcm->getTime(2000); commands[2][2].arraySetSize(2); commands[2][2][0] = 1.0; commands[2][2][1] = dcm->getTime(3000); commands[2][3].arraySetSize(2); commands[2][3][0] = 0.0; commands[2][3][1] = dcm->getTime(4000); dcm->set(commands); } AL_CATCH_ERR(return false;);
Note: |
All examples here use dcm.getTime() to get all times 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 afterwards increment the integer value for each ms. Or you can use the CPU clock if you have a module running on the robot. |
---|