سؤال

لقد أخذت الرمز الحالي من هذا المشروع, وسعيد جدا معها حتى الآن.

ومع ذلك ، فأنا الآن في وضع أحتاج فيه إلى الاستفادة من بعض مستشعرات الطرف الثالث الذي اشتريته من Hitechnic, ، مثل مقياس التسارع ، جيروسكوب ، بوصلة ثلاثية الأبعاد - على سبيل المثال لا الحصر.

لست متأكدًا من أين أبدأ الآن ، ولكن ما أحتاج إلى القيام به هو إضافة إلى قاعدة الكود الحالية (والتي تستند إلى هذه) ، و glue بشكل فعال إطاري على الأجهزة الجديدة.

يمكن لأي شخص لي نقطة في الاتجاه الصحيح؟ لا يمكنني العثور على أي واجهات برمجة التطبيقات من الشركة المصنعة للأجهزة ، (لكنني قمت بإرسال بريد إلكتروني إليها وسألتها - لا رد حتى الآن).

لقد بدأت أيضًا في توثيق النتائج التي توصلت إليها على هذه صفحة.

هل كانت مفيدة؟

المحلول

حسنًا ، لقد ألقيت نظرة. أجهزة الاستشعار التناظرية ، مثل الدوران ، ميتة سهلة ...

لقد أعادت استخدام مستشعر التناظرية الآخر - مستشعر الضوء ...

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

للاقتراع ، استخدمت طريقة الاقتراع العامة ...

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

... من رمز Legonxtremote.

الرقمية ليست سهلة - خاصة لشخص لديه تجربة صفر/HW. فيما يلي رمز المستشعر بالموجات فوق الصوتية العاملة ، والإعداد ، وللمرق. سأكتب فقط النموذج الأولي لهذه الأساليب واستنساخ 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 ، فإن بعض المؤشرات على الخطأ كانت لطيفة).

//. 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

مراجع:

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top