Parcourir la source

修改arduino代码中文件名变量名。

adam_zhuo il y a 3 ans
Parent
commit
6c0bbfa33a

+ 1 - 0
README.md

@@ -0,0 +1 @@
+arduino代码分两个版本,一个是串口通信,一个是IIC通信。如果想用串口使用serial_6dof_imu包,如果想用IIC使用iic_6dof_imu包。如果想要编译双击打开对应的.ino文件即可在arduino ide中编译。

+ 11 - 11
iic_6dof_imu/iic_6dof_imu.ino

@@ -1,32 +1,32 @@
 #include <Wire.h>
-#include "JY901.h"
+#include "imuData.h"
 /*
 Test on Uno R3.
-JY901    UnoR3
+imuData    UnoR3
 SDA <---> SDA
 SCL <---> SCL
 */
 void setup() 
 {
   Serial.begin(115200);
-  JY901.StartIIC();
+  imuData.StartIIC();
 } 
 
 void loop() 
 {
   //print received data. Data was received in serialEvent;
   Serial.println("");
-  JY901.GetAcc();
-  Serial.print("Acc:");Serial.print((float)JY901.stcAcc.a[0]/32768*16);Serial.print(" ");Serial.print((float)JY901.stcAcc.a[1]/32768*16);Serial.print(" ");Serial.println((float)JY901.stcAcc.a[2]/32768*16);
+  imuData.GetAcc();
+  Serial.print("Acc:");Serial.print((float)imuData.stcAcc.a[0]/32768*16);Serial.print(" ");Serial.print((float)imuData.stcAcc.a[1]/32768*16);Serial.print(" ");Serial.println((float)imuData.stcAcc.a[2]/32768*16);
   
-  JY901.GetGyro();  
-  Serial.print("Gyro:");Serial.print((float)JY901.stcGyro.w[0]/32768*2000);Serial.print(" ");Serial.print((float)JY901.stcGyro.w[1]/32768*2000);Serial.print(" ");Serial.println((float)JY901.stcGyro.w[2]/32768*2000);
+  imuData.GetGyro();  
+  Serial.print("Gyro:");Serial.print((float)imuData.stcGyro.w[0]/32768*2000);Serial.print(" ");Serial.print((float)imuData.stcGyro.w[1]/32768*2000);Serial.print(" ");Serial.println((float)imuData.stcGyro.w[2]/32768*2000);
   
-  JY901.GetAngle();
-  Serial.print("Angle:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
+  imuData.GetAngle();
+  Serial.print("Angle:");Serial.print((float)imuData.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)imuData.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)imuData.stcAngle.Angle[2]/32768*180);
 
-  JY901.GetQuater();
-  Serial.print("Quater:");Serial.print((float)JY901.stcQuater.q[0]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[1]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[2]/32768);Serial.print(" ");Serial.println((float)JY901.stcQuater.q[3]/32768);
+  imuData.GetQuater();
+  Serial.print("Quater:");Serial.print((float)imuData.stcQuater.q[0]/32768);Serial.print(" ");Serial.print((float)imuData.stcQuater.q[1]/32768);Serial.print(" ");Serial.print((float)imuData.stcQuater.q[2]/32768);Serial.print(" ");Serial.println((float)imuData.stcQuater.q[3]/32768);
   Serial.println("");
   delay(500);
 }

+ 21 - 21
iic_6dof_imu/JY901.cpp → iic_6dof_imu/imuData.cpp

@@ -1,21 +1,21 @@
-#include "JY901.h"
+#include "imuData.h"
 #include "string.h"
 
-CJY901 ::CJY901 ()
+ImuDataClass ::ImuDataClass ()
 {
 	ucDevAddr =0x50;
 }
-void CJY901::StartIIC()
+void ImuDataClass::StartIIC()
 {
 	ucDevAddr = 0x50;
 	Wire.begin();
 }
-void CJY901::StartIIC(unsigned char ucAddr)
+void ImuDataClass::StartIIC(unsigned char ucAddr)
 {
 	ucDevAddr = ucAddr;
 	Wire.begin();
 }
-void CJY901 ::CopeSerialData(unsigned char ucData)
+void ImuDataClass ::CopeSerialData(unsigned char ucData)
 {
 	static unsigned char ucRxBuffer[250];
 	static unsigned char ucRxCnt = 0;	
@@ -44,7 +44,7 @@ void CJY901 ::CopeSerialData(unsigned char ucData)
 		ucRxCnt=0;
 	}
 }
-void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
+void ImuDataClass::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
 {
   Wire.beginTransmission(deviceAddr);
   Wire.write(addressToRead);
@@ -57,7 +57,7 @@ void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead,
   for(int x = 0 ; x < bytesToRead ; x++)
     dest[x] = Wire.read();    
 }
-void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
+void ImuDataClass::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
 {
   Wire.beginTransmission(deviceAddr);
   Wire.write(addressToWrite);
@@ -66,60 +66,60 @@ void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite
   Wire.endTransmission(); //Stop transmitting
 }
 
-short CJY901::ReadWord(unsigned char ucAddr)
+short ImuDataClass::ReadWord(unsigned char ucAddr)
 {
 	short sResult;
 	readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
 	return sResult;
 }
-void CJY901::WriteWord(unsigned char ucAddr,short sData)
+void ImuDataClass::WriteWord(unsigned char ucAddr,short sData)
 {	
 	writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
 }
-void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
+void ImuDataClass::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
 {
 	readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
 }
 
-void CJY901::GetTime()
+void ImuDataClass::GetTime()
 {
 	readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);	
 }
-void CJY901::GetAcc()
+void ImuDataClass::GetAcc()
 {
 	readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
 }
-void CJY901::GetGyro()
+void ImuDataClass::GetGyro()
 {
 	readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
 }
 
-void CJY901::GetAngle()
+void ImuDataClass::GetAngle()
 {
 	readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
 }
-void CJY901::GetMag()
+void ImuDataClass::GetMag()
 {
 	readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
 }
-void CJY901::GetPress()
+void ImuDataClass::GetPress()
 {
 	readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
 }
-void CJY901::GetDStatus()
+void ImuDataClass::GetDStatus()
 {
 	readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
 }
-void CJY901::GetLonLat()
+void ImuDataClass::GetLonLat()
 {
 	readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
 }
-void CJY901::GetGPSV()
+void ImuDataClass::GetGPSV()
 {
 	readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
 }
-void CJY901::GetQuater()
+void ImuDataClass::GetQuater()
 {
   readRegisters(ucDevAddr, QUATER, 8, (char *)&stcQuater);
 }
-CJY901 JY901 = CJY901();
+ImuDataClass imuData = ImuDataClass();

+ 5 - 5
iic_6dof_imu/JY901.h → iic_6dof_imu/imuData.h

@@ -1,5 +1,5 @@
-#ifndef JY901_h
-#define JY901_h
+#ifndef IMUDATA_h
+#define IMUDATA_h
 
 #define SAVE 			0x00
 #define CALSW 		0x01
@@ -132,7 +132,7 @@ struct SQuater
   short q[4];
   short T;
 };
-class CJY901 
+class ImuDataClass 
 {
   public: 
 	struct STime		stcTime;
@@ -146,7 +146,7 @@ class CJY901
 	struct SGPSV 		stcGPSV;
   struct SQuater     stcQuater;
 	
-    CJY901 (); 
+    ImuDataClass (); 
 	void StartIIC();
 	void StartIIC(unsigned char ucAddr);
     void CopeSerialData(unsigned char ucData);
@@ -169,6 +169,6 @@ class CJY901
 	void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
 	void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
 };
-extern CJY901 JY901;
+extern ImuDataClass imuData;
 #include <Wire.h>
 #endif

+ 24 - 21
serial_6dof_imu/JY901.cpp → serial_6dof_imu/imuData.cpp

@@ -1,21 +1,21 @@
-#include "JY901.h"
+#include "imuData.h"
 #include "string.h"
 
-CJY901 ::CJY901 ()
+ImuDataClass ::ImuDataClass ()
 {
 	ucDevAddr =0x50;
 }
-void CJY901::StartIIC()
+void ImuDataClass::StartIIC()
 {
 	ucDevAddr = 0x50;
 	Wire.begin();
 }
-void CJY901::StartIIC(unsigned char ucAddr)
+void ImuDataClass::StartIIC(unsigned char ucAddr)
 {
 	ucDevAddr = ucAddr;
 	Wire.begin();
 }
-void CJY901 ::CopeSerialData(unsigned char ucData)
+void ImuDataClass ::CopeSerialData(unsigned char ucData)
 {
 	static unsigned char ucRxBuffer[250];
 	static unsigned char ucRxCnt = 0;	
@@ -40,12 +40,11 @@ void CJY901 ::CopeSerialData(unsigned char ucData)
 			case 0x56:	memcpy(&stcPress,&ucRxBuffer[2],8);break;
 			case 0x57:	memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
 			case 0x58:	memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
-      case 0x59:  memcpy(&stcQuater,&ucRxBuffer[2],8);break;
 		}
 		ucRxCnt=0;
 	}
 }
-void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
+void ImuDataClass::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
 {
   Wire.beginTransmission(deviceAddr);
   Wire.write(addressToRead);
@@ -58,7 +57,7 @@ void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead,
   for(int x = 0 ; x < bytesToRead ; x++)
     dest[x] = Wire.read();    
 }
-void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
+void ImuDataClass::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
 {
   Wire.beginTransmission(deviceAddr);
   Wire.write(addressToWrite);
@@ -67,56 +66,60 @@ void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite
   Wire.endTransmission(); //Stop transmitting
 }
 
-short CJY901::ReadWord(unsigned char ucAddr)
+short ImuDataClass::ReadWord(unsigned char ucAddr)
 {
 	short sResult;
 	readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
 	return sResult;
 }
-void CJY901::WriteWord(unsigned char ucAddr,short sData)
+void ImuDataClass::WriteWord(unsigned char ucAddr,short sData)
 {	
 	writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
 }
-void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
+void ImuDataClass::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
 {
 	readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
 }
 
-void CJY901::GetTime()
+void ImuDataClass::GetTime()
 {
 	readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);	
 }
-void CJY901::GetAcc()
+void ImuDataClass::GetAcc()
 {
 	readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
 }
-void CJY901::GetGyro()
+void ImuDataClass::GetGyro()
 {
 	readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
 }
 
-void CJY901::GetAngle()
+void ImuDataClass::GetAngle()
 {
 	readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
 }
-void CJY901::GetMag()
+void ImuDataClass::GetMag()
 {
 	readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
 }
-void CJY901::GetPress()
+void ImuDataClass::GetPress()
 {
 	readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
 }
-void CJY901::GetDStatus()
+void ImuDataClass::GetDStatus()
 {
 	readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
 }
-void CJY901::GetLonLat()
+void ImuDataClass::GetLonLat()
 {
 	readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
 }
-void CJY901::GetGPSV()
+void ImuDataClass::GetGPSV()
 {
 	readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
 }
-CJY901 JY901 = CJY901();
+void ImuDataClass::GetQuater()
+{
+  readRegisters(ucDevAddr, QUATER, 8, (char *)&stcQuater);
+}
+ImuDataClass imuData = ImuDataClass();

+ 9 - 7
serial_6dof_imu/JY901.h → serial_6dof_imu/imuData.h

@@ -1,5 +1,5 @@
-#ifndef JY901_h
-#define JY901_h
+#ifndef IMUDATA_h
+#define IMUDATA_h
 
 #define SAVE 			0x00
 #define CALSW 		0x01
@@ -64,6 +64,7 @@
 #define GPSYAW      0x4e
 #define GPSVL				0x4f
 #define GPSVH				0x50
+#define QUATER      0x51
       
 #define DIO_MODE_AIN 0
 #define DIO_MODE_DIN 1
@@ -131,7 +132,7 @@ struct SQuater
   short q[4];
   short T;
 };
-class CJY901 
+class ImuDataClass 
 {
   public: 
 	struct STime		stcTime;
@@ -143,9 +144,9 @@ class CJY901
 	struct SPress 		stcPress;
 	struct SLonLat 		stcLonLat;
 	struct SGPSV 		stcGPSV;
-  struct SQuater  stcQuater;
+  struct SQuater     stcQuater;
 	
-    CJY901 (); 
+    ImuDataClass (); 
 	void StartIIC();
 	void StartIIC(unsigned char ucAddr);
     void CopeSerialData(unsigned char ucData);
@@ -161,12 +162,13 @@ class CJY901
 	void GetDStatus();
 	void GetLonLat();
 	void GetGPSV();
-	
+  void GetQuater();
+  
   private: 
 	unsigned char ucDevAddr; 
 	void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
 	void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
 };
-extern CJY901 JY901;
+extern ImuDataClass imuData;
 #include <Wire.h>
 #endif

+ 7 - 7
serial_6dof_imu/serial_6dof_imu.ino

@@ -1,8 +1,8 @@
 #include <Wire.h>
-#include "JY901.h"
+#include "imuData.h"
 /*
 Test on Uno R3.
-JY901   UnoR3
+imuData   UnoR3
 TX <---> 0(Rx)
 */
 void setup() 
@@ -14,13 +14,13 @@ void loop()
 {
   //print received data. Data was received in serialEvent;
                
-  Serial.print("Acc:");Serial.print((float)JY901.stcAcc.a[0]/32768*16);Serial.print(" ");Serial.print((float)JY901.stcAcc.a[1]/32768*16);Serial.print(" ");Serial.println((float)JY901.stcAcc.a[2]/32768*16);
+  Serial.print("Acc:");Serial.print((float)imuData.stcAcc.a[0]/32768*16);Serial.print(" ");Serial.print((float)imuData.stcAcc.a[1]/32768*16);Serial.print(" ");Serial.println((float)imuData.stcAcc.a[2]/32768*16);
   
-  Serial.print("Gyro:");Serial.print((float)JY901.stcGyro.w[0]/32768*2000);Serial.print(" ");Serial.print((float)JY901.stcGyro.w[1]/32768*2000);Serial.print(" ");Serial.println((float)JY901.stcGyro.w[2]/32768*2000);
+  Serial.print("Gyro:");Serial.print((float)imuData.stcGyro.w[0]/32768*2000);Serial.print(" ");Serial.print((float)imuData.stcGyro.w[1]/32768*2000);Serial.print(" ");Serial.println((float)imuData.stcGyro.w[2]/32768*2000);
   
-  Serial.print("Angle:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
+  Serial.print("Angle:");Serial.print((float)imuData.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)imuData.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)imuData.stcAngle.Angle[2]/32768*180);
   
-  Serial.print("Quater:");Serial.print((float)JY901.stcQuater.q[0]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[1]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[2]/32768);Serial.print(" ");Serial.println((float)JY901.stcQuater.q[3]/32768);
+  Serial.print("Quater:");Serial.print((float)imuData.stcQuater.q[0]/32768);Serial.print(" ");Serial.print((float)imuData.stcQuater.q[1]/32768);Serial.print(" ");Serial.print((float)imuData.stcQuater.q[2]/32768);Serial.print(" ");Serial.println((float)imuData.stcQuater.q[3]/32768);
   
   Serial.println("");
   delay(500);
@@ -36,6 +36,6 @@ void serialEvent()
 {
   while (Serial.available()) 
   {
-    JY901.CopeSerialData(Serial.read()); //Call JY901 data cope function
+    imuData.CopeSerialData(Serial.read()); //Call imuData data cope function
   }
 }