Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

3-axis accelerometer


vk Jun 14, 2011 01:26 PM

Hello

I have accelerometer which gives roll,pitch and yaw Euler angles in addition to many other functions output in digital form.command (0x0E)is one byte length and it give 11 byte hex output with last two bytes check sum as follows.
byte1- header byte(i.e. as command byte),byte2-roll MSB,byte3-roll LSB,byte4-pitch MSB,byte5-pitch LSB,byte6-yaw MSB. byte7-yaw LSB,byte8&9-timertick MSB&LSB,byte10&11-ckecksum MSB&LSB.Detail communication protocol is given at www.microstrain.com/manuals/3DM-GX1%20Data%20Communication%20Protocol%203102.pdf.

I have following difficulties:

1) I aligned accelerometer in such a manner that it should give output close to zero when it is kept on a table. I noticed that its roll,pitch & yaw keeps varying (e.g roll & yaw sometimes goes to 150 Deg.) Sensor gives correct reading when supplier's software is used, confirms that sensor is working fine.
2) buffer & NBytesReturned keeps changing sometimes goes to 20 byte. I guess 11 byte output.
3) when accelerometer tilted to some angle "Instring" displaying digit 1 followed by some characters which is either non-distinguishable or some other ASCII characters and often NON.
4) when it is tilted at one angle say positive from main axis, opposite tilt from main axis should provide negative angle( e.g roll varies from -180 to + 180 deg). I do not know in CR code how to achieve negative angle.

Any help would be greatly appreciated. Thanks

below is code:

'CR3000 Series Datalogger
Public NBytesReturned As Long *100
Public Instring(1) As String *100
Public buffer As Long *100
Public roll As Float
Public pitch As Float
Public yaw As Float
Public command As String
Public roll_str_MSB As Long
Public roll_str_LSB As Long
Public pitch_str_MSB As Long
Public pitch_str_LSB As Long
Public yaw_str_MSB As Long
Public yaw_str_LSB As Long
Public header_info
Public time_tik_MSB As Long
Public time_tik_LSB As Long
Public cheksm_MSB As Long
Public cheksm_LSB As Long
Public cheksm As Long
Public roll_2,roll_3,pitch_4,pitch_5,yaw_6,yaw_7 As Float
Public time_tik_8,time_tik_9,cheksm_10,cheksm_11 As Float
Dim rolldigit,pitchdigit,yawdigit As Float
Dim time_tikdigit,cheksmdigit As Float
Dim euler_convert_factor As Float

'------------------------------------
'SequentialMode
DataTable (attitude,1,-1)
DataInterval (0,1,Min,10)
'Sample (1,roll,FP2)
'Sample (1, pitch,FP2)
'Sample (1,yaw,FP2)
Average(1, roll,FP2,0)
Average(1, pitch,FP2,0)
Average(1, yaw,FP2,0)

EndTable
'-------------------------------------
'Main Program

BeginProg
euler_convert_factor = (360.0 / 65536.0)
Instring =0
buffer = 0
SerialOpen(Com1,38400,0,0,200)
Delay (0,15,mSec)
Scan (1,Sec,3,0)
SerialFlush(Com1)
command = &H0E
SerialOut(com1,command,"",0,100)
Delay(0,100,mSec)
buffer = SerialInChk(Com1)
SerialInRecord(Com1,Instring,&H00,0,&H00,NBytesReturned,01)
'---------------------------------------
header_info = ASCII(Instring(1,1,1))
roll_str_MSB = ASCII(Instring(1,1,2))
roll_str_LSB = ASCII (Instring(1,1,3))
pitch_str_MSB = ASCII (Instring(1,1,4))
pitch_str_LSB = ASCII (Instring(1,1,5))
yaw_str_MSB = ASCII (Instring (1,1,6))
yaw_str_LSB = ASCII (Instring (1,1,7))
time_tik_MSB = ASCII(Instring (1,1,8))
time_tik_LSB = ASCII(Instring(1,1,9))
cheksm_MSB = ASCII (Instring(1,1,10))
cheksm_LSB = ASCII (Instring(1,1,11))
'-----------------------------------
roll_2 = roll_str_MSB *256 'adjust MSB
roll_3 = roll_str_LSB
rolldigit = roll_2 + roll_3
roll = rolldigit *euler_convert_factor

pitch_4 = pitch_str_MSB *256
pitch_5 = pitch_str_LSB
pitchdigit = pitch_4 + pitch_5
pitch = pitchdigit *euler_convert_factor

yaw_6 = yaw_str_MSB *256
yaw_7 = pitch_str_LSB
yawdigit = yaw_6 + yaw_7
yaw = yawdigit *euler_convert_factor
'----------------------------------
CallTable attitude
NextScan
EndProg


JDavis Aug 4, 2011 08:17 PM

Fill in the BeginWord and NBytes parameters of SerialinRecord.
Doing so, you can indicate which byte the response begins with, and the number of bytes in the response. Note that BeginWord will not be included in the result from SerialInRecord.

16 bit signed integers are not too hard to handle.
To handle the negative values do something like:

If rolldigit > 32767 then
rolldigit = rolldigit - 65536
Endif


vk Dec 30, 2011 07:23 AM

JDavis:

Thanks for hint and sorry for delay in response. I made it working and that data is coming now as expected. I modified above code again with your suggestions.
Thanks.vk

Log in or register to post/reply in the forum.