Hi
I'm using the MTi-G-710 sensor with the Arduino Uno via UART communication.
The communication is established between both.
I'm using the program from an old thread and here is the code after some modification and after I comment the xconfig function cause am already doing that on the MT manager.
#include <SoftwareSerial.h>
SoftwareSerial Serial1(7, 6); //232_TX,232_RX
//0xFA preamble
byte gotoConfig[] = {0xFA,0xFF,0x30,0x00,0xD1};
byte gotoMeasurement[] = {0xFA,0xFF,0x10,0x00,0xF1};
byte setOutputSkipFactor[] = {0xFA,0x01,0xD4,0x02,0xFF,0xFF,0x2B};
byte reqData[] = {0xFA,0x01,0x34,0x00,0xCB};
byte inByte = 0x00;
byte xsensBID,xsensMID,xsensLEN,xsensCHECKSUM,xsensSTATUS;
union {
byte asByte[4];
float asFloat;
} xsensLatitude;
union {
byte asByte[4];
float asFloat;
} xsensLongitude;
union {
byte asByte[4];
float asFloat;
} xsensAltitude;
union {
byte asByte[2];
unsigned int asInt;
} xsensSample;
void setup(){
Serial.begin(115200);
Serial1.begin(115200);
//xsensConfigure();
}
void loop() {
/*poll xsens for a message*/
xsensGetData();
delay(2000);
}
/*********************************************************
This function is to take the MTData message from xsens and
place it into global variables which can be recorded by the
microcontroller
**********************************************************/
void xsensGetData()
{
Serial.println("HI Xsens");
byte xsensBuffer[100];
int i = 0;
Serial1.write(reqData,5);
//Serial.print("\nRequest Data");
while(Serial1.available() ==0){}
while(Serial1.available())
{
xsensBuffer[i] = Serial1.read();
Serial.println("xsensBuffer");
Serial.println(xsensBuffer[i]);
delay(20);
i++;
if(i==100)
break;
}
xsensBID=xsensBuffer[1];
xsensMID=xsensBuffer[3];
xsensLEN=xsensBuffer[5];
/*if(xsensBID==0xFF && xsensMID == 0x32){*/
//Latitude, longitude, altitude
xsensLatitude.asByte[3] = xsensBuffer[11];
xsensLatitude.asByte[2] = xsensBuffer[12];
xsensLatitude.asByte[1] = xsensBuffer[13];
xsensLatitude.asByte[0] = xsensBuffer[14];
xsensLongitude.asByte[3] = xsensBuffer[15];
xsensLongitude.asByte[2] = xsensBuffer[16];
xsensLongitude.asByte[1] = xsensBuffer[17];
xsensLongitude.asByte[0] = xsensBuffer[18];
xsensAltitude.asByte[3] = xsensBuffer[19];
xsensAltitude.asByte[2] = xsensBuffer[20];
xsensAltitude.asByte[1] = xsensBuffer[21];
xsensAltitude.asByte[0] = xsensBuffer[22];
xsensSTATUS = xsensBuffer[16];
xsensSample.asByte[1] = xsensBuffer[23];
xsensSample.asByte[0] = xsensBuffer[24];
xsensCHECKSUM = xsensBuffer[22];
byte byteSum = 0;
for(i = 1;i<=24;i++){
byteSum += xsensBuffer[i];
}
// The following will print GPS Active - 1, Kalman filter active -1, latitude, longitude, altidude, sample number*/
Serial.print("MSG-0:");Serial.print(byteSum,HEX);
Serial.print("\tGPS:");Serial.print(bitRead(xsensSTATUS,2));
Serial.print("\tKXF:");Serial.print(bitRead(xsensSTATUS,1));
Serial.print("\t");Serial.print(xsensLatitude.asFloat,DEC);
Serial.print("\t");Serial.print(xsensLongitude.asFloat,DEC);
Serial.print("\t");Serial.print(xsensAltitude.asFloat,DEC);
Serial.print("\t");Serial.print(xsensSample.asInt,DEC);
xsensLatitude.asFloat = 0;
xsensLongitude.asFloat = 0;
xsensAltitude.asFloat = 0;
xsensSample.asInt = 0;
Serial.print("\tBID:");
Serial.print(xsensBID,HEX);
Serial.print("\tMID:");
Serial.print(xsensMID,HEX);
Serial.print("\tLEN:");
Serial.print(xsensLEN,DEC);
Serial.print("\n");
}
/********************************************************
the purpose of this function is to configure the
xsens to only send data when it is polled
*********************************************************/
void xsensConfigure(){
byte xsensByte = 0x00;
int i = 0; //i is a generic counter
Serial.println("\nConfiguration Mode\n");
/*set xsens to configuration mode*/
Serial1.write(gotoConfig,5);
while(Serial1.available() ==0)
{
}
while(Serial1.available())
{
xsensByte = Serial1.read();
Serial.print(xsensByte);
Serial.print("\t");
delay(5);
}
/*Tells xsens to only send messagewhen polled*/
Serial.println("\nOnly send data when polled\n");
Serial1.write(setOutputSkipFactor,7);
while(Serial1.available() ==0){}
while(Serial1.available()){
xsensByte = Serial1.read();
Serial.print(xsensByte);
Serial.print("\t");
delay(5);
}
/*set xsens to configuration mode*/
Serial.println("\nMeasurement Mode\n");
Serial1.write(gotoMeasurement,5);
while(Serial1.available() ==0){}
while(Serial1.available()){
xsensByte = Serial1.read();
Serial.print(xsensByte);
Serial.print("\t");
delay(5);
}
Serial.print("\n");
}
/*Message Order
1. GPSPVT Data
2.Temp
3. Calibrated Data
4. Orientation Data
5. Auxiliary Data
6. Position (float - 4 BYTE)
7. Velocity (float - 4 BYTE)
8. Status
9. Sample (unsigned int 2 BYTES)
*/
My configuration on the MT manager is only reading the status word and the GNSS PVT Data.
in the code I didn't understand the order of the message and from where we get the request data.
why the first three bytes are BID,MID and the length.
cause when am reading the xsens using the MT manager, I'm getting only the PVT data which is 94 bytes.
I feel that my data that am reading is not correct and sometime the GPS is active and sometimes not.
I need to know how can I read the sensor according to my configuration on the MT manger.
Your help and support will be really appreciated.
Thank you in advance
Nada