@@ -78,6 +78,7 @@ void Sih::run()
7878 _last_run = task_start;
7979 _airspeed_time = task_start;
8080 _dist_snsr_time = task_start;
81+ _ranging_beacon_time = task_start;
8182 _vehicle = static_cast <VehicleType>(constrain (_sih_vtype.get (),
8283 static_cast <int32_t >(VehicleType::First),
8384 static_cast <int32_t >(VehicleType::Last)));
@@ -232,6 +233,12 @@ void Sih::sensor_step()
232233 send_dist_snsr (now);
233234 }
234235
236+ // ranging beacon published at 2 Hz (each beacon at 0.5 Hz)
237+ if (now - _ranging_beacon_time >= 500_ms) {
238+ _ranging_beacon_time = now;
239+ send_ranging_beacon (now);
240+ }
241+
235242 publish_ground_truth (now);
236243
237244 perf_end (_loop_perf);
@@ -259,7 +266,7 @@ void Sih::parameters_updated()
259266 _lla.setAltitude (_lpos_ref_alt);
260267 _p_E = _lla.toEcef ();
261268
262- const Dcmf R_E2N = computeRotEcefToNed (_lla );
269+ const Dcmf R_E2N = _lla. computeRotEcefToNed ();
263270 _R_N2E = R_E2N.transpose ();
264271 _v_E = _R_N2E * _v_N;
265272
@@ -571,7 +578,7 @@ void Sih::ecefToNed()
571578{
572579 _lla = LatLonAlt::fromEcef (_p_E);
573580
574- const Dcmf C_SE = computeRotEcefToNed (_lla );
581+ const Dcmf C_SE = _lla. computeRotEcefToNed ();
575582 _R_N2E = C_SE.transpose ();
576583
577584 // Transform velocity to NED frame
@@ -582,22 +589,6 @@ void Sih::ecefToNed()
582589 _q.normalize ();
583590}
584591
585- Dcmf Sih::computeRotEcefToNed (const LatLonAlt &lla)
586- {
587- // Calculate the ECEF to NED coordinate transformation matrix
588- const double cos_lat = cos (lla.latitude_rad ());
589- const double sin_lat = sin (lla.latitude_rad ());
590- const double cos_lon = cos (lla.longitude_rad ());
591- const double sin_lon = sin (lla.longitude_rad ());
592-
593- const float val[] = {(float )(-sin_lat * cos_lon), (float )(-sin_lat * sin_lon), (float )cos_lat,
594- (float ) - sin_lon, (float )cos_lon, 0 .f ,
595- (float )(-cos_lat * cos_lon), (float )(-cos_lat * sin_lon), (float ) - sin_lat
596- };
597-
598- return Dcmf (val);
599- }
600-
601592void Sih::reconstruct_sensors_signals (const hrt_abstime &time_now_us)
602593{
603594 // The sensor signals reconstruction and noise levels are from [1]
@@ -678,6 +669,55 @@ void Sih::send_dist_snsr(const hrt_abstime &time_now_us)
678669 _distance_snsr_pub.publish (distance_sensor);
679670}
680671
672+ void Sih::send_ranging_beacon (const hrt_abstime &time_now_us)
673+ {
674+ if (_lpos_ref.isInitialized ()) {
675+
676+ if (!_beacons_configured) {
677+ _beacons_configured = true ;
678+
679+ for (uint8_t i = 0 ; i < NUM_RANGING_BEACONS; i++) {
680+ _lpos_ref.reproject (RANGING_BEACON_OFFSETS[i].north_m , RANGING_BEACON_OFFSETS[i].east_m ,
681+ _ranging_beacons[i].lat_deg , _ranging_beacons[i].lon_deg );
682+ _ranging_beacons[i].alt_m = _sih_h0.get () + RANGING_BEACON_OFFSETS[i].alt_offset_m ;
683+ }
684+ }
685+
686+ const RangingBeaconConfig &beacon = _ranging_beacons[_ranging_beacon_idx];
687+ const LatLonAlt beacon_lla (beacon.lat_deg , beacon.lon_deg , beacon.alt_m );
688+ const matrix::Vector3d beacon_ecef = beacon_lla.toEcef ();
689+
690+ // Compute true range in ECEF
691+ const matrix::Vector3d delta_ecef = beacon_ecef - _p_E;
692+ const double true_range_m = delta_ecef.norm ();
693+
694+ const float noise_std = _sih_ranging_beacon_noise.get ();
695+ const float noise_m = (noise_std > 0 .f ) ? generate_wgn () * noise_std : 0 .f ;
696+ const double measured_range_m = math::max (0.0 , true_range_m + static_cast <double >(noise_m));
697+
698+ ranging_beacon_s msg{};
699+ msg.timestamp = hrt_absolute_time ();
700+ msg.timestamp_sample = time_now_us;
701+ msg.beacon_id = _ranging_beacon_idx;
702+ msg.range = static_cast <float >(measured_range_m);
703+ msg.lat = beacon.lat_deg ;
704+ msg.lon = beacon.lon_deg ;
705+ msg.alt = beacon.alt_m ;
706+ msg.alt_type = 0 ; // WGS84
707+ msg.hacc = 1 .0f ;
708+ msg.vacc = 1 .0f ;
709+ msg.range_accuracy = noise_std;
710+ msg.sequence_nr = 0 ;
711+ msg.status = 0 ;
712+ msg.carrier_freq = 0 ;
713+
714+ _ranging_beacon_pub.publish (msg);
715+
716+ // cycle through the beacons
717+ _ranging_beacon_idx = (_ranging_beacon_idx + 1 ) % NUM_RANGING_BEACONS;
718+ }
719+ }
720+
681721void Sih::publish_ground_truth (const hrt_abstime &time_now_us)
682722{
683723 {
0 commit comments