Lego神鬼奇兵六角形、可可和HiTechnic传感器
-
21-09-2019 - |
解决方案
好吧,我去看过。模拟传感器,如陀螺,都死了容易...
我非常简单,只是重复使用另一个模拟传感器的 - 光传感器...
- (void)setupGyroscopicSensor:(UInt8)port {
[self setInputMode:port
type:kNXTGyroscope
mode:kNXTRawMode];
}
有关轮询,我使用的通用轮询方法...
- (void)pollSensor:(UInt8)port interval:(NSTimeInterval)seconds;
...从LegoNXTRemote代码。
在数字1是不容易 - 特别是对谁的人有零点软件/硬件体验。下面是工作超声波传感器代码,设置和轮询。我只写的这些方法的原型,并为那些有兴趣在最后的完整代码一个git克隆
- (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
这是所有基于从此处的示例代码,它是如下...
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,错误的一些指示本来不错)<。 / p>
//. 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的。
我想我现在可以关闭该关闭和清理框架的工作。
的代码可以在被检查出:
git clone git://git.autonomy.net.au/nimachine Nimachine
其他提示
我听说回来,从HiTechnic今天,和与他们的许可,我发布它们响应这里的每一个人。
Hi Nima,
There are two types of sensors, digital and analog. The Analog sensors you
can basically read like you would the LEGO light sensor. If you have that
working then you can read the HiTechnic analog sensors. These include the
EOPD, Gyro as well as the Touch Multiplexer.
For the TMUX there is [sample NXC code][1] on the product info page.
You should be able to use that as a basis if you want to support this device.
The other sensors are digital I2C sensors. Most of these sensors have I2C
register information on their respective product information page and/or it
was included on a sheet that came with the sensor. First of all, to make
these sensors work with your framework you need to have I2C communications
working. After that it will be a matter of creating your own API that uses
the I2C interface with the sensors. I recommend that you download and look
at Xander Soldaat's RobotC driver suite for the HiTechnic sensors. You will
find this near the bottom of the HiTechnic downloads page.
Regards,
Gus
HiTechnic Support
参考文献: