【发布时间】:2014-06-16 23:06:05
【问题描述】:
我正在尝试使用 C++ 与 LEGO Mindstorms EV3 积木进行通信。我克隆了ev3sources repo,它允许我通过蓝牙来执行此操作 - 例如,启动连接到端口 A 的电机,我们可以这样做:
#include <unistd.h>
#include <fcntl.h>
#include "ev3sources/lms2012/c_com/source/c_com.h"
int main()
{
// start motor on port A at speed 20
unsigned const char start_motor[] {12, 0, 0, 0,
DIRECT_COMMAND_NO_REPLY,
0, 0,
opOUTPUT_POWER, LC0(0), LC0(0x01), LC0(20),
opOUTPUT_START, LC0(0), LC0(0x01)};
// send above command to EV3 via Bluetooth
int bt = open("/dev/tty.EV3-SerialPort", O_WRONLY);
write(bt, start_motor, 14);
close(bt);
}
但是如何从 EV3 程序块取回数据?例如,假设我想读取连接到端口 1 的任何传感器捕获的数据。基于the repo examples,我知道我需要一些看起来像这样的东西:
#include <unistd.h>
#include <fcntl.h>
#include "ev3sources/lms2012/c_com/source/c_com.h"
int main()
{
// read sensor on port 1
unsigned const char read_sensor[] {11, 0, 0, 0,
DIRECT_COMMAND_REPLY,
0, 0,
opINPUT_READ, LC0(0), LC0(0), LC0(0), LC0(0), GV0(0)};
// send above command to EV3 via Bluetooth
int bt = open("/dev/tty.EV3-SerialPort", O_WRONLY);
write(bt, read_sensor, 13);
close(bt);
}
但是缺少一些东西 - 上面的 sn-p 没有返回任何错误,但我不知道传感器数据在哪里。那么,我该如何找回呢?我想它也是通过蓝牙发回的,但我该如何捕捉呢?
(OS X 10.9.3,Xcode 5.1.1,EV3 [31313])
【问题讨论】:
-
你从哪里得到:#include "ev3sources/lms2012/c_com/source/c_com.h" 来自?
-
谢谢蒂亚戈,那么您是在拖动整个 lms2012 目录还是在使用 DLL?
-
我正在拖动整个 lms2012 目录。
-
嗯,我是 - 一年前我停止在 C++ 中这样做,并制作了一个 Python 模块来让我的生活更轻松 (github.com/thiagomarzagao/ev3py)。
标签: c++ lego mindstorms