initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
[gd_scene format=3 uid="uid://c82t66hq0g1sq"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_mgj8s"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ivcly"]
|
||||
albedo_color = Color(0, 1, 1, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(1, 1, 1, 1)
|
||||
emission_energy_multiplier = 100.0
|
||||
|
||||
[node name="Satellite" type="Node3D" unique_id=990255812]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=829681102]
|
||||
transform = Transform3D(100, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0, 0)
|
||||
mesh = SubResource("SphereMesh_mgj8s")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_ivcly")
|
||||
@@ -0,0 +1,30 @@
|
||||
[gd_scene format=3 uid="uid://b71kuj4yole3j"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dwif4hgjhkd4j" path="res://widgets/satellites/scripts/satellite_widget_node.gd" id="1_q0bd2"]
|
||||
[ext_resource type="Script" uid="uid://cr4y57bw6jfd1" path="res://MoveableControl.gd" id="2_a0wwr"]
|
||||
|
||||
[node name="SatelliteWidget" type="Node2D" unique_id=931018379]
|
||||
script = ExtResource("1_q0bd2")
|
||||
metadata/_custom_type_script = "uid://dwif4hgjhkd4j"
|
||||
|
||||
[node name="Panel" type="Panel" parent="." unique_id=1980601372]
|
||||
offset_right = 4000.0
|
||||
offset_bottom = 698.0
|
||||
|
||||
[node name="Label" type="Label" parent="." unique_id=1126441894]
|
||||
offset_left = 2.0
|
||||
offset_top = 2.0
|
||||
offset_right = 42.0
|
||||
offset_bottom = 26.0
|
||||
theme_override_font_sizes/font_size = 512
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="MovableControl" type="Control" parent="." unique_id=73140661 node_paths=PackedStringArray("move_target")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 4000.0
|
||||
offset_bottom = 698.0
|
||||
mouse_filter = 1
|
||||
script = ExtResource("2_a0wwr")
|
||||
move_target = NodePath("..")
|
||||
metadata/_custom_type_script = "uid://cr4y57bw6jfd1"
|
||||
@@ -0,0 +1,101 @@
|
||||
extends Node3D
|
||||
class_name SatelliteWidget3dNode
|
||||
|
||||
var sensor_class: String
|
||||
var used_sensors: Dictionary = {}
|
||||
|
||||
var host_vehicle: VehicleNode
|
||||
var vehicle_3d_node: Node3D
|
||||
var vehicle_position: Vector3 = Vector3.ZERO
|
||||
var sat_scene: PackedScene = preload("res://widgets/satellites/satellite.tscn")
|
||||
var sat_nodes = {}
|
||||
var need_sat_update: bool = true
|
||||
var sat_update_timer: float = 0
|
||||
var sat_update_rate: float = 60.
|
||||
|
||||
var lines = []
|
||||
|
||||
var GPS_ALT_KM = 20_200
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
GPS_ALT_KM += Constants.EARTH_RADIUS_KM
|
||||
Signals.vehicle_added.connect(_on_vehicle_added)
|
||||
Signals.requested_host_vehicle.emit(self)
|
||||
Signals.sat_position_updated.connect(_on_sat_position_updated)
|
||||
Signals.position_updated.connect(_on_position_updated)
|
||||
|
||||
func _process(delta: float):
|
||||
sat_update_timer += delta
|
||||
if sat_update_timer >= sat_update_rate:
|
||||
sat_update_timer = 0
|
||||
need_sat_update = true
|
||||
if host_vehicle != null:
|
||||
return
|
||||
Signals.requested_host_vehicle.emit(self)
|
||||
|
||||
func _on_vehicle_added(new_vehicle):
|
||||
host_vehicle = new_vehicle
|
||||
|
||||
func set_host_vehicle(new_vehicle):
|
||||
host_vehicle = new_vehicle
|
||||
vehicle_3d_node = Node3D.new()
|
||||
add_child(vehicle_3d_node)
|
||||
|
||||
func check_valid_sensor(sensor_ip: String, sensor_class: String):
|
||||
if host_vehicle == null:
|
||||
return false
|
||||
if sensor_ip not in host_vehicle.sensors:
|
||||
return false
|
||||
if sensor_class == null:
|
||||
return true
|
||||
if sensor_class not in host_vehicle.sensor_classes:
|
||||
return false
|
||||
if sensor_ip not in host_vehicle.sensor_classes[sensor_class]:
|
||||
return false
|
||||
return true
|
||||
|
||||
func _on_sat_position_updated(sensor_ip: String, sat_position_data: Array):
|
||||
if vehicle_3d_node == null:
|
||||
return
|
||||
if not need_sat_update:
|
||||
return
|
||||
need_sat_update = false
|
||||
var current_sat_ids = []
|
||||
for sat_data in sat_position_data:
|
||||
var sat_id = sat_data[0]
|
||||
var el_rad = deg_to_rad(sat_data[1])
|
||||
var az_rad = deg_to_rad(sat_data[2])
|
||||
current_sat_ids.append(sat_id)
|
||||
if sat_id not in sat_nodes:
|
||||
_create_sat_node(sat_id)
|
||||
_update_sat_position(sat_id, el_rad, az_rad)
|
||||
for old_sat_id in sat_nodes.keys():
|
||||
if old_sat_id not in current_sat_ids:
|
||||
vehicle_3d_node.remove_child(sat_nodes[old_sat_id])
|
||||
sat_nodes[old_sat_id].queue_free()
|
||||
sat_nodes.erase(old_sat_id)
|
||||
|
||||
func _create_sat_node(sat_id: String):
|
||||
var new_sat_node = sat_scene.instantiate()
|
||||
sat_nodes[sat_id] = new_sat_node
|
||||
vehicle_3d_node.add_child(new_sat_node)
|
||||
|
||||
func _update_sat_position(sat_id, el_rad, az_rad):
|
||||
# vehicle node is rotated to SEZ.
|
||||
# Az is rotated clockwise from north
|
||||
# 0 el is horizon. 90 is zenith
|
||||
var x = sin(el_rad) * cos(az_rad + PI)
|
||||
var y = sin(el_rad) * sin(az_rad + PI)
|
||||
var z = cos(el_rad)
|
||||
var sat_position = Vector3(x, y, z)
|
||||
var global_sat_position = ((vehicle_position.normalized() + sat_position) * GPS_ALT_KM)
|
||||
var local_sat_position = global_sat_position - vehicle_position
|
||||
sat_nodes[sat_id].position = Vector3(local_sat_position.x, local_sat_position.z, local_sat_position.y)
|
||||
|
||||
func _on_position_updated(sensor_ip: String, physics_position: Vector3):
|
||||
if vehicle_3d_node == null:
|
||||
return
|
||||
vehicle_position = physics_position
|
||||
vehicle_3d_node.position = Vector3(physics_position.x, physics_position.z, physics_position.y)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://1825fgmcotxw
|
||||
@@ -0,0 +1,40 @@
|
||||
extends BaseWidgetNode
|
||||
class_name SatelliteWidgetNode
|
||||
|
||||
@export_enum("Total", "BeiDou", "Galileo", "GLONASS", "GNSS", "GPS", "NavIC", "QZSS") var sat_category: String = "Total"
|
||||
#[ga, gb, gi, gl, gp, gq, gn]
|
||||
var sat_idx_map = {
|
||||
"Galileo": 0,
|
||||
"BeiDou": 1,
|
||||
"NavIC": 2,
|
||||
"GLONASS": 3,
|
||||
"GPS": 4,
|
||||
"QZSS": 5,
|
||||
"GNSS": 6,
|
||||
}
|
||||
|
||||
var label_node: Label
|
||||
|
||||
var prev_num_connections: int = 0
|
||||
var num_connections: int = 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
sensor_class = "PNT"
|
||||
label_node = get_node("Label")
|
||||
Signals.sat_count_updated.connect(_on_sat_count_updated)
|
||||
label_node.text = sat_category + ": 0"
|
||||
|
||||
func _on_sat_count_updated(sensor_ip: String, sat_count_array: Array):
|
||||
if sat_category == "Total":
|
||||
var sat_sum = 0
|
||||
for val in sat_count_array:
|
||||
sat_sum += val
|
||||
num_connections = sat_sum
|
||||
else:
|
||||
num_connections = sat_count_array[sat_idx_map[sat_category]]
|
||||
if num_connections == prev_num_connections:
|
||||
return
|
||||
label_node.text = sat_category + ": " + str(num_connections)
|
||||
prev_num_connections = num_connections
|
||||
@@ -0,0 +1 @@
|
||||
uid://dwif4hgjhkd4j
|
||||
Reference in New Issue
Block a user