gpt4 book ai didi

c - PX4自动驾驶仪: "initialization makes integer from pointer without a cast"

转载 作者:行者123 更新时间:2023-11-30 21:10:08 32 4
gpt4 key购买 nike

我目前已经开始开发 PX4 自动驾驶仪,并且正在研究示例应用程序之一,并尝试编译固件并将其上传到 Pixhawk。

问题是它无法加载,给我这些错误:

make[2]: * [px4_simple_app.c.o] Error 1 make[1]: * [/c/px4/Firmware/Build/px4fmu-v2_default.build//c/px4/Firmware/src/examples/px4_simple_app/module.pre.o] Error 2 make[1]: Leaving directory `/c/px4/Firmware/Build/px4fmu-v2_default.build' make: *** [/c/px4/Firmware/Build/px4fmu-v2_default.build/firmware.px4] Error 2

我不确定这些是什么意思,但检查代码在某一行中给了我这个错误:

初始化从指针生成整数,无需强制转换

从这一行开始:

int att_pub_fd = orb_advertise(ORB_ID(vehicle_attitude), &att);

我不知道如何解决这个问题。有人可以给我一些帮助吗?

这是代码的其余部分:

/**
* @file px4_simple_app.c
* Minimal application example for PX4 autopilot
*/

#include <string.h>
#include <nuttx/config.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>

#include <uORB/uORB.h>
#include <uORB/topics/sensor_combined.h>
#include <uORB/topics/vehicle_attitude.h>

__EXPORT int px4_simple_app_main(int argc, char *argv[]);

int px4_simple_app_main(int argc, char *argv[])
{
printf("Hello Sky!\n");

/* subscribe to sensor_combined topic */
int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
orb_set_interval(sensor_sub_fd, 1000);

/* advertise attitude topic */
struct vehicle_attitude_s att;
memset(&att, 0, sizeof(att));
int att_pub_fd = orb_advertise(ORB_ID(vehicle_attitude), &att);

/* one could wait for multiple topics with this technique, just using one here */
struct pollfd fds[] = {
{ .fd = sensor_sub_fd, .events = POLLIN },
/* there could be more file descriptors here, in the form like:
* { .fd = other_sub_fd, .events = POLLIN },
*/
};

int error_counter = 0;

while (true) {
/* wait for sensor update of 1 file descriptor for 1000 ms (1 second) */
int poll_ret = poll(fds, 1, 1000);

/* handle the poll result */
if (poll_ret == 0) {
/* this means none of our providers is giving us data */
printf("[px4_simple_app] Got no data within a second\n");
} else if (poll_ret < 0) {
/* this is seriously bad - should be an emergency */
if (error_counter < 10 || error_counter % 50 == 0) {
/* use a counter to prevent flooding (and slowing us down) */
printf("[px4_simple_app] ERROR return value from poll(): %d\n"
, poll_ret);
}
error_counter++;
} else {

if (fds[0].revents & POLLIN) {
/* obtained data for the first file descriptor */
struct sensor_combined_s raw;
/* copy sensors raw data into local buffer */
orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
printf("[px4_simple_app] Accelerometer:\t%8.4f\t%8.4f\t%8.4f\n",
(double)raw.accelerometer_m_s2[0],
(double)raw.accelerometer_m_s2[1],
(double)raw.accelerometer_m_s2[2]);

/* set att and publish this information for other apps */
att.roll = raw.accelerometer_m_s2[0];
att.pitch = raw.accelerometer_m_s2[1];
att.yaw = raw.accelerometer_m_s2[2];
orb_publish(ORB_ID(vehicle_attitude), att_pub_fd, &att);
}
/* there could be more file descriptors here, in the form like:
* if (fds[1..n].revents & POLLIN) {}
*/
}
}

return 0;
}

最佳答案

函数

orb_advertise(ORB_ID(vehicle_attitude), &att) 

返回一个指针,并且您将其分配给一个 int。 我不确定你想做什么,但如果它指向一个整数,那么你需要取消引用指针。

关于c - PX4自动驾驶仪: "initialization makes integer from pointer without a cast",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31528157/

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