本文整理汇总了C++中LSM303类的典型用法代码示例。如果您正苦于以下问题:C++ LSM303类的具体用法?C++ LSM303怎么用?C++ LSM303使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LSM303类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
compass.setMagGain(LSM303::magGain_47);
}
示例2: setup
/**
* @brief Initializes the gyro/accelerometer and the magnetometer unit of the imu.
* As well as the arduino subsystem
*/
void setup() {
Wire.begin();
delay(1500);
/********/
/* GYRO */
/********/
gyro.init();
gyro.writeReg(L3G_CTRL_REG4, 0x00); // 245 dps scale
gyro.writeReg(L3G_CTRL_REG1, 0x0F); // normal power mode, all axes enabled, 100 Hz
//8.75 mdps/LSB
/****************/
/* MAGNETOMETER */
/****************/
compass.init();
compass.enableDefault();
compass.writeReg(LSM303::CTRL2, 0x08); // 4 g scale: AFS = 001
//0.122 mg/LSB
compass.writeReg(LSM303::CTRL5, 0x10); // Magnetometer Low Resolution 50 Hz
//Magnetometer 4 gauss scale : 0.16mgauss/LSB
//ROS-TF base frame of the imu_data
imu_msg.header.frame_id="base_imu_link";
//Register ROS messages
nh.initNode();
nh.advertise(imu_pub);
nh.advertise(mag_pub);
//starting value for the timer
timer=millis();
}
示例3: Accel_Init
void Accel_Init()
{
compass.init();
if (compass.getDeviceType() == LSM303DLHC_DEVICE)
{
compass.writeAccReg(LSM303_CTRL_REG1_A, 0x47); // normal power mode, all axes enabled, 50 Hz
compass.writeAccReg(LSM303_CTRL_REG4_A, 0x28); // 8 g full scale: FS = 10 on DLHC; high resolution output mode
}
else
{
compass.writeAccReg(LSM303_CTRL_REG1_A, 0x27); // normal power mode, all axes enabled, 50 Hz
compass.writeAccReg(LSM303_CTRL_REG4_A, 0x30); // 8 g full scale: FS = 11 on DLH, DLM
}
}
示例4: Compass_Calibrate
void Compass_Calibrate() {
long timer=millis();
LSM303::vector running_min = {2047, 2047, 2047}, running_max = {-2048, -2048, -2048};
while((millis()-timer)<=60000){ //calibrate for 1 minutes
compass.read();
running_min.x = min(running_min.x, compass.m.x);
running_min.y = min(running_min.y, compass.m.y);
running_min.z = min(running_min.z, compass.m.z);
running_max.x = max(running_max.x, compass.m.x);
running_max.y = max(running_max.y, compass.m.y);
running_max.z = max(running_max.z, compass.m.z);
delay(100);
}
compass.m_max.x = running_max.x;
compass.m_max.y = running_max.y;
compass.m_max.z = running_max.z;
compass.m_min.x = running_min.x;
compass.m_min.y = running_min.y;
compass.m_min.z = running_min.z;
}
示例5: setup
void setup(){
Serial.begin(115200);
Wire.begin(); //gyro code
gyro.init();//gyro code
gyro.enableDefault(); //gyro code
ps.enableDefault(); //baro code
handshaken = 0;
/*accelerometer code*/
compass.init();
compass.enableDefault();
/*accelerometer code*/
/*sonar code*/
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(TRIGGER_PIN2, OUTPUT);
pinMode(ECHO_PIN2, INPUT);
pinMode(TRIGGER_PIN3, OUTPUT);
pinMode(ECHO_PIN3, INPUT);
pinMode(TRIGGER_PIN4, OUTPUT);
pinMode(ECHO_PIN4, INPUT);
pinMode(TRIGGER_PIN5, OUTPUT);
pinMode(ECHO_PIN5, INPUT);
/*sonar code*/
pinMode(MOTOR, OUTPUT);
/*
Calibration values; the default values of +/-32767 for each axis
lead to an assumed magnetometer bias of 0. Use the ACCalibrate
program to determine appropriate values for your particular unit.
*/
//compass.m_min = (LSM303::vector<int16_t>){-32767, -32767, -32767};
//compass.m_max = (LSM303::vector<int16_t>){+32767, +32767, +32767};
//LSM303::vector<int16_t> running_min = {-2872, -3215, -1742}, running_max = {+3019, +3108, +3570}; //calibration init data for compass
compass.m_min = (LSM303::vector<int16_t>){-2872, -3215, -1742};
compass.m_max = (LSM303::vector<int16_t>) {+3019, +3108, +3570};
}
示例6: abs
int8_t Hal::LSM303_Update()
{
int offset = 700;
compass.read();
d_x = abs(compass.m.x - ax_o);
d_y = abs(compass.m.y - ay_o);
d_z = abs(compass.m.z - az_o);
if ( d_x > offset || d_y > offset || d_z > offset)
{
hasMoved = true;
}
ax_o = compass.m.x;
ay_o = compass.m.y;
az_o = compass.m.z;
}
示例7: Accel_Init
void Accel_Init()
{
compass.init();
compass.enableDefault();
switch (compass.getDeviceType())
{
case LSM303::device_D:
compass.writeReg(LSM303::CTRL2, 0x18); // 8 g full scale: AFS = 011
break;
case LSM303::device_DLHC:
compass.writeReg(LSM303::CTRL_REG4_A, 0x28); // 8 g full scale: FS = 10; high resolution output mode
break;
default: // DLM, DLH
compass.writeReg(LSM303::CTRL_REG4_A, 0x30); // 8 g full scale: FS = 11
}
//compass.heading((LSM303::vector<int>){0, 0, -1});
//compass.m_min = (LSM303::vector<int16_t>){-2304, -2194, -2156};
//compass.m_max = (LSM303::vector<int16_t>){+2771, +2860, +2753};
}
示例8: loop
/**
* @brief provides imu readings in a 50 Hz rate.
*
*/
void loop() {
if((millis()-timer)>=20) { // Main loop runs at 50Hz
timer=millis();
//Read data from the hardware
gyro.read();
compass.readAcc();
compass.readMag();
//Assign read data to the ros messages
imu_msg.angular_velocity.x=gyro.g.x;
imu_msg.angular_velocity.y=gyro.g.y;
imu_msg.angular_velocity.z=gyro.g.z;
imu_msg.linear_acceleration.x=compass.a.x;
imu_msg.linear_acceleration.y=compass.a.y;
imu_msg.linear_acceleration.z=compass.a.z;
mag_msg.magnetic_field.x=compass.m.x;
mag_msg.magnetic_field.y=compass.m.y;
mag_msg.magnetic_field.z=compass.m.z;
//Publish the data to the ros message system
imu_pub.publish( &imu_msg );
mag_pub.publish( &mag_msg);
nh.spinOnce();
}
nh.spinOnce();
}
示例9: setup
void Accelerometer::setup(){
Wire.begin();
compass.init();
compass.enableDefault();
memset(lastValuesX,0,sizeof(lastValuesX));
memset(lastValuesY,0,sizeof(lastValuesY));
memset(lastValuesZ,0,sizeof(lastValuesZ));
index =0;
}
示例10: task_headingNdist
void task_headingNdist(void* p){
while(1){
//Serial.print("z");
compass.read();
//dprintf("%d mem",(int)freeRAM());
//Serial.print("a");
float heading = compass.heading();
//Serial.print("b");
//dprintf("%d mem2",(int)freeRAM());
//dprintf("%d",(int)compass.a.x);
float ZaVal,XaVal,YaVal,RZaVal;
//ZaVal = compass.a.z/16.0;
XaVal = compass.a.x/16.0;
YaVal = compass.a.y/16.0;
ZaVal = compass.a.z/16.0;
RZaVal = sqrt( ((XaVal*XaVal)+(YaVal*YaVal))/4.0 + (ZaVal*ZaVal));
//ZaVal = sqrt( ((compass.a.x*compass.a.x)+(compass.a.y*compass.a.y))/4.0 + (compass.a.z*compass.a.z));
//ZaVal = ZaVal/16.0;
// dprintf("%d", (int)compass.a.x);
//dprintf("%d", (int)((compass.a.x*compass.a.x)/*+(compass.a.y*compass.a.y)/4.0*/));
// dprintf("%d x %d y %d z", (int)compass.a.x, (int)compass.a.y,(int) compass.a.z);
// dprintf("%d z val",(int) ZaVal);
// dprintf("%d",(int) ZaVal);
//Serial.print("a");
//dprintf("%d",(int)heading);
//dprintf("%d",(int)compass.heading());
//compass.heading();
//Serial.print("b");
//data[ID_DATA_HEADING] = (int) compass.heading();
/* if(ZaVal<-965){
distFromStart+=33; //1 step is 33 cm
step++;
}*/
float currentTime = millis();
if(RZaVal>1000 && (currentTime - prevTime) >= 600){
distFromStart+=33; //1 step is 33 cm
step++;
dprintf("%d_RZaval",(int)RZaVal);
dprintf("%d ",(int)step);
prevTime = currentTime;
}
data[ID_DATA_DIST] = (int) distFromStart;
//dprintf("dist is %d",(int)data[ID_DATA_DIST]);
//dprintf("a");
//delay(100);*/
delay(100);
vTaskDelay(taskDelay);
}
}
示例11: initHal
bool Hal::initHal()
{
debugPrintLn("Start init");
// initialize all the hardware
initLora();
initSwitch();
initLTC();
compass.init();
compass.enableDefault();
htu.begin();
// setAckOn();
debugPrintLn("Einde init");
}
示例12: Read_Compass
void Read_Compass()
{
compass.readMag();
magnetom_x = SENSOR_SIGN[6] * compass.m.x;
magnetom_y = SENSOR_SIGN[7] * compass.m.y;
magnetom_z = SENSOR_SIGN[8] * compass.m.z;
}
示例13: main
int main() {
pc.printf("Starting \r\n");
setup(); //initializes sensors
t.start();
timeLastPoll = t.read_ms();
while(button){
altitude = ps.pressureToAltitudeMeters(ps.readPressureMillibars());
gyr.read();
acc.read();
fprintf(fp, "%f, %d, %d, %d \r\n",
altitude,gyr.g.x,gyr.g.y,gyr.g.z);
pc.printf("%d Att: %2.2f \tGyr: %d %d %d \tAcc: %d %d %d \tT: %d\r\n",
iter,
altitude,
gyr.g.x,gyr.g.y,gyr.g.z,
acc.a.x,acc.a.y,acc.a.z,
t.read_ms()-timeLastPoll);
while( (t.read_ms() - timeLastPoll) < MBED_POLLING_PERIOD){
}
// pc.printf("Loop Time: %d",t.read_ms()-timeLastPoll);
timeLastPoll = t.read_ms();
iter++;
}
fclose(fp);
pc.printf("File successfully written! \r\n");
printf("End of Program. \r\n");
}
示例14: update
void Accelerometer::update(){
/*
return
*/
compass.read();
lastValuesX[index] = compass.a.x;
lastValuesY[index] = compass.a.y;
lastValuesZ[index] = compass.a.z;
long averagedX = averageArray(lastValuesX);
long averagedY = averageArray(lastValuesY);
long averagedZ = averageArray(lastValuesZ);
index = index + 1;
index = index % SENSITIVITY;
long averageXY = sqrt(averagedX*averagedX + averagedY*averagedY);
/*Serial.print(averagedX);
Serial.print(" ");
Serial.print(averagedY);
Serial.print(" ");
Serial.print(averageXY);
Serial.print(" ");*/
//int degree = atan2(averagedX, averagedY) * 180.0 / M_PI;
//Serial.println(degree);
if(averageXY > 3000)
{
Serial.println("SMASH!");
}
}
示例15: loop
void loop() {
compass.read();
running_min.x = min(running_min.x, compass.m.x);
running_min.y = min(running_min.y, compass.m.y);
running_min.z = min(running_min.z, compass.m.z);
running_max.x = max(running_max.x, compass.m.x);
running_max.y = max(running_max.y, compass.m.y);
running_max.z = max(running_max.z, compass.m.z);
Serial.print("M min ");
Serial.print("X: ");
Serial.print((int)running_min.x);
Serial.print(" Y: ");
Serial.print((int)running_min.y);
Serial.print(" Z: ");
Serial.print((int)running_min.z);
Serial.print(" M max ");
Serial.print("X: ");
Serial.print((int)running_max.x);
Serial.print(" Y: ");
Serial.print((int)running_max.y);
Serial.print(" Z: ");
Serial.println((int)running_max.z);
delay(100);
}