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


C++ HMC5883L类代码示例

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


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

示例1: loadCompassOffset

void loadCompassOffset()
{
    byte high,low;
    uint addr = CompassStorageAddr;
    int offsetX,offsetY;

    Wire.begin();
    compass.setRange(HMC5883L_RANGE_1_3GA);
    compass.setMeasurementMode(HMC5883L_CONTINOUS);
    compass.setDataRate(HMC5883L_DATARATE_30HZ);
    compass.setSamples(HMC5883L_SAMPLES_8);

    offsetX = EEPROM_readInt(addr);
    addr += 2;
    offsetY = EEPROM_readInt(addr);

    compass.setOffset(offsetX,offsetY);

#ifdef DEBUG
    debugSerial.print("Compass Offset:");
    debugSerial.print(offsetX);
    debugSerial.print(" | ");
    debugSerial.print(offsetY);
    debugSerial.print("\n");
#endif // DEBUG
}
开发者ID:xxzl0130,项目名称:Football,代码行数:26,代码来源:DefendMain.cpp

示例2: HMC5883L

Comp::Comp()
{
	Compass = HMC5883L();

	Serial.println("setting scale to +/- 2.0 Ga");
	int error = Compass.SetScale(0.88);

	error = Compass.SetMeasurementMode(Measurement_Continuous);
	if (error != 0)
	{
		Serial.println(Compass.GetErrorText(error));
	}
}
开发者ID:omarelkawokgy,项目名称:Area_Coverage,代码行数:13,代码来源:COMH.cpp

示例3: getIMUReadings

void getIMUReadings( ADXL345& a, BMP085& b, HMC5883L& c, L3G4200D& g)
{
	a.readAccel();  					// WORKING
	b.calculateAll(); 				// WORKING		
	g.computeValues();				// appears to be WORKING
	c.readCompassHeading();		// appears to be WORKING
}
开发者ID:oitoito,项目名称:buoysbueysbuoys,代码行数:7,代码来源:main.cpp

示例4: report

/**
 * Report magnetometer values
 *
 * @param magnetometer Magnetometer to use
 */
void report(HMC5883L &magnetometer) {
      int16_t compassX,compassY,compassZ;
      magnetometer.doMeasurement(&compassX, &compassY, &compassZ);
      console.
         write("X=").write(compassX).
         write("Y=").write(compassY).
         write("Z=").writeln(compassZ);
}
开发者ID:podonoghue,项目名称:usbdm-eclipse-makefiles-build,代码行数:13,代码来源:hmc5883l-example.cpp

示例5: updateGCSHeading

void updateGCSHeading() {
	//Get the reading from the HMC5883L and calculate the heading
	MagnetometerScaled scaled = compass.ReadScaledAxis(); //scaled values from compass.

	int angle = atan2(-scaled.YAxis , scaled.XAxis) / M_PI * 180; // angle is atan(-y/x)
	if(angle < 0) angle = angle  + 360;
	homeBearing = angle;
}
开发者ID:AQ-AirWolf,项目名称:FPV-Tracker,代码行数:8,代码来源:GPS_Tracker.cpp

示例6: main

/**
 * Funcion principal donde se piden los datos a la libreria y se publican una vez tratados.
 */
int main(int argc, char **argv)
{

  // Iniciamos el nodo.
  ros::init(argc, argv, nodo_name);
  ros::NodeHandle nodo;
  ROS_INFO("nodo_brujula creado y registrado");
  // Cargamos el modulo de la brujula.
  HMC5883L brujula;
  CompassMsg brujula_struct;
  int respuesta = brujula.conectamos_brujula();
  ROS_INFO("Modulo de la brujula cargado; (id-i2c = %d)", respuesta);
  // Definimos el publicador.
  ros::Publisher publicador = nodo.advertise<std_msgs::Float64>(topic_name, 0);
  ros::Duration seconds_sleep(tiempo_muestreo);

  // Bucle donde continuamente se va a realizar la lectura y publicacion de datos.
  // Este proceso se realizara cada float tiempo_muestreo
  while (ros::ok())
  {

  	// Tomamos un dato de la brujula a partir de la funcion de la libreria.
    brujula_struct = brujula.get_data();

    // Calibramos el dato obtenido.
	//calibracion(brujula_struct);
	//maximos_minimos(brujula_struct);
	calibracion_rapida(brujula_struct);

    // Aplicamos el filtro de la mediana.
    filtro_mediana(brujula_struct.angle);

    //printf("Magnetometro [x, y, z] = [%d, %d, %d] - Angulo = %f \n", brujula_struct.x, brujula_struct.y, brujula_struct.z, brujula_struct.angle);
    std_msgs::Float64 mensaje_ros;
    mensaje_ros.data = brujula_struct.angle;
    publicador.publish(mensaje_ros);
    ros::spinOnce();
    seconds_sleep.sleep();
  }


  return 0;
}
开发者ID:cabama,项目名称:PatatitasRobot,代码行数:46,代码来源:publicador_brujula.cpp

示例7: factor

void ExtendoHand::setupOther() {
    if (nineAxis) {
        // adjust the power settings after you call this method if you want the accelerometer
        // to enter standby mode, or another less demanding mode of operation
        accel.setRange(1); // 4g
        accel.setFullResolution(1); // maintain 4mg/LSB scale factor (irrespective of range)
        accel.initialize();
        if (!accel.testConnection()) {
            osc.sendError("ADXL345 connection failed");
        } else {
            randomSeed(accel.getAccelerationX() - accel.getAccelerationY() + accel.getAccelerationZ());
        }

#ifdef ENABLE_GYRO
        gyro.initialize();
        if (!gyro.testConnection()) {
            osc.sendError("ITG3200 connection failed");
        }
#endif // ENABLE_GYRO

#ifdef ENABLE_MAGNETOMETER
        magnet.initialize();
        if (!magnet.testConnection()) {
            osc.sendError("HMC5883L connection failed");
        }
#endif // ENABLE_MAGNETOMETER
    } else {
#ifdef THREE_AXIS
        randomSeed(motionSensor.rawX() + motionSensor.rawY() + motionSensor.rawZ());

        // 1.5g constants, sampled 2014-06-21
        motionSensor.calibrateX(272, 794);
        motionSensor.calibrateY(332, 841);
        motionSensor.calibrateZ(175, 700);
#endif // THREE_AXIS
    }

    vibrateStart = 0;
    alertStart = 0;
}
开发者ID:XixiLuo,项目名称:extendo,代码行数:40,代码来源:ExtendoHand.cpp

示例8: setupMotionSensors

int setupMotionSensors() {
  
  int error = 0;
  
  // Initialization
  Wire.begin();
  acc.initialize();
  mag.initialize();
  gyr.initialize();
  
  // Verification
  if (!acc.testConnection() ||
      !mag.testConnection() ||
      !gyr.testConnection())
      error = 1;
  
  // Configuration
  acc.setRange(ADXL345_RANGE_16G);
  mag.setMode(HMC5883L_MODE_CONTINUOUS);
    
  return error;
  
}
开发者ID:CarterA,项目名称:Oz,代码行数:23,代码来源:Motion.cpp

示例9: setCompassOffset

void setCompassOffset()
{
#ifdef DEBUG
    debugSerial.println("setCompassOffset");
#endif
    Wire.begin();
    compass.setRange(HMC5883L_RANGE_1_3GA);
    compass.setMeasurementMode(HMC5883L_CONTINOUS);
    compass.setDataRate(HMC5883L_DATARATE_30HZ);
    compass.setSamples(HMC5883L_SAMPLES_8);

    int minX = INT_MAX,maxX = INT_MIN,minY = INT_MAX,maxY = INT_MIN;
    int offsetX,offsetY;

    motor.rotateRun(FORWORD, 128);
    delay(200);
#ifdef DEBUG
    debugSerial.println("setCompassOffset2");
#endif
    for(int i = 0; i < 500; ++i)
    {
        Vector mag = compass.readRaw();

        maxX = max(maxX,mag.XAxis);
        maxY = max(maxY,mag.XAxis);

        minX = min(minX,mag.XAxis);
        minY = min(minY,mag.XAxis);

        delay(20);
#ifdef DEBUG
        debugSerial.println(i);
#endif // DEBUG
    }

    motor.stop();

    offsetX = (maxX + minX) / 2;
    offsetY = (maxY + minY) / 2;

    uint addr = CompassStorageAddr;

    EEPROM_writeInt(addr,offsetX);
    addr += 2;
    EEPROM_writeInt(addr,offsetY);
    addr += 2;

    compass.setOffset(offsetX,offsetY);

#ifdef DEBUG
    debugSerial.print("Compass Offset:");
    debugSerial.print(offsetX);
    debugSerial.print(" | ");
    debugSerial.print(offsetY);
    debugSerial.print("\n");
#endif // DEBUG
}
开发者ID:xxzl0130,项目名称:Football,代码行数:57,代码来源:DefendMain.cpp

示例10: main

int main(int argc, char **argv) {
  printf("HMC5883L 3-axis acceleromter example program\n");
  I2Cdev::initialize();
  HMC5883L mag ;
  if ( mag.testConnection() ) 
    printf("HMC5883L connection test successful\n") ;
  else {
    fprintf( stderr, "HMC5883L connection test failed! something maybe wrong, continueing anyway though ...\n");
    //return 1;
  }
  mag.initialize();
  mag.setSampleAveraging(HMC5883L_AVERAGING_8);
  mag.setGain(HMC5883L_GAIN_1090);
  int16_t mx, my, mz;
  float heading ;
  while (true) {
    mag.getHeading(&mx, &my, &mz);
    heading = atan2(my, mx)  * 180 / PI;
    printf("  mx:  %d       my:  %d      mz:  %d     heading:  %3.1f deg\r", mx, my, mz, heading);
    fflush(stdout);
    bcm2835_delay(200);
  }
  return 1; 
}
开发者ID:0w0miki,项目名称:i2cdevlib,代码行数:24,代码来源:HMC5883L_example_1.cpp

示例11: 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

示例12: ReadRawData

uint16 Comp::ReadRawData(void)
{
  uint16 Temp_angle;
#ifdef ENABLE_SIMULATION
  cout << "Angle from compass:" << endl;
  cin >> Temp_angle;
#else
/* CONNECTION PINS FOR THIS ARE A5 PIN (I2C PIN) >> SCL ..... A4 PIN (I2C PIN) >> SCA */
    //raw data so its not scaled
  MagnetometerRaw raw = Compass.ReadRawAxis();
  
  MagnetometerScaled scaled = Compass.ReadScaledAxis();

  float heading = atan2(raw.YAxis, raw.XAxis);

  if (heading < 0)
  {
    heading += 2 * PI;
  }

  //convert radians to degrees
  Temp_angle = (uint16)(heading * 180 / M_PI);
  
  
#endif
#ifdef DEBUG
Serial.print("read compass: ");
Serial.println(Temp_angle);
#endif

  return Temp_angle;
}
开发者ID:omarelkawokgy,项目名称:Area_Coverage,代码行数:32,代码来源:COMH.cpp

示例13: getMotionData

void getMotionData(Datum *datum) {
  
  acc.getAcceleration(&datum->acc.x, &datum->acc.y, &datum->acc.z);
  mag.getHeading(&datum->mag.x, &datum->mag.y, &datum->mag.z);
  gyr.getRotation(&datum->gyr.x, &datum->gyr.y, &datum->gyr.z);
  
}
开发者ID:CarterA,项目名称:Oz,代码行数:7,代码来源:Motion.cpp

示例14: loop

void loop() {
  long t = millis();
  // put your main code here, to run repeatedly: 
  droid.exec(t);
#ifdef hal_beeps
  beeps.exec(t);
#endif
#ifdef hal_ir
  ir_update();
#endif
#ifdef hal_tft
  // read joystick
  int ana[2];
  ana[0] = 1024 - analogRead(A1); 
  ana[1] = analogRead(A2);
  int b0 = (digitalRead(A3) == LOW); 
  droid.update_joystick(ana,b0,t);
  droid.update_display(t);
#endif
#ifdef hal_compass
  int v[3];
  compass.get_vector(v);
  for(byte i=0; i<3; i++) droid.set_signal(124+i, v[i]);
  /* Serial.print(v[0]); Serial.print(','); 
  Serial.print(v[1]); Serial.print(','); 
  Serial.print(v[2]); Serial.print("\n"); 
  delay(100); */
#endif

}
开发者ID:fuinha,项目名称:unorthodox-arduino,代码行数:30,代码来源:droid-beeps.cpp

示例15: setup

void setup() {
// start the spi bus
#ifdef hal_spi
  SPI.begin();
#endif
#ifdef hal_tft
  lcd.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  lcd.fillScreen(ST7735_BLACK);
#endif
  // initialize serial port
  Serial.begin(9600);
  // leonardo - wait for connection
  while(!Serial) { }
#ifdef TwoWire_h
  // start the i2C bus
  Wire.begin();
#endif
#ifdef hal_raster
  Raster.start();
#endif
#ifdef hal_compass
  compass.start();
#endif
  // start the droid filesystem (now we have serial)
  droid.fs.start();
  // center the joystick
#ifdef hal_tft
  droid.joystick[0].center = 1024 - analogRead(A1);
  droid.joystick[1].center = analogRead(A2);
#endif
  // droid.joystick_center[0] = 1024 - analogRead(A1);
  // droid.joystick_center[1] = analogRead(A2);
}
开发者ID:fuinha,项目名称:unorthodox-arduino,代码行数:33,代码来源:droid-beeps.cpp


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