我正在Urbi为Aibo ERS-7开展一个项目。由于Urib 2不适用于Aibo,我使用以下内容:
URBI Language specif 1.0 - Copyright (C) 2005-2008 Gostai SAS
URBI Kernel version 1.5 rev. 51997ef
我想知道为什么以下代码生成错误。它旨在在听到嘈杂的噪音时做出随机动作。代码如下。
motor on;
robot.initial();
robot.stretch();
whenever (micro.volume >= 1000)
{
randomval = random(16);
switch (randomval)
{
case 0: //LF1
legLF1.val = (random(254) - 120);
case 1: //LF2
legLF2.val = (random(100) - 9);
case 2: //LF3
legLF3.val = (random(148) - 29);
case 3: //RF1
legRF1.val = (random(254) - 134);
case 4: //RF2
legRF2.val = (random(100) - 9);
case 5: //RF3
legRF3.val = (random(148) - 29);
case 6: //LH1
legLH1.val = (random(254) - 120);
case 7: //LH2
legLH2.val = (random(100) - 9);
case 8: //LH3
legLH3.val = (random(148) - 29);
case 9: //RH1
legRH1.val = (random(254) - 134);
case 10: //RH2
legRH2.val = (random(100) - 9);
case 11: //RH3
legRH1.val = (random(148) - 29);
case 12: //neck
neck.val = (random(80) - 2);
case 13: //headTilt
headTilt.val = (random(60) - 16);
case 14: //headPan
neck.val = (random(182) - 91);
case 15: //mouth
mouth.val = (random(55) - 58);
}
};
生成的错误如下:
/MS/clap.u:50.10: syntax error, unexpected (
[0000037549]!!! 22.1-15: Error loading file: clap.u
[0000037549]!!! 22.1-15: Error with function eval: U596213128.load [nb param=1]
[0000037549]!!! 22.1-15: EXPR evaluation failed
据我所知,它不喜欢“switch”行的括号。我在我使用的版本中并没有真正看到“切换”的引用,并且它突出显示好像它存在于Gostai编辑器中,但在最新版本的任何更改日志中都没有提及它。它是否存在,如果存在,我做错了什么。如果它不存在,我应该只使用一堆if语句(请,不)。
答案 0 :(得分:2)
urbi 1.0确实没有开关/案例。
对一堆ifs的更好的替代方法是使用数组来存储设备和参数:
var devices = [legLF1, legLF2, ...];
var ranges = [254, 100, ...];
var offsets = [...];
devices[randomval].val = random(ranges[randomval]) + offsets[randomval];