|
46 | 46 | #include <px4_log.h>
|
47 | 47 |
|
48 | 48 | #include <drivers/drv_pwm_output.h> // to get PWM flags
|
| 49 | +#include <uORB/topics/actuator_outputs.h> |
49 | 50 | #include <uORB/topics/vehicle_status.h> // to get the HIL status
|
50 | 51 |
|
51 | 52 | #include <unistd.h>
|
@@ -283,28 +284,6 @@ void Sih::init_variables()
|
283 | 284 |
|
284 | 285 | void Sih::init_sensors()
|
285 | 286 | {
|
286 |
| - |
287 |
| - _sensor_accel.device_id=1; |
288 |
| - _sensor_accel.error_count=0; |
289 |
| - _sensor_accel.integral_dt=0; |
290 |
| - _sensor_accel.temperature=T1_C; |
291 |
| - _sensor_accel.scaling=0.0f; |
292 |
| - |
293 |
| - _sensor_gyro.device_id=1; |
294 |
| - _sensor_gyro.error_count=0; |
295 |
| - _sensor_gyro.integral_dt=0; |
296 |
| - _sensor_gyro.temperature=T1_C; |
297 |
| - _sensor_gyro.scaling=0.0f; |
298 |
| - |
299 |
| - _sensor_mag.device_id=1; |
300 |
| - _sensor_mag.error_count=0; |
301 |
| - _sensor_mag.temperature=T1_C; |
302 |
| - _sensor_mag.scaling=0.0f; |
303 |
| - _sensor_mag.is_external=false; |
304 |
| - |
305 |
| - _sensor_baro.error_count=0; |
306 |
| - _sensor_baro.device_id=1; |
307 |
| - |
308 | 287 | _vehicle_gps_pos.fix_type=3; // 3D fix
|
309 | 288 | _vehicle_gps_pos.satellites_used=8;
|
310 | 289 | _vehicle_gps_pos.heading=NAN;
|
@@ -410,44 +389,35 @@ void Sih::reconstruct_sensors_signals()
|
410 | 389 |
|
411 | 390 | void Sih::send_IMU()
|
412 | 391 | {
|
413 |
| - _sensor_accel.timestamp=_now; |
414 |
| - _sensor_accel.x=_acc(0); |
415 |
| - _sensor_accel.y=_acc(1); |
416 |
| - _sensor_accel.z=_acc(2); |
417 |
| - if (_sensor_accel_pub != nullptr) { |
418 |
| - orb_publish(ORB_ID(sensor_accel), _sensor_accel_pub, &_sensor_accel); |
419 |
| - } else { |
420 |
| - _sensor_accel_pub = orb_advertise(ORB_ID(sensor_accel), &_sensor_accel); |
421 |
| - } |
| 392 | + // gyro |
| 393 | + { |
| 394 | + static constexpr float scaling = 1000.0f; |
| 395 | + _px4_gyro.set_scale(1 / scaling); |
| 396 | + _px4_gyro.set_temperature(T1_C); |
| 397 | + _px4_gyro.update(_now, _gyro(0) * scaling, _gyro(1) * scaling, _gyro(2) * scaling); |
| 398 | + } |
422 | 399 |
|
423 |
| - _sensor_gyro.timestamp=_now; |
424 |
| - _sensor_gyro.x=_gyro(0); |
425 |
| - _sensor_gyro.y=_gyro(1); |
426 |
| - _sensor_gyro.z=_gyro(2); |
427 |
| - if (_sensor_gyro_pub != nullptr) { |
428 |
| - orb_publish(ORB_ID(sensor_gyro), _sensor_gyro_pub, &_sensor_gyro); |
429 |
| - } else { |
430 |
| - _sensor_gyro_pub = orb_advertise(ORB_ID(sensor_gyro), &_sensor_gyro); |
431 |
| - } |
| 400 | + // accel |
| 401 | + { |
| 402 | + static constexpr float scaling = 1000.0f; |
| 403 | + _px4_accel.set_scale(1 / scaling); |
| 404 | + _px4_accel.set_temperature(T1_C); |
| 405 | + _px4_accel.update(_now, _acc(0) * scaling, _acc(1) * scaling, _acc(2) * scaling); |
| 406 | + } |
432 | 407 |
|
433 |
| - _sensor_mag.timestamp=_now; |
434 |
| - _sensor_mag.x=_mag(0); |
435 |
| - _sensor_mag.y=_mag(1); |
436 |
| - _sensor_mag.z=_mag(2); |
437 |
| - if (_sensor_mag_pub != nullptr) { |
438 |
| - orb_publish(ORB_ID(sensor_mag), _sensor_mag_pub, &_sensor_mag); |
439 |
| - } else { |
440 |
| - _sensor_mag_pub = orb_advertise(ORB_ID(sensor_mag), &_sensor_mag); |
441 |
| - } |
| 408 | + // magnetometer |
| 409 | + { |
| 410 | + static constexpr float scaling = 1000.0f; |
| 411 | + _px4_mag.set_scale(1 / scaling); |
| 412 | + _px4_mag.set_temperature(T1_C); |
| 413 | + _px4_mag.update(_now, _mag(0) * scaling, _mag(1) * scaling, _mag(2) * scaling); |
| 414 | + } |
442 | 415 |
|
443 |
| - _sensor_baro.timestamp=_now; |
444 |
| - _sensor_baro.pressure=_baro_p_mBar; |
445 |
| - _sensor_baro.temperature=_baro_temp_c; |
446 |
| - if (_sensor_baro_pub != nullptr) { |
447 |
| - orb_publish(ORB_ID(sensor_baro), _sensor_baro_pub, &_sensor_baro); |
448 |
| - } else { |
449 |
| - _sensor_baro_pub = orb_advertise(ORB_ID(sensor_baro), &_sensor_baro); |
450 |
| - } |
| 416 | + // baro |
| 417 | + { |
| 418 | + _px4_baro.set_temperature(_baro_temp_c); |
| 419 | + _px4_baro.update(_now, _baro_p_mBar); |
| 420 | + } |
451 | 421 | }
|
452 | 422 |
|
453 | 423 | void Sih::send_gps()
|
@@ -501,7 +471,7 @@ void Sih::publish_sih()
|
501 | 471 | } else {
|
502 | 472 | _att_gt_sub = orb_advertise(ORB_ID(vehicle_attitude_groundtruth), &_att_gt);
|
503 | 473 | }
|
504 |
| -} |
| 474 | +} |
505 | 475 |
|
506 | 476 | float Sih::generate_wgn() // generate white Gaussian noise sample with std=1
|
507 | 477 | {
|
|
0 commit comments