Set
概述
这是一个向致动器发送一个或多个命令(定时命令)的基本命令。
也可以使用一个别名而不是致动器名(见下文)。在这一情况下,在别名里的每一个致动器都可以使用相同的命令进行更新。
/** * Call this function to send a timed-command list to an actuator * Command send from an other module * * @param pCommands ALValue with all data * pCommands[0] has the actuator name (with or without the base 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 commands that are after the time of the 1st one on the list (the soonest) * "ClearBefore" : Delete all commands that are before the time of the last one on the list (the oldest) * pCommands[2][x] is a list of x timed-command * pCommands[2][x][0] is the float command (offset and gain are then used) * pCommands[2][x][1] is the DCM Time for the command to be applied * pCommands[2][x][2] is the optional importance level. Minimum if not specified * */ void DCM::set(ALValue& pCommands)
更新类型
共有4种更新: “ClearAll”、“Merge”、“ClearAfter”和“ClearBefore”。
这些更新告诉DCM,当针对同一致动器的定时命令已经在其内部缓冲区(由其它模块或同一模块发送)时,如何添加新命令。
- “ClearAll”是一个很简单的类型,它删除(针对该致动器)以前的命令, 并由新命令取代。可以使用不带新命令的“clearAll”来删除所有的命令。 会保留最后发送的值。
- “Merge”也同样简单:新命令只是与以前的命令混合在一起 (如果有两个命令的时间完全相同,就需小心):
- “ClearAfter”是指在第一个新命令后面的所有以前的命令都会被删除:
- “ClearBefore”是指在最后一个新命令前面的所有以前的命令都会被删除:
Importance level (重要程度)
目前尚未应用。使用时请设定为“0”。
使用实例
Python语言:
import naoqi from naoqi import ALProxy dcm = ALProxy("DCM","127.0.0.1",9559) dcm.set(["ChestBoard/Led/Red/Actuator/Value", "Merge", [[1.0,dcm.getTime(10000)]] ])
C++语言
// Program running in a module. Do not forget the #include "dcmproxy.h" try { DCMProxy* dcm = new DCMProxy(pBroker); ALValue commands; commands.arraySetSize(3); commands[0] = string("ChestBoard/Led/Red/Actuator/Value"); commands[1] = string("Merge"); commands[2].arraySetSize(1); commands[2][0].arraySetSize(2); commands[2][0][0] = 1.0; commands[2][0][1] = dcm->getTime(10000); dcm->set(commands); } AL_CATCH_ERR(return false;);
胸部红色发光二极管的新值会在10s里变为1.0。DCM会使用当前发送的值进行插值。
Python语言:
import naoqi from naoqi import ALProxy dcm = ALProxy("DCM","127.0.0.1",9559) dcm.set([ "ChestBoard/Led/Red/Actuator/Value", "ClearAll", [ [1.0, dcm.getTime(2000) ], [0.0, dcm.getTime(4000) ], [1.0, dcm.getTime(6000) ], [0.0, dcm.getTime(8000) ] ] ])
C++语言:
// Program running in a module. Do not forget the #include "dcmproxy.h" try { DCMProxy* dcm = new DCMProxy(pBroker); ALValue commands; commands.arraySetSize(3); commands[0] = string("ChestBoard/Led/Red/Actuator/Value"); 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(2000); commands[2][1].arraySetSize(2); commands[2][1][0] = 0.0; commands[2][1][1] = dcm->getTime(4000); commands[2][2].arraySetSize(2); commands[2][2][0] = 1.0; commands[2][2][1] = dcm->getTime(6000); commands[2][3].arraySetSize(2); commands[2][3][0] = 0.0; commands[2][3][1] = dcm->getTime(8000); dcm->set(commands); } AL_CATCH_ERR(return false;);
这是发送至胸部绿色发光二极管的4个命令的列表。
发光二极管的值在2s里将为1.0,在4s里为0,在6s里 重为1.0,然后在8s重又回到0。
结果是您可以看到发光二极管在80s里渐亮、渐暗两次。
注释: |
这里所有的范例都使用“dcm.getTime()”来获得定时命令请求的所有时间。 这只是一个例子,还有其它更好的使用方式。 例如,您可以在启动时只完成一次“dcm.getTime()”,然后增加每毫秒整数值。 或者如果机器人上有一个模块在运行时,您也可以使用CPU时钟。 |
---|
Python语言:
import naoqi from naoqi import ALProxy dcm = ALProxy("DCM","127.0.0.1",9559) dcm.set([ "US/Actuator/Value", "ClearAll", [ [64.0+4.0, dcm.getTime(0) ], [32.0 , dcm.getTime(3000) ] ] ])
C++语言:
// Program running in a module. Do not forget the #include "dcmproxy.h" try { DCMProxy* dcm = new DCMProxy(pBroker); ALValue commands; commands.arraySetSize(3); commands[0] = string("US/Actuator/Value"); commands[1] = string("ClearAll"); commands[2].arraySetSize(2); commands[2][0].arraySetSize(2); commands[2][0][0] = 68.0; commands[2][0][1] = dcm->getTime(0); commands[2][1].arraySetSize(2); commands[2][1][0] = 32.0; commands[2][1][1] = dcm->getTime(3000); dcm->set(commands); } AL_CATCH_ERR(return false;);
这个命令会在三秒内、在左右两侧每100ms进行一次测量。 每次测量时,两侧的10个回声会保存在ALmemory中的如下位置: Device/SubDeviceList/US/Left/Sensor/Value, Device/SubDeviceList/US/Right/Sensor/Value, Device/SubDeviceList/US/Left/Sensor/Value1, Device/SubDeviceList/US/Right1/Sensor/Value1, Device/SubDeviceList/US/Left/Sensor/Value2, Device/SubDeviceList/US/Right1/Sensor/Value2……