小编tra*_*rad的帖子

如何在C中正确整合曲线?

我正在从陀螺仪(MPU6050)读取数据.它给了我角速度.我试图整合这些数据,以了解陀螺仪的角度.我这样做的方法是将读取数据乘以经过的时间并不断累加这些结果,即积分:

在此输入图像描述

但它似乎不起作用,这是我的代码和我得到的输出:

#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <sys/types.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>

#define A_SCALE (16384.0)
#define ANG_SCALE (131.0)

int main(int argc, char *argv[])
{
    int fd;
    int data;
    int i=0;

    float gyroXangle=0;
    float gyroYangle=0;
    float gyroZangle=0;
    float gyroOffset = 151;
    float gyroScale = 0.02;

    struct timeval startTime, stopTime;
    long timeDifference;
    int i=0;

    wiringPiSetup();
    fd = wiringPiI2CSetup(0x68);
    wiringPiI2CWriteReg8(fd, 0x6b, 0);

    if(fd==-1)
    {
        printf("can't setup device\n");
        return -1;
    }
    else
    {

        printf("successfully setup device\n");

        while(1) {
            msb = wiringPiI2CReadReg8(fd, MPU6050_REG_DATA_START+8); …
Run Code Online (Sandbox Code Playgroud)

c math

5
推荐指数
1
解决办法
166
查看次数

如何知道应将_POSIX_C_SOURCE定义为哪个值?

假设我要使用timespec在time.h中定义的structure。根据手册,我只需要包含time.h。但是,在c99中编译时,这还不够:

#include <stdio.h>
#include <time.h>

struct timespec abcd;

int main(int argc, char *argv[])
{
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

根据我在网上找到的信息(不在手册页中),我需要添加以下内容:

#define _POSIX_C_SOURCE 200809L

所以我有几个问题:

  • 我怎么知道我需要_POSIX_C_SOURCE等于哪个值?我在网上发现了多个价值。

  • 为什么此定义的位置会影响编译?(请参阅下文)

#include <stdio.h>

#define _POSIX_C_SOURCE 200809L

#include <time.h>

struct timespec abcd;

int main(int argc, char *argv[]) { return 0; }

$ gcc test.c -Wall -Wpedantic -std=c99 -o test test.c:9:25: error: field ‘time_last_package’ has incomplete type struct timespec time_last_package;

编译良好:

#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <time.h>
....
Run Code Online (Sandbox Code Playgroud)

谢谢

c posix

5
推荐指数
1
解决办法
311
查看次数

subprocess.Popen()和os.fork()有什么区别?

似乎subprocess.Popen ()os.fork()都能够创建子进程.但我想知道两者之间的区别.你什么时候使用哪一个?我试着查看他们的源代码,但是我在我的机器上找不到fork()的源代码,并且不完全清楚Popen如何在Unix机器上工作.

有人可以详细说明吗?

谢谢

python fork

3
推荐指数
2
解决办法
1965
查看次数

%PRId和%d格式字符有什么区别?

请考虑以下代码:

#include <stdio.h>
#include <inttypes.h>

void main(void)
{
    int32_t a = 44;

    fprintf(stdout, "%d\n", a);
    fprintf(stdout, "%"PRId32"\n", a);
}
Run Code Online (Sandbox Code Playgroud)

什么时候使用%d更好,"%"PRId32什么时候使用会更好?这两种格式字符有何不同?这是否与int32_t您的硬件/机器上的typedeffed有关?

c printf conversion-specifier length-modifiers

3
推荐指数
1
解决办法
108
查看次数

Qt-新QThread(this)和新QThread()有什么区别?

我想知道有什么区别之间存在new QThread(this)以及new QThread()和这将如何使用时,影响我的代码的行为的QThread.

c++ qt qthread

2
推荐指数
1
解决办法
324
查看次数

标签 统计

c ×3

c++ ×1

conversion-specifier ×1

fork ×1

length-modifiers ×1

math ×1

posix ×1

printf ×1

python ×1

qt ×1

qthread ×1