質問

既存のコードをから取得しました このプロジェクト, 、今のところとても満足しています。

ただし、現在は、購入したいくつかのサードパーティ製センサーを使用する必要がある状況にあります。 ハイテクな, いくつか例を挙げると、加速度計、ジャイロスコープ、3D コンパスなどがあります。

どこから始めればよいかわかりませんが、既存のコード ベース ( これ)、フレームワークを新しいハードウェアに効果的に接着します。

誰か私を正しい方向に向けてくれませんか?デバイスの製造元からの API が見つかりません (ただし、電子メールで問い合わせましたが、まだ返答はありません)。

また、調査結果を文書化することも始めました。 これ ページ。

役に立ちましたか?

解決

さて、私は見ていたしました。ジャイロなどのアナログセンサは、簡単に死んでいる...

私はかなりちょうど再利用している他のアナログセンサの - ライトセンサー...

- (void)setupGyroscopicSensor:(UInt8)port {
    [self setInputMode:port
                  type:kNXTGyroscope
                  mode:kNXTRawMode];
}

ポーリングのために、私は一般的なポーリング方式を使用...

- (void)pollSensor:(UInt8)port interval:(NSTimeInterval)seconds;

... LegoNXTRemoteコードから。

デジタルものは同じくらい簡単ではありません - 特別ゼロSW / HW経験を持っている人に。ここで働いて超音波センサコード、設定、およびポーリングのためです。私は最後に、これらのメソッドのプロトタイプと完全なコードに興味のある人のためのgitのクローンを作成します。

- (void)setupUltrasoundSensor:(UInt8)port continuous:(BOOL)continuous;
- (void)getUltrasoundByte:(UInt8)port byte:(UInt8)byte;
- (void)pollUltrasoundSensor:(UInt8)port interval:(NSTimeInterval)seconds;
それは、ポーリングのためにそれ自身の専用のメソッドを持っているか

注。だから、今の質問は、加速度計のための1つを書く方法です。

センサーを購入する際、あなたが取得する情報は、コンテンツのテーブルマッピングアドレスです。

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への参照を見ることができます - 。アドレスがどこに行くである私は推測していたが、それがすべてです私はできの推測の今

私はこの上の任意の進捗状況を取得する場合、あなたが知ってもらおう。

<時間>

さて、ここでは加速度センサーとATの場所です。

私が最初のデバイスに次のようなメッセージを送って...

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]];
誰もがこのに興味を持っている場合は、

、私はソースをダウンロードし、それを試してみるためにあなたを招待 - 。私は、これは一見それはOKに見えるにもかかわらず、

、実際に正しいことを科学的に証明するためにまだです <時間> さて、私はいくつかのテストをやった - それは良いように見えます。 1 G〜200単位(私は、彼らが少し良く200〜よりやった希望、エラーのいくつかの兆候が素敵だっただろう)ことを示す< - 私は、デバイスに付属の説明書に従って、Gさんに値を変換しました。 / 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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top