From adf7cedeba0f18defa319d30abf0d2a9d94eff35 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Sun, 21 Jul 2019 23:38:51 +0200 Subject: [PATCH] * Fixed truck placement callback registration. --- telemetry.cpp | 27 +++++++++++++-------------- telemetry.h | 11 +++++++---- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/telemetry.cpp b/telemetry.cpp index 342303e..6030b3a 100644 --- a/telemetry.cpp +++ b/telemetry.cpp @@ -147,7 +147,7 @@ SCSAPI_VOID telemetry_frame_end(const scs_event_t UNUSED(event), const void *con // The data line. log_print("%" SCS_PF_U64 ";%" SCS_PF_U64 ";%" SCS_PF_U64 ";%" SCS_PF_U64, telemetry->timestamp, telemetry->raw_rendering_timestamp, telemetry->raw_simulation_timestamp, telemetry->raw_paused_simulation_timestamp); - if (telemetry->orientation_available) { + if (telemetry->placement_available) { log_print(";%f;%f;%f", telemetry->heading, telemetry->pitch, telemetry->roll); } else { @@ -283,25 +283,24 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e // Handling of individual channels. -SCSAPI_VOID telemetry_store_orientation(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context) +SCSAPI_VOID telemetry_store_dplacement(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context) { assert(context); - telemetry_state_t *const state = static_cast(context); + telemetry_state_t *const tele = static_cast(context); // This callback was registered with the SCS_TELEMETRY_CHANNEL_FLAG_no_value flag // so it is called even when the value is not available. - - if (! value) { - state->orientation_available = false; + if ( !value || value->type != SCS_VALUE_TYPE_dplacement ) { + tele->placement_available = false; return; } - - assert(value); - assert(value->type == SCS_VALUE_TYPE_euler); - state->orientation_available = true; - state->heading = value->value_euler.heading * 360.0f; - state->pitch = value->value_euler.pitch * 360.0f; - state->roll = value->value_euler.roll * 360.0f; + tele->placement_available = true; + tele->x = value->value_dplacement.position.x; + tele->y = value->value_dplacement.position.y; + tele->z = value->value_dplacement.position.z; + tele->heading = value->value_dplacement.orientation.heading; + tele->pitch = value->value_dplacement.orientation.pitch; + tele->roll = value->value_dplacement.orientation.roll; } SCSAPI_VOID telemetry_store_float(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context) @@ -418,7 +417,7 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in // (SCS_RESULT_unsupported_type). For purpose of this example we ignore the failues // so the unsupported channels will remain at theirs default value. - version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_world_placement, SCS_U32_NIL, SCS_VALUE_TYPE_euler, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_orientation, &telemetry); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_world_placement, SCS_U32_NIL, SCS_VALUE_TYPE_dplacement, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_dplacement, telemetry); version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_speed, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->speed); version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_rpm, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->rpm); version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_gear, SCS_U32_NIL, SCS_VALUE_TYPE_s32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_s32, &telemetry->gear); diff --git a/telemetry.h b/telemetry.h index b9e5f70..2c09682 100644 --- a/telemetry.h +++ b/telemetry.h @@ -9,10 +9,13 @@ struct telemetry_state_t { uint64_t raw_simulation_timestamp; uint64_t raw_paused_simulation_timestamp; - bool orientation_available; - float heading; - float pitch; - float roll; + bool placement_available; + double x; + double y; + double z; + double heading; + double pitch; + double roll; float speed; float rpm; -- 2.30.2