Adding lidar sensor handling
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
[gd_scene format=3 uid="uid://c2yga5koqwo72"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bbdbyjievjpsq" path="res://widgets/compass/compass_widget_scene.tscn" id="1_fyqef"]
|
||||
[ext_resource type="Script" uid="uid://ba7ta7jjrjuhg" path="res://views/2d/view_2d.gd" id="1_n6fjn"]
|
||||
[ext_resource type="PackedScene" uid="uid://b71kuj4yole3j" path="res://widgets/satellites/satellite_widget.tscn" id="2_3b2b5"]
|
||||
[ext_resource type="PackedScene" uid="uid://m14p8xxs14rf" path="res://widgets/altitude/altitude_widget.tscn" id="3_g6l6n"]
|
||||
@@ -14,9 +13,6 @@ script = ExtResource("1_n6fjn")
|
||||
|
||||
[node name="HUD" type="CanvasLayer" parent="." unique_id=1826106128]
|
||||
|
||||
[node name="Compass" parent="HUD" unique_id=2062816665 instance=ExtResource("1_fyqef")]
|
||||
position = Vector2(104, 486)
|
||||
|
||||
[node name="TotalSatCount" parent="HUD" unique_id=931018379 instance=ExtResource("2_3b2b5")]
|
||||
visible = false
|
||||
scale = Vector2(0.05, 0.05)
|
||||
@@ -64,10 +60,10 @@ scale = Vector2(0.05, 0.05)
|
||||
sat_category = "QZSS"
|
||||
|
||||
[node name="AltitudeWidget" parent="HUD" unique_id=1004159593 instance=ExtResource("3_g6l6n")]
|
||||
position = Vector2(170, 481)
|
||||
position = Vector2(233, 479)
|
||||
|
||||
[node name="AccelerometerWidget" parent="HUD" unique_id=1057256615 instance=ExtResource("4_qui0h")]
|
||||
position = Vector2(675, 400)
|
||||
position = Vector2(673, 302)
|
||||
|
||||
[node name="RollWidget" parent="HUD" unique_id=1446458625 instance=ExtResource("6_s8d37")]
|
||||
position = Vector2(407, 267)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
extends Node2D
|
||||
|
||||
var line: Line2D
|
||||
|
||||
var points_angle = []
|
||||
var points_distance = []
|
||||
var timer_static = 60
|
||||
var timer = 0.
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
line = get_node('Line2D')
|
||||
DataSignals.lidar_2d_data_received.connect(_on_lidar_data_received)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
timer += delta
|
||||
if timer > timer_static:
|
||||
timer = 0
|
||||
points_angle.clear()
|
||||
points_distance.clear()
|
||||
for i in line.points:
|
||||
print(i - Vector2(400, 400))
|
||||
print()
|
||||
_update_line()
|
||||
|
||||
func _on_lidar_data_received(sensor_ip: String, timestamp_list: Array, lidar_point_count: int, lidar_data: Array):
|
||||
for point in lidar_data:
|
||||
var insert_idx = Bisect.bisect(points_angle, point[0])
|
||||
points_angle.insert(insert_idx, point[0])
|
||||
points_distance.insert(insert_idx, point[1])
|
||||
|
||||
func _update_line():
|
||||
line.clear_points()
|
||||
for idx in range(points_angle.size()):
|
||||
var x = 4*points_distance[idx] * cos(deg_to_rad(points_angle[idx])) + 400
|
||||
var y = 4*points_distance[idx] * sin(deg_to_rad(points_angle[idx])) + 400
|
||||
line.add_point(Vector2(x, y))
|
||||
@@ -0,0 +1 @@
|
||||
uid://cei6fgt3rsc2c
|
||||
@@ -0,0 +1,13 @@
|
||||
[gd_scene format=3 uid="uid://ch0lyqkkxaem"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cei6fgt3rsc2c" path="res://views/2d/test_lidar.gd" id="1_8h8gx"]
|
||||
|
||||
[node name="TestLidar" type="Node2D" unique_id=948964638]
|
||||
script = ExtResource("1_8h8gx")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=60160156]
|
||||
position = Vector2(400, 400)
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="." unique_id=1424623383]
|
||||
closed = true
|
||||
width = 1.0
|
||||
Reference in New Issue
Block a user