- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我从 this project 中获取了现有代码,并且到目前为止对此非常满意。
但是,我现在需要使用从 hitechnic 购买的一些第三方传感器。 ,例如加速度计、陀螺仪和 3D 罗盘 - 仅举几例。
我不确定现在从哪里开始,但我需要做的是添加到我现有的代码库(基于 this ),并将我的框架有效地粘合到新硬件上。
谁能指出我正确的方向?我找不到设备制造商提供的任何 API(但我已通过电子邮件向他们询问 - 尚未回复)。
我也开始在 this 上记录我的发现页面。
最佳答案
好的,我已经看过了。陀螺仪等模拟传感器非常简单...
我几乎只是重复使用了另一个模拟传感器 - 光传感器...
- (void)setupGyroscopicSensor:(UInt8)port {
[self setInputMode:port
type:kNXTGyroscope
mode:kNXTRawMode];
}
对于轮询,我使用了通用的轮询方法...
- (void)pollSensor:(UInt8)port interval:(NSTimeInterval)seconds;
...来自 LegoNXTRemote 代码。
数字版本并不那么容易 - 特别是对于软件/硬件经验为零的人。这是工作的超声波传感器代码、设置和轮询。最后我只会写这些方法的原型(prototype)和一个 git clone 给那些对完整代码感兴趣的人。
- (void)setupUltrasoundSensor:(UInt8)port continuous:(BOOL)continuous;
- (void)getUltrasoundByte:(UInt8)port byte:(UInt8)byte;
- (void)pollUltrasoundSensor:(UInt8)port interval:(NSTimeInterval)seconds;
请注意它如何拥有自己的专用轮询方法。所以,现在的问题是如何为加速度计编写一个。
您在购买传感器时获得的信息是一个将地址映射到内容的表格:
42H (byte) -> X-axis upper 8 bits
43H (byte) -> X-axis upper 8 bits
44H (byte) -> X-axis upper 8 bits
45H (byte) -> X-axis lower 8 bits
46H (byte) -> X-axis lower 8 bits
47H (byte) -> X-axis lower 8 bits
...查看超声波传感器,我可以看到对 0x42
的引用 - 我猜这就是地址所在的位置,但我只能猜了现在。
如果我在这方面取得任何进展,我会通知您。
好的,这里是加速度计所在的位置。
我首先向设备发送以下消息...
0x07, 0x00, 0x00, 0x0f, 0x03, 0x02, 0x08, 0x02, 0x42
这分别意味着什么(我很可能是错的)是......
kNXTRawMode
kNXTGetInputValues
kNXTRet //. Meaning we expect a return value
kNXTLSWrite //. As opposed to read
port //. Port 0x03 --> Port 4
txLength
rxLength
//. message...
0x02 //. Set the I2C slave address
0x42 //. Set the register we're interested in
接下来我们发送一个读取请求...
0x03, 0x00, 0x00, 0x0e, 0x03
然后我们得到回应...
0x03, 0x00, 0x02, 0x0f, 0xe0
...并以错误结束。
这是一大块日志...
libNXT[0x02]: Attempting to connect to NXT...
libNXT[0x02]: Open sequence initiating...
libNXT[0x02]: Channel Opening Completed
libNXT[0x08]: >>> :0x06, 0x00, 0x80, 0x03, 0x0b, 0x02, 0xf4, 0x01,
libNXT[0x08]: >>> :0x02, 0x00, 0x00, 0x0b,
libNXT[0x08]: <<< :0x05, 0x00, 0x02, 0x0b, 0x00, 0x82, 0x1e,
libNXT[0x08]: @selector does NOT respond to NXTOperationError:operation:status:
libNXT[0x08]: @selector responds to NXTBatteryLevel:batteryLevel:
startPollingSensor: setup sensor
startPollingSensor: start polling
libNXT[0x02]: Polling Port 3
libNXT[0x08]: >>> :0x07, 0x00, 0x00, 0x0f, 0x03, 0x02, 0x08, 0x02, 0x42,
libNXT[0x08]: >>> :0x03, 0x00, 0x00, 0x0e, 0x03,
libNXT[0x08]: <<< :0x03, 0x00, 0x02, 0x0f, 0xe0,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xf status=0xe0
libNXT[0x08]: <<< :0x04, 0x00, 0x02, 0x0e, 0xe0, 0x00,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xe status=0xe0
libNXT[0x08]: @selector does NOT respond to NXTOperationError:operation:status:
libNXT[0x02]: Polling Port 3
libNXT[0x08]: >>> :0x07, 0x00, 0x00, 0x0f, 0x03, 0x02, 0x08, 0x02, 0x42,
libNXT[0x08]: >>> :0x03, 0x00, 0x00, 0x0e, 0x03,
libNXT[0x08]: <<< :0x03, 0x00, 0x02, 0x0f, 0xe0,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xf status=0xe0
libNXT[0x08]: <<< :0x04, 0x00, 0x02, 0x0e, 0xe0, 0x00,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xe status=0xe0
libNXT[0x08]: @selector does NOT respond to NXTOperationError:operation:status:
libNXT[0x02]: Polling Port 3
libNXT[0x08]: >>> :0x07, 0x00, 0x00, 0x0f, 0x03, 0x02, 0x08, 0x02, 0x42,
libNXT[0x08]: >>> :0x03, 0x00, 0x00, 0x0e, 0x03,
libNXT[0x08]: <<< :0x03, 0x00, 0x02, 0x0f, 0xe0,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xf status=0xe0
libNXT[0x08]: <<< :0x04, 0x00, 0x02, 0x0e, 0xe0, 0x00,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xe status=0xe0
libNXT[0x08]: @selector does NOT respond to NXTOperationError:operation:status:
Error while running hook_stop:
libNXT[0x08]: >>> :0x03, 0x00, 0x00, 0x0e, 0x03,
libNXT[0x08]: <<< :0x03, 0x00, 0x02, 0x0f, 0xe0,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xf status=0xe0
libNXT[0x08]: <<< :0x04, 0x00, 0x02, 0x0e, 0xe0, 0x00,
libNXT[0x08]: @selector responds to NXTOperationError:operation:status:
nxt error: operation=0xe status=0xe0
这全部基于 here 中的示例代码, 如下...
SetSensorLowspeed(IN_1);
int count;
int xval;
int yval;
int zval;
byte inI2Ccmd[];
byte outbuf[];
while (TRUE) {
ArrayInit(inI2Ccmd, 0, 2); // set the buffer to hold 10 values (initially all are zero)
inI2Ccmd[0] = 0x02; // set values in the array
inI2Ccmd[1] = 0x42;
count=8; //read count set to 8 bytes
I2CBytes(IN_1, inI2Ccmd, count, outbuf); //read the acceleration sensor on port 1
xval=outbuf[0]; //load x axis upper 8 bits
yval=outbuf[1]; //load Y axis upper 8 bits
zval=outbuf[2]; //load z axis upper 8 bits
if (xval > 127) xval-=256; //convert x to 10 bit value
xval=xval*4 + outbuf[3];
if (yval > 127) yval-=256; //convert y to 10 bit value
yval=yval*4 + outbuf[4];
if (zval > 127) zval-=256; //convert z to 10 bit value
zval=zval*4 + outbuf[5];
...
}
太棒了!看起来它现在可以工作了——我只需要摆弄输出以提取实际的 X、Y 和 Z 读数。
如果它确实有效,我会让大家知道,但在我证明它之前,我会保留这张票。
好的,看起来它现在可以工作了,但是传感器中有足够多的错误,而且我还没有证明我已经真正解决了这个问题。这是代码片段:
SInt8 *outbuf = malloc(48);
[data getBytes:outbuf length:6];
SInt16 x = outbuf[0]; x <<= 2; x += outbuf[3];
SInt16 y = outbuf[1]; y <<= 2; y += outbuf[4];
SInt16 z = outbuf[2]; z <<= 2; z += outbuf[5];
free(outbuf);
[self setSensorTextField:port
value:[NSString stringWithFormat:@"<%d, %d, %d>",
x, y, z]];
如果有人对此感兴趣,我邀请您下载源代码并尝试一下 - 我还没有科学地证明这实际上是正确的,尽管乍一看它看起来不错。
好的,我已经进行了一些测试 - 看起来不错。根据设备随附的说明,我已将值转换为 G 值 - 说明 1 G ~ 200 单位(我希望他们做得比 ~200 好一点,一些错误指示会很好)。
//. Acceleration in G's
SInt8 *outbuf = malloc(48);
[data getBytes:outbuf length:6];
SInt16 x = outbuf[0]; x <<= 2; x += outbuf[3]; float gX = x/200.f;
SInt16 y = outbuf[1]; y <<= 2; y += outbuf[4]; float gY = y/200.f;
SInt16 z = outbuf[2]; z <<= 2; z += outbuf[5]; float gZ = z/200.f;
free(outbuf);
[self setSensorTextField:port
value:[NSString stringWithFormat:@"%0.2f, %0.2f, %0.2f",
gX, gY, gZ]];
如果您按照供应商页面放置设备,您可以看到每次访问都命中了约 1.02f 的加速度读数。
我想我现在可以关闭它并着手清理框架。
可以在以下位置 checkout 代码:
git clone git://git.autonomy.net.au/nimachine Nimachine
关于objective-c - Lego Mindstorm NXT、Cocoa 和 HiTechnic 传感器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1967978/
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
使用 NXT 拖放环境时,是否可以向 Lego Mindstorms 程序添加任何类型的调试? 如果能够监控各种传感器的状态,那就太好了,但甚至知道程序中正在运行的步骤也更好。 最佳答案 事实证明,这
所以我正在使用legOS(小乐高机器人),基本上我正在做的就是找到A*迷宫的解决方案,我想用它来告诉机器人在迷宫中移动的位置。 但是我一直遇到的问题是,当我尝试启动优先队列时,它给了我这个异常 js.
我做了这个例子https://github.com/jetstack/kube-lego/tree/master/examples/gce ,然后创建 ClusterRole kube-lego 失败
我尝试在 eclipse 中设置 leJOS,并从 git 导入所有库,但使用 ant 构建进行编译时遇到问题。这是我的构建文件:
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 2 年前。 Improve this qu
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
前几天我正在玩乐高数字设计师(http://ldd.lego.com/),我想知道保存的文件是否可以相对容易地解析。以前有人这样做过吗?我正在寻找代码示例,无论使用哪种语言:) 谢谢! 罗曼 最佳答案
这个问题是指编写一个与乐高头脑 Storm 机器人上的 NXT block 通信的应用程序。 我想做什么 NXC(不完全是 C,一种用于为 NXT 编写程序的语言)提供了一个函数 until(cond
是否有用于 Lego Mindstorms 的 Java SDK?我可以将 Scala 代码编译为 JAR 并在 Lego Mindstorms 中运行吗? 最佳答案 可能不会,但很难说。 Minds
有人知道如何在 Android 和 LEGO-Mindstorm-NXT 之间建立蓝牙连接吗?两个 NXT 之间的连接工作正常。但是其他的Connection-type就没那么容易了。我正在使用 Le
前阵子,我为圣诞节准备了一套 LEGO Mindstorms NXT,现在我想用 C++ 对其进行编程。 我环顾四周,在这里和其他地方,找不到“感觉正确”的跨平台、开源、OOP C++ 库,包括 le
我想使用 nginx 和用 Go 编写的 lego 客户端将 Let's Encrypt 证书设置为实时服务器 https://github.com/xenolf/lego/ 我将如何使用 nginx
我正在开发一个从计算机运行 LEGO NXT 的程序。我找到了 MindSqualls用于与 LEGO NXT 一起工作的 .NET 库,但我不知道如何使用 DLL 和/或 c# 库来使软件正常工作。
有谁知道如何从一个自己编写的 iOS 应用程序建立一个蓝牙连接到新的 LEGO Mindstorms EV3 可编程积木? 我试图通过 CBCentralManager 的 scanForPeriph
我想开始使用 Python 或 Ruby 进行编码。由于我拥有 Lego Midstorms套件我认为对它进行编程会很好。 Mindstorms 砖有什么好的翻译/解释者吗? 最佳答案 nxt-pyt
我一直在使用新的 LEGO® MINDSTORMS® Robot Inventor。 创建新的“项目”时,所述项目似乎包含一个文件。但是,在每个示例代码文件的开头,可以看到 mindstorm 模块被
对于一个大学项目,我们的项目团队想要为 Lego Mindstorm EV3 平台编写一个裸机操作系统。尽管我们做了很多研究和测试,但我们遇到了一个无法解决的中断处理问题。 这是平台的详细信息: CP
我从 this project 中获取了现有代码,并且到目前为止对此非常满意。 但是,我现在需要使用从 hitechnic 购买的一些第三方传感器。 ,例如加速度计、陀螺仪和 3D 罗盘 - 仅举几例
我是一名优秀的程序员,十分优秀!