gpt4 book ai didi

C:输入if语句后如何自增

转载 作者:行者123 更新时间:2023-11-30 21:44:01 25 4
gpt4 key购买 nike

当计数器达到值 51 时,我尝试输入 if 语句,然后递增 if 语句内的计数器,使其不再为 true:

void imu_raw_handler (const lcm_recv_buf_t *rbuf, const char *channel,
const imu_raw_t *msg, void *userdata) {
for(counter = 1; counter < 51; counter++)
{
gyro_roll = (gyro_roll + gyro_roll_old*(counter-1))/counter;
gyro_pitch = (gyro_pitch + gyro_pitch_old*(counter-1))/counter;
gyro_yaw = (gyro_yaw + gyro_yaw_old*(counter-1))/counter;
accel_x = (accel_x + accel_x_old*(counter-1))/counter;
accel_y = (accel_y + accel_y_old*(counter-1))/counter;
accel_z = (accel_z + accel_z_old*(counter-1))/counter;
}
if (counter == 51){
// set zero points
axo = accel_x;
ayo = accel_y;
azo = accel_z;
gro = gyro_roll;
gpo = gyro_pitch;
gyo = gyro_yaw;
printf("Ready for Takeoff\n");
counter++;
}
}

编辑:我的主要功能如下所示。只要它正在运行,它就应该订阅流主题。我将计数器定义为全局变量。

int main()
{
lcm_t *lcm = lcm_create(NULL);

imu_raw_t_subscribe(lcm, "IMU_RAW", imu_raw_handler, NULL);
// Enter read loop
while (1) {
if(!lcm_handle_timeout(lcm, 1000)) {
printf("Failed read from IMU_RAW channel\n");
}
}

lcm_destroy(lcm);
}

但这将永远重复打印我的消息,而不是使 counter = 52 并且不再发生。为什么这不起作用?

最佳答案

问题很可能存在于这些代码片段之外。请检查其他地方是否没有打印。

关于C:输入if语句后如何自增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26968097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com