123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "AP_Beacon_Backend.h"
- #include <stdio.h>
- AP_Beacon_Backend::AP_Beacon_Backend(AP_Beacon &frontend) :
- _frontend(frontend)
- {
- }
- void AP_Beacon_Backend::set_vehicle_position(const Vector3f& pos, float accuracy_estimate)
- {
- _frontend.veh_pos_update_ms = AP_HAL::millis();
- _frontend.veh_pos_accuracy = accuracy_estimate;
- _frontend.veh_pos_ned = correct_for_orient_yaw(pos);
- }
- void AP_Beacon_Backend::set_beacon_distance(uint8_t beacon_instance, float distance)
- {
-
- if (beacon_instance >= AP_BEACON_MAX_BEACONS) {
- return;
- }
-
- if (beacon_instance >= _frontend.num_beacons) {
- _frontend.num_beacons = beacon_instance+1;
- }
- _frontend.beacon_state[beacon_instance].distance_update_ms = AP_HAL::millis();
- _frontend.beacon_state[beacon_instance].distance = distance;
- _frontend.beacon_state[beacon_instance].healthy = true;
- }
- void AP_Beacon_Backend::set_beacon_position(uint8_t beacon_instance, const Vector3f& pos)
- {
-
- if (beacon_instance >= AP_BEACON_MAX_BEACONS) {
- return;
- }
-
- if (beacon_instance >= _frontend.num_beacons) {
- _frontend.num_beacons = beacon_instance+1;
- }
-
- _frontend.beacon_state[beacon_instance].position = correct_for_orient_yaw(pos);
- }
- Vector3f AP_Beacon_Backend::correct_for_orient_yaw(const Vector3f &vector)
- {
-
- if (_frontend.orient_yaw == 0) {
- return vector;
- }
-
- if (orient_yaw_deg != _frontend.orient_yaw) {
- _frontend.orient_yaw = wrap_180(_frontend.orient_yaw.get());
-
- orient_yaw_deg = _frontend.orient_yaw;
- orient_cos_yaw = cosf(radians(orient_yaw_deg));
- orient_sin_yaw = sinf(radians(orient_yaw_deg));
- }
-
- Vector3f vec_rotated;
- vec_rotated.x = vector.x*orient_cos_yaw - vector.y*orient_sin_yaw;
- vec_rotated.y = vector.x*orient_sin_yaw + vector.y*orient_cos_yaw;
- vec_rotated.z = vector.z;
- return vec_rotated;
- }
|