Hello,
I am having difficulty understanding why I cannot read the accelerometer and/or gyroscope data from my pixhawk. I am using the following code to do so.
int accel_sub = orb_subscribe(ORB_ID(sensor_accel));
struct sensor_accel_s accel;
orb_copy(ORB_ID(sensor_accel), accel_sub, &accel);
If anybody can point out why this is not working, I would greatly appreciate it. I have tried doing this by polling as well. Something like:
/* polling setup */
struct pollfd fds[1] = {};
fds[0].fd = accel_sub;
fds[0].events = POLLIN;
/* check if we have rc input */
int ret = poll(fds,sizeof(fds)/sizeof(fds[0]),500);
if (ret == 0) {
/* nothing changed */
} else if (ret < 0) {
/* this is bad */
warn("error reading rc input");
} else {
orb_copy(ORB_ID(sensor_accel), accel_sub, &accel);
}
I’m really scratching my head on this one because I can read the “input_rc” topic this way, but not the sensor_accel. When I print out the accelerometer data, it returns all zeros. The same code was applied to the sensor_gyro topic as well.
Thanks,
Jon
After further investigation, it appears that the accelerometer and gyro drivers failed to start. I went through this and ran the commands listed there: ls /dev
and sensors status
. Here is the output from those:
nsh> ls /dev
/dev:
console
led0
mmcsd0
mtdblock0
mtdblock1
null
pipe0
pipe1
pwm_output0
pwm_output1
px4fmu
px4io
ram0
rgbled0
tone_alarm0
ttyACM0
ttyS0
ttyS1
ttyS2
ttyS3
ttyS4
ttyS5
ttyS6
nsh>
and
nsh> sensors status
INFO [sensors] gyro status:
INFO [lib__ecl] validator: best: -1, prev best: -1, failsafe: NO (0 events)
INFO [sensors] accel status:
INFO [lib__ecl] validator: best: -1, prev best: -1, failsafe: NO (0 events)
INFO [sensors] mag status:
INFO [lib__ecl] validator: best: -1, prev best: -1, failsafe: NO (0 events)
INFO [sensors] baro status:
INFO [lib__ecl] validator: best: -1, prev best: -1, failsafe: NO (0 events)
INFO [sensors] Temperature Compensation:
INFO [sensors] gyro: enabled: 0
INFO [sensors] accel: enabled: 0
INFO [sensors] baro: enabled: 0
INFO [sensors] Airspeed status:
INFO [lib__ecl] no data
It seems that the accelerometer and gyroscope drivers are not being started. I tried sensors stop
and restarted the driver with sensors start
, but the results were the same. Any ideas?
Thanks,
Jon
For anybody that may be interested or run into this, I found out that I had set the SYS_HITL parameter to 1 enabling Hardware In The Loop which seemed to disable the sensors. When I turned this off, I was able to read the accelerometer and gyro values.
I am the same problem. But just with sensor baro.
. Can someone help me ?