- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 STM32 世界的新手,我对 STM32F429-DISC1 板上的板载 L3GD20 陀螺仪有疑问。
我在让它运行时遇到了麻烦(陀螺仪不断发送相同的数据,即使在重置或断电后也是如此),在我最终设法让它工作(通过发送几次指令)后,我看到了奇怪的结果(x 轴、y 轴和 z 轴)(见下图)。
我是否遗漏了什么,或者我应该对原始数据做一些事情,以使其平滑? IC 是否有可能有缺陷?
我使用 Atollic TrueStudio v9.0 for STM32 和 STM32F429-DISC1。
这是我的代码:
#include "stm32f4xx.h"
#include "stm32f429i_discovery.h"
#include "stdio.h"
volatile uint32_t elapsed = 0;
#define CS_gyro_start GPIO_ResetBits( GPIOC, GPIO_Pin_1 )
#define CS_gyro_stop GPIO_SetBits( GPIOC, GPIO_Pin_1 )
void DelayMS( int time ){
elapsed = time;
while( elapsed > 0 );
}
void SysTick_Handler(){
if( elapsed > 0 ) --elapsed;
}
void SendChar( char ch ){
while( USART_GetFlagStatus( USART1, USART_FLAG_TXE ) == RESET ){}
USART_SendData( USART1, ch );
}
void sendString( const char *s ){
while( *s ){
SendChar( *s++ );
}
}
int _write( int file, char *ptr, int len ){
sendString( ptr );
return len;
} //sadly this doesn't work with float variables
void initialize( void ){
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA |
RCC_AHB1Periph_GPIOC |
RCC_AHB1Periph_GPIOF, ENABLE );
RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI5 |
RCC_APB2Periph_SYSCFG |
RCC_APB2Periph_USART1, ENABLE );
GPIO_InitTypeDef gpio;
USART_InitTypeDef usart;
SPI_InitTypeDef spi;
GPIO_StructInit( &gpio );
USART_StructInit( &usart );
SPI_StructInit( &spi );
//usart
GPIO_PinAFConfig( GPIOA, GPIO_PinSource10, GPIO_AF_USART1 );
GPIO_PinAFConfig( GPIOA, GPIO_PinSource9, GPIO_AF_USART1 );
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init( GPIOA, &gpio );
usart.USART_BaudRate = 115200;
USART_Init( USART1, &usart );
USART_Cmd( USART1, ENABLE );
//spi
GPIO_PinAFConfig( GPIOF, GPIO_PinSource7, GPIO_AF_SPI5 );
GPIO_PinAFConfig( GPIOF, GPIO_PinSource9, GPIO_AF_SPI5 );
GPIO_PinAFConfig( GPIOF, GPIO_PinSource8, GPIO_AF_SPI5 );
//SS
gpio.GPIO_Pin = GPIO_Pin_1;
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOC, &gpio );
GPIO_SetBits( GPIOC, GPIO_Pin_1 );
//SCK, MOSI
gpio.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_7;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOF, &gpio );
//MISO
gpio.GPIO_Pin = GPIO_Pin_8;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOF, &gpio );
spi.SPI_Mode = SPI_Mode_Master;
spi.SPI_NSS = SPI_NSS_Soft;
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_Init( SPI5, &spi );
SPI_Cmd( SPI5, ENABLE );
}
uint8_t SPI_sendByte( uint8_t byte_ ){
while( SPI_I2S_GetFlagStatus( SPI5, SPI_I2S_FLAG_TXE ) == RESET ){}
SPI_I2S_SendData( SPI5, byte_ );
while( SPI_I2S_GetFlagStatus( SPI5, SPI_I2S_FLAG_RXNE ) == RESET ){}
return SPI_I2S_ReceiveData( SPI5 );
}
void SPI_writeData( uint8_t address, uint8_t byteToWrite ){
CS_gyro_start;
SPI_sendByte( address );
SPI_sendByte( byteToWrite );
CS_gyro_stop;
}
void GetGyroValues( uint16_t *x, uint16_t *y, uint16_t *z ){
CS_gyro_start;
SPI_sendByte( 0x29 | 0x80 );
*x = SPI_sendByte( 0xff );
CS_gyro_stop;
CS_gyro_start;
SPI_sendByte( 0x28 | 0x80 );
*x |= (SPI_sendByte( 0xff ) << 8);
CS_gyro_stop;
CS_gyro_start;
SPI_sendByte( 0x2B | 0x80 );
*y = SPI_sendByte( 0xff );
CS_gyro_stop;
CS_gyro_start;
SPI_sendByte( 0x2A | 0x80 );
*y |= (SPI_sendByte( 0xff ) << 8);
CS_gyro_stop;
CS_gyro_start;
SPI_sendByte( 0x2D | 0x80 );
*z = SPI_sendByte( 0xff );
CS_gyro_stop;
CS_gyro_start;
SPI_sendByte( 0x2C | 0x80 );
*z |= (SPI_sendByte( 0xff ) << 8);
CS_gyro_stop;
}
int main( void ){
SysTick_Config( SystemCoreClock / 1000 );
initialize();
SPI_writeData(0x20, 0xff); //power on, settings from TM-library & datasheet
SPI_writeData(0x21, 0x00); //high-pass filter settings
SPI_writeData(0x24, 0x10); //high-pass filter en
SPI_writeData(0x23, 0x20); //scale 2000
uint16_t x, y, z;
while( 1 ){
GetGyroValues( &x, &y, &z );
printf( "x: %d\r\n", x );
DelayMS( 100 );
}
}
uint32_t sEE_TIMEOUT_UserCallback(void)
{
/* TODO, implement your code here */
while (1)
{
}
}// This is required by Atollic
最佳答案
来自L3GD20 app note :
注意最后一部分“表示为二进制补码”;您错误地将数据解释为无符号。看起来该值徘徊在零附近;或者实际上看起来您将其不稳定地固定在某个位置,但肯定不会以稳定的速度连续旋转它。该设备是陀螺仪,而不是加速度计。它测量角速度而不加速度(或倾斜 - 即重力加速度)。当静止时,您会期望所有轴上都为零。您的图表显示的可能是您的手在试图将其保持在 45 度时颤抖。
void GetGyroValues( int16_t *x, int16_t *y, int16_t *z )
应该会更成功,当然:
int16_t x, y, z;
您可以通过对角速度进行积分来获得角度变化的近似测量值,但不能获得绝对角度。即使如此,您可能也必须经常校准零 - 积分中的小非零偏差将表现为错误的缓慢旋转。
关于c - STM32F429-DISC1 上的陀螺仪表现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48938408/
我需要一种方法来从局部获取全局引用系中旋转的欧拉角。我正在使用 c#、wpf 3d 和陀螺仪。我在屏幕上有一个地球仪,它应该以与陀螺仪相同的方式移动。由于陀螺仪发送相对于自身的运动,我需要使用四元数来
我试图理解不同的运动/位置陀螺仪、运动和加速度所代表的含义。 (startGyroUpdates、startDeviceMotionUpdates 等)。 但是,经过一些研究后,我很难看出陀螺仪和运动
我想使用陀螺仪、加速度计和磁力计来获得 3 轴完全平滑的旋转。 第一个问题是我的输出有很大的噪音,我想知道如何消除它。 第二个问题是陀螺仪漂移,我认为应该用卡尔曼滤波器来解决。 第三个问题是加速度计。
我正在开发一个游戏,需要检测设备是否向上或向下移动以向上或向下移动角色,因为我正在使用陀螺仪(如果有更好的方法请纠正我) 但是陀螺仪对我来说非常复杂(因为我不太了解 phisyc),所以我不知道如何根
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我一直在尝试确定如何将 iPhone 陀螺仪用于驾驶员安全应用程序,但我对此感到非常困惑。我知道手机中的陀螺仪可以测量手机本身的变化和旋转,但是它可以用来测量手机在行驶的汽车中发生的变化吗? 例如,如
我正在尝试创建一个应用程序来跟踪设备在 2D 空间中的移动。在网上查了下,我能找到的一种方法是积分两次线性加速,但是错误很可怕。 这个问题有什么解决办法吗?我希望能够向上移动手机,这会导致在屏幕上绘制
我正在使用 Unity 制作一款使用陀螺仪的游戏。我正在尝试检测设备围绕穿过屏幕的轴的旋转,我假设它是 Unity Space 中的 Z 轴。我尝试使用 Input.gyro.attitude.eul
我正在学习使用 iOS 中的陀螺仪传感器编写应用。是否有处理陀螺仪的类,类似于加速度计的 UIAcceleration/UIAccelerometer/UIAccelerometerDelegate?
我想通过陀螺仪传感器的能力得到我想“看”的X、Y、Z位置的精确位置 我能够从陀螺仪传感器获得 9 的值,但我无法计算出从该陀螺仪传感器获得准确位置的公式。 我想要公式或例子来得到正确的答案 这是我想要
最近我做了一些研究,使用加速度计 + 陀螺仪来使用这些传感器在没有 GPS 帮助的情况下跟踪智能手机(见这篇文章) Indoor Positioning System based on Gyrosco
我正在测试 Core Motion 并使用陀螺仪。现在我得到了我不理解的值(value)观。我的假设是对于每个 x、y 和 z,我会得到一个 0-360 之间的值,这将是一个完整的旋转,但事实并非如此
我正在尝试使用陀螺仪制作一个简单的应用程序,其中角色会根据 iPad 1 的旋转进行移动。 我的代码无法正常工作,因此我测试了原始、俯仰、偏航的值,无论我如何移动设备,它们实际上都保持为零。我确定 i
我有一个非常简单的应用程序,我试图通过核心运动使用陀螺仪。 此时,出于测试目的,我只是获取滚动、俯仰和偏航的值并在屏幕上打印。根据下图,据我所知,roll、pitch、yaw分别对应红、绿、蓝轴,对吗
我正在使用 Core Motion,并且收到“展开可选值时意外发现 nil”,但只有大约一半的时间加载应用程序。如何更正下面的代码,使其稳定? import UIKit import CoreMoti
我有一些代码旨在测量移动设备上的设备运动,它曾经可以在移动浏览器中运行,但现在不再可以了。以下是直接取自 Mozilla 网络文档的示例: function handleMotionEvent(eve
Original Question 我正尝试在我的 iPhone 6s 上使用 A-Frame 运行一个 webVR 程序,而我测试过的这三个浏览器无法访问我的陀螺仪。 Safari Chrome F
我想知道 Apple 开发人员是否可以澄清 API 是否可用。 互联网上有一些猜测,似乎没有人回答这个问题。 或多或少,Apple Watch OS 2.0 并不是最容易使用的测试版,甚至发行版似乎也
我想制作一个应用程序来获取 Android 手机的所有读数,例如加速度计、GPS、陀螺仪、摄像头等。记录所有这些数据并将其发送到云端以供使用。 我是一名初学者 android 开发人员,想基本了解如何
我是一名优秀的程序员,十分优秀!