小编Wou*_*ert的帖子

对象链接与API扩展中的方法

所以我正在寻求根据自己的需要扩展/调整API.我说的是Lego Mindstorms C#API.我正在围绕它构建自己的API(基于适配器模式),因此我可以以更好的OO方式对机器人进行编程.

以下是有关API如何工作的链接:Lego Mindstorms EV3 C#API

但现在我陷入了一种非常奇怪的方式,C#API处理砖块的命令.

绝对不是OO方式......

示例:要向砖块发送命令,您需要有一个砖块实例来发送命令.但DirectCommand实例与砖块无关.

await brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, 50, 5000);
Run Code Online (Sandbox Code Playgroud)

所以我想要做的就是让brick和DirectCommand松散耦合.

这是另一个例子:执行一批命令.您必须写出所有命令,然后执行某种方法.在当前的API中,无法循环遍历数组并添加堆栈元素,以便稍后执行它们.

brick.BatchCommand.TurnMotorAtSpeedForTime(OutputPort.A, 50, 1000, false);
brick.BatchCommand.TurnMotorAtPowerForTime(OutputPort.C, 50, 1000, false);
brick.BatchCommand.PlayTone(50, 1000, 500);
await brick.BatchCommand.SendCommandAsync();
Run Code Online (Sandbox Code Playgroud)

所以我想做的是:

创建一个像PlayTone(..)这样的命令,将它添加到命令的arrayList中,然后遍历它......

List<Command> toBeExecuted = new List<Command>;
toBeExecuted.Add(DirectCommand.PlayTone(50, 1000, 500));
brick.DirectCommand(toBeExecuted[0]);
Run Code Online (Sandbox Code Playgroud)

所以,如果有人可以帮助......我会非常高兴:)

c# oop lego-mindstorms

5
推荐指数
1
解决办法
106
查看次数

标签 统计

c# ×1

lego-mindstorms ×1

oop ×1