diff --git a/project/aircraft/aircraft.gd b/project/aircraft/aircraft.gd index 3870b93..090e0fe 100644 --- a/project/aircraft/aircraft.gd +++ b/project/aircraft/aircraft.gd @@ -49,6 +49,7 @@ func _process(delta: float) -> void: # Update the instruments instruments.call("set_controls", connector.get_controls()) instruments.call("set_trim", connector.get_trim()) + instruments.call("update_pfd", connector.get_aircraft(), connector.get_velocity()) # Spin the rotor only when receiving flight data if connector.get_model_connected(): diff --git a/project/aircraft/aircraft.tscn b/project/aircraft/aircraft.tscn index 484b3e1..9b65e24 100644 --- a/project/aircraft/aircraft.tscn +++ b/project/aircraft/aircraft.tscn @@ -66,7 +66,6 @@ fov = 60.0 [node name="Instruments" parent="AttitudeRoot" instance=ExtResource("3_5w717")] transform = Transform3D(-0.5, -1.27582e-08, 7.43353e-08, 4.33325e-10, 0.4923, 0.0874084, -7.5421e-08, 0.0874084, -0.4923, 0.00724897, -1.1581, 2.40391) -lidia_hostname = "127.0.0.1" [node name="MarshConnector" type="MarshConnector" parent="."] diff --git a/project/instruments.gd b/project/instruments.gd index 46ee8e3..de11eba 100644 --- a/project/instruments.gd +++ b/project/instruments.gd @@ -1,32 +1,12 @@ extends Node -const PFD_PATH: String = "pfd#adi,vsi,alt,ias,rht,rpm,hsi" - -@export var lidia_hostname: String = "localhost" -@export var lidia_port: int = 5555 - @onready var controls: Node = $SubViewport2/Controls - -func _ready(): - if !$CEF.initialize({"incognito":true, "locale":"en-US"}): - push_error($CEF.get_error()) - get_tree().quit() - return - print("CEF version: " + $CEF.get_full_version()) - - # Wait one frame for the texture rect to get its size - await get_tree().process_frame - - var browser_pfd = $CEF.create_browser( - "http://{}:{}/{}".format([lidia_hostname, lidia_port, PFD_PATH], "{}"), - $SubViewport/TextureRect, - { "frame_rate": 90, "javascript": true }, - ) - browser_pfd.name = "pfd" - browser_pfd.enable_ad_block(false) # Required for lidia static assets +@onready var pfd: Node = $SubViewport/PFD # Propagate the calls to child func set_controls(current: Vector4): controls.set("controls", current) func set_trim(trim: Vector4): controls.set("trim", trim) +func update_pfd(aircraft: Transform3D, velocity: Vector3): + pfd.call("update", aircraft, velocity) diff --git a/project/instruments/RobotoMono-LICENSE.txt b/project/instruments/RobotoMono-LICENSE.txt new file mode 100644 index 0000000..f08da9b --- /dev/null +++ b/project/instruments/RobotoMono-LICENSE.txt @@ -0,0 +1,41 @@ +Roboto Mono + +Copyright 2015 Google + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +===================================================================== + +Socket.IO + +MIT License + +Copyright (c) 2014-2022 Guillermo Rauch + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/project/instruments/RobotoMono-Regular.ttf b/project/instruments/RobotoMono-Regular.ttf new file mode 100644 index 0000000..d9371a1 Binary files /dev/null and b/project/instruments/RobotoMono-Regular.ttf differ diff --git a/project/instruments/RobotoMono-Regular.ttf.import b/project/instruments/RobotoMono-Regular.ttf.import new file mode 100644 index 0000000..5f58fa5 --- /dev/null +++ b/project/instruments/RobotoMono-Regular.ttf.import @@ -0,0 +1,35 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://chqgmpsthpbgt" +path="res://.godot/imported/RobotoMono-Regular.ttf-48a8b9dfd581c05f54f90e11c9fc9d5f.fontdata" + +[deps] + +source_file="res://instruments/RobotoMono-Regular.ttf" +dest_files=["res://.godot/imported/RobotoMono-Regular.ttf-48a8b9dfd581c05f54f90e11c9fc9d5f.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +disable_embedded_bitmaps=true +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=4 +keep_rounding_remainders=true +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/project/instruments/heading-ticks.png b/project/instruments/heading-ticks.png new file mode 100644 index 0000000..ab34048 --- /dev/null +++ b/project/instruments/heading-ticks.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb45a774c6a9381a172996207b5b2b3c23e902990b22f8e4888d282dadc3ac0c +size 21042 diff --git a/project/instruments/heading-ticks.png.import b/project/instruments/heading-ticks.png.import new file mode 100644 index 0000000..19e6c58 --- /dev/null +++ b/project/instruments/heading-ticks.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c36kaqyfalb2v" +path="res://.godot/imported/heading-ticks.png-8d0b08e5e3af463192c04d5a2068a1e0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://instruments/heading-ticks.png" +dest_files=["res://.godot/imported/heading-ticks.png-8d0b08e5e3af463192c04d5a2068a1e0.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/instruments/horizon-mask.png b/project/instruments/horizon-mask.png new file mode 100644 index 0000000..24cd07a --- /dev/null +++ b/project/instruments/horizon-mask.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b5aa4314b575de2f8a680150f96f3f6510984356293977c28201e637e4e7229 +size 5964 diff --git a/project/instruments/horizon-mask.png.import b/project/instruments/horizon-mask.png.import new file mode 100644 index 0000000..d6e70d0 --- /dev/null +++ b/project/instruments/horizon-mask.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c5nbrnus8pcyd" +path="res://.godot/imported/horizon-mask.png-03d2bafdd84b9816ae1fe68fc4baf43d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://instruments/horizon-mask.png" +dest_files=["res://.godot/imported/horizon-mask.png-03d2bafdd84b9816ae1fe68fc4baf43d.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/instruments/horizon-overlay.png b/project/instruments/horizon-overlay.png new file mode 100644 index 0000000..100f1e8 --- /dev/null +++ b/project/instruments/horizon-overlay.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:496d869e45085d3547edeab73e93711320bd7f2dc7f314f28db47750348f6dce +size 4334 diff --git a/project/instruments/horizon-overlay.png.import b/project/instruments/horizon-overlay.png.import new file mode 100644 index 0000000..cae3ce4 --- /dev/null +++ b/project/instruments/horizon-overlay.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b703lu8yhaoav" +path="res://.godot/imported/horizon-overlay.png-7e128e1a0dd8183251d6119879899864.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://instruments/horizon-overlay.png" +dest_files=["res://.godot/imported/horizon-overlay.png-7e128e1a0dd8183251d6119879899864.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/instruments/horizon.png b/project/instruments/horizon.png new file mode 100644 index 0000000..19ecd6f --- /dev/null +++ b/project/instruments/horizon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20b2cd5de91fbc589e3a0c33b67b8837b535a2c41a0f256940c779bfb4339f98 +size 16585 diff --git a/project/instruments/horizon.png.import b/project/instruments/horizon.png.import new file mode 100644 index 0000000..9196986 --- /dev/null +++ b/project/instruments/horizon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bxdfrv8bovdai" +path="res://.godot/imported/horizon.png-9384af1095d9251c4f8861113a545ccf.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://instruments/horizon.png" +dest_files=["res://.godot/imported/horizon.png-9384af1095d9251c4f8861113a545ccf.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/instruments/instruments.tscn b/project/instruments/instruments.tscn index 1a4f7fe..dcd9dc1 100644 --- a/project/instruments/instruments.tscn +++ b/project/instruments/instruments.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=8 format=3 uid="uid://cis4s43ubuynp"] +[gd_scene load_steps=9 format=3 uid="uid://cis4s43ubuynp"] [ext_resource type="Script" uid="uid://01bmfj4wthwg" path="res://instruments.gd" id="1_wlkep"] [ext_resource type="PackedScene" uid="uid://bgkpwebqksth5" path="res://instruments/controls.tscn" id="2_372d7"] +[ext_resource type="PackedScene" uid="uid://b26tu6wb2h3ce" path="res://instruments/pfd.tscn" id="2_uhiu3"] [sub_resource type="QuadMesh" id="QuadMesh_nowl7"] @@ -21,14 +22,11 @@ albedo_texture = SubResource("ViewportTexture_h5at3") [node name="Instruments" type="Node3D"] script = ExtResource("1_wlkep") -lidia_hostname = "192.168.1.2" [node name="SubViewport" type="SubViewport" parent="."] +size = Vector2i(1024, 1024) -[node name="TextureRect" type="TextureRect" parent="SubViewport"] -offset_right = 512.0 -offset_bottom = 512.0 -expand_mode = 5 +[node name="PFD" parent="SubViewport" instance=ExtResource("2_uhiu3")] [node name="Quad" type="MeshInstance3D" parent="."] transform = Transform3D(0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, -0.35, 0, 0) diff --git a/project/instruments/pfd-background.png b/project/instruments/pfd-background.png new file mode 100644 index 0000000..d160558 --- /dev/null +++ b/project/instruments/pfd-background.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24e12f54cb40f58eb2e51247e6f90bc9daf9d46017ac7f531364d099b435889d +size 60304 diff --git a/project/instruments/pfd-background.png.import b/project/instruments/pfd-background.png.import new file mode 100644 index 0000000..4efb713 --- /dev/null +++ b/project/instruments/pfd-background.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://colp4xsovikmv" +path="res://.godot/imported/pfd-background.png-99626101f4d3a30d7dd189ac71adf1c0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://instruments/pfd-background.png" +dest_files=["res://.godot/imported/pfd-background.png-99626101f4d3a30d7dd189ac71adf1c0.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/instruments/pfd-ref.png b/project/instruments/pfd-ref.png index 08a7309..b765e28 100644 --- a/project/instruments/pfd-ref.png +++ b/project/instruments/pfd-ref.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3e079dc36171686e572fe77691d340b82e43288c4b6aaf81776158162e3e50ce -size 70065 +oid sha256:44f6cebabe3ae23e9993b7485ee2fb3904a3312dd1ba388d6e76306e856ceccc +size 133172 diff --git a/project/instruments/pfd.gd b/project/instruments/pfd.gd new file mode 100644 index 0000000..bd92309 --- /dev/null +++ b/project/instruments/pfd.gd @@ -0,0 +1,50 @@ +@tool +class_name PFD +extends Node2D + +@export var euler_attitude_deg: Vector3: + set(value): + euler_attitude_deg = value + horizon_pivot.rotation = deg_to_rad(-value.x) + const px_per_deg: float = 6.56 + horizon_background.position.y = px_per_deg * clamp(value.y, -30, 30) + heading_ticks.rotation = deg_to_rad(-value.z) + heading_label.text = "%03d" % (int(round(value.z) + 360) % 360) + +@export var airspeed: float: + set(value): + airspeed = value + airspeed_label.text = str(int(round(value))) + +@export var groundspeed: float: + set(value): + groundspeed = value + groundspeed_label.text = str(int(round(value))) + +@export var altitude: float: + set(value): + altitude = value + var step = 1 + if value > 49.5: + step = 5 + if value > 99.5: + step = 10 + altitude_label.text = str(int(step * round(value / step))) + +@export var climbrate: float = 1000: + set(value): + climbrate = value + climbrate_arrow.scale.y = clamp(value / 1000.0, -1, 1) + +@onready var horizon_pivot: Node2D = $HorizonMask/HorizonOrigin/Pivot +@onready var horizon_background: Node2D = $HorizonMask/HorizonOrigin/Pivot/Background +@onready var heading_ticks: Node2D = $HeadingOrigin/Ticks +@onready var climbrate_arrow: Node2D = $ClimbrateOrigin/Polygon2D +@onready var airspeed_label: Label = $Airspeed +@onready var groundspeed_label: Label = $Groundspeed +@onready var altitude_label: Label = $Altitude +@onready var heading_label: Label = $Heading + +func update(aircraft: Transform3D, velocity: Vector3): + var godot_euler = aircraft.basis.get_euler() + euler_attitude_deg = Vector3(godot_euler.z, -godot_euler.x, -godot_euler.y) * rad_to_deg(1) diff --git a/project/instruments/pfd.gd.uid b/project/instruments/pfd.gd.uid new file mode 100644 index 0000000..fbc3cd3 --- /dev/null +++ b/project/instruments/pfd.gd.uid @@ -0,0 +1 @@ +uid://368tfiyen071 diff --git a/project/instruments/pfd.tscn b/project/instruments/pfd.tscn new file mode 100644 index 0000000..306ed2a --- /dev/null +++ b/project/instruments/pfd.tscn @@ -0,0 +1,103 @@ +[gd_scene load_steps=9 format=3 uid="uid://b26tu6wb2h3ce"] + +[ext_resource type="Texture2D" uid="uid://colp4xsovikmv" path="res://instruments/pfd-background.png" id="1_inkqg"] +[ext_resource type="Script" uid="uid://368tfiyen071" path="res://instruments/pfd.gd" id="1_t02it"] +[ext_resource type="Texture2D" uid="uid://c5nbrnus8pcyd" path="res://instruments/horizon-mask.png" id="2_t02it"] +[ext_resource type="Texture2D" uid="uid://bxdfrv8bovdai" path="res://instruments/horizon.png" id="3_kwqn1"] +[ext_resource type="Texture2D" uid="uid://b703lu8yhaoav" path="res://instruments/horizon-overlay.png" id="4_1vq1p"] +[ext_resource type="Texture2D" uid="uid://c36kaqyfalb2v" path="res://instruments/heading-ticks.png" id="5_3w2cf"] +[ext_resource type="FontFile" uid="uid://chqgmpsthpbgt" path="res://instruments/RobotoMono-Regular.ttf" id="6_wtx4e"] +[ext_resource type="Texture2D" uid="uid://toojp8r3424r" path="res://instruments/pfd-ref.png" id="7_86xjv"] + +[node name="PFD" type="Node2D"] +script = ExtResource("1_t02it") + +[node name="Background" type="Sprite2D" parent="."] +position = Vector2(512, 512) +texture = ExtResource("1_inkqg") + +[node name="HorizonMask" type="Sprite2D" parent="."] +clip_children = 1 +position = Vector2(512, 512) +texture = ExtResource("2_t02it") + +[node name="HorizonOrigin" type="Node2D" parent="HorizonMask"] +position = Vector2(-82, -244) + +[node name="Pivot" type="Node2D" parent="HorizonMask/HorizonOrigin"] + +[node name="Background" type="Sprite2D" parent="HorizonMask/HorizonOrigin/Pivot"] +texture = ExtResource("3_kwqn1") + +[node name="RollArrowContour" type="Polygon2D" parent="HorizonMask/HorizonOrigin/Pivot"] +position = Vector2(-430, -267) +color = Color(0, 0, 0, 1) +polygon = PackedVector2Array(430, 70, 416, 92, 444, 92) + +[node name="RollArrowFill" type="Polygon2D" parent="HorizonMask/HorizonOrigin/Pivot"] +position = Vector2(-430, -267) +polygon = PackedVector2Array(430, 74, 420, 90, 440, 90) + +[node name="Overlay" type="Sprite2D" parent="HorizonMask/HorizonOrigin"] +texture = ExtResource("4_1vq1p") + +[node name="HeadingOrigin" type="Node2D" parent="."] +position = Vector2(430, 794) + +[node name="Ticks" type="Sprite2D" parent="HeadingOrigin"] +texture = ExtResource("5_3w2cf") + +[node name="ClimbrateOrigin" type="Node2D" parent="."] +position = Vector2(711, 268) + +[node name="Polygon2D" type="Polygon2D" parent="ClimbrateOrigin"] +polygon = PackedVector2Array(12, 0, -12, 0, -12, -121, 0, -133, 12, -121) + +[node name="Airspeed" type="Label" parent="."] +offset_left = 35.0 +offset_top = 233.0 +offset_right = 154.0 +offset_bottom = 298.0 +theme_override_fonts/font = ExtResource("6_wtx4e") +theme_override_font_sizes/font_size = 48 +text = "0" +horizontal_alignment = 2 +vertical_alignment = 1 + +[node name="Groundspeed" type="Label" parent="."] +offset_left = 59.0 +offset_top = 477.0 +offset_right = 178.0 +offset_bottom = 542.0 +theme_override_fonts/font = ExtResource("6_wtx4e") +theme_override_font_sizes/font_size = 33 +text = "0" +horizontal_alignment = 2 +vertical_alignment = 1 + +[node name="Altitude" type="Label" parent="."] +offset_left = 859.0 +offset_top = 233.0 +offset_right = 978.0 +offset_bottom = 298.0 +theme_override_fonts/font = ExtResource("6_wtx4e") +theme_override_font_sizes/font_size = 48 +text = "0" +horizontal_alignment = 2 +vertical_alignment = 1 + +[node name="Heading" type="Label" parent="."] +offset_left = 370.0 +offset_top = 498.0 +offset_right = 489.0 +offset_bottom = 563.0 +theme_override_fonts/font = ExtResource("6_wtx4e") +theme_override_font_sizes/font_size = 33 +text = "000" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Reference" type="Sprite2D" parent="."] +visible = false +position = Vector2(512, 512) +texture = ExtResource("7_86xjv") diff --git a/src/marshconnector.cpp b/src/marshconnector.cpp index fa2a9b9..5d4266e 100644 --- a/src/marshconnector.cpp +++ b/src/marshconnector.cpp @@ -34,6 +34,7 @@ using namespace godot; void MarshConnector::_bind_methods() { // Data access ClassDB::bind_method(D_METHOD("get_aircraft"), &MarshConnector::get_aircraft); + ClassDB::bind_method(D_METHOD("get_velocity"), &MarshConnector::get_velocity); ClassDB::bind_method(D_METHOD("get_cyclic"), &MarshConnector::get_cyclic); ClassDB::bind_method(D_METHOD("get_collective"), &MarshConnector::get_collective); @@ -242,6 +243,8 @@ Transform3D MarshConnector::get_aircraft() { return offset * marsh; } +Vector3 MarshConnector::get_velocity() { return last_velocity; } + Vector2 MarshConnector::get_cyclic() { return Vector2{last_controls.x, last_controls.y}; } @@ -293,6 +296,8 @@ void MarshConnector::handle_sim_state(mavlink_message_t message) { local_position.x, local_position.y, sim_state.alt)); receive_rotation(godot_rotation_from_mavlink(sim_state.roll, sim_state.pitch, sim_state.yaw)); + + last_velocity = Vector3{-sim_state.ve, -sim_state.vd, sim_state.vn}; } Vector3 MarshConnector::godot_location_from_mavlink(float north_meters, float east_meters, diff --git a/src/marshconnector.h b/src/marshconnector.h index 52ae44a..c136cb9 100644 --- a/src/marshconnector.h +++ b/src/marshconnector.h @@ -39,6 +39,7 @@ public: // Get current state of the aircraft Transform3D get_aircraft(); + Vector3 get_velocity(); // Get normalized (-1 to 1) cyclic position, where X is right, Y is pitch up Vector2 get_cyclic(); // Get normalized (0 to 1) collective position, positive to climb @@ -118,6 +119,7 @@ private: // Or not, in practice the simple solution works nicely Vector3 last_location; Quaternion last_rotation; + Vector3 last_velocity; Vector4 last_controls; Vector4 last_trim;