123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #include <AP_HAL/AP_HAL.h>
- #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
- #include "AP_Beacon_SITL.h"
- #include <stdio.h>
- extern const AP_HAL::HAL& hal;
- #define NUM_BEACONS 4
- #define BEACON_SPACING_NORTH 10.0
- #define BEACON_SPACING_EAST 20.0
- #define ORIGIN_OFFSET_NORTH 2.5
- #define ORIGIN_OFFSET_EAST 5.0
- AP_Beacon_SITL::AP_Beacon_SITL(AP_Beacon &frontend) :
- AP_Beacon_Backend(frontend),
- sitl(AP::sitl())
- {
- }
- bool AP_Beacon_SITL::healthy()
- {
-
- return ((AP_HAL::millis() - last_update_ms) < AP_BEACON_TIMEOUT_MS);
- }
- void AP_Beacon_SITL::update(void)
- {
- uint32_t now = AP_HAL::millis();
- if (now - last_update_ms < 10) {
- return;
- }
- uint8_t beacon_id = next_beacon;
- next_beacon = (next_beacon+1) % NUM_BEACONS;
-
- Location current_loc;
- current_loc.lat = sitl->state.latitude * 1.0e7f;
- current_loc.lng = sitl->state.longitude * 1.0e7f;
- current_loc.alt = sitl->state.altitude * 1.0e2;
-
- Location beacon_origin;
- beacon_origin.lat = get_beacon_origin_lat() * 1.0e7f;
- beacon_origin.lng = get_beacon_origin_lon() * 1.0e7f;
- beacon_origin.alt = get_beacon_origin_alt() * 1.0e2;
-
- Location beacon_loc = beacon_origin;
- switch (beacon_id) {
- case 0:
-
- beacon_loc.offset(ORIGIN_OFFSET_NORTH + BEACON_SPACING_NORTH/2, ORIGIN_OFFSET_EAST + BEACON_SPACING_EAST/2);
- break;
- case 1:
-
- beacon_loc.offset(ORIGIN_OFFSET_NORTH - BEACON_SPACING_NORTH/2, ORIGIN_OFFSET_EAST + BEACON_SPACING_EAST/2);
- break;
- case 2:
-
- beacon_loc.offset(ORIGIN_OFFSET_NORTH - BEACON_SPACING_NORTH/2, ORIGIN_OFFSET_EAST - BEACON_SPACING_EAST/2);
- break;
- case 3:
-
- beacon_loc.offset(ORIGIN_OFFSET_NORTH + BEACON_SPACING_NORTH/2, ORIGIN_OFFSET_EAST - BEACON_SPACING_EAST/2);
- break;
- }
- const Vector2f beac_diff = beacon_origin.get_distance_NE(beacon_loc);
- const Vector2f veh_diff = beacon_origin.get_distance_NE(current_loc);
- Vector3f veh_pos3d(veh_diff.x, veh_diff.y, (current_loc.alt - beacon_origin.alt)*1.0e-2f);
- Vector3f beac_pos3d(beac_diff.x, beac_diff.y, (beacon_origin.alt - beacon_loc.alt)*1.0e-2f);
- Vector3f beac_veh_offset = veh_pos3d - beac_pos3d;
- set_beacon_position(beacon_id, beac_pos3d);
- set_beacon_distance(beacon_id, beac_veh_offset.length());
- set_vehicle_position(veh_pos3d, 0.5f);
- last_update_ms = now;
- }
- #endif
|