openc3 5.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/Guardfile +35 -0
- data/LICENSE.txt +727 -0
- data/README.md +37 -0
- data/Rakefile +131 -0
- data/bin/cstol_converter +1178 -0
- data/bin/openc3cli +531 -0
- data/bin/rubysloc +139 -0
- data/data/config/_array_params.yaml +23 -0
- data/data/config/_id_items.yaml +24 -0
- data/data/config/_id_params.yaml +58 -0
- data/data/config/_interfaces.yaml +214 -0
- data/data/config/_interfaces.yaml.err +1017 -0
- data/data/config/_items.yaml +20 -0
- data/data/config/_params.yaml +60 -0
- data/data/config/cmd_tlm_server.yaml +136 -0
- data/data/config/command.yaml +44 -0
- data/data/config/command_modifiers.yaml +160 -0
- data/data/config/command_telemetry.yaml +3 -0
- data/data/config/interface_modifiers.yaml +104 -0
- data/data/config/item_modifiers.yaml +221 -0
- data/data/config/microservice.yaml +78 -0
- data/data/config/param_item_modifiers.yaml +52 -0
- data/data/config/parameter_modifiers.yaml +200 -0
- data/data/config/plugins.yaml +80 -0
- data/data/config/protocols.yaml +290 -0
- data/data/config/screen.yaml +147 -0
- data/data/config/table_manager.yaml +89 -0
- data/data/config/table_parameter_modifiers.yaml +9 -0
- data/data/config/target.yaml +142 -0
- data/data/config/target_config.yaml +94 -0
- data/data/config/telemetry.yaml +87 -0
- data/data/config/telemetry_modifiers.yaml +159 -0
- data/data/config/tool.yaml +63 -0
- data/data/config/unknown.yaml +3 -0
- data/data/config/widgets.yaml +1505 -0
- data/ext/mkrf_conf.rb +49 -0
- data/ext/openc3/ext/array/array.c +122 -0
- data/ext/openc3/ext/array/extconf.rb +13 -0
- data/ext/openc3/ext/buffered_file/buffered_file.c +198 -0
- data/ext/openc3/ext/buffered_file/extconf.rb +13 -0
- data/ext/openc3/ext/config_parser/config_parser.c +280 -0
- data/ext/openc3/ext/config_parser/extconf.rb +13 -0
- data/ext/openc3/ext/crc/crc.c +351 -0
- data/ext/openc3/ext/crc/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/openc3_io.c +158 -0
- data/ext/openc3/ext/packet/extconf.rb +13 -0
- data/ext/openc3/ext/packet/packet.c +318 -0
- data/ext/openc3/ext/platform/extconf.rb +13 -0
- data/ext/openc3/ext/platform/platform.c +134 -0
- data/ext/openc3/ext/polynomial_conversion/extconf.rb +13 -0
- data/ext/openc3/ext/polynomial_conversion/polynomial_conversion.c +79 -0
- data/ext/openc3/ext/string/extconf.rb +13 -0
- data/ext/openc3/ext/string/string.c +63 -0
- data/ext/openc3/ext/structure/structure.c +1719 -0
- data/ext/openc3/ext/tabbed_plots_config/extconf.rb +13 -0
- data/ext/openc3/ext/tabbed_plots_config/tabbed_plots_config.c +62 -0
- data/ext/openc3/ext/telemetry/extconf.rb +13 -0
- data/ext/openc3/ext/telemetry/telemetry.c +336 -0
- data/lib/cosmos.rb +20 -0
- data/lib/cosmosc2.rb +20 -0
- data/lib/openc3/api/api.rb +39 -0
- data/lib/openc3/api/authorized_api.rb +30 -0
- data/lib/openc3/api/cmd_api.rb +451 -0
- data/lib/openc3/api/config_api.rb +58 -0
- data/lib/openc3/api/interface_api.rb +117 -0
- data/lib/openc3/api/limits_api.rb +375 -0
- data/lib/openc3/api/router_api.rb +117 -0
- data/lib/openc3/api/settings_api.rb +70 -0
- data/lib/openc3/api/target_api.rb +78 -0
- data/lib/openc3/api/tlm_api.rb +455 -0
- data/lib/openc3/bridge/bridge.rb +54 -0
- data/lib/openc3/bridge/bridge_config.rb +167 -0
- data/lib/openc3/bridge/bridge_interface_thread.rb +42 -0
- data/lib/openc3/bridge/bridge_router_thread.rb +42 -0
- data/lib/openc3/ccsds/ccsds_packet.rb +68 -0
- data/lib/openc3/ccsds/ccsds_parser.rb +148 -0
- data/lib/openc3/config/config_parser.rb +549 -0
- data/lib/openc3/config/meta_config_parser.rb +74 -0
- data/lib/openc3/conversions/conversion.rb +70 -0
- data/lib/openc3/conversions/generic_conversion.rb +83 -0
- data/lib/openc3/conversions/packet_time_formatted_conversion.rb +43 -0
- data/lib/openc3/conversions/packet_time_seconds_conversion.rb +43 -0
- data/lib/openc3/conversions/polynomial_conversion.rb +87 -0
- data/lib/openc3/conversions/processor_conversion.rb +70 -0
- data/lib/openc3/conversions/received_count_conversion.rb +38 -0
- data/lib/openc3/conversions/received_time_formatted_conversion.rb +42 -0
- data/lib/openc3/conversions/received_time_seconds_conversion.rb +42 -0
- data/lib/openc3/conversions/segmented_polynomial_conversion.rb +171 -0
- data/lib/openc3/conversions/unix_time_conversion.rb +68 -0
- data/lib/openc3/conversions/unix_time_formatted_conversion.rb +49 -0
- data/lib/openc3/conversions/unix_time_seconds_conversion.rb +49 -0
- data/lib/openc3/conversions.rb +34 -0
- data/lib/openc3/core_ext/array.rb +416 -0
- data/lib/openc3/core_ext/binding.rb +29 -0
- data/lib/openc3/core_ext/class.rb +72 -0
- data/lib/openc3/core_ext/exception.rb +61 -0
- data/lib/openc3/core_ext/file.rb +83 -0
- data/lib/openc3/core_ext/hash.rb +37 -0
- data/lib/openc3/core_ext/io.rb +134 -0
- data/lib/openc3/core_ext/kernel.rb +42 -0
- data/lib/openc3/core_ext/math.rb +128 -0
- data/lib/openc3/core_ext/matrix.rb +156 -0
- data/lib/openc3/core_ext/objectspace.rb +36 -0
- data/lib/openc3/core_ext/openc3_io.rb +57 -0
- data/lib/openc3/core_ext/range.rb +27 -0
- data/lib/openc3/core_ext/socket.rb +38 -0
- data/lib/openc3/core_ext/string.rb +389 -0
- data/lib/openc3/core_ext/stringio.rb +33 -0
- data/lib/openc3/core_ext/time.rb +508 -0
- data/lib/openc3/core_ext.rb +36 -0
- data/lib/openc3/interfaces/interface.rb +498 -0
- data/lib/openc3/interfaces/linc_interface.rb +475 -0
- data/lib/openc3/interfaces/protocols/burst_protocol.rb +192 -0
- data/lib/openc3/interfaces/protocols/crc_protocol.rb +193 -0
- data/lib/openc3/interfaces/protocols/fixed_protocol.rb +155 -0
- data/lib/openc3/interfaces/protocols/ignore_packet_protocol.rb +56 -0
- data/lib/openc3/interfaces/protocols/length_protocol.rb +165 -0
- data/lib/openc3/interfaces/protocols/override_protocol.rb +60 -0
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +206 -0
- data/lib/openc3/interfaces/protocols/protocol.rb +82 -0
- data/lib/openc3/interfaces/protocols/template_protocol.rb +261 -0
- data/lib/openc3/interfaces/protocols/terminated_protocol.rb +93 -0
- data/lib/openc3/interfaces/serial_interface.rb +94 -0
- data/lib/openc3/interfaces/simulated_target_interface.rb +168 -0
- data/lib/openc3/interfaces/stream_interface.rb +81 -0
- data/lib/openc3/interfaces/tcpip_client_interface.rb +69 -0
- data/lib/openc3/interfaces/tcpip_server_interface.rb +629 -0
- data/lib/openc3/interfaces/udp_interface.rb +169 -0
- data/lib/openc3/interfaces.rb +44 -0
- data/lib/openc3/io/buffered_file.rb +109 -0
- data/lib/openc3/io/io_multiplexer.rb +80 -0
- data/lib/openc3/io/json_api_object.rb +208 -0
- data/lib/openc3/io/json_drb.rb +335 -0
- data/lib/openc3/io/json_drb_object.rb +114 -0
- data/lib/openc3/io/json_drb_rack.rb +84 -0
- data/lib/openc3/io/json_rpc.rb +420 -0
- data/lib/openc3/io/openc3_snmp.rb +58 -0
- data/lib/openc3/io/posix_serial_driver.rb +156 -0
- data/lib/openc3/io/raw_logger.rb +167 -0
- data/lib/openc3/io/raw_logger_pair.rb +77 -0
- data/lib/openc3/io/serial_driver.rb +105 -0
- data/lib/openc3/io/stderr.rb +43 -0
- data/lib/openc3/io/stdout.rb +43 -0
- data/lib/openc3/io/udp_sockets.rb +194 -0
- data/lib/openc3/io/win32_serial_driver.rb +196 -0
- data/lib/openc3/logs/log_writer.rb +302 -0
- data/lib/openc3/logs/packet_log_constants.rb +62 -0
- data/lib/openc3/logs/packet_log_reader.rb +345 -0
- data/lib/openc3/logs/packet_log_writer.rb +299 -0
- data/lib/openc3/logs/text_log_writer.rb +68 -0
- data/lib/openc3/logs.rb +25 -0
- data/lib/openc3/microservices/cleanup_microservice.rb +68 -0
- data/lib/openc3/microservices/decom_microservice.rb +136 -0
- data/lib/openc3/microservices/interface_microservice.rb +532 -0
- data/lib/openc3/microservices/log_microservice.rb +108 -0
- data/lib/openc3/microservices/microservice.rb +204 -0
- data/lib/openc3/microservices/plugin_microservice.rb +43 -0
- data/lib/openc3/microservices/reaction_microservice.rb +541 -0
- data/lib/openc3/microservices/reducer_microservice.rb +313 -0
- data/lib/openc3/microservices/router_microservice.rb +44 -0
- data/lib/openc3/microservices/text_log_microservice.rb +84 -0
- data/lib/openc3/microservices/timeline_microservice.rb +363 -0
- data/lib/openc3/microservices/trigger_group_microservice.rb +638 -0
- data/lib/openc3/models/activity_model.rb +319 -0
- data/lib/openc3/models/auth_model.rb +65 -0
- data/lib/openc3/models/cvt_model.rb +185 -0
- data/lib/openc3/models/environment_model.rb +58 -0
- data/lib/openc3/models/gem_model.rb +137 -0
- data/lib/openc3/models/info_model.rb +31 -0
- data/lib/openc3/models/interface_model.rb +281 -0
- data/lib/openc3/models/interface_status_model.rb +117 -0
- data/lib/openc3/models/metadata_model.rb +139 -0
- data/lib/openc3/models/metric_model.rb +59 -0
- data/lib/openc3/models/microservice_model.rb +206 -0
- data/lib/openc3/models/microservice_status_model.rb +74 -0
- data/lib/openc3/models/model.rb +204 -0
- data/lib/openc3/models/note_model.rb +122 -0
- data/lib/openc3/models/notification_model.rb +40 -0
- data/lib/openc3/models/ping_model.rb +35 -0
- data/lib/openc3/models/plugin_model.rb +292 -0
- data/lib/openc3/models/process_status_model.rb +76 -0
- data/lib/openc3/models/reaction_model.rb +322 -0
- data/lib/openc3/models/reducer_model.rb +65 -0
- data/lib/openc3/models/router_model.rb +35 -0
- data/lib/openc3/models/router_status_model.rb +27 -0
- data/lib/openc3/models/scope_model.rb +153 -0
- data/lib/openc3/models/settings_model.rb +55 -0
- data/lib/openc3/models/sorted_model.rb +167 -0
- data/lib/openc3/models/target_model.rb +759 -0
- data/lib/openc3/models/timeline_model.rb +154 -0
- data/lib/openc3/models/tool_config_model.rb +38 -0
- data/lib/openc3/models/tool_model.rb +262 -0
- data/lib/openc3/models/trigger_group_model.rb +186 -0
- data/lib/openc3/models/trigger_model.rb +330 -0
- data/lib/openc3/models/widget_model.rb +138 -0
- data/lib/openc3/operators/microservice_operator.rb +128 -0
- data/lib/openc3/operators/operator.rb +277 -0
- data/lib/openc3/packets/binary_accessor.rb +1207 -0
- data/lib/openc3/packets/commands.rb +373 -0
- data/lib/openc3/packets/json_packet.rb +134 -0
- data/lib/openc3/packets/limits.rb +271 -0
- data/lib/openc3/packets/limits_response.rb +53 -0
- data/lib/openc3/packets/packet.rb +1168 -0
- data/lib/openc3/packets/packet_config.rb +625 -0
- data/lib/openc3/packets/packet_item.rb +586 -0
- data/lib/openc3/packets/packet_item_limits.rb +162 -0
- data/lib/openc3/packets/parsers/format_string_parser.rb +65 -0
- data/lib/openc3/packets/parsers/limits_parser.rb +159 -0
- data/lib/openc3/packets/parsers/limits_response_parser.rb +61 -0
- data/lib/openc3/packets/parsers/packet_item_parser.rb +272 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +134 -0
- data/lib/openc3/packets/parsers/processor_parser.rb +73 -0
- data/lib/openc3/packets/parsers/state_parser.rb +127 -0
- data/lib/openc3/packets/parsers/xtce_converter.rb +442 -0
- data/lib/openc3/packets/parsers/xtce_parser.rb +722 -0
- data/lib/openc3/packets/structure.rb +553 -0
- data/lib/openc3/packets/structure_item.rb +365 -0
- data/lib/openc3/packets/telemetry.rb +487 -0
- data/lib/openc3/processors/processor.rb +86 -0
- data/lib/openc3/processors/statistics_processor.rb +82 -0
- data/lib/openc3/processors/watermark_processor.rb +58 -0
- data/lib/openc3/processors.rb +24 -0
- data/lib/openc3/script/api_shared.rb +828 -0
- data/lib/openc3/script/calendar.rb +89 -0
- data/lib/openc3/script/commands.rb +227 -0
- data/lib/openc3/script/exceptions.rb +29 -0
- data/lib/openc3/script/extract.rb +161 -0
- data/lib/openc3/script/limits.rb +60 -0
- data/lib/openc3/script/script.rb +299 -0
- data/lib/openc3/script/script_runner.rb +238 -0
- data/lib/openc3/script/storage.rb +146 -0
- data/lib/openc3/script/suite.rb +542 -0
- data/lib/openc3/script/suite_results.rb +196 -0
- data/lib/openc3/script/suite_runner.rb +217 -0
- data/lib/openc3/script.rb +21 -0
- data/lib/openc3/streams/serial_stream.rb +167 -0
- data/lib/openc3/streams/stream.rb +63 -0
- data/lib/openc3/streams/tcpip_client_stream.rb +116 -0
- data/lib/openc3/streams/tcpip_socket_stream.rb +195 -0
- data/lib/openc3/system/system.rb +127 -0
- data/lib/openc3/system/system_config.rb +411 -0
- data/lib/openc3/system/target.rb +269 -0
- data/lib/openc3/system.rb +24 -0
- data/lib/openc3/tools/cmd_tlm_server/api.rb +20 -0
- data/lib/openc3/tools/cmd_tlm_server/cmd_tlm_server_config.rb +320 -0
- data/lib/openc3/tools/cmd_tlm_server/interface_thread.rb +294 -0
- data/lib/openc3/tools/table_manager/table.rb +77 -0
- data/lib/openc3/tools/table_manager/table_config.rb +273 -0
- data/lib/openc3/tools/table_manager/table_item.rb +90 -0
- data/lib/openc3/tools/table_manager/table_item_parser.rb +66 -0
- data/lib/openc3/tools/table_manager/table_manager_core.rb +333 -0
- data/lib/openc3/tools/table_manager/table_parser.rb +93 -0
- data/lib/openc3/tools/test_runner/test.rb +67 -0
- data/lib/openc3/top_level.rb +595 -0
- data/lib/openc3/topics/autonomic_topic.rb +52 -0
- data/lib/openc3/topics/calendar_topic.rb +44 -0
- data/lib/openc3/topics/command_decom_topic.rb +76 -0
- data/lib/openc3/topics/command_topic.rb +83 -0
- data/lib/openc3/topics/config_topic.rb +68 -0
- data/lib/openc3/topics/interface_topic.rb +73 -0
- data/lib/openc3/topics/limits_event_topic.rb +109 -0
- data/lib/openc3/topics/notifications_topic.rb +28 -0
- data/lib/openc3/topics/router_topic.rb +85 -0
- data/lib/openc3/topics/telemetry_decom_topic.rb +54 -0
- data/lib/openc3/topics/telemetry_topic.rb +36 -0
- data/lib/openc3/topics/timeline_topic.rb +45 -0
- data/lib/openc3/topics/topic.rb +53 -0
- data/lib/openc3/utilities/authentication.rb +141 -0
- data/lib/openc3/utilities/authorization.rb +51 -0
- data/lib/openc3/utilities/crc.rb +278 -0
- data/lib/openc3/utilities/csv.rb +153 -0
- data/lib/openc3/utilities/logger.rb +187 -0
- data/lib/openc3/utilities/message_log.rb +91 -0
- data/lib/openc3/utilities/metric.rb +141 -0
- data/lib/openc3/utilities/process_manager.rb +139 -0
- data/lib/openc3/utilities/quaternion.rb +257 -0
- data/lib/openc3/utilities/ruby_lex_utils.rb +568 -0
- data/lib/openc3/utilities/s3.rb +202 -0
- data/lib/openc3/utilities/s3_autoload.rb +9 -0
- data/lib/openc3/utilities/s3_file_cache.rb +274 -0
- data/lib/openc3/utilities/simulated_target.rb +117 -0
- data/lib/openc3/utilities/sleeper.rb +51 -0
- data/lib/openc3/utilities/store.rb +23 -0
- data/lib/openc3/utilities/store_autoload.rb +237 -0
- data/lib/openc3/utilities/zip.rb +21 -0
- data/lib/openc3/utilities.rb +35 -0
- data/lib/openc3/version.rb +14 -0
- data/lib/openc3/win32/excel.rb +132 -0
- data/lib/openc3/win32/win32.rb +402 -0
- data/lib/openc3/win32/win32_main.rb +333 -0
- data/lib/openc3.rb +49 -0
- data/tasks/gemfile_stats.rake +113 -0
- data/tasks/spec.rake +30 -0
- data/templates/plugin-template/README.md +15 -0
- data/templates/plugin-template/Rakefile +12 -0
- data/templates/plugin-template/plugin.gemspec +23 -0
- data/templates/plugin-template/plugin.txt +9 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/cmd.txt +8 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/tlm.txt +8 -0
- data/templates/plugin-template/targets/TARGET/lib/target.rb +10 -0
- data/templates/plugin-template/targets/TARGET/procedures/procedure.rb +3 -0
- data/templates/plugin-template/targets/TARGET/screens/status.txt +9 -0
- data/templates/plugin-template/targets/TARGET/target.txt +5 -0
- metadata +849 -0
@@ -0,0 +1,257 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
4
|
+
# All Rights Reserved.
|
5
|
+
#
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
7
|
+
# under the terms of the GNU Affero General Public License
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
|
16
|
+
# Modified by OpenC3, Inc.
|
17
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
18
|
+
# All Rights Reserved
|
19
|
+
|
20
|
+
require 'openc3/core_ext/matrix'
|
21
|
+
|
22
|
+
include Math
|
23
|
+
|
24
|
+
module OpenC3
|
25
|
+
# A quaternion where q[3] is the scalar component
|
26
|
+
class Quaternion
|
27
|
+
# Create a Quaternion given the initial components
|
28
|
+
#
|
29
|
+
# @param array [Array<Float, Float, Float, Float>] Initial values where
|
30
|
+
# the forth value is the scalar
|
31
|
+
# or [Array<Float, Float, Float>] which as an axis of rotation
|
32
|
+
# @param angle [Float] if axis given for array parameter
|
33
|
+
def initialize(array = [0.0, 0.0, 0.0, 0.0], angle = nil)
|
34
|
+
if array.length == 4
|
35
|
+
@data = array.clone
|
36
|
+
elsif array.length == 3 and angle
|
37
|
+
a = 0.5 * angle
|
38
|
+
s = sin(a) / sqrt(array[0] * array[0] + array[1] * array[1] + array[2] * array[2])
|
39
|
+
@data = []
|
40
|
+
@data[0] = array[0] * s
|
41
|
+
@data[1] = array[1] * s
|
42
|
+
@data[2] = array[2] * s
|
43
|
+
@data[3] = cos(a)
|
44
|
+
else
|
45
|
+
raise "Invalid arguments given to Quaternion.new"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String] The name of the class and the object_id followed by the
|
50
|
+
# data
|
51
|
+
def to_s
|
52
|
+
"#<OpenC3::Quaternion:0x#{self.object_id.to_s(16)}> #{@data}"
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param index [Integer] Which component to access
|
56
|
+
# @return [Float] The quaternion component
|
57
|
+
def [](index)
|
58
|
+
return data[index]
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param index [Integer] The component to set
|
62
|
+
# @param value [Float] The quaternion component
|
63
|
+
def []=(index, value)
|
64
|
+
@data[index] = value
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array<Float, Float, Float, Float>] The entire quaternion where the
|
68
|
+
# the last element is the scalar
|
69
|
+
attr_accessor :data
|
70
|
+
|
71
|
+
# @return [Float] The first element
|
72
|
+
def q0
|
73
|
+
return @data[0]
|
74
|
+
end
|
75
|
+
alias x q0
|
76
|
+
|
77
|
+
# @return [Float] The second element
|
78
|
+
def q1
|
79
|
+
return @data[1]
|
80
|
+
end
|
81
|
+
alias y q1
|
82
|
+
|
83
|
+
# @return [Float] The third element
|
84
|
+
def q2
|
85
|
+
return @data[2]
|
86
|
+
end
|
87
|
+
alias z q2
|
88
|
+
|
89
|
+
# @return [Float] The scalar element
|
90
|
+
def q3
|
91
|
+
return @data[3]
|
92
|
+
end
|
93
|
+
alias w q3
|
94
|
+
|
95
|
+
# @param value [Float] Set the first element
|
96
|
+
def q0=(value)
|
97
|
+
@data[0] = value
|
98
|
+
end
|
99
|
+
|
100
|
+
# @param value [Float] Set the second element
|
101
|
+
def q1=(value)
|
102
|
+
@data[1] = value
|
103
|
+
end
|
104
|
+
|
105
|
+
# @param value [Float] Set the third element
|
106
|
+
def q2=(value)
|
107
|
+
@data[2] = value
|
108
|
+
end
|
109
|
+
|
110
|
+
# @param value [Float] Set the scalar element
|
111
|
+
def q3=(value)
|
112
|
+
@data[3] = value
|
113
|
+
end
|
114
|
+
|
115
|
+
# @param other [Quaternion] Quaternion to multiply with
|
116
|
+
# @return [Quaternion] New quaternion resulting from the muliplication
|
117
|
+
def *(other)
|
118
|
+
q = Quaternion.new()
|
119
|
+
|
120
|
+
q[0] = (@data[3] * other[0]) - (@data[2] * other[1]) +
|
121
|
+
(@data[1] * other[2]) + (@data[0] * other[3])
|
122
|
+
q[1] = (@data[2] * other[0]) + (@data[3] * other[1]) -
|
123
|
+
(@data[0] * other[2]) + (@data[1] * other[3])
|
124
|
+
q[2] = -(@data[1] * other[0]) + (@data[0] * other[1]) +
|
125
|
+
(@data[3] * other[2]) + (@data[2] * other[3])
|
126
|
+
q[3] = -(@data[0] * other[0]) - (@data[1] * other[1]) -
|
127
|
+
(@data[2] * other[2]) + (@data[3] * other[3])
|
128
|
+
|
129
|
+
return q
|
130
|
+
end
|
131
|
+
alias qmult *
|
132
|
+
|
133
|
+
# @return [Quaternion] The inverse of the current quaternion
|
134
|
+
def inverse
|
135
|
+
Quaternion.new([-@data[0], -@data[1], -@data[2], @data[3]])
|
136
|
+
end
|
137
|
+
alias inv inverse
|
138
|
+
|
139
|
+
# @return [Quaternion] The normalized version of the current quaternion
|
140
|
+
def normalize
|
141
|
+
t = @data[0] * @data[0] + @data[1] * @data[1] + @data[2] * @data[2] + @data[3] * @data[3]
|
142
|
+
if t > 0.0
|
143
|
+
f = 1.0 / sqrt(t)
|
144
|
+
@data[0] *= f
|
145
|
+
@data[1] *= f
|
146
|
+
@data[2] *= f
|
147
|
+
@data[3] *= f
|
148
|
+
end
|
149
|
+
return self
|
150
|
+
end
|
151
|
+
|
152
|
+
# Rotate a vector using this quaternion
|
153
|
+
#
|
154
|
+
# @param vector [Array<Float, Float Float>] Vector to rotate
|
155
|
+
# @return [Array<Float, Float, Float>] New rotated vector
|
156
|
+
def vecrot(vector)
|
157
|
+
temp_q = self.inverse * (Quaternion.new([vector[0], vector[1], vector[2], 0]) * self)
|
158
|
+
return [temp_q[0], temp_q[1], temp_q[2]]
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.arc(f, t)
|
162
|
+
dot = f[0] * t[0] + f[1] * t[1] + f[2] * t[2]
|
163
|
+
if dot > 0.999999
|
164
|
+
x = 0.0
|
165
|
+
y = 0.0
|
166
|
+
z = 0.0
|
167
|
+
w = 1.0
|
168
|
+
elsif dot < -0.999999
|
169
|
+
if (f.z.abs < f.x.abs) && (f.z.abs < f.y.abs)
|
170
|
+
x = f[0] * f[2] - f[2] * f[1]
|
171
|
+
y = f[2] * f[0] + f[1] * f[2]
|
172
|
+
z = -f[1] * f[1] - f[0] * f[0]
|
173
|
+
elsif f.y.abs < f.x.abs
|
174
|
+
x = f[1] * f[2] - f[0] * f[1]
|
175
|
+
y = f[0] * f[0] + f[2] * f[2]
|
176
|
+
z = -f[2] * f[1] - f[1] * f[0]
|
177
|
+
else
|
178
|
+
x = -f[2] * f[2] - f[1] * f[1]
|
179
|
+
y = f[1] * f[0] - f[0] * f[2]
|
180
|
+
z = f[0] * f[1] + f[2] * f[0]
|
181
|
+
end
|
182
|
+
|
183
|
+
dot = x * x + y * y + z * z
|
184
|
+
div = sqrt(dot)
|
185
|
+
x /= div
|
186
|
+
y /= div
|
187
|
+
z /= div
|
188
|
+
w = 0.0
|
189
|
+
else
|
190
|
+
div = sqrt((dot + 1.0) * 2.0)
|
191
|
+
x = (f[1] * t[2] - f[2] * t[1]) / div
|
192
|
+
y = (f[2] * t[0] - f[0] * t[2]) / div
|
193
|
+
z = (f[0] * t[1] - f[1] * t[0]) / div
|
194
|
+
w = div * 0.5
|
195
|
+
end
|
196
|
+
return Quaternion.new([x, y, z, w])
|
197
|
+
end
|
198
|
+
|
199
|
+
# @param value [Numeric]
|
200
|
+
# @return [Float] The sign of a number as 1.0 = positive, -1.0 = negative
|
201
|
+
def self.signnz(value)
|
202
|
+
if value >= 0.0
|
203
|
+
return 1.0
|
204
|
+
else
|
205
|
+
return -1.0
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Create a quaternion from a direction-cosine matrix (rotation matrix).
|
210
|
+
# Reference Article: J. Spacecraft Vol.13, No.12 Dec.1976 p754
|
211
|
+
#
|
212
|
+
# @param rotation_matrix [Matrix] The rotation matrix
|
213
|
+
# @return [Quaternion] New quaternion resulting from the matrix
|
214
|
+
def self.qfromc(rotation_matrix)
|
215
|
+
tracec = rotation_matrix.trace()
|
216
|
+
p = 1.0 + tracec
|
217
|
+
if p < 0.0
|
218
|
+
p = 0.0
|
219
|
+
end
|
220
|
+
q = Quaternion.new([0.0, 0.0, 0.0, sqrt(p) / 2.0])
|
221
|
+
if q[3] >= 0.1
|
222
|
+
factor = 1.0 / (4.0 * q[3])
|
223
|
+
q[0] = (rotation_matrix[1][2] - rotation_matrix[2][1]) * factor
|
224
|
+
q[1] = (rotation_matrix[2][0] - rotation_matrix[0][2]) * factor
|
225
|
+
q[2] = (rotation_matrix[0][1] - rotation_matrix[1][0]) * factor
|
226
|
+
else # For rotations near 180 degrees
|
227
|
+
q[0] = sqrt(((2.0 * rotation_matrix[0][0]) + 1.0 - tracec) / 4.0)
|
228
|
+
q[1] = sqrt(((2.0 * rotation_matrix[1][1]) + 1.0 - tracec) / 4.0)
|
229
|
+
q[2] = sqrt(((2.0 * rotation_matrix[2][2]) + 1.0 - tracec) / 4.0)
|
230
|
+
|
231
|
+
i = 0
|
232
|
+
if q[1] >= q[i]
|
233
|
+
i = 1
|
234
|
+
end
|
235
|
+
if q[2] >= q[i]
|
236
|
+
i = 2
|
237
|
+
end
|
238
|
+
case i
|
239
|
+
when 0
|
240
|
+
q[0] = q[0].abs * Quaternion.signnz(rotation_matrix[1][2] - rotation_matrix[2][1])
|
241
|
+
q[1] = q[1].abs * Quaternion.signnz((rotation_matrix[1][0] + rotation_matrix[0][1]) * q[0])
|
242
|
+
q[2] = q[2].abs * Quaternion.signnz((rotation_matrix[2][0] + rotation_matrix[0][2]) * q[0])
|
243
|
+
when 1
|
244
|
+
q[1] = q[1].abs * Quaternion.signnz(rotation_matrix[2][0] - rotation_matrix[0][2])
|
245
|
+
q[0] = q[0].abs * Quaternion.signnz((rotation_matrix[1][0] + rotation_matrix[0][1]) * q[1])
|
246
|
+
q[2] = q[2].abs * Quaternion.signnz((rotation_matrix[2][1] + rotation_matrix[1][2]) * q[1])
|
247
|
+
else
|
248
|
+
q[2] = q[2].abs * Quaternion.signnz(rotation_matrix[0][1] - rotation_matrix[1][0])
|
249
|
+
q[0] = q[0].abs * Quaternion.signnz((rotation_matrix[0][2] + rotation_matrix[2][0]) * q[2])
|
250
|
+
q[1] = q[1].abs * Quaternion.signnz((rotation_matrix[1][2] + rotation_matrix[2][1]) * q[2])
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
return q
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|