当前位置: 首页>>代码示例>>C++>>正文


C++ HMC5883L::init方法代码示例

本文整理汇总了C++中HMC5883L::init方法的典型用法代码示例。如果您正苦于以下问题:C++ HMC5883L::init方法的具体用法?C++ HMC5883L::init怎么用?C++ HMC5883L::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HMC5883L的用法示例。


在下文中一共展示了HMC5883L::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{ 
 	const char *fileName = "/dev/i2c-1";
   	int 		countdown 		= 0;
   	int 		blink 			= 1;
   	float 		timeStep		= 83.33;	
   	int 		printTerminal 	= 1;
   	
    int 		fd;// File description
	string 		buttonInput;
	
	float lastBlink		= 0.0f;
	bool  isOnLED		= false;
		
	float 	timeStamp	= 0.0f;
	int		delay		= 0;
	
	CTimeClass timer;
	Logger logger;
	
   	ADXL345 	acc;
   	BMP085 		baro;
   	L3G4200D 	gyro;
   	HMC5883L 	compass;
   	    
   	GPIOClass 	gpioLED("17");
	GPIOClass 	gpioButton("4");

	// init GPIOs
	gpioLED.export_gpio();
	gpioButton.export_gpio();
	
	gpioLED.setdir_gpio("out"); //GPIO4 set to output
    gpioButton.setdir_gpio("in"); // GPIO17 set to input
    
    // switch off LED just in case
    gpioLED.setval_gpio("0");
    
	// parse input arguments
	if( argc > 1 ) {
		parseArgv( countdown, blink, timeStep, printTerminal, argc, argv );	
		
		printf("c = %d, b = %d, t = %f, p = %d\n", countdown, blink, timeStep, printTerminal);
	}
	
    // init i2c
   	if(!init(&fd, fileName)) {
		exit(1);
	}
   	
   	// wait for a little
   	usleep(100000);

    // init imu
   	acc.init(&fd, ((int) ((1000/timeStep)+0.5)), timeStep);
	baro.init(&fd);
	compass.init(&fd);
	gyro.init(&fd, ((int) ((1000/timeStep)+0.5)));
		
	if( countdown > 0 ) {
		waitUntilButton(gpioButton, gpioLED, countdown, blink );	
	}
	
	timer.init();
	
	if( logger.openLogFile( timeStep, timer ) == false ) {
		exit( 1 );
	}
			
	printf("GO\n");
	
	for(;;) {	
		// read current Time
		timer.computeStartTime();
		
		getIMUReadings( acc, baro, compass, gyro );

		timer.computeTime( timeStamp );
				
		// print data to file																						MATLAB:						    1		   2	  3 	  4            5             6                7                    8       			9					 10				 	  11			    12		      13			14			   15			16			  17		18		    19			   20			   21
		fprintf(logger.fp, "%d, %4d %4d %4d %.2f %.2f %.2f %.2f %5.3f %5.3f %5.3f %5.3f %5.3f %d %d %d %5.3f %5.3f %5.3f %5.3f %5.3f\n", ((int) timeStamp), gyro.x, gyro.y, gyro.z, compass.heading, baro.altitude, baro.pressure / 100, baro.temperature, acc.accKalman[ X ], acc.accKalman[ Y ], acc.accKalman[ Z ], acc.acc[ Z ], acc.magnitude, acc.zeroX[X], acc.zeroX[Y], acc.zeroX[Z], acc.pitch, acc.roll, acc.deriv2[X], acc.deriv2[Y], acc.deriv2[Z]);
	
		//fprintf(logger.fp, "%d %5d %5d %5d %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n", ((int) timeStamp), acc.raw[0], acc.raw[1], acc.raw[2], acc.acc[ 0 ], acc.acc[ 1 ], acc.acc[ 2 ], acc.accKalman[ 0 ], acc.accKalman[ 1 ], acc.accKalman[ 2 ]); //, acc.movingAverage[ 0 ], acc.movingAverage[ 1 ],acc.movingAverage[ 2 ]);
		
		if( printTerminal == 1 ) {
			printf("%d, %4d %4d %4d %.2f %.2f %.2f %.2f %5.3f %5.3f %5.3f %5.3f %5.3f %d %d %d %5.3f %5.3f\n", ((int) timeStamp), gyro.x, gyro.y, gyro.z, compass.heading, baro.altitude, baro.pressure / 100, baro.temperature, acc.accKalman[ X ], acc.accKalman[ Y ], acc.accKalman[ Z ], acc.acc[ Z ], acc.magnitude,acc.zeroX[X], acc.zeroX[Y], acc.zeroX[Z], acc.pitch, acc.roll);
		}
		
		// see if user wants to quit
		gpioButton.getval_gpio(buttonInput);
		
		// button pressed, so exit program
		if( buttonInput == "0" ) {
			printf("Exiting\n");	
			break;
		}
		
		timer.computeEndTime();
						
		// delay in microseconds
//.........这里部分代码省略.........
开发者ID:oitoito,项目名称:buoysbueysbuoys,代码行数:101,代码来源:main.cpp


注:本文中的HMC5883L::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。