yilonglucky 发表于 2024-11-27 18:19

【Follow me第二季第4期】任务二 通过串口打印六轴原始数据

<p>先看最终串口监视器和绘图仪的显示效果:</p>

<p>&nbsp; 注意加速度和陀螺仪的量程数量级相差很大,两组数据在绘图仪中可以分别显示。</p>

<p>代码参考:</p>

<pre>
<code class="language-cpp">#include &lt;Arduino_LSM6DSOX.h&gt;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1)
      ;
}
}

void loop() {
// put your main code here, to run repeatedly:
float accx, accy, accz;
float gyrx, gyry, gyrz;

if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(accx, accy, accz);
    Serial.print(accx);
    Serial.print('\t');
    Serial.print(accy);
    Serial.print('\t');
    Serial.print(accz);

}

if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(gyrx, gyry, gyrz);
    Serial.print('\t');
    Serial.print(gyrx);
    Serial.print('\t');
    Serial.print(gyry);
    Serial.print('\t');
    Serial.println(gyrz);
}
delay(500);
}
</code></pre>

<p>&nbsp;</p>

<div style="position: fixed; opacity: 1; height: 300px; width: 100%; font-size: 25px; text-align: center; bottom: 200px; left: 0px; display: none; flex-direction: column; justify-content: center; z-index: 1661789940; top: calc(50% + 0px);">&nbsp;</div>

yilonglucky 发表于 2024-11-27 18:24

<p>感觉这个功能很适合做无人机啊,加速度用来检测前倾后仰,左侧倾斜右侧倾斜,陀螺仪可以检测水平方向原地顺时针旋转和逆时针旋转</p>

<div style="position: fixed; opacity: 1; height: 300px; width: 100%; font-size: 25px; text-align: center; bottom: 200px; left: 0px; display: none; flex-direction: column; justify-content: center; z-index: 1661789940; top: calc(50% + 0px);">&nbsp;</div>
页: [1]
查看完整版本: 【Follow me第二季第4期】任务二 通过串口打印六轴原始数据