Nyika yeinertial sensors yakashanduka nekukurumidza, uye zvishandiso zvakaita seMPU9250, iyo inosanganisa accelerometer, gyroscope uye magnetometer mune imwechete module, yave chidimbu chakakosha chezvirongwa zvemarobhoti, drones uye masisitimu anoda kunyatsobata madiki uye makuru mafambiro. Muchikamu chino, tichaongorora mashandisiro e sensor iyi neArduino, kuti ndezvipi zvinozivikanwa maficha, pamwe nemimwe mienzaniso yekodhi yekutanga nayo.
Kushandisa iyo MPU9250 hakungobatsiri kune vanoita zvekutamba, asiwo kune nyanzvi dzinoda kuyera nemazvo mafambiro uye mafambiro. Mhinduro iyi inobvumira kuvandudzwa kwemasisitimu ekudzikamisa, mota dzinozvimiririra uye marobhoti anoda kuziva mafambiro adzo mumatemo akasiyana. Iyo sensor kuita kwakasiyana-siyana, pamwe nekurongeka kwayo uye mutengo wakaderera, yaita kuti ive nemukurumbira wakasimba pakati pevagadziri.
Chii chinonzi MPU9250?
El MPU9250 Iyo module inosanganisira accelerometer, gyroscope uye magnetometer pamudziyo mumwe chete. Nekusanganiswa uku, sensor inokwanisa kuyera ese ari maviri mutsara kukurumidza uye angular velocity, uye iyo magineti yenzvimbo yayo. Iyi Invense sensor ine 9 madhigirii erusununguko, zvinoreva kuti inogona kuyera mumatemo matatu akasiyana, kumhanyisa, kutenderera (gyroscope) uye magineti (magnetometer), zvichipa mukana wekuverenga kutaridzika kwakazara kwechishandiso.
Iyo module yakagadzirirwa kutaurirana uchishandisa SPI kana I2C, iyo inobvumira kuti ibatane nyore nyore kuvhura sosi mapuratifomu akadai seArduino kana Raspberry Pi. Uyezve, thanks to Digital Motion processor (DMP), inokwanisa kuita macalculation akaoma kusanganisa data yakawanikwa nemasensor matatu uye kupa zviyero zvakanyatsojeka.
Zvinhu zvikuru zveMPU9250
Iyo MPU9250 inomira pachena nekuve nehuwandu hukuru hwezvinhu zvinoita kuti ive inonakidza module yemapurojekiti anoda kutora chaiwo mafambiro, pakati pawo ari:
- Accelerometer: Kukwidziridzwa kunogadziriswa pakati pe ± 2g, ± 4g, ± 8g, uye ± 16g.
- Gyroscope: Hurongwa hunorongwa hwe ±250°/s, ±500°/s, ±1000°/s, ±2000°/s.
- Magnetometer: Sensitivity ye 0.6µT/LSB uye inorongeka renji kusvika ku4800µT.
- Kushandiswa kwesimba: Yakaderera kwazvo, yakanakira midziyo inotakurika kana zvishandiso zvinoda kushanda kwenguva yakareba (3.5 mA mune inoshanda mode).
Kubatanidza iyo MPU9250 module neArduino
Kubatanidza module kune yako Arduino inzira yakapusa nekuda kwekuti inoshanda kuburikidza neI2C protocol. Iye yakajairika yekubatanidza dhizaini pakati peMPU9250 uye a Arduino Uno es:
- VCC: Batanidza ku3.3V.
- GND: Kudzika (GND).
- zviwanikwa: Batanidza iyo pini A4 yeArduino.
- SCL: Batanidza iyo pini A5 yeArduino.
Zvakakosha kuve nechokwadi kuti simba rakarurama kuitira kuti sensor inogona kushanda zvakanaka. Mazhinji mamodule atove ane voltage regulator kuti akwanise kushandisa iyo 5V yeArduino pasina kuikuvadza.
Mienzaniso yekodhi yeMPU9250
Pazasi tinokuratidza kuti ungatanga sei kuronga iyo MPU9250 muArduino, uchiverenga data kubva kune accelerometer, gyroscope uye magnetometer. Raibhurari MPU9250.h
Izvo zvinobatsira kwazvo kufambisa hurongwa, uye mumuenzaniso wedu isu tinotsanangura maverengero e data raw:
#include <Wire.h>
#include <MPU9250.h>
MPU9250 imu(Wire, 0x68);
void setup() {
Wire.begin();
Serial.begin(115200);
if (imu.begin() != 0) {
Serial.println("Error al iniciar MPU9250");
} else {
Serial.println("MPU9250 iniciado");
}
}
void loop() {
imu.readSensor();
Serial.print("Aceleracion: ");
Serial.print(imu.getAccelX_mss());
Serial.print(", ");
Serial.print(imu.getAccelY_mss());
Serial.print(", ");
Serial.print(imu.getAccelZ_mss());
Serial.println();
delay(1000);
}
Iyi kodhi inoverenga zvikamu zvitatu zvekumhanyisa. Gyroscope uye kuverenga kwemagnetometer kunogona kuitwa zvakafanana uchishandisa nzira getGyroX_rads()
y getMagX_uT()
zvakateerana.
Anoshanda mafomu
Kune akawanda maapplication apo iyo MPU9250 inova chishandiso chakakosha. Ngationgororei zvimwe zvezvinonyanya kukosha:
- Drones uye marobhoti: Imwe yeanonyanya kushandiswa kweMPU9250 iri mukudzikamisa ndege uye marobhoti masisitimu, uko kuwana chaiyo-nguva yekumisikidza kwakakosha.
- Virtual reality: Nekunyatso kubata kutarisisa uye kufamba, iyo sensor inogona kushandiswa pakutevera mumavhidhiyo emitambo maapplication kana chaiwo chaiwo simulators.
- Navigation systems: Mukubatana nemamwe masensor, akadai seGPS, iyo MPU9250 inoshandiswa muinertial navigation kuti inzwisise mafambiro uye kuona mafambiro.
Magnetometer Calibration
Imwe yematanho akanyanya kukosha kana uchishandisa iyo MPU9250 ndeye magnetometer calibration. Iyo magnetometer yakakosha pakubvisa zvikanganiso zvinogadzirwa nenharaunda yemagineti (senge yekuvaka tsoka kana kukanganiswa kubva kune mamwe emagetsi emagetsi), saka kuita calibration kwakakosha kuyera kuyerwa.
Kuti tinyatso gadzirisa iyo magnetometer, tinogona kushandisa iyo RTIMULib-Arduino raibhurari. Heino chirongwa chakareruka chekugadzirisa:
#include <RTIMULib.h>
RTIMU *imu;
RTIMUSettings settings;
void setup() {
Wire.begin();
Serial.begin(115200);
imu = RTIMU::createIMU(&settings);
imu->IMUInit();
imu->setCalibrationMode(true);
}
void loop() {
if (imu->IMURead()) {
RTVector3 mag = imu->getCompass();
Serial.print("Magnetómetro: ");
Serial.print(mag.x());
Serial.print(", ");
Serial.print(mag.y());
Serial.print(", ");
Serial.print(mag.z());
Serial.println();
}
}
Iyo kodhi iri pamusoro inoverenga iyo data kubva kune magnetometer kuti iwe ugone kuita mafambiro pamatemo uye kuvhara iyo yakazara huwandu hwekuverenga kunobvira. Izvi zvinobatsira kuona kukanganiswa kwemagineti uye kunatsiridza kuverenga kwekutarisa.
Masefa ekunatsiridza kurongeka
Kuvandudza kurongeka kwekuverenga kweMPU9250, imwe yenzira dzakajairika ndeye kusefa kushandiswa iyo inosanganisa iyo data yakawanikwa kubva kugyroscope, accelerometer uye magnetometer.
El complementary sefa Iyo inobudirira uye iri nyore mhinduro yekushandisa. Iyi sefa inotsamira pane gyroscope kuti iwane mhedzisiro nekukurumidza, nepo accelerometer uye magnetometer inogadzirisa kutsauka kwenguva refu kubva kugyroscope (inozivikanwa seDrift). Kodhi yakapfava inoshandisa iyi sefa inogona kuonekwa mumuenzaniso unotevera:
#include <ComplementaryFilter.h>
ComplementaryFilter cf;
void setup() {
cf.setAccelerometerGain(0.02);
cf.setMagnetometerGain(0.98);
}
void loop() {
// Integrar lecturas de acelerómetro y giroscopio
cf.update(sensorData.accelX, sensorData.gyroX);
float pitch = cf.getPitch();
float roll = cf.getRoll();
Serial.print("Pitch: ");
Serial.print(pitch);
Serial.print(" Roll: ");
Serial.println(roll);
}
Iyi sefa yakakosha kubvisa gyroscope drift uye kugadzira yakadzikama yakatarisana. Uye zvakare, inokurumidza kuuraya pane microcontrollers seArduino pane dzimwe nzira dzakaomarara senge Kalman sefa, iyo inoshandisa zvimwe zviwanikwa.
Iyo MPU9250 mhinduro inoshamisa inogoneka kune akasiyana siyana mapurojekiti anoda kutariswa kwakaringana uye kuyerwa kwekufamba. Kuibatanidza neArduino uye kuwana maverengero ekutanga kuri nyore, uye nekushandisa mashoma mafirita, unogona kuwana akanyatso uye anobatsira mhedzisiro yeakasiyana maapplication.