Compare commits
203 Commits
8f36f89d7a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 01261272b4 | |||
| e61146db69 | |||
| 2eb7b214b2 | |||
| 27b1cecc7b | |||
| 9e84306a94 | |||
| c0c36388db | |||
| ed24d0b9e2 | |||
| bccc7a9b29 | |||
| 873f292a11 | |||
| f7cb279841 | |||
| fd96dc395b | |||
|
|
0aa0113be3 | ||
| 01d5657b1b | |||
| 09cf5f9c19 | |||
| 66c3c7e6c7 | |||
| fd2776084a | |||
|
|
bbc35b02bb | ||
|
|
8ce6ffc41c | ||
| 54d6c25171 | |||
| 2c7d563994 | |||
| bc12777f18 | |||
| 7948321cce | |||
| b12c0ec521 | |||
|
|
d417c03f59 | ||
| a8dd511366 | |||
| a30729fb37 | |||
| a70339c55e | |||
| 6fca94e571 | |||
| 255c34dbb2 | |||
| 3c0c719e37 | |||
|
|
0ddd633bc9 | ||
| 28ecf307a8 | |||
| 57467ce48f | |||
| 196ed3be1b | |||
| acd26edc9c | |||
| da9cd51e5c | |||
| d868810048 | |||
|
|
7c9612c3a2 | ||
| 54419b8e60 | |||
| 7dfb0d5e9b | |||
| bbf7314592 | |||
| 6dde28e8d9 | |||
| 9066b3f091 | |||
| c514d4adcc | |||
| cca58e8ba9 | |||
| bf55a45cf9 | |||
| a825a6935b | |||
| 43638f383f | |||
| a42f6dbc98 | |||
|
|
acced75fa2 | ||
| e548451617 | |||
| e529265a63 | |||
| b2c27a6f5c | |||
| 6214b82a6c | |||
|
|
c6b47d8ad6 | ||
| 273f239abb | |||
|
|
14e583a244 | ||
| 771619b832 | |||
|
|
e0c8d8f39b | ||
|
|
0ce4430668 | ||
|
|
e18066e4a6 | ||
| 1c774d2d69 | |||
| 9e8a7a62c9 | |||
| 1ea5fb623d | |||
| 078e3f38f2 | |||
| 94fb4c6a48 | |||
| b3a257fab6 | |||
| 08ad1e665b | |||
| 90acf1ee8c | |||
| 15cf04f164 | |||
| 6fc0b8bb4e | |||
| c0f274cec0 | |||
|
|
511956531e | ||
| 3f108fcc13 | |||
| 683da9739d | |||
| a7fbae47f0 | |||
| 8a202bd38c | |||
| d69ea51b0c | |||
| a1fa54c636 | |||
|
|
cb362c6e49 | ||
| f2be52d17c | |||
| 3682ccdda6 | |||
|
|
85259fc6ad | ||
| 620f8ba136 | |||
| 50e79aa0ae | |||
| 6a72ead855 | |||
| bc300bb3de | |||
| 78e4bb182c | |||
|
|
85dfa2e9a5 | ||
|
|
bdfc5dbc1c | ||
|
|
ec27cd981a | ||
| 47c57dca72 | |||
| e6b4604bfa | |||
| 412f038eb0 | |||
|
|
80ec2382ea | ||
| 42a4349c76 | |||
|
|
e50fbfc57e | ||
| 49a2e2f9c1 | |||
| fc64642bd6 | |||
|
|
cbe106fe95 | ||
| f618fb64cb | |||
|
|
04272b8e1d | ||
| e0e10395fb | |||
|
|
27dccfe7c0 | ||
| 8b16ac79b8 | |||
| 58d62d85b3 | |||
|
|
9c13def8be | ||
| 5fe2788cd7 | |||
| 962504ed98 | |||
|
|
4d7e830798 | ||
|
|
3d769d79eb | ||
| 0b7261a431 | |||
| c5aa3dc495 | |||
| 98c46c2b8c | |||
| d8fae31406 | |||
| 4a9ecf8639 | |||
|
|
b8383c1375 | ||
| f729799335 | |||
| b1a48d2b77 | |||
| fedc324410 | |||
|
|
1a4d998141 | ||
| 0f955b3c91 | |||
| f5039a329b | |||
| 83b7e0d924 | |||
| 1087e043a8 | |||
| 281ceacf89 | |||
| 4e3a50acba | |||
| 732cd33947 | |||
|
|
bb41710645 | ||
|
|
0b084f44f6 | ||
|
|
92b1a3cfd5 | ||
| 3ae2d41fc8 | |||
| c7dd816481 | |||
| 5f802ff57e | |||
| 8e8cb543ae | |||
| ab49f927fb | |||
| 00354d9b41 | |||
| 2478c1e8d2 | |||
|
|
460fc360c6 | ||
|
|
36ffde80f5 | ||
| fe6492e4fc | |||
|
|
de80acf315 | ||
| 3d3b57a311 | |||
| 227f501d6f | |||
|
|
218da42a1d | ||
|
|
c2627ecd89 | ||
| 4696daa2ee | |||
|
|
2e5e1918e1 | ||
| 45f655dc90 | |||
| 9fb33e5bec | |||
|
|
31cf0a45dd | ||
|
|
4bf95c1043 | ||
| 052d4e2eb4 | |||
| 7556539084 | |||
|
|
8b1873b40b | ||
| 0295d93cd3 | |||
| 60cade4d1f | |||
| dc87ce0fb9 | |||
| 06c8345fc9 | |||
|
|
33002f1711 | ||
| 99a28d87ec | |||
| c6a1caea08 | |||
|
|
da46ab3e3b | ||
| 3640882874 | |||
| ca74d1dd73 | |||
|
|
6c10c6b6ff | ||
| 61e41b1a1d | |||
|
|
e934bd3932 | ||
| 3659ddab01 | |||
| e59f9a05b2 | |||
| 22097610f9 | |||
| b99263a014 | |||
| c45d17b236 | |||
| a3b901223a | |||
| 34d22614a6 | |||
| f0ab4ae770 | |||
| 2fee216924 | |||
| 6315d5e18e | |||
| 138e4bf84d | |||
| 864e257884 | |||
| f661dfad44 | |||
| 219cec6055 | |||
| 25438960e6 | |||
| 9bfe1c3ad5 | |||
| 750d29ceb9 | |||
| 9fbd858086 | |||
| ca9dcdfa68 | |||
| c39496ff25 | |||
| a96682bc12 | |||
| 04ee999159 | |||
| 502014bee4 | |||
| c862d160fe | |||
| 89b86f8b7f | |||
| 7363d608ea | |||
| 4ef6f2f6f9 | |||
| bed7ac87f8 | |||
| 2ff2c24e52 | |||
| c71cf98dd9 | |||
| 1d49077d7b | |||
|
|
7c8bf5bb0b | ||
| 1033506c11 | |||
| 961c72f17f | |||
| 7e1709727a |
@@ -2,14 +2,21 @@ cmake_minimum_required(VERSION 3.14)
|
|||||||
|
|
||||||
|
|
||||||
#**********************************************
|
#**********************************************
|
||||||
# Astrosib(c) BM-700 mount control software *
|
# Astrosib(c) FM-700 mount control software *
|
||||||
#**********************************************
|
#**********************************************
|
||||||
|
|
||||||
project(ASIB_BM700 LANGUAGES C CXX)
|
project(ASIB_FM700 LANGUAGES C CXX)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
#
|
#
|
||||||
# ******* C++ PART OF THE PROJECT *******
|
# ******* C++ PART OF THE PROJECT *******
|
||||||
|
|
||||||
add_subdirectory(cxx)
|
set(EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||||
|
# set(CMAKE_BUILD_TYPE "Release")
|
||||||
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
|
add_subdirectory(LibSidServo)
|
||||||
|
|
||||||
|
# add_subdirectory(cxx)
|
||||||
|
add_subdirectory(mcc)
|
||||||
|
add_subdirectory(asibfm700)
|
||||||
|
|||||||
218
LibSidServo/.qtcreator/libsidservo.creator.user
Normal file
218
LibSidServo/.qtcreator/libsidservo.creator.user
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 18.0.0, 2026-03-11T12:36:26. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="RcSync">0</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="bool" key="HasPerBcDcs">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/10micron/C-sources/erfa_functions</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
218
LibSidServo/.qtcreator/libsidservo.creator.user.cf63021
Normal file
218
LibSidServo/.qtcreator/libsidservo.creator.user.cf63021
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 18.0.0, 2025-11-27T17:22:09. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="RcSync">0</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="bool" key="HasPerBcDcs">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/10micron/C-sources/erfa_functions</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
221
LibSidServo/PID.c
Normal file
221
LibSidServo/PID.c
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libsidservo project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "PID.h"
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
|
PIDController_t *pid_create(const PIDpar_t *gain, size_t Iarrsz){
|
||||||
|
if(!gain || Iarrsz < 3) return NULL;
|
||||||
|
PIDController_t *pid = (PIDController_t*)calloc(1, sizeof(PIDController_t));
|
||||||
|
pid->gain = *gain;
|
||||||
|
DBG("Created PID with P=%g, I=%g, D=%g\n", gain->P, gain->I, gain->D);
|
||||||
|
pid->pidIarrSize = Iarrsz;
|
||||||
|
pid->pidIarray = (double*)calloc(Iarrsz, sizeof(double));
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't clear lastT!
|
||||||
|
void pid_clear(PIDController_t *pid){
|
||||||
|
if(!pid) return;
|
||||||
|
DBG("CLEAR PID PARAMETERS");
|
||||||
|
bzero(pid->pidIarray, sizeof(double) * pid->pidIarrSize);
|
||||||
|
pid->integral = 0.;
|
||||||
|
pid->prev_error = 0.;
|
||||||
|
pid->curIidx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pid_delete(PIDController_t **pid){
|
||||||
|
if(!pid || !*pid) return;
|
||||||
|
if((*pid)->pidIarray) free((*pid)->pidIarray);
|
||||||
|
free(*pid);
|
||||||
|
*pid = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
double pid_calculate(PIDController_t *pid, double error, double dt){
|
||||||
|
// calculate flowing integral
|
||||||
|
double oldi = pid->pidIarray[pid->curIidx], newi = error * dt;
|
||||||
|
//DBG("oldi/new: %g, %g", oldi, newi);
|
||||||
|
pid->pidIarray[pid->curIidx++] = newi;
|
||||||
|
if(pid->curIidx >= pid->pidIarrSize) pid->curIidx = 0;
|
||||||
|
pid->integral += newi - oldi;
|
||||||
|
double derivative = (error - pid->prev_error) / dt;
|
||||||
|
pid->prev_error = error;
|
||||||
|
double sum = pid->gain.P * error + pid->gain.I * pid->integral + pid->gain.D * derivative;
|
||||||
|
DBG("P=%g, I=%g, D=%g; sum=%g", pid->gain.P * error, pid->gain.I * pid->integral, pid->gain.D * derivative, sum);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
PIDController_t *PIDC;
|
||||||
|
PIDController_t *PIDV;
|
||||||
|
} PIDpair_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
axis_status_t state;
|
||||||
|
coordval_t position;
|
||||||
|
coordval_t speed;
|
||||||
|
} axisdata_t;
|
||||||
|
/**
|
||||||
|
* @brief process - Process PID for given axis
|
||||||
|
* @param tagpos - given coordinate of target position
|
||||||
|
* @param endpoint - endpoint for this coordinate
|
||||||
|
* @param pid - pid itself
|
||||||
|
* @return calculated new speed or -1 for max speed
|
||||||
|
*/
|
||||||
|
static double getspeed(const coordval_t *tagpos, PIDpair_t *pidpair, axisdata_t *axis){
|
||||||
|
double dt = timediff(&tagpos->t, &axis->position.t);
|
||||||
|
if(dt < 0 || dt > Conf.PIDMaxDt){
|
||||||
|
DBG("target time: %ld, axis time: %ld - too big! (tag-ax=%g)", tagpos->t.tv_sec, axis->position.t.tv_sec, dt);
|
||||||
|
return axis->speed.val; // data is too old or wrong
|
||||||
|
}
|
||||||
|
double error = tagpos->val - axis->position.val, fe = fabs(error);
|
||||||
|
DBG("error: %g", error);
|
||||||
|
PIDController_t *pid = NULL;
|
||||||
|
switch(axis->state){
|
||||||
|
case AXIS_SLEWING:
|
||||||
|
if(fe < Conf.MaxPointingErr){
|
||||||
|
axis->state = AXIS_POINTING;
|
||||||
|
DBG("--> Pointing");
|
||||||
|
pid = pidpair->PIDC;
|
||||||
|
}else{
|
||||||
|
DBG("Slewing...");
|
||||||
|
return NAN; // max speed for given axis
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AXIS_POINTING:
|
||||||
|
if(fe < Conf.MaxFinePointingErr){
|
||||||
|
axis->state = AXIS_GUIDING;
|
||||||
|
DBG("--> Guiding");
|
||||||
|
pid = pidpair->PIDV;
|
||||||
|
}else if(fe > Conf.MaxPointingErr){
|
||||||
|
DBG("--> Slewing");
|
||||||
|
axis->state = AXIS_SLEWING;
|
||||||
|
return NAN;
|
||||||
|
} else pid = pidpair->PIDC;
|
||||||
|
break;
|
||||||
|
case AXIS_GUIDING:
|
||||||
|
pid = pidpair->PIDV;
|
||||||
|
if(fe > Conf.MaxFinePointingErr){
|
||||||
|
DBG("--> Pointing");
|
||||||
|
axis->state = AXIS_POINTING;
|
||||||
|
pid = pidpair->PIDC;
|
||||||
|
}else if(fe < Conf.MaxGuidingErr){
|
||||||
|
DBG("At target");
|
||||||
|
// TODO: we can point somehow that we are at target or introduce new axis state
|
||||||
|
}else DBG("Current error: %g", fe);
|
||||||
|
break;
|
||||||
|
case AXIS_STOPPED: // start pointing to target; will change speed next time
|
||||||
|
DBG("AXIS STOPPED!!!! --> Slewing");
|
||||||
|
axis->state = AXIS_SLEWING;
|
||||||
|
return getspeed(tagpos, pidpair, axis);
|
||||||
|
case AXIS_ERROR:
|
||||||
|
DBG("Can't move from erroneous state");
|
||||||
|
return 0.;
|
||||||
|
}
|
||||||
|
if(!pid){
|
||||||
|
DBG("WTF? Where is a PID?");
|
||||||
|
return axis->speed.val;
|
||||||
|
}
|
||||||
|
double dtpid = timediff(&tagpos->t, &pid->prevT);
|
||||||
|
if(dtpid < 0 || dtpid > Conf.PIDMaxDt){
|
||||||
|
DBG("time diff too big: clear PID");
|
||||||
|
pid_clear(pid);
|
||||||
|
}
|
||||||
|
if(dtpid > Conf.PIDMaxDt) dtpid = Conf.PIDCycleDt;
|
||||||
|
pid->prevT = tagpos->t;
|
||||||
|
DBG("CALC PID (er=%g, dt=%g), state=%d", error, dtpid, axis->state);
|
||||||
|
double tagspeed = pid_calculate(pid, error, dtpid);
|
||||||
|
if(axis->state == AXIS_GUIDING) return axis->speed.val + tagspeed / dtpid; // velocity-based
|
||||||
|
return tagspeed; // coordinate-based
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief correct2 - recalculate PID and move telescope to new point with new speed
|
||||||
|
* @param target - target position (for error calculations)
|
||||||
|
* @param endpoint - stop point (some far enough point to stop in case of hang)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
mcc_errcodes_t correct2(const coordval_pair_t *target){
|
||||||
|
static PIDpair_t pidX = {0}, pidY = {0};
|
||||||
|
if(!pidX.PIDC){
|
||||||
|
pidX.PIDC = pid_create(&Conf.XPIDC, Conf.PIDCycleDt / Conf.PIDRefreshDt);
|
||||||
|
if(!pidX.PIDC) return MCC_E_FATAL;
|
||||||
|
pidX.PIDV = pid_create(&Conf.XPIDV, Conf.PIDCycleDt / Conf.PIDRefreshDt);
|
||||||
|
if(!pidX.PIDV) return MCC_E_FATAL;
|
||||||
|
}
|
||||||
|
if(!pidY.PIDC){
|
||||||
|
pidY.PIDC = pid_create(&Conf.YPIDC, Conf.PIDCycleDt / Conf.PIDRefreshDt);
|
||||||
|
if(!pidY.PIDC) return MCC_E_FATAL;
|
||||||
|
pidY.PIDV = pid_create(&Conf.YPIDV, Conf.PIDCycleDt / Conf.PIDRefreshDt);
|
||||||
|
if(!pidY.PIDV) return MCC_E_FATAL;
|
||||||
|
}
|
||||||
|
mountdata_t m;
|
||||||
|
coordpair_t tagspeed; // absolute value of speed
|
||||||
|
double Xsign = 1., Ysign = 1.; // signs of speed (for target calculation)
|
||||||
|
if(MCC_E_OK != Mount.getMountData(&m)) return MCC_E_FAILED;
|
||||||
|
axisdata_t axis;
|
||||||
|
DBG("state: %d/%d", m.Xstate, m.Ystate);
|
||||||
|
axis.state = m.Xstate;
|
||||||
|
axis.position = m.encXposition;
|
||||||
|
axis.speed = m.encXspeed;
|
||||||
|
tagspeed.X = getspeed(&target->X, &pidX, &axis);
|
||||||
|
if(isnan(tagspeed.X)){ // max speed
|
||||||
|
if(target->X.val < axis.position.val) Xsign = -1.;
|
||||||
|
tagspeed.X = Xlimits.max.speed;
|
||||||
|
}else{
|
||||||
|
if(tagspeed.X < 0.){ tagspeed.X = -tagspeed.X; Xsign = -1.; }
|
||||||
|
if(tagspeed.X > Xlimits.max.speed) tagspeed.X = Xlimits.max.speed;
|
||||||
|
}
|
||||||
|
axis_status_t xstate = axis.state;
|
||||||
|
axis.state = m.Ystate;
|
||||||
|
axis.position = m.encYposition;
|
||||||
|
axis.speed = m.encYspeed;
|
||||||
|
tagspeed.Y = getspeed(&target->Y, &pidY, &axis);
|
||||||
|
if(isnan(tagspeed.Y)){ // max speed
|
||||||
|
if(target->Y.val < axis.position.val) Ysign = -1.;
|
||||||
|
tagspeed.Y = Ylimits.max.speed;
|
||||||
|
}else{
|
||||||
|
if(tagspeed.Y < 0.){ tagspeed.Y = -tagspeed.Y; Ysign = -1.; }
|
||||||
|
if(tagspeed.Y > Ylimits.max.speed) tagspeed.Y = Ylimits.max.speed;
|
||||||
|
}
|
||||||
|
axis_status_t ystate = axis.state;
|
||||||
|
if(m.Xstate != xstate || m.Ystate != ystate){
|
||||||
|
DBG("State changed");
|
||||||
|
setStat(xstate, ystate);
|
||||||
|
}
|
||||||
|
coordpair_t endpoint;
|
||||||
|
// allow at least PIDMaxDt moving with target speed
|
||||||
|
double dv = fabs(tagspeed.X - m.encXspeed.val);
|
||||||
|
double adder = dv/Xlimits.max.accel * (m.encXspeed.val + dv / 2.) // distanse with changing speed
|
||||||
|
+ Conf.PIDMaxDt * tagspeed.X // PIDMaxDt const speed moving
|
||||||
|
+ tagspeed.X * tagspeed.X / Xlimits.max.accel / 2.; // stopping
|
||||||
|
endpoint.X = m.encXposition.val + Xsign * adder;
|
||||||
|
dv = fabs(tagspeed.Y - m.encYspeed.val);
|
||||||
|
adder = dv/Ylimits.max.accel * (m.encYspeed.val + dv / 2.)
|
||||||
|
+ Conf.PIDMaxDt * tagspeed.Y
|
||||||
|
+ tagspeed.Y * tagspeed.Y / Ylimits.max.accel / 2.;
|
||||||
|
endpoint.Y = m.encYposition.val + Ysign * adder;
|
||||||
|
DBG("TAG speeds: %g/%g (deg/s); TAG pos: %g/%g (deg)", tagspeed.X/M_PI*180., tagspeed.Y/M_PI*180., endpoint.X/M_PI*180., endpoint.Y/M_PI*180.);
|
||||||
|
return Mount.moveWspeed(&endpoint, &tagspeed);
|
||||||
|
}
|
||||||
40
LibSidServo/PID.h
Normal file
40
LibSidServo/PID.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libsidservo project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "sidservo.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PIDpar_t gain; // PID gains
|
||||||
|
double prev_error; // Previous error
|
||||||
|
double integral; // Integral term
|
||||||
|
double *pidIarray; // array for Integral
|
||||||
|
struct timespec prevT; // time of previous correction
|
||||||
|
size_t pidIarrSize; // it's size
|
||||||
|
size_t curIidx; // and index of current element
|
||||||
|
} PIDController_t;
|
||||||
|
|
||||||
|
PIDController_t *pid_create(const PIDpar_t *gain, size_t Iarrsz);
|
||||||
|
void pid_clear(PIDController_t *pid);
|
||||||
|
void pid_delete(PIDController_t **pid);
|
||||||
|
double pid_calculate(PIDController_t *pid, double error, double dt);
|
||||||
|
|
||||||
|
mcc_errcodes_t correct2(const coordval_pair_t *target);
|
||||||
141
LibSidServo/PID_test.deprecated/Dramp.c
Normal file
141
LibSidServo/PID_test.deprecated/Dramp.c
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "Dramp.h"
|
||||||
|
|
||||||
|
static movestate_t state = ST_STOP;
|
||||||
|
static moveparam_t target, Min, Max;
|
||||||
|
static double T0 = -1., Xlast0; // time when move starts, last stage starting coordinate
|
||||||
|
static moveparam_t curparams = {0}; // current coordinate/speed/acceleration
|
||||||
|
static double T1 = -1.; // time to switch into minimal speed for best coord tolerance
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
STAGE_NORMALSPEED,
|
||||||
|
STAGE_MINSPEED,
|
||||||
|
STAGE_STOPPED
|
||||||
|
} movingsage_t;
|
||||||
|
|
||||||
|
static movingsage_t movingstage = STAGE_STOPPED;
|
||||||
|
|
||||||
|
static int initlims(limits_t *lim){
|
||||||
|
if(!lim) return FALSE;
|
||||||
|
Min = lim->min;
|
||||||
|
Max = lim->max;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int calc(moveparam_t *x, double t){
|
||||||
|
DBG("target: %g, tagspeed: %g (maxspeed: %g, minspeed: %g)", x->coord, x->speed, Max.speed, Min.speed);
|
||||||
|
if(!x || t < 0.) return FALSE;
|
||||||
|
if(x->speed > Max.speed || x->speed < Min.speed || x->coord < Min.coord || x->coord > Max.coord) return FALSE;
|
||||||
|
double adist = fabs(x->coord - curparams.coord);
|
||||||
|
DBG("want dist: %g", adist);
|
||||||
|
if(adist < coord_tolerance) return TRUE; // we are at place
|
||||||
|
if(adist < time_tick * Min.speed) return FALSE; // cannot reach with current parameters
|
||||||
|
target = *x;
|
||||||
|
if(x->speed * time_tick > adist) target.speed = adist / (10. * time_tick); // take at least 10 ticks to reach position
|
||||||
|
if(target.speed < Min.speed) target.speed = Min.speed;
|
||||||
|
DBG("Approximate tag speed: %g", target.speed);
|
||||||
|
T0 = t;
|
||||||
|
// calculate time to switch into minimal speed
|
||||||
|
T1 = -1.; // no min speed phase
|
||||||
|
if(target.speed > Min.speed){
|
||||||
|
double dxpertick = target.speed * time_tick;
|
||||||
|
DBG("dX per one tick: %g", dxpertick);
|
||||||
|
double ticks_need = floor(adist / dxpertick);
|
||||||
|
DBG("ticks need: %g", ticks_need);
|
||||||
|
if(ticks_need < 1.) return FALSE; // cannot reach
|
||||||
|
if(fabs(ticks_need * dxpertick - adist) > coord_tolerance){
|
||||||
|
DBG("Need to calculate slow phase; can't reach for %g ticks at current speed", ticks_need);
|
||||||
|
double dxpersmtick = Min.speed * time_tick;
|
||||||
|
DBG("dX per smallest tick: %g", dxpersmtick);
|
||||||
|
while(--ticks_need > 1.){
|
||||||
|
double part = adist - ticks_need * dxpertick;
|
||||||
|
double smticks = floor(part / dxpersmtick);
|
||||||
|
double least = part - smticks * dxpersmtick;
|
||||||
|
if(least < coord_tolerance) break;
|
||||||
|
}
|
||||||
|
DBG("now BIG ticks: %g, T1=T0+%g", ticks_need, ticks_need*time_tick);
|
||||||
|
T1 = t + ticks_need * time_tick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = ST_MOVE;
|
||||||
|
Xlast0 = curparams.coord;
|
||||||
|
if(target.speed > Min.speed) movingstage = STAGE_NORMALSPEED;
|
||||||
|
else movingstage = STAGE_MINSPEED;
|
||||||
|
if(x->coord < curparams.coord) target.speed *= -1.; // real speed
|
||||||
|
curparams.speed = target.speed;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(double _U_ t){
|
||||||
|
T0 = -1.;
|
||||||
|
curparams.accel = 0.;
|
||||||
|
curparams.speed = 0.;
|
||||||
|
state = ST_STOP;
|
||||||
|
movingstage = STAGE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t proc(moveparam_t *next, double t){
|
||||||
|
if(T0 < 0.) return ST_STOP;
|
||||||
|
curparams.coord = Xlast0 + (t - T0) * curparams.speed;
|
||||||
|
//DBG("coord: %g (dTmon: %g, speed: %g)", curparams.coord, t-T0, curparams.speed);
|
||||||
|
int ooops = FALSE; // oops - we are over target!
|
||||||
|
if(curparams.speed < 0.){ if(curparams.coord < target.coord) ooops = TRUE;}
|
||||||
|
else{ if(curparams.coord > target.coord) ooops = TRUE; }
|
||||||
|
if(ooops){
|
||||||
|
DBG("OOOps! We are (%g) over target (%g) -> stop", curparams.coord, target.coord);
|
||||||
|
stop(t);
|
||||||
|
if(next) *next = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
if(movingstage == STAGE_NORMALSPEED && T1 > 0.){ // check need of T1
|
||||||
|
if(t >= T1){
|
||||||
|
DBG("T1=%g, t=%g -->", T1, t);
|
||||||
|
curparams.speed = (curparams.speed > 0.) ? Min.speed : -Min.speed;
|
||||||
|
movingstage = STAGE_MINSPEED;
|
||||||
|
Xlast0 = curparams.coord;
|
||||||
|
T0 = T1;
|
||||||
|
DBG("Go further with minimal speed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(fabs(curparams.coord - target.coord) < coord_tolerance){ // we are at place
|
||||||
|
DBG("OK, we are in place");
|
||||||
|
stop(t);
|
||||||
|
}
|
||||||
|
if(next) *next = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t getst(moveparam_t *cur){
|
||||||
|
if(cur) *cur = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t dumb = {
|
||||||
|
.init_limits = initlims,
|
||||||
|
.calculate = calc,
|
||||||
|
.proc_move = proc,
|
||||||
|
.stop = stop,
|
||||||
|
.emergency_stop = stop,
|
||||||
|
.get_state = getst,
|
||||||
|
};
|
||||||
23
LibSidServo/PID_test.deprecated/Dramp.h
Normal file
23
LibSidServo/PID_test.deprecated/Dramp.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "moving_private.h"
|
||||||
|
|
||||||
|
extern movemodel_t dumb;
|
||||||
57
LibSidServo/PID_test.deprecated/Makefile
Normal file
57
LibSidServo/PID_test.deprecated/Makefile
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# run `make DEF=...` to add extra defines
|
||||||
|
PROGRAM := moving
|
||||||
|
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
|
||||||
|
LDFLAGS += -lusefull_macros -lm
|
||||||
|
SRCS := $(wildcard *.c)
|
||||||
|
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
||||||
|
OBJDIR := mk
|
||||||
|
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99
|
||||||
|
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
||||||
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
TARGFILE := $(OBJDIR)/TARGET
|
||||||
|
CC = gcc
|
||||||
|
#TARGET := RELEASE
|
||||||
|
|
||||||
|
ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes)
|
||||||
|
TARGET := $(file < $(TARGFILE))
|
||||||
|
else
|
||||||
|
TARGET := RELEASE
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET), DEBUG)
|
||||||
|
.DEFAULT_GOAL := debug
|
||||||
|
endif
|
||||||
|
|
||||||
|
release: $(PROGRAM)
|
||||||
|
|
||||||
|
debug: CFLAGS += -DEBUG -Werror
|
||||||
|
debug: TARGET := DEBUG
|
||||||
|
debug: $(PROGRAM)
|
||||||
|
|
||||||
|
$(TARGFILE): $(OBJDIR)
|
||||||
|
@echo -e "\t\tTARGET: $(TARGET)"
|
||||||
|
@echo "$(TARGET)" > $(TARGFILE)
|
||||||
|
|
||||||
|
$(PROGRAM) : $(TARGFILE) $(OBJS)
|
||||||
|
@echo -e "\t\tLD $(PROGRAM)"
|
||||||
|
$(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
@mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
|
-include $(DEPS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.c
|
||||||
|
@echo -e "\t\tCC $<"
|
||||||
|
$(CC) $< -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo -e "\t\tCLEAN"
|
||||||
|
@rm -rf $(OBJDIR) 2>/dev/null || true
|
||||||
|
|
||||||
|
xclean: clean
|
||||||
|
@rm -f $(PROGRAM)
|
||||||
|
|
||||||
|
.PHONY: clean xclean
|
||||||
27
LibSidServo/PID_test.deprecated/Sramp.c
Normal file
27
LibSidServo/PID_test.deprecated/Sramp.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// quasi non-jerk s-ramp
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "Sramp.h"
|
||||||
|
|
||||||
|
|
||||||
|
movemodel_t s_shaped = { 0 };
|
||||||
23
LibSidServo/PID_test.deprecated/Sramp.h
Normal file
23
LibSidServo/PID_test.deprecated/Sramp.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "moving_private.h"
|
||||||
|
|
||||||
|
extern movemodel_t s_shaped;
|
||||||
223
LibSidServo/PID_test.deprecated/Tramp.c
Normal file
223
LibSidServo/PID_test.deprecated/Tramp.c
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// simplest trapezioidal ramp
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "Tramp.h"
|
||||||
|
|
||||||
|
#undef DBG
|
||||||
|
#define DBG(...)
|
||||||
|
|
||||||
|
static movestate_t state = ST_STOP;
|
||||||
|
static moveparam_t Min, Max; // `Min` acceleration not used!
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
STAGE_ACCEL, // start from zero speed and accelerate to Max speed
|
||||||
|
STAGE_MAXSPEED, // go with target speed
|
||||||
|
STAGE_DECEL, // go from target speed to zero
|
||||||
|
STAGE_STOPPED, // stop
|
||||||
|
STAGE_AMOUNT
|
||||||
|
} movingstage_t;
|
||||||
|
|
||||||
|
static movingstage_t movingstage = STAGE_STOPPED;
|
||||||
|
static double Times[STAGE_AMOUNT] = {0}; // time when each stage starts
|
||||||
|
static moveparam_t Params[STAGE_AMOUNT] = {0}; // starting parameters for each stage
|
||||||
|
static moveparam_t curparams = {0}; // current coordinate/speed/acceleration
|
||||||
|
|
||||||
|
static int initlims(limits_t *lim){
|
||||||
|
if(!lim) return FALSE;
|
||||||
|
Min = lim->min;
|
||||||
|
Max = lim->max;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void emstop(double _U_ t){
|
||||||
|
curparams.accel = 0.;
|
||||||
|
curparams.speed = 0.;
|
||||||
|
bzero(Times, sizeof(Times));
|
||||||
|
bzero(Params, sizeof(Params));
|
||||||
|
state = ST_STOP;
|
||||||
|
movingstage = STAGE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(double t){
|
||||||
|
if(state == ST_STOP || movingstage == STAGE_STOPPED) return;
|
||||||
|
movingstage = STAGE_DECEL;
|
||||||
|
state = ST_MOVE;
|
||||||
|
Times[STAGE_DECEL] = t;
|
||||||
|
Params[STAGE_DECEL].speed = curparams.speed;
|
||||||
|
if(curparams.speed > 0.) Params[STAGE_DECEL].accel = -Max.accel;
|
||||||
|
else Params[STAGE_DECEL].accel = Max.accel;
|
||||||
|
Params[STAGE_DECEL].coord = curparams.coord;
|
||||||
|
// speed: v=v2+a2(t-t2), v2 and a2 have different signs; t3: v3=0 -> t3=t2-v2/a2
|
||||||
|
Times[STAGE_STOPPED] = t - curparams.speed / Params[STAGE_DECEL].accel;
|
||||||
|
// coordinate: x=x2+v2(t-t2)+a2(t-t2)^2/2 -> x3=x2+v2(t3-t2)+a2(t3-t2)^2/2
|
||||||
|
double dt = Times[STAGE_STOPPED] - t;
|
||||||
|
Params[STAGE_STOPPED].coord = curparams.coord + curparams.speed * dt +
|
||||||
|
Params[STAGE_DECEL].accel * dt * dt / 2.;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief calc - moving calculation
|
||||||
|
* @param x - using max speed (>0!!!) and coordinate
|
||||||
|
* @param t - current time value
|
||||||
|
* @return FALSE if can't move with given parameters
|
||||||
|
*/
|
||||||
|
static int calc(moveparam_t *x, double t){
|
||||||
|
if(!x) return FALSE;
|
||||||
|
if(x->coord < Min.coord || x->coord > Max.coord) return FALSE;
|
||||||
|
if(x->speed < Min.speed || x->speed > Max.speed) return FALSE;
|
||||||
|
double Dx = fabs(x->coord - curparams.coord); // full distance
|
||||||
|
double sign = (x->coord > curparams.coord) ? 1. : -1.; // sign of target accelerations and speeds
|
||||||
|
// we have two variants: with or without stage with constant speed
|
||||||
|
double dt23 = x->speed / Max.accel; // time of deceleration stage for given speed
|
||||||
|
double dx23 = x->speed * dt23 / 2.; // distance on dec stage (abs)
|
||||||
|
DBG("Dx=%g, sign=%g, dt23=%g, dx23=%g", Dx, sign, dt23, dx23);
|
||||||
|
double setspeed = x->speed; // new max speed (we can change it if need)
|
||||||
|
double dt01, dx01; // we'll fill them depending on starting conditions
|
||||||
|
Times[0] = t;
|
||||||
|
Params[0].speed = curparams.speed;
|
||||||
|
Params[0].coord = curparams.coord;
|
||||||
|
|
||||||
|
double curspeed = fabs(curparams.speed);
|
||||||
|
double dt0s = curspeed / Max.accel; // time of stopping phase
|
||||||
|
double dx0s = curspeed * dt0s / 2.; // distance
|
||||||
|
DBG("dt0s=%g, dx0s=%g", dt0s, dx0s);
|
||||||
|
if(dx0s > Dx){
|
||||||
|
WARNX("distance too short");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if(fabs(Dx - dx0s) < coord_tolerance){ // just stop and we'll be on target
|
||||||
|
DBG("Distance good to just stop");
|
||||||
|
stop(t);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if(curparams.speed * sign < 0. || state == ST_STOP){ // we should change speed sign
|
||||||
|
// after stop we will have full profile
|
||||||
|
double dxs3 = Dx - dx0s;
|
||||||
|
double newspeed = sqrt(Max.accel * dxs3);
|
||||||
|
if(newspeed < setspeed) setspeed = newspeed; // we can't reach user speed
|
||||||
|
DBG("dxs3=%g, setspeed=%g", dxs3, setspeed);
|
||||||
|
dt01 = fabs(sign*setspeed - curparams.speed) / Max.accel;
|
||||||
|
Params[0].accel = sign * Max.accel;
|
||||||
|
if(state == ST_STOP) dx01 = setspeed * dt01 / 2.;
|
||||||
|
else dx01 = dt01 * (dt01 / 2. * Max.accel - curspeed);
|
||||||
|
DBG("dx01=%g, dt01=%g", dx01, dt01);
|
||||||
|
}else{ // increase or decrease speed without stopping phase
|
||||||
|
dt01 = fabs(sign*setspeed - curparams.speed) / Max.accel;
|
||||||
|
double a = sign * Max.accel;
|
||||||
|
if(sign * curparams.speed < 0.){DBG("change direction"); a = -a;}
|
||||||
|
else if(curspeed > setspeed){ DBG("lower speed @ this direction"); a = -a;}
|
||||||
|
//double a = (curspeed > setspeed) ? -Max.accel : Max.accel;
|
||||||
|
dx01 = curspeed * dt01 + a * dt01 * dt01 / 2.;
|
||||||
|
DBG("dt01=%g, a=%g, dx01=%g", dt01, a, dx01);
|
||||||
|
if(dx01 + dx23 > Dx){ // calculate max speed
|
||||||
|
setspeed = sqrt(Max.accel * Dx - curspeed * curspeed / 2.);
|
||||||
|
if(setspeed < curspeed){
|
||||||
|
setspeed = curparams.speed;
|
||||||
|
dt01 = 0.; dx01 = 0.;
|
||||||
|
Params[0].accel = 0.;
|
||||||
|
}else{
|
||||||
|
Params[0].accel = a;
|
||||||
|
dt01 = fabs(setspeed - curspeed) / Max.accel;
|
||||||
|
dx01 = curspeed * dt01 + Max.accel * dt01 * dt01 / 2.;
|
||||||
|
}
|
||||||
|
}else Params[0].accel = a;
|
||||||
|
}
|
||||||
|
if(setspeed < Min.speed){
|
||||||
|
WARNX("New speed should be too small");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
moveparam_t *p = &Params[STAGE_MAXSPEED];
|
||||||
|
p->accel = 0.; p->speed = sign * setspeed;
|
||||||
|
p->coord = curparams.coord + dx01 * sign;
|
||||||
|
Times[STAGE_MAXSPEED] = Times[0] + dt01;
|
||||||
|
dt23 = setspeed / Max.accel;
|
||||||
|
dx23 = setspeed * dt23 / 2.;
|
||||||
|
// calculate dx12 and dt12
|
||||||
|
double dx12 = Dx - dx01 - dx23;
|
||||||
|
if(dx12 < -coord_tolerance){
|
||||||
|
WARNX("Oops, WTF dx12=%g?", dx12);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
double dt12 = dx12 / setspeed;
|
||||||
|
p = &Params[STAGE_DECEL];
|
||||||
|
p->accel = -sign * Max.accel;
|
||||||
|
p->speed = sign * setspeed;
|
||||||
|
p->coord = Params[STAGE_MAXSPEED].coord + sign * dx12;
|
||||||
|
Times[STAGE_DECEL] = Times[STAGE_MAXSPEED] + dt12;
|
||||||
|
p = &Params[STAGE_STOPPED];
|
||||||
|
p->accel = 0.; p->speed = 0.; p->coord = x->coord;
|
||||||
|
Times[STAGE_STOPPED] = Times[STAGE_DECEL] + dt23;
|
||||||
|
for(int i = 0; i < 4; ++i)
|
||||||
|
DBG("%d: t=%g, coord=%g, speed=%g, accel=%g", i,
|
||||||
|
Times[i], Params[i].coord, Params[i].speed, Params[i].accel);
|
||||||
|
state = ST_MOVE;
|
||||||
|
movingstage = STAGE_ACCEL;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t proc(moveparam_t *next, double t){
|
||||||
|
if(state == ST_STOP) goto ret;
|
||||||
|
for(movingstage_t s = STAGE_STOPPED; s >= 0; --s){
|
||||||
|
if(Times[s] <= t){ // check time for current stage
|
||||||
|
movingstage = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(movingstage == STAGE_STOPPED){
|
||||||
|
curparams.coord = Params[STAGE_STOPPED].coord;
|
||||||
|
emstop(t);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
// calculate current parameters
|
||||||
|
double dt = t - Times[movingstage];
|
||||||
|
double a = Params[movingstage].accel;
|
||||||
|
double v0 = Params[movingstage].speed;
|
||||||
|
double x0 = Params[movingstage].coord;
|
||||||
|
curparams.accel = a;
|
||||||
|
curparams.speed = v0 + a * dt;
|
||||||
|
curparams.coord = x0 + v0 * dt + a * dt * dt / 2.;
|
||||||
|
ret:
|
||||||
|
if(next) *next = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t getst(moveparam_t *cur){
|
||||||
|
if(cur) *cur = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double gettstop(){
|
||||||
|
return Times[STAGE_STOPPED];
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t trapez = {
|
||||||
|
.init_limits = initlims,
|
||||||
|
.stop = stop,
|
||||||
|
.emergency_stop = emstop,
|
||||||
|
.get_state = getst,
|
||||||
|
.calculate = calc,
|
||||||
|
.proc_move = proc,
|
||||||
|
.stoppedtime = gettstop,
|
||||||
|
};
|
||||||
23
LibSidServo/PID_test.deprecated/Tramp.h
Normal file
23
LibSidServo/PID_test.deprecated/Tramp.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "moving_private.h"
|
||||||
|
|
||||||
|
extern movemodel_t trapez;
|
||||||
243
LibSidServo/PID_test.deprecated/main.c
Normal file
243
LibSidServo/PID_test.deprecated/main.c
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "moving.h"
|
||||||
|
|
||||||
|
// errors for states: slewing/pointing/guiding
|
||||||
|
#define MAX_POINTING_ERR (50.)
|
||||||
|
#define MAX_GUIDING_ERR (5.)
|
||||||
|
// timeout to "forget" old data from I sum array; seconds
|
||||||
|
#define PID_I_PERIOD (3.)
|
||||||
|
|
||||||
|
static movemodel_t *model = NULL;
|
||||||
|
static FILE *coordslog = NULL;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
Slewing,
|
||||||
|
Pointing,
|
||||||
|
Guiding
|
||||||
|
} state_t;
|
||||||
|
|
||||||
|
static state_t state = Slewing;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
int help;
|
||||||
|
char *ramptype;
|
||||||
|
char *xlog;
|
||||||
|
double dTmon;
|
||||||
|
double dTcorr;
|
||||||
|
double Tend;
|
||||||
|
double minerr;
|
||||||
|
double P, I, D;
|
||||||
|
} pars;
|
||||||
|
|
||||||
|
static pars G = {
|
||||||
|
.ramptype = "t",
|
||||||
|
.dTmon = 0.01,
|
||||||
|
.dTcorr = 0.05,
|
||||||
|
.Tend = 100.,
|
||||||
|
.minerr = 0.1,
|
||||||
|
.P = 0.8,
|
||||||
|
};
|
||||||
|
|
||||||
|
static limits_t limits = {
|
||||||
|
.min = {.coord = -1e6, .speed = 0.01, .accel = 0.1},
|
||||||
|
.max = {.coord = 1e6, .speed = 1e3, .accel = 500.},
|
||||||
|
.jerk = 10.
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
double kp, ki, kd; // PID gains
|
||||||
|
double prev_error; // Previous error
|
||||||
|
double integral; // Integral term
|
||||||
|
double *pidIarray; // array for Integral
|
||||||
|
size_t pidIarrSize; // it's size
|
||||||
|
size_t curIidx; // and index of current element
|
||||||
|
} PIDController;
|
||||||
|
|
||||||
|
static PIDController pid;
|
||||||
|
|
||||||
|
static sl_option_t opts[] = {
|
||||||
|
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
|
||||||
|
{"ramp", NEED_ARG, NULL, 'r', arg_string, APTR(&G.ramptype), "ramp type: \"d\", \"t\" or \"s\" - dumb, trapezoid, s-type"},
|
||||||
|
{"tmon", NEED_ARG, NULL, 'T', arg_double, APTR(&G.dTmon), "time interval for monitoring (seconds, default: 0.001)"},
|
||||||
|
{"tcor", NEED_ARG, NULL, 't', arg_double, APTR(&G.dTcorr), "time interval for corrections (seconds, default: 0.05)"},
|
||||||
|
{"xlog", NEED_ARG, NULL, 'l', arg_string, APTR(&G.xlog), "log file name for coordinates logging"},
|
||||||
|
{"tend", NEED_ARG, NULL, 'e', arg_double, APTR(&G.Tend), "end time of monitoring (seconds, default: 100)"},
|
||||||
|
{"minerr", NEED_ARG, NULL, 'm', arg_double, APTR(&G.minerr), "minimal error for corrections (units, default: 0.1)"},
|
||||||
|
{"prop", NEED_ARG, NULL, 'P', arg_double, APTR(&G.P), "P-coefficient of PID"},
|
||||||
|
{"integ", NEED_ARG, NULL, 'I', arg_double, APTR(&G.I), "I-coefficient of PID"},
|
||||||
|
{"diff", NEED_ARG, NULL, 'D', arg_double, APTR(&G.D), "D-coefficient of PID"},
|
||||||
|
// TODO: add parameters for limits setting
|
||||||
|
end_option
|
||||||
|
};
|
||||||
|
|
||||||
|
// calculate coordinate target for given time (starting from zero)
|
||||||
|
static double target_coord(double t){
|
||||||
|
if(t > 20. && t < 30.) return target_coord(20.);
|
||||||
|
double pos = 150. + 10. * sin(M_2_PI * t / 10.) + 0.02 * (drand48() - 0.5);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* P-only == oscillations
|
||||||
|
static double getNewSpeed(const moveparam_t *p, double targcoord, double dt){
|
||||||
|
double error = targcoord - p->coord;
|
||||||
|
if(fabs(error) < G.minerr) return p->speed;
|
||||||
|
return p->speed + error / dt / 500.;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void pid_init(PIDController *pid, double kp, double ki, double kd) {
|
||||||
|
pid->kp = fabs(kp);
|
||||||
|
pid->ki = fabs(ki);
|
||||||
|
pid->kd = fabs(kd);
|
||||||
|
pid->prev_error = 0.;
|
||||||
|
pid->integral = 0.;
|
||||||
|
pid->curIidx = 0;
|
||||||
|
pid->pidIarrSize = PID_I_PERIOD / G.dTcorr;
|
||||||
|
if(pid->pidIarrSize < 2) ERRX("I-array for PID have less than 2 elements");
|
||||||
|
pid->pidIarray = MALLOC(double, pid->pidIarrSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pid_clear(PIDController *pid){
|
||||||
|
if(!pid) return;
|
||||||
|
bzero(pid->pidIarray, sizeof(double) * pid->pidIarrSize);
|
||||||
|
pid->integral = 0.;
|
||||||
|
pid->prev_error = 0.;
|
||||||
|
pid->curIidx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double getNewSpeed(const moveparam_t *p, double targcoord, double dt){
|
||||||
|
double error = targcoord - p->coord, fe = fabs(error);
|
||||||
|
switch(state){
|
||||||
|
case Slewing:
|
||||||
|
if(fe < MAX_POINTING_ERR){
|
||||||
|
pid_clear(&pid);
|
||||||
|
state = Pointing;
|
||||||
|
green("--> Pointing\n");
|
||||||
|
}else{
|
||||||
|
red("Slewing...\n");
|
||||||
|
return (error > 0.) ? limits.max.speed : -limits.max.speed;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Pointing:
|
||||||
|
if(fe < MAX_GUIDING_ERR){
|
||||||
|
pid_clear(&pid);
|
||||||
|
state = Guiding;
|
||||||
|
green("--> Guiding\n");
|
||||||
|
}else if(fe > MAX_POINTING_ERR){
|
||||||
|
red("--> Slewing\n");
|
||||||
|
state = Slewing;
|
||||||
|
return (error > 0.) ? limits.max.speed : -limits.max.speed;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Guiding:
|
||||||
|
if(fe > MAX_GUIDING_ERR){
|
||||||
|
red("--> Pointing\n");
|
||||||
|
state = Pointing;
|
||||||
|
}else if(fe < G.minerr){
|
||||||
|
green("At target\n");
|
||||||
|
//pid_clear(&pid);
|
||||||
|
//return p->speed;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
red("Calculate PID\n");
|
||||||
|
double oldi = pid.pidIarray[pid.curIidx], newi = error * dt;
|
||||||
|
pid.pidIarray[pid.curIidx++] = oldi;
|
||||||
|
if(pid.curIidx >= pid.pidIarrSize) pid.curIidx = 0;
|
||||||
|
pid.integral += newi - oldi;
|
||||||
|
double derivative = (error - pid.prev_error) / dt;
|
||||||
|
pid.prev_error = error;
|
||||||
|
DBG("P=%g, I=%g, D=%g", pid.kp * error, pid.integral, derivative);
|
||||||
|
double add = (pid.kp * error + pid.ki * pid.integral + pid.kd * derivative);
|
||||||
|
if(state == Pointing) add /= 3.;
|
||||||
|
else if(state == Guiding) add /= 7.;
|
||||||
|
DBG("ADD = %g; new speed = %g", add, p->speed + add);
|
||||||
|
if(state == Guiding) return p->speed + add / dt / 10.;
|
||||||
|
return add / dt;
|
||||||
|
}
|
||||||
|
// ./moving -l coords -P.5 -I.05 -D1.5
|
||||||
|
// ./moving -l coords -P1.3 -D1.6
|
||||||
|
|
||||||
|
static void start_model(double Tend){
|
||||||
|
double T = 0., Tcorr = 0.;//, Tlast = 0.;
|
||||||
|
moveparam_t target;
|
||||||
|
while(T <= Tend){
|
||||||
|
moveparam_t p;
|
||||||
|
movestate_t st = model->get_state(&p);
|
||||||
|
if(st == ST_MOVE) st = model->proc_move(&p, T);
|
||||||
|
double nextcoord = target_coord(T);
|
||||||
|
double error = nextcoord - p.coord;
|
||||||
|
if(T - Tcorr >= G.dTcorr){ // check correction
|
||||||
|
double speed = getNewSpeed(&p, nextcoord, T - Tcorr);
|
||||||
|
target.coord = (speed > 0) ? p.coord + 5e5 : p.coord - 5e5;
|
||||||
|
target.speed = fabs(speed);
|
||||||
|
double res_speed = limits.max.speed / 2.;
|
||||||
|
if(target.speed > limits.max.speed){
|
||||||
|
target.speed = limits.max.speed;
|
||||||
|
res_speed = limits.max.speed / 4.;
|
||||||
|
}else if(target.speed < limits.min.speed){
|
||||||
|
target.speed = limits.min.speed;
|
||||||
|
res_speed = limits.min.speed * 4.;
|
||||||
|
}
|
||||||
|
if(!move_to(&target, T)){
|
||||||
|
target.speed = res_speed;
|
||||||
|
if(!move_to(&target, T))
|
||||||
|
WARNX("move(): can't move to %g with max speed %g", target.coord, target.speed);
|
||||||
|
}
|
||||||
|
DBG("%g: tag/cur speed= %g / %g; tag/cur pos = %g / %g; err = %g", T, target.speed, p.speed, target.coord, p.coord, error);
|
||||||
|
Tcorr = T;
|
||||||
|
}
|
||||||
|
// make log
|
||||||
|
fprintf(coordslog, "%-9.4f\t%-10.4f\t%-10.4f\t%-10.4f\t%-10.4f\t%-10.4f\n",
|
||||||
|
T, nextcoord, p.coord, p.speed, p.accel, error);
|
||||||
|
T += G.dTmon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
sl_init();
|
||||||
|
sl_parseargs(&argc, &argv, opts);
|
||||||
|
if(G.help) sl_showhelp(-1, opts);
|
||||||
|
if(G.xlog){
|
||||||
|
coordslog = fopen(G.xlog, "w");
|
||||||
|
if(!coordslog) ERR("Can't open %s", G.xlog);
|
||||||
|
} else coordslog = stdout;
|
||||||
|
if(G.dTmon <= 0.) ERRX("tmon should be > 0.");
|
||||||
|
if(G.dTcorr <= 0. || G.dTcorr > 1.) ERRX("tcor should be > 0. and < 1.");
|
||||||
|
if(G.Tend <= 0.) ERRX("tend should be > 0.");
|
||||||
|
pid_init(&pid, G.P, G.I, G.D);
|
||||||
|
fprintf(coordslog, "%-9s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\n", "time", "target", "curpos", "speed", "accel", "error");
|
||||||
|
ramptype_t ramp = RAMP_AMOUNT;
|
||||||
|
if(*G.ramptype == 'd' || *G.ramptype == 'D') ramp = RAMP_DUMB;
|
||||||
|
else if(*G.ramptype == 't' || *G.ramptype == 'T') ramp = RAMP_TRAPEZIUM;
|
||||||
|
else if(*G.ramptype == 's' || *G.ramptype == 'S') ramp = RAMP_S;
|
||||||
|
else ERRX("Point \"d\" (dumb), \"s\" (s-type), or \"t\" (trapez) for ramp type");
|
||||||
|
model = init_moving(ramp, &limits);
|
||||||
|
if(!model) ERRX("Can't init moving model: check parameters");
|
||||||
|
start_model(G.Tend);
|
||||||
|
fclose(coordslog);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
105
LibSidServo/PID_test.deprecated/moving.c
Normal file
105
LibSidServo/PID_test.deprecated/moving.c
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "moving.h"
|
||||||
|
#include "moving_private.h"
|
||||||
|
#include "Dramp.h"
|
||||||
|
#include "Sramp.h"
|
||||||
|
#include "Tramp.h"
|
||||||
|
|
||||||
|
//static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static movemodel_t *model = NULL;
|
||||||
|
double coord_tolerance = COORD_TOLERANCE_DEFAULT;
|
||||||
|
double time_tick = TIME_TICK_DEFAULT;
|
||||||
|
|
||||||
|
// difference of time from first call, using nanoseconds
|
||||||
|
double nanot(){
|
||||||
|
static struct timespec *start = NULL;
|
||||||
|
struct timespec now;
|
||||||
|
if(!start){
|
||||||
|
start = MALLOC(struct timespec, 1);
|
||||||
|
if(!start) return -1.;
|
||||||
|
if(clock_gettime(CLOCK_REALTIME, start)) return -1.;
|
||||||
|
}
|
||||||
|
if(clock_gettime(CLOCK_REALTIME, &now)) return -1.;
|
||||||
|
//DBG("was: %ld, now: %ld", start->tv_nsec, now.tv_nsec);
|
||||||
|
double nd = ((double)now.tv_nsec - (double)start->tv_nsec) * 1e-9;
|
||||||
|
double sd = (double)now.tv_sec - (double)start->tv_sec;
|
||||||
|
return sd + nd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void chkminmax(double *min, double *max){
|
||||||
|
if(*min <= *max) return;
|
||||||
|
double t = *min;
|
||||||
|
*min = *max;
|
||||||
|
*max = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t *init_moving(ramptype_t type, limits_t *l){
|
||||||
|
if(!l) return FALSE;
|
||||||
|
switch(type){
|
||||||
|
case RAMP_DUMB:
|
||||||
|
model = &dumb;
|
||||||
|
break;
|
||||||
|
case RAMP_TRAPEZIUM:
|
||||||
|
model = &trapez;
|
||||||
|
break;
|
||||||
|
case RAMP_S:
|
||||||
|
model = &s_shaped;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if(!model->init_limits) return NULL;
|
||||||
|
moveparam_t *max = &l->max, *min = &l->min;
|
||||||
|
if(min->speed < 0.) min->speed = -min->speed;
|
||||||
|
if(max->speed < 0.) max->speed = -max->speed;
|
||||||
|
if(min->accel < 0.) min->accel = -min->accel;
|
||||||
|
if(max->accel < 0.) max->accel = -max->accel;
|
||||||
|
chkminmax(&min->coord, &max->coord);
|
||||||
|
chkminmax(&min->speed, &max->speed);
|
||||||
|
chkminmax(&min->accel, &max->accel);
|
||||||
|
if(!model->init_limits(l)) return NULL;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
int move_to(moveparam_t *target, double t){
|
||||||
|
if(!target || !model) return FALSE;
|
||||||
|
DBG("MOVE to %g at speed %g", target->coord, target->speed);
|
||||||
|
// only positive velocity
|
||||||
|
if(target->speed < 0.) target->speed = -target->speed;
|
||||||
|
// don't mind about acceleration - user cannot set it now
|
||||||
|
return model->calculate(target, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
int init_coordtol(double tolerance){
|
||||||
|
if(tolerance < COORD_TOLERANCE_MIN || tolerance > COORD_TOLERANCE_MAX) return FALSE;
|
||||||
|
coord_tolerance = tolerance;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
int init_timetick(double tick){
|
||||||
|
if(tick < TIME_TICK_MIN || tick > TIME_TICK_MAX) return FALSE;
|
||||||
|
time_tick = tick;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
70
LibSidServo/PID_test.deprecated/moving.h
Normal file
70
LibSidServo/PID_test.deprecated/moving.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// tolerance, time ticks
|
||||||
|
#define COORD_TOLERANCE_DEFAULT (0.01)
|
||||||
|
#define COORD_TOLERANCE_MIN (0.0001)
|
||||||
|
#define COORD_TOLERANCE_MAX (10.)
|
||||||
|
#define TIME_TICK_DEFAULT (0.0001)
|
||||||
|
#define TIME_TICK_MIN (1e-9)
|
||||||
|
#define TIME_TICK_MAX (10.)
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
RAMP_DUMB, // no ramp: infinite acceleration/deceleration
|
||||||
|
RAMP_TRAPEZIUM, // trapezium ramp
|
||||||
|
RAMP_S, // s-shaped ramp
|
||||||
|
RAMP_AMOUNT
|
||||||
|
} ramptype_t;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
ST_STOP, // stopped
|
||||||
|
ST_MOVE, // moving
|
||||||
|
ST_AMOUNT
|
||||||
|
} movestate_t;
|
||||||
|
|
||||||
|
typedef struct{ // all values could be both as positive and negative
|
||||||
|
double coord;
|
||||||
|
double speed;
|
||||||
|
double accel;
|
||||||
|
} moveparam_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
moveparam_t min;
|
||||||
|
moveparam_t max;
|
||||||
|
double jerk;
|
||||||
|
} limits_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
int (*init_limits)(limits_t *lim); // init values of limits, jerk
|
||||||
|
int (*calculate)(moveparam_t *target, double t); // calculate stages of traectory beginning from t
|
||||||
|
movestate_t (*proc_move)(moveparam_t *next, double t); // calculate next model point for time t
|
||||||
|
movestate_t (*get_state)(moveparam_t *cur); // get current moving state
|
||||||
|
void (*stop)(double t); // stop by ramp
|
||||||
|
void (*emergency_stop)(double t); // stop with highest acceleration
|
||||||
|
double (*stoppedtime)(); // time when moving will ends
|
||||||
|
} movemodel_t;
|
||||||
|
|
||||||
|
extern double coord_tolerance;
|
||||||
|
|
||||||
|
double nanot();
|
||||||
|
movemodel_t *init_moving(ramptype_t type, limits_t *l);
|
||||||
|
int init_coordtol(double tolerance);
|
||||||
|
int init_timetick(double tick);
|
||||||
|
int move_to(moveparam_t *target, double t);
|
||||||
1
LibSidServo/PID_test.deprecated/moving_model.cflags
Normal file
1
LibSidServo/PID_test.deprecated/moving_model.cflags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-std=c17
|
||||||
4
LibSidServo/PID_test.deprecated/moving_model.config
Normal file
4
LibSidServo/PID_test.deprecated/moving_model.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Add predefined macros for your project here. For example:
|
||||||
|
// #define THE_ANSWER 42
|
||||||
|
#define _XOPEN_SOURCE 666
|
||||||
|
#define EBUG
|
||||||
1
LibSidServo/PID_test.deprecated/moving_model.creator
Normal file
1
LibSidServo/PID_test.deprecated/moving_model.creator
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[General]
|
||||||
221
LibSidServo/PID_test.deprecated/moving_model.creator.user
Normal file
221
LibSidServo/PID_test.deprecated/moving_model.creator.user
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 17.0.0, 2025-07-29T13:32:31. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">1</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="bool" key="HasPerBcDcs">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/C-files/mountcontrol.git/moving_model</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.ShowReachable">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.ShowReachable">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 16.0.0, 2025-03-18T22:08:04. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">8</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Big/Data/00__Small_tel/moving_model</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
1
LibSidServo/PID_test.deprecated/moving_model.cxxflags
Normal file
1
LibSidServo/PID_test.deprecated/moving_model.cxxflags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-std=c++17
|
||||||
10
LibSidServo/PID_test.deprecated/moving_model.files
Normal file
10
LibSidServo/PID_test.deprecated/moving_model.files
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Dramp.c
|
||||||
|
Dramp.h
|
||||||
|
Sramp.c
|
||||||
|
Sramp.h
|
||||||
|
Tramp.c
|
||||||
|
Tramp.h
|
||||||
|
main.c
|
||||||
|
moving.c
|
||||||
|
moving.h
|
||||||
|
moving_private.h
|
||||||
26
LibSidServo/PID_test.deprecated/moving_private.h
Normal file
26
LibSidServo/PID_test.deprecated/moving_private.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "moving.h"
|
||||||
|
|
||||||
|
extern double coord_tolerance;
|
||||||
|
extern double time_tick;
|
||||||
|
|
||||||
|
|
||||||
4
LibSidServo/PID_test.deprecated/plot
Executable file
4
LibSidServo/PID_test.deprecated/plot
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
plot for [col in "target curpos speed error"] 'coords' using 1:col with lines title columnheader
|
||||||
|
pause mouse
|
||||||
8
LibSidServo/PID_test.deprecated/plot.cont
Executable file
8
LibSidServo/PID_test.deprecated/plot.cont
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
#set term pdf
|
||||||
|
#set output "output.pdf"
|
||||||
|
while(1){
|
||||||
|
plot for [col in "target curpos speed error"] 'coords' using 1:col with lines title columnheader
|
||||||
|
pause 1
|
||||||
|
}
|
||||||
6
LibSidServo/PID_test.deprecated/plot_jpg
Executable file
6
LibSidServo/PID_test.deprecated/plot_jpg
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
set terminal jpeg size 1000,500
|
||||||
|
set output "all.jpg"
|
||||||
|
|
||||||
|
plot for [col in "target curpos speed error"] 'coords' using 1:col with lines title columnheader
|
||||||
5
LibSidServo/PID_test.deprecated/plot_pdf
Executable file
5
LibSidServo/PID_test.deprecated/plot_pdf
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
set term pdf
|
||||||
|
set output "output.pdf"
|
||||||
|
plot for [col=2:4] 'coordlog' using 1:col with lines title columnheader
|
||||||
4
LibSidServo/PID_test.deprecated/plotacc
Executable file
4
LibSidServo/PID_test.deprecated/plotacc
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
plot 'coords' using 1:5 with lines title columnheader
|
||||||
|
pause mouse
|
||||||
4
LibSidServo/PID_test.deprecated/ploterr
Executable file
4
LibSidServo/PID_test.deprecated/ploterr
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
plot 'coords' using 1:6 with lines title columnheader
|
||||||
|
pause mouse
|
||||||
6
LibSidServo/PID_test.deprecated/ploterr.cont
Executable file
6
LibSidServo/PID_test.deprecated/ploterr.cont
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
plot 'coords' using 1:6 with lines title columnheader
|
||||||
|
pause 1
|
||||||
|
}
|
||||||
5
LibSidServo/PID_test.deprecated/ploterr_jpg
Executable file
5
LibSidServo/PID_test.deprecated/ploterr_jpg
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
set term jpeg size 1000,500
|
||||||
|
set output "error.jpg"
|
||||||
|
plot 'coords' using 1:6 with lines title columnheader
|
||||||
57
LibSidServo/PID_test/Makefile
Normal file
57
LibSidServo/PID_test/Makefile
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# run `make DEF=...` to add extra defines
|
||||||
|
PROGRAM := moving
|
||||||
|
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
|
||||||
|
LDFLAGS += -lusefull_macros -lm
|
||||||
|
SRCS := $(wildcard *.c)
|
||||||
|
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
||||||
|
OBJDIR := mk
|
||||||
|
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99
|
||||||
|
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
||||||
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
TARGFILE := $(OBJDIR)/TARGET
|
||||||
|
CC = gcc
|
||||||
|
#TARGET := RELEASE
|
||||||
|
|
||||||
|
ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes)
|
||||||
|
TARGET := $(file < $(TARGFILE))
|
||||||
|
else
|
||||||
|
TARGET := RELEASE
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(TARGET), DEBUG)
|
||||||
|
.DEFAULT_GOAL := debug
|
||||||
|
endif
|
||||||
|
|
||||||
|
release: $(PROGRAM)
|
||||||
|
|
||||||
|
debug: CFLAGS += -DEBUG -Werror
|
||||||
|
debug: TARGET := DEBUG
|
||||||
|
debug: $(PROGRAM)
|
||||||
|
|
||||||
|
$(TARGFILE): $(OBJDIR)
|
||||||
|
@echo -e "\t\tTARGET: $(TARGET)"
|
||||||
|
@echo "$(TARGET)" > $(TARGFILE)
|
||||||
|
|
||||||
|
$(PROGRAM) : $(TARGFILE) $(OBJS)
|
||||||
|
@echo -e "\t\tLD $(PROGRAM)"
|
||||||
|
$(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
@mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
|
-include $(DEPS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.c
|
||||||
|
@echo -e "\t\tCC $<"
|
||||||
|
$(CC) $< -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo -e "\t\tCLEAN"
|
||||||
|
@rm -rf $(OBJDIR) 2>/dev/null || true
|
||||||
|
|
||||||
|
xclean: clean
|
||||||
|
@rm -f $(PROGRAM)
|
||||||
|
|
||||||
|
.PHONY: clean xclean
|
||||||
64
LibSidServo/PID_test/PID.c
Normal file
64
LibSidServo/PID_test/PID.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "PID.h"
|
||||||
|
|
||||||
|
PIDController_t *pid_create(PIDpar_t *gain, size_t Iarrsz){
|
||||||
|
if(!gain || Iarrsz < 3) return NULL;
|
||||||
|
PIDController_t *pid = (PIDController_t*)calloc(1, sizeof(PIDController_t));
|
||||||
|
pid->gain = *gain;
|
||||||
|
pid->pidIarrSize = Iarrsz;
|
||||||
|
pid->pidIarray = (double*)calloc(Iarrsz, sizeof(double));
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pid_clear(PIDController_t *pid){
|
||||||
|
if(!pid) return;
|
||||||
|
DBG("CLEAR PID PARAMETERS");
|
||||||
|
bzero(pid->pidIarray, sizeof(double) * pid->pidIarrSize);
|
||||||
|
pid->integral = 0.;
|
||||||
|
pid->prev_error = 0.;
|
||||||
|
pid->curIidx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pid_delete(PIDController_t **pid){
|
||||||
|
if(!pid || !*pid) return;
|
||||||
|
if((*pid)->pidIarray) free((*pid)->pidIarray);
|
||||||
|
free(*pid);
|
||||||
|
*pid = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
double pid_calculate(PIDController_t *pid, double error, double dt){
|
||||||
|
// calculate flowing integral
|
||||||
|
double oldi = pid->pidIarray[pid->curIidx], newi = error * dt;
|
||||||
|
DBG("oldi/new: %g, %g", oldi, newi);
|
||||||
|
pid->pidIarray[pid->curIidx++] = newi;
|
||||||
|
if(pid->curIidx >= pid->pidIarrSize) pid->curIidx = 0;
|
||||||
|
pid->integral += newi - oldi;
|
||||||
|
double derivative = (error - pid->prev_error) / dt;
|
||||||
|
pid->prev_error = error;
|
||||||
|
double sum = pid->gain.P * error + pid->gain.I * pid->integral + pid->gain.D * derivative;
|
||||||
|
DBG("P=%g, I=%g, D=%g; sum=%g", pid->gain.P * error, pid->gain.I * pid->integral, pid->gain.D * derivative, sum);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
39
LibSidServo/PID_test/PID.h
Normal file
39
LibSidServo/PID_test/PID.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
double P, I, D;
|
||||||
|
} PIDpar_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PIDpar_t gain; // PID gains
|
||||||
|
double prev_error; // Previous error
|
||||||
|
double integral; // Integral term
|
||||||
|
double *pidIarray; // array for Integral
|
||||||
|
size_t pidIarrSize; // it's size
|
||||||
|
size_t curIidx; // and index of current element
|
||||||
|
} PIDController_t;
|
||||||
|
|
||||||
|
PIDController_t *pid_create(PIDpar_t *gain, size_t Iarrsz);
|
||||||
|
void pid_clear(PIDController_t *pid);
|
||||||
|
void pid_delete(PIDController_t **pid);
|
||||||
|
double pid_calculate(PIDController_t *pid, double error, double dt);
|
||||||
223
LibSidServo/PID_test/Tramp.c
Normal file
223
LibSidServo/PID_test/Tramp.c
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// simplest trapezioidal ramp
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "Tramp.h"
|
||||||
|
|
||||||
|
#undef DBG
|
||||||
|
#define DBG(...)
|
||||||
|
|
||||||
|
static movestate_t state = ST_STOP;
|
||||||
|
static moveparam_t Min, Max; // `Min` acceleration not used!
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
STAGE_ACCEL, // start from zero speed and accelerate to Max speed
|
||||||
|
STAGE_MAXSPEED, // go with target speed
|
||||||
|
STAGE_DECEL, // go from target speed to zero
|
||||||
|
STAGE_STOPPED, // stop
|
||||||
|
STAGE_AMOUNT
|
||||||
|
} movingstage_t;
|
||||||
|
|
||||||
|
static movingstage_t movingstage = STAGE_STOPPED;
|
||||||
|
static double Times[STAGE_AMOUNT] = {0}; // time when each stage starts
|
||||||
|
static moveparam_t Params[STAGE_AMOUNT] = {0}; // starting parameters for each stage
|
||||||
|
static moveparam_t curparams = {0}; // current coordinate/speed/acceleration
|
||||||
|
|
||||||
|
static int initlims(limits_t *lim){
|
||||||
|
if(!lim) return FALSE;
|
||||||
|
Min = lim->min;
|
||||||
|
Max = lim->max;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void emstop(double _U_ t){
|
||||||
|
curparams.accel = 0.;
|
||||||
|
curparams.speed = 0.;
|
||||||
|
bzero(Times, sizeof(Times));
|
||||||
|
bzero(Params, sizeof(Params));
|
||||||
|
state = ST_STOP;
|
||||||
|
movingstage = STAGE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(double t){
|
||||||
|
if(state == ST_STOP || movingstage == STAGE_STOPPED) return;
|
||||||
|
movingstage = STAGE_DECEL;
|
||||||
|
state = ST_MOVE;
|
||||||
|
Times[STAGE_DECEL] = t;
|
||||||
|
Params[STAGE_DECEL].speed = curparams.speed;
|
||||||
|
if(curparams.speed > 0.) Params[STAGE_DECEL].accel = -Max.accel;
|
||||||
|
else Params[STAGE_DECEL].accel = Max.accel;
|
||||||
|
Params[STAGE_DECEL].coord = curparams.coord;
|
||||||
|
// speed: v=v2+a2(t-t2), v2 and a2 have different signs; t3: v3=0 -> t3=t2-v2/a2
|
||||||
|
Times[STAGE_STOPPED] = t - curparams.speed / Params[STAGE_DECEL].accel;
|
||||||
|
// coordinate: x=x2+v2(t-t2)+a2(t-t2)^2/2 -> x3=x2+v2(t3-t2)+a2(t3-t2)^2/2
|
||||||
|
double dt = Times[STAGE_STOPPED] - t;
|
||||||
|
Params[STAGE_STOPPED].coord = curparams.coord + curparams.speed * dt +
|
||||||
|
Params[STAGE_DECEL].accel * dt * dt / 2.;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief calc - moving calculation
|
||||||
|
* @param x - using max speed (>0!!!) and coordinate
|
||||||
|
* @param t - current time value
|
||||||
|
* @return FALSE if can't move with given parameters
|
||||||
|
*/
|
||||||
|
static int calc(moveparam_t *x, double t){
|
||||||
|
if(!x) return FALSE;
|
||||||
|
if(x->coord < Min.coord || x->coord > Max.coord) return FALSE;
|
||||||
|
if(x->speed < Min.speed || x->speed > Max.speed) return FALSE;
|
||||||
|
double Dx = fabs(x->coord - curparams.coord); // full distance
|
||||||
|
double sign = (x->coord > curparams.coord) ? 1. : -1.; // sign of target accelerations and speeds
|
||||||
|
// we have two variants: with or without stage with constant speed
|
||||||
|
double dt23 = x->speed / Max.accel; // time of deceleration stage for given speed
|
||||||
|
double dx23 = x->speed * dt23 / 2.; // distance on dec stage (abs)
|
||||||
|
DBG("Dx=%g, sign=%g, dt23=%g, dx23=%g", Dx, sign, dt23, dx23);
|
||||||
|
double setspeed = x->speed; // new max speed (we can change it if need)
|
||||||
|
double dt01, dx01; // we'll fill them depending on starting conditions
|
||||||
|
Times[0] = t;
|
||||||
|
Params[0].speed = curparams.speed;
|
||||||
|
Params[0].coord = curparams.coord;
|
||||||
|
|
||||||
|
double curspeed = fabs(curparams.speed);
|
||||||
|
double dt0s = curspeed / Max.accel; // time of stopping phase
|
||||||
|
double dx0s = curspeed * dt0s / 2.; // distance
|
||||||
|
DBG("dt0s=%g, dx0s=%g", dt0s, dx0s);
|
||||||
|
if(dx0s > Dx){
|
||||||
|
WARNX("distance too short");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if(fabs(Dx - dx0s) < coord_tolerance){ // just stop and we'll be on target
|
||||||
|
DBG("Distance good to just stop");
|
||||||
|
stop(t);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if(curparams.speed * sign < 0. || state == ST_STOP){ // we should change speed sign
|
||||||
|
// after stop we will have full profile
|
||||||
|
double dxs3 = Dx - dx0s;
|
||||||
|
double newspeed = sqrt(Max.accel * dxs3);
|
||||||
|
if(newspeed < setspeed) setspeed = newspeed; // we can't reach user speed
|
||||||
|
DBG("dxs3=%g, setspeed=%g", dxs3, setspeed);
|
||||||
|
dt01 = fabs(sign*setspeed - curparams.speed) / Max.accel;
|
||||||
|
Params[0].accel = sign * Max.accel;
|
||||||
|
if(state == ST_STOP) dx01 = setspeed * dt01 / 2.;
|
||||||
|
else dx01 = dt01 * (dt01 / 2. * Max.accel - curspeed);
|
||||||
|
DBG("dx01=%g, dt01=%g", dx01, dt01);
|
||||||
|
}else{ // increase or decrease speed without stopping phase
|
||||||
|
dt01 = fabs(sign*setspeed - curparams.speed) / Max.accel;
|
||||||
|
double a = sign * Max.accel;
|
||||||
|
if(sign * curparams.speed < 0.){DBG("change direction"); a = -a;}
|
||||||
|
else if(curspeed > setspeed){ DBG("lower speed @ this direction"); a = -a;}
|
||||||
|
//double a = (curspeed > setspeed) ? -Max.accel : Max.accel;
|
||||||
|
dx01 = curspeed * dt01 + a * dt01 * dt01 / 2.;
|
||||||
|
DBG("dt01=%g, a=%g, dx01=%g", dt01, a, dx01);
|
||||||
|
if(dx01 + dx23 > Dx){ // calculate max speed
|
||||||
|
setspeed = sqrt(Max.accel * Dx - curspeed * curspeed / 2.);
|
||||||
|
if(setspeed < curspeed){
|
||||||
|
setspeed = curparams.speed;
|
||||||
|
dt01 = 0.; dx01 = 0.;
|
||||||
|
Params[0].accel = 0.;
|
||||||
|
}else{
|
||||||
|
Params[0].accel = a;
|
||||||
|
dt01 = fabs(setspeed - curspeed) / Max.accel;
|
||||||
|
dx01 = curspeed * dt01 + Max.accel * dt01 * dt01 / 2.;
|
||||||
|
}
|
||||||
|
}else Params[0].accel = a;
|
||||||
|
}
|
||||||
|
if(setspeed < Min.speed){
|
||||||
|
WARNX("New speed should be too small");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
moveparam_t *p = &Params[STAGE_MAXSPEED];
|
||||||
|
p->accel = 0.; p->speed = sign * setspeed;
|
||||||
|
p->coord = curparams.coord + dx01 * sign;
|
||||||
|
Times[STAGE_MAXSPEED] = Times[0] + dt01;
|
||||||
|
dt23 = setspeed / Max.accel;
|
||||||
|
dx23 = setspeed * dt23 / 2.;
|
||||||
|
// calculate dx12 and dt12
|
||||||
|
double dx12 = Dx - dx01 - dx23;
|
||||||
|
if(dx12 < -coord_tolerance){
|
||||||
|
WARNX("Oops, WTF dx12=%g?", dx12);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
double dt12 = dx12 / setspeed;
|
||||||
|
p = &Params[STAGE_DECEL];
|
||||||
|
p->accel = -sign * Max.accel;
|
||||||
|
p->speed = sign * setspeed;
|
||||||
|
p->coord = Params[STAGE_MAXSPEED].coord + sign * dx12;
|
||||||
|
Times[STAGE_DECEL] = Times[STAGE_MAXSPEED] + dt12;
|
||||||
|
p = &Params[STAGE_STOPPED];
|
||||||
|
p->accel = 0.; p->speed = 0.; p->coord = x->coord;
|
||||||
|
Times[STAGE_STOPPED] = Times[STAGE_DECEL] + dt23;
|
||||||
|
for(int i = 0; i < 4; ++i)
|
||||||
|
DBG("%d: t=%g, coord=%g, speed=%g, accel=%g", i,
|
||||||
|
Times[i], Params[i].coord, Params[i].speed, Params[i].accel);
|
||||||
|
state = ST_MOVE;
|
||||||
|
movingstage = STAGE_ACCEL;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t proc(moveparam_t *next, double t){
|
||||||
|
if(state == ST_STOP) goto ret;
|
||||||
|
for(movingstage_t s = STAGE_STOPPED; s >= 0; --s){
|
||||||
|
if(Times[s] <= t){ // check time for current stage
|
||||||
|
movingstage = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(movingstage == STAGE_STOPPED){
|
||||||
|
curparams.coord = Params[STAGE_STOPPED].coord;
|
||||||
|
emstop(t);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
// calculate current parameters
|
||||||
|
double dt = t - Times[movingstage];
|
||||||
|
double a = Params[movingstage].accel;
|
||||||
|
double v0 = Params[movingstage].speed;
|
||||||
|
double x0 = Params[movingstage].coord;
|
||||||
|
curparams.accel = a;
|
||||||
|
curparams.speed = v0 + a * dt;
|
||||||
|
curparams.coord = x0 + v0 * dt + a * dt * dt / 2.;
|
||||||
|
ret:
|
||||||
|
if(next) *next = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t getst(moveparam_t *cur){
|
||||||
|
if(cur) *cur = curparams;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double gettstop(){
|
||||||
|
return Times[STAGE_STOPPED];
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t trapez = {
|
||||||
|
.init_limits = initlims,
|
||||||
|
.stop = stop,
|
||||||
|
.emergency_stop = emstop,
|
||||||
|
.get_state = getst,
|
||||||
|
.calculate = calc,
|
||||||
|
.proc_move = proc,
|
||||||
|
.stoppedtime = gettstop,
|
||||||
|
};
|
||||||
23
LibSidServo/PID_test/Tramp.h
Normal file
23
LibSidServo/PID_test/Tramp.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "moving_private.h"
|
||||||
|
|
||||||
|
extern movemodel_t trapez;
|
||||||
222
LibSidServo/PID_test/main.c
Normal file
222
LibSidServo/PID_test/main.c
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#include "moving.h"
|
||||||
|
#include "PID.h"
|
||||||
|
|
||||||
|
// errors for states: slewing/pointing/guiding
|
||||||
|
// 10-degrees zone - Coordinate-driven PID
|
||||||
|
#define MAX_POINTING_ERR (36000.)
|
||||||
|
// 1-arcminute zone - Velocity-dtiven PID
|
||||||
|
#define MAX_GUIDING_ERR (60.)
|
||||||
|
// timeout to "forget" old data from I sum array; seconds
|
||||||
|
#define PID_I_PERIOD (3.)
|
||||||
|
|
||||||
|
// PID for coordinate-driven and velocity-driven parts
|
||||||
|
static PIDController_t *pidC = NULL, *pidV = NULL;
|
||||||
|
static movemodel_t *model = NULL;
|
||||||
|
static FILE *coordslog = NULL;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
Slewing,
|
||||||
|
Pointing,
|
||||||
|
Guiding
|
||||||
|
} state_t;
|
||||||
|
|
||||||
|
static state_t state = Slewing;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
int help;
|
||||||
|
char *ramptype;
|
||||||
|
char *xlog;
|
||||||
|
double dTmon;
|
||||||
|
double dTcorr;
|
||||||
|
double Tend;
|
||||||
|
double minerr;
|
||||||
|
double startcoord;
|
||||||
|
double error;
|
||||||
|
PIDpar_t gainC, gainV;
|
||||||
|
} pars;
|
||||||
|
|
||||||
|
static pars G = {
|
||||||
|
.dTmon = 0.01,
|
||||||
|
.dTcorr = 0.05,
|
||||||
|
.Tend = 100.,
|
||||||
|
.minerr = 0.1,
|
||||||
|
.gainC.P = 0.1,
|
||||||
|
.gainV.P = 0.1,
|
||||||
|
.startcoord = 100.,
|
||||||
|
};
|
||||||
|
|
||||||
|
static limits_t limits = {
|
||||||
|
.min = {.coord = -1e6, .speed = 0.01, .accel = 0.1},
|
||||||
|
.max = {.coord = 6648000, .speed = 36000., .accel = 36000.}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static sl_option_t opts[] = {
|
||||||
|
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
|
||||||
|
{"tmon", NEED_ARG, NULL, 'T', arg_double, APTR(&G.dTmon), "time interval for monitoring (seconds, default: 0.001)"},
|
||||||
|
{"tcor", NEED_ARG, NULL, 't', arg_double, APTR(&G.dTcorr), "time interval for corrections (seconds, default: 0.05)"},
|
||||||
|
{"xlog", NEED_ARG, NULL, 'l', arg_string, APTR(&G.xlog), "log file name for coordinates logging"},
|
||||||
|
{"tend", NEED_ARG, NULL, 'e', arg_double, APTR(&G.Tend), "end time of monitoring (seconds, default: 100)"},
|
||||||
|
{"minerr", NEED_ARG, NULL, 'm', arg_double, APTR(&G.minerr), "minimal error for corrections (units, default: 0.1)"},
|
||||||
|
{"propC", NEED_ARG, NULL, 'P', arg_double, APTR(&G.gainC.P), "P-coefficient of coordinate-driven PID"},
|
||||||
|
{"integC", NEED_ARG, NULL, 'I', arg_double, APTR(&G.gainC.I), "I-coefficient of coordinate-driven PID"},
|
||||||
|
{"diffC", NEED_ARG, NULL, 'D', arg_double, APTR(&G.gainC.D), "D-coefficient of coordinate-driven PID"},
|
||||||
|
{"propV", NEED_ARG, NULL, 'p', arg_double, APTR(&G.gainV.P), "P-coefficient of velocity-driven PID"},
|
||||||
|
{"integV", NEED_ARG, NULL, 'i', arg_double, APTR(&G.gainV.I), "I-coefficient of velocity-driven PID"},
|
||||||
|
{"diffV", NEED_ARG, NULL, 'd', arg_double, APTR(&G.gainV.D), "D-coefficient of velocity-driven PID"},
|
||||||
|
{"xstart", NEED_ARG, NULL, '0', arg_double, APTR(&G.startcoord), "starting coordinate of target"},
|
||||||
|
{"error", NEED_ARG, NULL, 'E', arg_double, APTR(&G.error), "error range"},
|
||||||
|
// TODO: add parameters for limits setting
|
||||||
|
end_option
|
||||||
|
};
|
||||||
|
|
||||||
|
// calculate coordinate target for given time (starting from zero)
|
||||||
|
static double target_coord(double t){
|
||||||
|
if(t > 20. && t < 30.) return 0.;
|
||||||
|
//double pos = G.startcoord + 15. * t + G.error * (drand48() - 0.5);
|
||||||
|
double pos = G.startcoord + 15. * sin(2*M_PI * t / 10.) + G.error * (drand48() - 0.5);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double getNewSpeed(const moveparam_t *p, double targcoord, double dt){
|
||||||
|
double error = targcoord - p->coord, fe = fabs(error);
|
||||||
|
PIDController_t *pid = NULL;
|
||||||
|
switch(state){
|
||||||
|
case Slewing:
|
||||||
|
if(fe < MAX_POINTING_ERR){
|
||||||
|
pid_clear(pidC);
|
||||||
|
state = Pointing;
|
||||||
|
green("--> Pointing\n");
|
||||||
|
pid = pidC;
|
||||||
|
}else{
|
||||||
|
red("Slewing...\n");
|
||||||
|
return (error > 0.) ? limits.max.speed : -limits.max.speed;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Pointing:
|
||||||
|
if(fe < MAX_GUIDING_ERR){
|
||||||
|
pid_clear(pidV);
|
||||||
|
state = Guiding;
|
||||||
|
green("--> Guiding\n");
|
||||||
|
pid = pidV;
|
||||||
|
}else if(fe > MAX_POINTING_ERR){
|
||||||
|
red("--> Slewing\n");
|
||||||
|
state = Slewing;
|
||||||
|
return (error > 0.) ? limits.max.speed : -limits.max.speed;
|
||||||
|
} else pid = pidC;
|
||||||
|
break;
|
||||||
|
case Guiding:
|
||||||
|
pid= pidV;
|
||||||
|
if(fe > MAX_GUIDING_ERR){
|
||||||
|
red("--> Pointing\n");
|
||||||
|
state = Pointing;
|
||||||
|
pid_clear(pidC);
|
||||||
|
pid = pidC;
|
||||||
|
}else if(fe < G.minerr){
|
||||||
|
green("At target\n");
|
||||||
|
}else printf("Current error: %g\n", fe);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!pid){
|
||||||
|
WARNX("where is PID?"); return p->speed;
|
||||||
|
}
|
||||||
|
double tagspeed = pid_calculate(pid, error, dt);
|
||||||
|
if(state == Guiding) return p->speed + tagspeed;
|
||||||
|
return tagspeed;
|
||||||
|
}
|
||||||
|
// -P0.8 -D0.1 -I0.02 -p20 -d.5 -i.02
|
||||||
|
// another: P0.8 -D0.1 -I0.02 -p5 -d0.9 -i0.1
|
||||||
|
|
||||||
|
static void start_model(double Tend){
|
||||||
|
double T = 0., Tcorr = 0.;
|
||||||
|
moveparam_t target;
|
||||||
|
uint64_t N = 0;
|
||||||
|
double errmax = 0., errsum = 0., errsum2 = 0.;
|
||||||
|
while(T <= Tend){
|
||||||
|
moveparam_t p;
|
||||||
|
movestate_t st = model->get_state(&p);
|
||||||
|
if(st == ST_MOVE) st = model->proc_move(&p, T);
|
||||||
|
double nextcoord = target_coord(T);
|
||||||
|
double error = nextcoord - p.coord;
|
||||||
|
if(state == Guiding){
|
||||||
|
double ae = fabs(error);
|
||||||
|
if(ae > errmax) errmax = ae;
|
||||||
|
errsum += error; errsum2 += error * error;
|
||||||
|
++N;
|
||||||
|
}
|
||||||
|
if(T - Tcorr >= G.dTcorr){ // check correction
|
||||||
|
double speed = getNewSpeed(&p, nextcoord, T - Tcorr);
|
||||||
|
target.coord = (speed > 0) ? p.coord + 5e5 : p.coord - 5e5;
|
||||||
|
target.speed = fabs(speed);
|
||||||
|
double res_speed = limits.max.speed / 2.;
|
||||||
|
if(target.speed > limits.max.speed){
|
||||||
|
target.speed = limits.max.speed;
|
||||||
|
res_speed = limits.max.speed / 4.;
|
||||||
|
}else if(target.speed < limits.min.speed){
|
||||||
|
target.speed = limits.min.speed;
|
||||||
|
res_speed = limits.min.speed * 4.;
|
||||||
|
}
|
||||||
|
if(!move_to(&target, T)){
|
||||||
|
target.speed = res_speed;
|
||||||
|
if(!move_to(&target, T))
|
||||||
|
WARNX("move(): can't move to %g with max speed %g", target.coord, target.speed);
|
||||||
|
}
|
||||||
|
DBG("%g: tag/cur speed= %g / %g; tag/cur pos = %g / %g; err = %g", T, target.speed, p.speed, target.coord, p.coord, error);
|
||||||
|
Tcorr = T;
|
||||||
|
}
|
||||||
|
// make log
|
||||||
|
fprintf(coordslog, "%-9.4f\t%-10.4f\t%-10.4f\t%-10.4f\t%-10.4f\t%-10.4f\n",
|
||||||
|
T, nextcoord, p.coord, p.speed, p.accel, error);
|
||||||
|
T += G.dTmon;
|
||||||
|
}
|
||||||
|
printf("\n\n\n"); red("Calculated errors in `guiding` mode:\n");
|
||||||
|
double mean = errsum / (double)N;
|
||||||
|
printf("max error: %g, mean error: %g, std: %g\n\n", errmax, mean, sqrt(errsum2/(double)N - mean*mean));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
sl_init();
|
||||||
|
sl_parseargs(&argc, &argv, opts);
|
||||||
|
if(G.help) sl_showhelp(-1, opts);
|
||||||
|
if(G.xlog){
|
||||||
|
coordslog = fopen(G.xlog, "w");
|
||||||
|
if(!coordslog) ERR("Can't open %s", G.xlog);
|
||||||
|
} else coordslog = stdout;
|
||||||
|
if(G.dTmon <= 0.) ERRX("tmon should be > 0.");
|
||||||
|
if(G.dTcorr <= 0. || G.dTcorr > 1.) ERRX("tcor should be > 0. and < 1.");
|
||||||
|
if(G.Tend <= 0.) ERRX("tend should be > 0.");
|
||||||
|
pidC = pid_create(&G.gainC, PID_I_PERIOD / G.dTcorr);
|
||||||
|
pidV = pid_create(&G.gainV, PID_I_PERIOD / G.dTcorr);
|
||||||
|
if(!pidC || !pidV) ERRX("Can't init PID regulators");
|
||||||
|
model = init_moving(&limits);
|
||||||
|
if(!model) ERRX("Can't init moving model: check parameters");
|
||||||
|
fprintf(coordslog, "%-9s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\n", "time", "target", "curpos", "speed", "accel", "error");
|
||||||
|
start_model(G.Tend);
|
||||||
|
pid_delete(&pidC);
|
||||||
|
pid_delete(&pidV);
|
||||||
|
fclose(coordslog);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
89
LibSidServo/PID_test/moving.c
Normal file
89
LibSidServo/PID_test/moving.c
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "moving.h"
|
||||||
|
#include "moving_private.h"
|
||||||
|
#include "Tramp.h"
|
||||||
|
|
||||||
|
static movemodel_t *model = &trapez;
|
||||||
|
double coord_tolerance = COORD_TOLERANCE_DEFAULT;
|
||||||
|
double time_tick = TIME_TICK_DEFAULT;
|
||||||
|
|
||||||
|
// difference of time from first call, using nanoseconds
|
||||||
|
double nanot(){
|
||||||
|
static struct timespec *start = NULL;
|
||||||
|
struct timespec now;
|
||||||
|
if(!start){
|
||||||
|
start = MALLOC(struct timespec, 1);
|
||||||
|
if(!start) return -1.;
|
||||||
|
if(clock_gettime(CLOCK_REALTIME, start)) return -1.;
|
||||||
|
}
|
||||||
|
if(clock_gettime(CLOCK_REALTIME, &now)) return -1.;
|
||||||
|
//DBG("was: %ld, now: %ld", start->tv_nsec, now.tv_nsec);
|
||||||
|
double nd = ((double)now.tv_nsec - (double)start->tv_nsec) * 1e-9;
|
||||||
|
double sd = (double)now.tv_sec - (double)start->tv_sec;
|
||||||
|
return sd + nd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void chkminmax(double *min, double *max){
|
||||||
|
if(*min <= *max) return;
|
||||||
|
double t = *min;
|
||||||
|
*min = *max;
|
||||||
|
*max = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t *init_moving(limits_t *l){
|
||||||
|
if(!l) return FALSE;
|
||||||
|
if(!model->init_limits) return NULL;
|
||||||
|
moveparam_t *max = &l->max, *min = &l->min;
|
||||||
|
if(min->speed < 0.) min->speed = -min->speed;
|
||||||
|
if(max->speed < 0.) max->speed = -max->speed;
|
||||||
|
if(min->accel < 0.) min->accel = -min->accel;
|
||||||
|
if(max->accel < 0.) max->accel = -max->accel;
|
||||||
|
chkminmax(&min->coord, &max->coord);
|
||||||
|
chkminmax(&min->speed, &max->speed);
|
||||||
|
chkminmax(&min->accel, &max->accel);
|
||||||
|
if(!model->init_limits(l)) return NULL;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
int move_to(moveparam_t *target, double t){
|
||||||
|
if(!target || !model) return FALSE;
|
||||||
|
DBG("MOVE to %g at speed %g", target->coord, target->speed);
|
||||||
|
// only positive velocity
|
||||||
|
if(target->speed < 0.) target->speed = -target->speed;
|
||||||
|
// don't mind about acceleration - user cannot set it now
|
||||||
|
return model->calculate(target, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
int init_coordtol(double tolerance){
|
||||||
|
if(tolerance < COORD_TOLERANCE_MIN || tolerance > COORD_TOLERANCE_MAX) return FALSE;
|
||||||
|
coord_tolerance = tolerance;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
int init_timetick(double tick){
|
||||||
|
if(tick < TIME_TICK_MIN || tick > TIME_TICK_MAX) return FALSE;
|
||||||
|
time_tick = tick;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
62
LibSidServo/PID_test/moving.h
Normal file
62
LibSidServo/PID_test/moving.h
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// tolerance, time ticks
|
||||||
|
#define COORD_TOLERANCE_DEFAULT (0.01)
|
||||||
|
#define COORD_TOLERANCE_MIN (0.0001)
|
||||||
|
#define COORD_TOLERANCE_MAX (10.)
|
||||||
|
#define TIME_TICK_DEFAULT (0.0001)
|
||||||
|
#define TIME_TICK_MIN (1e-9)
|
||||||
|
#define TIME_TICK_MAX (10.)
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
ST_STOP, // stopped
|
||||||
|
ST_MOVE, // moving
|
||||||
|
ST_AMOUNT
|
||||||
|
} movestate_t;
|
||||||
|
|
||||||
|
typedef struct{ // all values could be both as positive and negative
|
||||||
|
double coord;
|
||||||
|
double speed;
|
||||||
|
double accel;
|
||||||
|
} moveparam_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
moveparam_t min;
|
||||||
|
moveparam_t max;
|
||||||
|
} limits_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
int (*init_limits)(limits_t *lim); // init values of limits, jerk
|
||||||
|
int (*calculate)(moveparam_t *target, double t); // calculate stages of traectory beginning from t
|
||||||
|
movestate_t (*proc_move)(moveparam_t *next, double t); // calculate next model point for time t
|
||||||
|
movestate_t (*get_state)(moveparam_t *cur); // get current moving state
|
||||||
|
void (*stop)(double t); // stop by ramp
|
||||||
|
void (*emergency_stop)(double t); // stop with highest acceleration
|
||||||
|
double (*stoppedtime)(); // time when moving will ends
|
||||||
|
} movemodel_t;
|
||||||
|
|
||||||
|
extern double coord_tolerance;
|
||||||
|
|
||||||
|
double nanot();
|
||||||
|
movemodel_t *init_moving(limits_t *l);
|
||||||
|
int init_coordtol(double tolerance);
|
||||||
|
int init_timetick(double tick);
|
||||||
|
int move_to(moveparam_t *target, double t);
|
||||||
1
LibSidServo/PID_test/moving_model.cflags
Normal file
1
LibSidServo/PID_test/moving_model.cflags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-std=c17
|
||||||
4
LibSidServo/PID_test/moving_model.config
Normal file
4
LibSidServo/PID_test/moving_model.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// Add predefined macros for your project here. For example:
|
||||||
|
// #define THE_ANSWER 42
|
||||||
|
#define _XOPEN_SOURCE 666
|
||||||
|
#define EBUG
|
||||||
1
LibSidServo/PID_test/moving_model.creator
Normal file
1
LibSidServo/PID_test/moving_model.creator
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[General]
|
||||||
221
LibSidServo/PID_test/moving_model.creator.user
Normal file
221
LibSidServo/PID_test/moving_model.creator.user
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 17.0.0, 2025-07-29T13:32:31. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">1</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="bool" key="HasPerBcDcs">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/C-files/mountcontrol.git/moving_model</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.ShowReachable">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.ShowReachable">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
184
LibSidServo/PID_test/moving_model.creator.user.7bd84e3
Normal file
184
LibSidServo/PID_test/moving_model.creator.user.7bd84e3
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE QtCreatorProject>
|
||||||
|
<!-- Written by QtCreator 16.0.0, 2025-03-18T22:08:04. -->
|
||||||
|
<qtcreator>
|
||||||
|
<data>
|
||||||
|
<variable>EnvironmentId</variable>
|
||||||
|
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
|
<value type="qlonglong">0</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
|
<value type="QString" key="language">Cpp</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||||
|
<value type="QString" key="language">QmlJS</value>
|
||||||
|
<valuemap type="QVariantMap" key="value">
|
||||||
|
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||||
|
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||||
|
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||||
|
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||||
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
|
<value type="int" key="ClangTools.ParallelJobs">8</value>
|
||||||
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
|
</valuemap>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||||
|
<valuemap type="QVariantMap">
|
||||||
|
<value type="QString" key="DeviceType">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Big/Data/00__Small_tel/moving_model</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">all</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||||
|
</valuemap>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
|
<value type="QString">clean</value>
|
||||||
|
</valuelist>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||||
|
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||||
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
|
</valuemap>
|
||||||
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
|
</valuemap>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
|
<value type="qlonglong">1</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
<data>
|
||||||
|
<variable>Version</variable>
|
||||||
|
<value type="int">22</value>
|
||||||
|
</data>
|
||||||
|
</qtcreator>
|
||||||
1
LibSidServo/PID_test/moving_model.cxxflags
Normal file
1
LibSidServo/PID_test/moving_model.cxxflags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-std=c++17
|
||||||
12
LibSidServo/PID_test/moving_model.files
Normal file
12
LibSidServo/PID_test/moving_model.files
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
Dramp.c
|
||||||
|
Dramp.h
|
||||||
|
PID.c
|
||||||
|
PID.h
|
||||||
|
Sramp.c
|
||||||
|
Sramp.h
|
||||||
|
Tramp.c
|
||||||
|
Tramp.h
|
||||||
|
main.c
|
||||||
|
moving.c
|
||||||
|
moving.h
|
||||||
|
moving_private.h
|
||||||
0
LibSidServo/PID_test/moving_model.includes
Normal file
0
LibSidServo/PID_test/moving_model.includes
Normal file
26
LibSidServo/PID_test/moving_private.h
Normal file
26
LibSidServo/PID_test/moving_private.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "moving.h"
|
||||||
|
|
||||||
|
extern double coord_tolerance;
|
||||||
|
extern double time_tick;
|
||||||
|
|
||||||
|
|
||||||
4
LibSidServo/PID_test/plot
Executable file
4
LibSidServo/PID_test/plot
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
plot for [col in "target curpos speed error"] 'coords' using 1:col with lines title columnheader
|
||||||
|
pause mouse
|
||||||
8
LibSidServo/PID_test/plot.cont
Executable file
8
LibSidServo/PID_test/plot.cont
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
#set term pdf
|
||||||
|
#set output "output.pdf"
|
||||||
|
while(1){
|
||||||
|
plot for [col in "target curpos speed error"] 'coords' using 1:col with lines title columnheader
|
||||||
|
pause 1
|
||||||
|
}
|
||||||
6
LibSidServo/PID_test/plot_jpg
Executable file
6
LibSidServo/PID_test/plot_jpg
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
set terminal jpeg size 1000,500
|
||||||
|
set output "all.jpg"
|
||||||
|
|
||||||
|
plot for [col in "target curpos speed error"] 'coords' using 1:col with lines title columnheader
|
||||||
5
LibSidServo/PID_test/plot_pdf
Executable file
5
LibSidServo/PID_test/plot_pdf
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
set term pdf
|
||||||
|
set output "output.pdf"
|
||||||
|
plot for [col=2:4] 'coordlog' using 1:col with lines title columnheader
|
||||||
4
LibSidServo/PID_test/plotacc
Executable file
4
LibSidServo/PID_test/plotacc
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
plot 'coords' using 1:5 with lines title columnheader
|
||||||
|
pause mouse
|
||||||
4
LibSidServo/PID_test/ploterr
Executable file
4
LibSidServo/PID_test/ploterr
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
plot 'coords' using 1:6 with lines title columnheader
|
||||||
|
pause mouse
|
||||||
6
LibSidServo/PID_test/ploterr.cont
Executable file
6
LibSidServo/PID_test/ploterr.cont
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
plot 'coords' using 1:6 with lines title columnheader
|
||||||
|
pause 1
|
||||||
|
}
|
||||||
5
LibSidServo/PID_test/ploterr_jpg
Executable file
5
LibSidServo/PID_test/ploterr_jpg
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/gnuplot
|
||||||
|
|
||||||
|
set term jpeg size 1000,500
|
||||||
|
set output "error.jpg"
|
||||||
|
plot 'coords' using 1:6 with lines title columnheader
|
||||||
@@ -1,15 +1,3 @@
|
|||||||
1. WTF after closing?
|
fix encoders opening for several tries
|
||||||
|
encoderthread2() - change main cycle (remove pause, read data independently, ask for new only after timeout after last request)
|
||||||
closeSerial (/home/eddy/C-files/LibSidServo/serial.c, line 484): close fd
|
Read HW config even in model mode
|
||||||
|
|
||||||
closeSerial (/home/eddy/C-files/LibSidServo/serial.c, line 489): Kill encoder thread
|
|
||||||
|
|
||||||
closeSerial (/home/eddy/C-files/LibSidServo/serial.c, line 491): close fd
|
|
||||||
*** bit out of range 0 - FD_SETSIZE on fd_set ***: terminated
|
|
||||||
Aborted
|
|
||||||
|
|
||||||
|
|
||||||
2. Init: set "motors" positions due to "encoders" position
|
|
||||||
|
|
||||||
3. From time to time: repeat 2
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <usefull_macros.h>
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
@@ -33,7 +34,9 @@ typedef struct{
|
|||||||
|
|
||||||
static hardware_configuration_t HW = {0};
|
static hardware_configuration_t HW = {0};
|
||||||
|
|
||||||
static parameters G = {0};
|
static parameters G = {
|
||||||
|
.conffile = "servo.conf",
|
||||||
|
};
|
||||||
|
|
||||||
static sl_option_t cmdlnopts[] = {
|
static sl_option_t cmdlnopts[] = {
|
||||||
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
|
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
|
||||||
@@ -50,6 +53,86 @@ static sl_option_t confopts[] = {
|
|||||||
end_option
|
end_option
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void dumpaxis(char axis, axis_config_t *c){
|
||||||
|
#define STRUCTPAR(p) (c)->p
|
||||||
|
#define DUMP(par) do{printf("%c%s=%.10g\n", axis, #par, STRUCTPAR(par));}while(0)
|
||||||
|
#define DUMPD(par) do{printf("%c%s=%g\n", axis, #par, RAD2DEG(STRUCTPAR(par)));}while(0)
|
||||||
|
DUMPD(accel);
|
||||||
|
DUMPD(backlash);
|
||||||
|
DUMPD(errlimit);
|
||||||
|
DUMP(propgain);
|
||||||
|
DUMP(intgain);
|
||||||
|
DUMP(derivgain);
|
||||||
|
DUMP(outplimit);
|
||||||
|
DUMP(currlimit);
|
||||||
|
DUMP(intlimit);
|
||||||
|
DUMP(motor_stepsperrev);
|
||||||
|
DUMP(axis_stepsperrev);
|
||||||
|
#undef DUMP
|
||||||
|
#undef DUMPD
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dumpxbits(xbits_t *c){
|
||||||
|
#define DUMPBIT(f) do{printf("X%s=%d\n", #f, STRUCTPAR(f));}while(0)
|
||||||
|
DUMPBIT(motrev);
|
||||||
|
DUMPBIT(motpolarity);
|
||||||
|
DUMPBIT(encrev);
|
||||||
|
DUMPBIT(dragtrack);
|
||||||
|
DUMPBIT(trackplat);
|
||||||
|
DUMPBIT(handpaden);
|
||||||
|
DUMPBIT(newpad);
|
||||||
|
DUMPBIT(guidemode);
|
||||||
|
#undef DUMPBIT
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dumpybits(ybits_t *c){
|
||||||
|
#define DUMPBIT(f) do{printf("Y%s=%d\n", #f, STRUCTPAR(f));}while(0)
|
||||||
|
DUMPBIT(motrev);
|
||||||
|
DUMPBIT(motpolarity);
|
||||||
|
DUMPBIT(encrev);
|
||||||
|
DUMPBIT(slewtrack);
|
||||||
|
DUMPBIT(digin_sens);
|
||||||
|
printf("Ydigin=%d\n", c->digin);
|
||||||
|
#undef DUMPBIT
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dumpHWconf(){
|
||||||
|
#undef STRUCTPAR
|
||||||
|
#define STRUCTPAR(p) (HW).p
|
||||||
|
#define DUMP(par) do{printf("%s=%g\n", #par, STRUCTPAR(par));}while(0)
|
||||||
|
#define DUMPD(par) do{printf("%s=%g\n", #par, RAD2DEG(STRUCTPAR(par)));}while(0)
|
||||||
|
#define DUMPU8(par) do{printf("%s=%u\n", #par, (uint8_t)STRUCTPAR(par));}while(0)
|
||||||
|
#define DUMPU32(par) do{printf("%s=%u\n", #par, (uint32_t)STRUCTPAR(par));}while(0)
|
||||||
|
green("X axis configuration:\n");
|
||||||
|
dumpaxis('X', &HW.Xconf);
|
||||||
|
green("X bits:\n");
|
||||||
|
dumpxbits(&HW.xbits);
|
||||||
|
green("Y axis configuration:\n");
|
||||||
|
dumpaxis('Y', &HW.Yconf);
|
||||||
|
green("Y bits:\n");
|
||||||
|
dumpybits(&HW.ybits);
|
||||||
|
green("Other:\n");
|
||||||
|
printf("address=%d\n", HW.address);
|
||||||
|
DUMP(eqrate);
|
||||||
|
DUMP(eqadj);
|
||||||
|
DUMP(trackgoal);
|
||||||
|
DUMPD(latitude);
|
||||||
|
DUMPU32(Xsetpr);
|
||||||
|
DUMPU32(Ysetpr);
|
||||||
|
DUMPU32(Xmetpr);
|
||||||
|
DUMPU32(Ymetpr);
|
||||||
|
DUMPD(Xslewrate);
|
||||||
|
DUMPD(Yslewrate);
|
||||||
|
DUMPD(Xpanrate);
|
||||||
|
DUMPD(Ypanrate);
|
||||||
|
DUMPD(Xguiderate);
|
||||||
|
DUMPD(Yguiderate);
|
||||||
|
DUMPU32(baudrate);
|
||||||
|
DUMPD(locsdeg);
|
||||||
|
DUMPD(locsspeed);
|
||||||
|
DUMPD(backlspd);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
sl_init();
|
sl_init();
|
||||||
sl_parseargs(&argc, &argv, cmdlnopts);
|
sl_parseargs(&argc, &argv, cmdlnopts);
|
||||||
@@ -64,13 +147,17 @@ int main(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
if(MCC_E_OK != Mount.init(sconf)) ERRX("Can't init mount");
|
if(MCC_E_OK != Mount.init(sconf)) ERRX("Can't init mount");
|
||||||
if(MCC_E_OK != Mount.getHWconfig(&HW)) ERRX("Can't read configuration");
|
if(MCC_E_OK != Mount.getHWconfig(&HW)) ERRX("Can't read configuration");
|
||||||
|
/*
|
||||||
char *c = sl_print_opts(confopts, TRUE);
|
char *c = sl_print_opts(confopts, TRUE);
|
||||||
green("Got configuration:\n");
|
green("Got configuration:\n");
|
||||||
printf("%s\n", c);
|
printf("%s\n", c);
|
||||||
FREE(c);
|
FREE(c);
|
||||||
|
*/
|
||||||
|
dumpHWconf();
|
||||||
|
/*
|
||||||
if(G.hwconffile && G.writeconf){
|
if(G.hwconffile && G.writeconf){
|
||||||
;
|
;
|
||||||
}
|
}*/
|
||||||
Mount.quit();
|
Mount.quit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,32 @@
|
|||||||
static conf_t Config = {
|
static conf_t Config = {
|
||||||
.MountDevPath = "/dev/ttyUSB0",
|
.MountDevPath = "/dev/ttyUSB0",
|
||||||
.MountDevSpeed = 19200,
|
.MountDevSpeed = 19200,
|
||||||
.EncoderXDevPath = "/dev/encoderX0",
|
.EncoderXDevPath = "/dev/encoder_X0",
|
||||||
.EncoderYDevPath = "/dev/encoderY0",
|
.EncoderYDevPath = "/dev/encoder_Y0",
|
||||||
.EncoderDevSpeed = 153000,
|
.EncoderDevSpeed = 153000,
|
||||||
.MountReqInterval = 0.1,
|
.MountReqInterval = 0.1,
|
||||||
.EncoderReqInterval = 0.05,
|
.EncoderReqInterval = 0.001,
|
||||||
.SepEncoder = 2,
|
.SepEncoder = 2,
|
||||||
.EncoderSpeedInterval = 0.1,
|
.EncoderSpeedInterval = 0.05,
|
||||||
|
.EncodersDisagreement = 1e-5, // 2''
|
||||||
|
.PIDMaxDt = 1.,
|
||||||
|
.PIDRefreshDt = 0.1,
|
||||||
|
.PIDCycleDt = 5.,
|
||||||
|
.XPIDC.P = 0.5,
|
||||||
|
.XPIDC.I = 0.1,
|
||||||
|
.XPIDC.D = 0.2,
|
||||||
|
.XPIDV.P = 0.09,
|
||||||
|
.XPIDV.I = 0.0,
|
||||||
|
.XPIDV.D = 0.05,
|
||||||
|
.YPIDC.P = 0.5,
|
||||||
|
.YPIDC.I = 0.1,
|
||||||
|
.YPIDC.D = 0.2,
|
||||||
|
.YPIDV.P = 0.09,
|
||||||
|
.YPIDV.I = 0.0,
|
||||||
|
.YPIDV.D = 0.05,
|
||||||
|
.MaxPointingErr = 0.13962634,
|
||||||
|
.MaxFinePointingErr = 0.026179939,
|
||||||
|
.MaxGuidingErr = 4.8481368e-7,
|
||||||
};
|
};
|
||||||
|
|
||||||
static sl_option_t opts[] = {
|
static sl_option_t opts[] = {
|
||||||
@@ -38,12 +57,35 @@ static sl_option_t opts[] = {
|
|||||||
{"MountDevSpeed", NEED_ARG, NULL, 0, arg_int, APTR(&Config.MountDevSpeed), "serial speed of mount device"},
|
{"MountDevSpeed", NEED_ARG, NULL, 0, arg_int, APTR(&Config.MountDevSpeed), "serial speed of mount device"},
|
||||||
{"EncoderDevPath", NEED_ARG, NULL, 0, arg_string, APTR(&Config.EncoderDevPath), "path to encoder device"},
|
{"EncoderDevPath", NEED_ARG, NULL, 0, arg_string, APTR(&Config.EncoderDevPath), "path to encoder device"},
|
||||||
{"EncoderDevSpeed", NEED_ARG, NULL, 0, arg_int, APTR(&Config.EncoderDevSpeed), "serial speed of encoder device"},
|
{"EncoderDevSpeed", NEED_ARG, NULL, 0, arg_int, APTR(&Config.EncoderDevSpeed), "serial speed of encoder device"},
|
||||||
{"MountReqInterval",NEED_ARG, NULL, 0, arg_double, APTR(&Config.MountReqInterval), "interval of mount requests (not less than 0.05s)"},
|
{"SepEncoder", NEED_ARG, NULL, 0, arg_int, APTR(&Config.SepEncoder), "encoder is separate device (1 - one device, 2 - two devices)"},
|
||||||
{"EncoderReqInterval",NEED_ARG, NULL, 0, arg_double, APTR(&Config.EncoderReqInterval),"interval of encoder requests (in case of sep=2)"},
|
|
||||||
{"SepEncoder", NO_ARGS, NULL, 0, arg_int, APTR(&Config.SepEncoder), "encoder is separate device (1 - one device, 2 - two devices)"},
|
|
||||||
{"EncoderXDevPath", NEED_ARG, NULL, 0, arg_string, APTR(&Config.EncoderXDevPath), "path to X encoder (/dev/encoderX0)"},
|
{"EncoderXDevPath", NEED_ARG, NULL, 0, arg_string, APTR(&Config.EncoderXDevPath), "path to X encoder (/dev/encoderX0)"},
|
||||||
{"EncoderYDevPath", NEED_ARG, NULL, 0, arg_string, APTR(&Config.EncoderYDevPath), "path to Y encoder (/dev/encoderY0)"},
|
{"EncoderYDevPath", NEED_ARG, NULL, 0, arg_string, APTR(&Config.EncoderYDevPath), "path to Y encoder (/dev/encoderY0)"},
|
||||||
|
{"EncodersDisagreement", NEED_ARG,NULL, 0, arg_double, APTR(&Config.EncodersDisagreement),"acceptable disagreement between motor and axis encoders"},
|
||||||
|
{"MountReqInterval",NEED_ARG, NULL, 0, arg_double, APTR(&Config.MountReqInterval), "interval of mount requests (not less than 0.05s)"},
|
||||||
|
{"EncoderReqInterval",NEED_ARG, NULL, 0, arg_double, APTR(&Config.EncoderReqInterval),"interval of encoder requests (in case of sep=2)"},
|
||||||
{"EncoderSpeedInterval", NEED_ARG,NULL, 0, arg_double, APTR(&Config.EncoderSpeedInterval),"interval of speed calculations, s"},
|
{"EncoderSpeedInterval", NEED_ARG,NULL, 0, arg_double, APTR(&Config.EncoderSpeedInterval),"interval of speed calculations, s"},
|
||||||
|
{"RunModel", NEED_ARG, NULL, 0, arg_int, APTR(&Config.RunModel), "instead of real hardware run emulation"},
|
||||||
|
{"PIDMaxDt", NEED_ARG, NULL, 0, arg_double, APTR(&Config.PIDMaxDt), "maximal PID refresh time interval (if larger all old data will be cleared)"},
|
||||||
|
{"PIDRefreshDt", NEED_ARG, NULL, 0, arg_double, APTR(&Config.PIDRefreshDt), "normal PID refresh interval by master process"},
|
||||||
|
{"PIDCycleDt", NEED_ARG, NULL, 0, arg_double, APTR(&Config.PIDCycleDt), "PID I cycle time (analog of \"RC\" for PID on opamps)"},
|
||||||
|
{"XPIDCP", NEED_ARG, NULL, 0, arg_double, APTR(&Config.XPIDC.P), "P of X PID (coordinate driven)"},
|
||||||
|
{"XPIDCI", NEED_ARG, NULL, 0, arg_double, APTR(&Config.XPIDC.I), "I of X PID (coordinate driven)"},
|
||||||
|
{"XPIDCD", NEED_ARG, NULL, 0, arg_double, APTR(&Config.XPIDC.D), "D of X PID (coordinate driven)"},
|
||||||
|
{"YPIDCP", NEED_ARG, NULL, 0, arg_double, APTR(&Config.YPIDC.P), "P of Y PID (coordinate driven)"},
|
||||||
|
{"YPIDCI", NEED_ARG, NULL, 0, arg_double, APTR(&Config.YPIDC.I), "I of Y PID (coordinate driven)"},
|
||||||
|
{"YPIDCD", NEED_ARG, NULL, 0, arg_double, APTR(&Config.YPIDC.D), "D of Y PID (coordinate driven)"},
|
||||||
|
{"XPIDVP", NEED_ARG, NULL, 0, arg_double, APTR(&Config.XPIDV.P), "P of X PID (velocity driven)"},
|
||||||
|
{"XPIDVI", NEED_ARG, NULL, 0, arg_double, APTR(&Config.XPIDV.I), "I of X PID (velocity driven)"},
|
||||||
|
{"XPIDVD", NEED_ARG, NULL, 0, arg_double, APTR(&Config.XPIDV.D), "D of X PID (velocity driven)"},
|
||||||
|
{"YPIDVP", NEED_ARG, NULL, 0, arg_double, APTR(&Config.YPIDV.P), "P of Y PID (velocity driven)"},
|
||||||
|
{"YPIDVI", NEED_ARG, NULL, 0, arg_double, APTR(&Config.YPIDV.I), "I of Y PID (velocity driven)"},
|
||||||
|
{"YPIDVD", NEED_ARG, NULL, 0, arg_double, APTR(&Config.YPIDV.D), "D of Y PID (velocity driven)"},
|
||||||
|
{"MaxPointingErr", NEED_ARG, NULL, 0, arg_double, APTR(&Config.MaxPointingErr), "if angle < this, change state from \"slewing\" to \"pointing\" (coarse pointing): 8 degrees"},
|
||||||
|
{"MaxFinePointingErr",NEED_ARG, NULL, 0, arg_double, APTR(&Config.MaxFinePointingErr), "if angle < this, chane state from \"pointing\" to \"guiding\" (fine poinging): 1.5 deg"},
|
||||||
|
{"MaxGuidingErr", NEED_ARG, NULL, 0, arg_double, APTR(&Config.MaxGuidingErr), "if error less than this value we suppose that target is captured and guiding is good (true guiding): 0.1''"},
|
||||||
|
{"XEncZero", NEED_ARG, NULL, 0, arg_int, APTR(&Config.XEncZero), "X axis encoder approximate zero position"},
|
||||||
|
{"YEncZero", NEED_ARG, NULL, 0, arg_int, APTR(&Config.YEncZero), "Y axis encoder approximate zero position"},
|
||||||
|
// {"",NEED_ARG, NULL, 0, arg_double, APTR(&Config.), ""},
|
||||||
end_option
|
end_option
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,5 +110,19 @@ void dumpConf(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void confHelp(){
|
void confHelp(){
|
||||||
sl_showhelp(-1, opts);
|
sl_conf_showhelp(-1, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* errcodes[MCC_E_AMOUNT] = {
|
||||||
|
[MCC_E_OK] = "OK",
|
||||||
|
[MCC_E_FATAL] = "Fatal error",
|
||||||
|
[MCC_E_BADFORMAT] = "Wrong data format",
|
||||||
|
[MCC_E_ENCODERDEV] = "Encoder error",
|
||||||
|
[MCC_E_MOUNTDEV] = "Mount error",
|
||||||
|
[MCC_E_FAILED] = "Failed to run"
|
||||||
|
};
|
||||||
|
// return string with error code
|
||||||
|
const char *EcodeStr(mcc_errcodes_t e){
|
||||||
|
if(e >= MCC_E_AMOUNT) return "Wrong error code";
|
||||||
|
return errcodes[e];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,3 +25,4 @@
|
|||||||
void confHelp();
|
void confHelp();
|
||||||
conf_t *readServoConf(const char *filename);
|
conf_t *readServoConf(const char *filename);
|
||||||
void dumpConf();
|
void dumpConf();
|
||||||
|
const char *EcodeStr(mcc_errcodes_t e);
|
||||||
|
|||||||
@@ -23,6 +23,9 @@
|
|||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
#include "simpleconv.h"
|
#include "simpleconv.h"
|
||||||
|
|
||||||
|
// starting dump time (to conform different logs)
|
||||||
|
static struct timespec dumpT0 = {0};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// amount of elements used for encoders' data filtering
|
// amount of elements used for encoders' data filtering
|
||||||
#define NFILT (10)
|
#define NFILT (10)
|
||||||
@@ -59,6 +62,12 @@ static double filter(double val, int idx){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// return starting time of dump
|
||||||
|
void dumpt0(struct timespec *t){
|
||||||
|
if(t) *t = dumpT0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief logmnt - log mount data into file
|
* @brief logmnt - log mount data into file
|
||||||
* @param fcoords - file to dump
|
* @param fcoords - file to dump
|
||||||
@@ -67,17 +76,13 @@ static double filter(double val, int idx){
|
|||||||
void logmnt(FILE *fcoords, mountdata_t *m){
|
void logmnt(FILE *fcoords, mountdata_t *m){
|
||||||
if(!fcoords) return;
|
if(!fcoords) return;
|
||||||
//DBG("LOG %s", m ? "data" : "header");
|
//DBG("LOG %s", m ? "data" : "header");
|
||||||
static double t0 = -1.;
|
|
||||||
if(!m){ // write header
|
if(!m){ // write header
|
||||||
fprintf(fcoords, "# time Xmot(deg) Ymot(deg) Xenc(deg) Yenc(deg) VX(d/s) VY(d/s) millis\n");
|
fprintf(fcoords, " time Xmot(deg) Ymot(deg) Xenc(deg) Yenc(deg) VX(d/s) VY(d/s) millis\n");
|
||||||
return;
|
return;
|
||||||
}
|
}else if(dumpT0.tv_sec == 0) dumpT0 = m->encXposition.t;
|
||||||
double tnow = (m->encXposition.t + m->encYposition.t) / 2.;
|
|
||||||
if(t0 < 0.) t0 = tnow;
|
|
||||||
double t = tnow - t0;
|
|
||||||
// write data
|
// write data
|
||||||
fprintf(fcoords, "%12.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10u\n",
|
fprintf(fcoords, "%12.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10u\n",
|
||||||
t, RAD2DEG(m->motXposition.val), RAD2DEG(m->motYposition.val),
|
Mount.timeDiff(&m->encXposition.t, &dumpT0), RAD2DEG(m->motXposition.val), RAD2DEG(m->motYposition.val),
|
||||||
RAD2DEG(m->encXposition.val), RAD2DEG(m->encYposition.val),
|
RAD2DEG(m->encXposition.val), RAD2DEG(m->encYposition.val),
|
||||||
RAD2DEG(m->encXspeed.val), RAD2DEG(m->encYspeed.val),
|
RAD2DEG(m->encXspeed.val), RAD2DEG(m->encYspeed.val),
|
||||||
m->millis);
|
m->millis);
|
||||||
@@ -103,19 +108,20 @@ void dumpmoving(FILE *fcoords, double t, int N){
|
|||||||
LOGWARN("Can't get mount data");
|
LOGWARN("Can't get mount data");
|
||||||
}
|
}
|
||||||
uint32_t mdmillis = mdata.millis;
|
uint32_t mdmillis = mdata.millis;
|
||||||
double enct = (mdata.encXposition.t + mdata.encYposition.t) / 2.;
|
struct timespec encXt = mdata.encXposition.t;
|
||||||
int ctr = -1;
|
int ctr = -1;
|
||||||
double xlast = mdata.motXposition.val, ylast = mdata.motYposition.val;
|
double xlast = mdata.motXposition.val, ylast = mdata.motYposition.val;
|
||||||
double t0 = Mount.currentT();
|
double t0 = Mount.timeFromStart();
|
||||||
while(Mount.currentT() - t0 < t && ctr < N){
|
while(Mount.timeFromStart() - t0 < t && ctr < N){
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
||||||
double tmsr = (mdata.encXposition.t + mdata.encYposition.t) / 2.;
|
//double tmsr = (mdata.encXposition.t + mdata.encYposition.t) / 2.;
|
||||||
if(tmsr == enct) continue;
|
struct timespec msrt = mdata.encXposition.t;
|
||||||
enct = tmsr;
|
if(msrt.tv_nsec == encXt.tv_nsec) continue;
|
||||||
|
encXt = msrt;
|
||||||
if(fcoords) logmnt(fcoords, &mdata);
|
if(fcoords) logmnt(fcoords, &mdata);
|
||||||
if(mdata.millis == mdmillis) continue;
|
if(mdata.millis == mdmillis) continue;
|
||||||
//DBG("ctr=%d", ctr);
|
//DBG("ctr=%d, motpos=%g/%g", ctr, mdata.motXposition.val, mdata.motYposition.val);
|
||||||
mdmillis = mdata.millis;
|
mdmillis = mdata.millis;
|
||||||
if(mdata.motXposition.val != xlast || mdata.motYposition.val != ylast){
|
if(mdata.motXposition.val != xlast || mdata.motYposition.val != ylast){
|
||||||
xlast = mdata.motXposition.val;
|
xlast = mdata.motXposition.val;
|
||||||
@@ -123,27 +129,26 @@ void dumpmoving(FILE *fcoords, double t, int N){
|
|||||||
ctr = 0;
|
ctr = 0;
|
||||||
}else ++ctr;
|
}else ++ctr;
|
||||||
}
|
}
|
||||||
|
DBG("Exit dumping; tend=%g, tmon=%g", t, Mount.timeFromStart() - t0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief waitmoving - wait until moving by both axes stops at least for N cycles
|
* @brief waitmoving - wait until moving by both axiss stops at least for N cycles
|
||||||
* @param N - amount of stopped cycles
|
* @param N - amount of stopped cycles
|
||||||
*/
|
*/
|
||||||
void waitmoving(int N){
|
void waitmoving(int N){
|
||||||
mountdata_t mdata;
|
mountdata_t mdata;
|
||||||
int ctr = -1;
|
int ctr = -1;
|
||||||
uint32_t millis = 0;
|
uint32_t millis = 0;
|
||||||
double xlast = 0., ylast = 0.;
|
//double xlast = 0., ylast = 0.;
|
||||||
|
DBG("Wait moving for %d stopped times", N);
|
||||||
while(ctr < N){
|
while(ctr < N){
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
||||||
if(mdata.millis == millis) continue;
|
if(mdata.millis == millis) continue;
|
||||||
millis = mdata.millis;
|
millis = mdata.millis;
|
||||||
if(mdata.motXposition.val != xlast || mdata.motYposition.val != ylast){
|
if(mdata.Xstate != AXIS_STOPPED || mdata.Ystate != AXIS_STOPPED) ctr = 0;
|
||||||
xlast = mdata.motXposition.val;
|
else ++ctr;
|
||||||
ylast = mdata.motYposition.val;
|
|
||||||
ctr = 0;
|
|
||||||
}else ++ctr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,3 +27,4 @@ void dumpmoving(FILE *fcoords, double t, int N);
|
|||||||
void waitmoving(int N);
|
void waitmoving(int N);
|
||||||
int getPos(coordval_pair_t *mot, coordval_pair_t *enc);
|
int getPos(coordval_pair_t *mot, coordval_pair_t *enc);
|
||||||
void chk0(int ncycles);
|
void chk0(int ncycles);
|
||||||
|
void dumpt0(struct timespec *t);
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ int main(int argc, char **argv){
|
|||||||
conf_t *Config = readServoConf(G.conffile);
|
conf_t *Config = readServoConf(G.conffile);
|
||||||
if(!Config){
|
if(!Config){
|
||||||
dumpConf();
|
dumpConf();
|
||||||
|
confHelp();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(G.coordsoutput){
|
if(G.coordsoutput){
|
||||||
|
|||||||
@@ -120,16 +120,13 @@ static coordpair_t lastTag = {0}, lastSpeed = {0};
|
|||||||
|
|
||||||
// slew to given position and start tracking
|
// slew to given position and start tracking
|
||||||
// pos/speed in deg and deg/s
|
// pos/speed in deg and deg/s
|
||||||
static mcc_errcodes_t gotos(coordpair_t *target, coordpair_t *speed){
|
static mcc_errcodes_t gotos(const coordpair_t *target, const coordpair_t *speed){
|
||||||
short_command_t cmd = {0};
|
short_command_t cmd = {0};
|
||||||
DBG("Try to move to (%g, %g) with speed (%g, %g)",
|
DBG("Try to move to (%g, %g) with speed (%g, %g)",
|
||||||
target->X, target->Y, speed->X, speed->Y);
|
target->X, target->Y, speed->X, speed->Y);
|
||||||
target->X = DEG2RAD(target->X);
|
cmd.Xmot = DEG2RAD(target->X); cmd.Ymot = DEG2RAD(target->Y);
|
||||||
target->Y = DEG2RAD(target->Y);
|
cmd.Xspeed = DEG2RAD(speed->X);
|
||||||
speed->X = DEG2RAD(speed->X);
|
cmd.Yspeed = DEG2RAD(speed->Y);
|
||||||
speed->Y = DEG2RAD(speed->Y);
|
|
||||||
cmd.Xmot = target->X; cmd.Ymot = target->Y;
|
|
||||||
cmd.Xspeed = speed->X; cmd.Yspeed = speed->Y;
|
|
||||||
lastTag = *target;
|
lastTag = *target;
|
||||||
lastSpeed = *speed;
|
lastSpeed = *speed;
|
||||||
/*cmd.xychange = 1;
|
/*cmd.xychange = 1;
|
||||||
@@ -142,7 +139,10 @@ static mcc_errcodes_t return2zero(){
|
|||||||
short_command_t cmd = {0};
|
short_command_t cmd = {0};
|
||||||
DBG("Try to move to zero");
|
DBG("Try to move to zero");
|
||||||
cmd.Xmot = 0.; cmd.Ymot = 0.;
|
cmd.Xmot = 0.; cmd.Ymot = 0.;
|
||||||
cmd.Xspeed = DEG2RAD(10.); cmd.Yspeed = DEG2RAD(10.);
|
coordpair_t maxspd;
|
||||||
|
if(MCC_E_OK != Mount.getMaxSpeed(&maxspd)) return MCC_E_FAILED;
|
||||||
|
cmd.Xspeed = maxspd.X;
|
||||||
|
cmd.Yspeed = maxspd.Y;
|
||||||
/*cmd.xychange = 1;
|
/*cmd.xychange = 1;
|
||||||
cmd.XBits = 100;
|
cmd.XBits = 100;
|
||||||
cmd.YBits = 20;*/
|
cmd.YBits = 20;*/
|
||||||
@@ -151,11 +151,11 @@ static mcc_errcodes_t return2zero(){
|
|||||||
|
|
||||||
static mcc_errcodes_t mkcorr(coordpair_t *adder, coordpair_t *time){
|
static mcc_errcodes_t mkcorr(coordpair_t *adder, coordpair_t *time){
|
||||||
long_command_t cmd = {0};
|
long_command_t cmd = {0};
|
||||||
cmd.Xspeed = lastSpeed.X;
|
cmd.Xspeed = DEG2RAD(lastSpeed.X);
|
||||||
cmd.Yspeed = lastSpeed.Y;
|
cmd.Yspeed = DEG2RAD(lastSpeed.Y);
|
||||||
cmd.Xmot = lastTag.X;
|
cmd.Xmot = DEG2RAD(lastTag.X);
|
||||||
cmd.Ymot = lastTag.Y;
|
cmd.Ymot = DEG2RAD(lastTag.Y);
|
||||||
cmd.Xadder = adder->X; cmd.Yadder = adder->Y;
|
cmd.Xadder = DEG2RAD(adder->X); cmd.Yadder = DEG2RAD(adder->Y);
|
||||||
cmd.Xatime = time->X; cmd.Yatime = time->Y;
|
cmd.Xatime = time->X; cmd.Yatime = time->Y;
|
||||||
return Mount.longCmd(&cmd);
|
return Mount.longCmd(&cmd);
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ int main(int argc, char **argv){
|
|||||||
sleep(5);
|
sleep(5);
|
||||||
// return to zero and wait
|
// return to zero and wait
|
||||||
green("Return 2 zero and wait\n");
|
green("Return 2 zero and wait\n");
|
||||||
return2zero();
|
if(MCC_E_OK != return2zero()) ERRX("Can't return");
|
||||||
Wait(0., 0);
|
Wait(0., 0);
|
||||||
Wait(0., 1);
|
Wait(0., 1);
|
||||||
// wait moving ends
|
// wait moving ends
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ static sl_option_t cmdlnopts[] = {
|
|||||||
{"coordsfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"output file with coordinates log"},
|
{"coordsfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"output file with coordinates log"},
|
||||||
{"axis", NEED_ARG, NULL, 'a', arg_string, APTR(&G.axis), "axis to move (X or Y)"},
|
{"axis", NEED_ARG, NULL, 'a', arg_string, APTR(&G.axis), "axis to move (X or Y)"},
|
||||||
{"period", NEED_ARG, NULL, 'p', arg_double, APTR(&G.period), "swinging period (could be not reached if amplitude is too small) - not more than 900s (default: 1)"},
|
{"period", NEED_ARG, NULL, 'p', arg_double, APTR(&G.period), "swinging period (could be not reached if amplitude is too small) - not more than 900s (default: 1)"},
|
||||||
{"amplitude", NEED_ARG, NULL, 'A', arg_double, APTR(&G.amplitude), "max amplitude (could be not reaced if period is too small) - not more than 45deg (default: 5)"},
|
{"amplitude", NEED_ARG, NULL, 'A', arg_double, APTR(&G.amplitude), "max amplitude (could be not reached if period is too small): [-45:45]deg (default: 5)"},
|
||||||
{"nswings", NEED_ARG, NULL, 'N', arg_int, APTR(&G.Nswings), "amount of swing periods (default: 10)"},
|
{"nswings", NEED_ARG, NULL, 'N', arg_int, APTR(&G.Nswings), "amount of swing periods (default: 10)"},
|
||||||
{"conffile", NEED_ARG, NULL, 'C', arg_int, APTR(&G.conffile), "configuration file name"},
|
{"conffile", NEED_ARG, NULL, 'C', arg_int, APTR(&G.conffile), "configuration file name"},
|
||||||
end_option
|
end_option
|
||||||
@@ -83,18 +83,18 @@ void waithalf(double t){
|
|||||||
uint32_t millis = 0;
|
uint32_t millis = 0;
|
||||||
double xlast = 0., ylast = 0.;
|
double xlast = 0., ylast = 0.;
|
||||||
while(ctr < 5){
|
while(ctr < 5){
|
||||||
if(Mount.currentT() >= t) return;
|
if(Mount.timeFromStart() >= t) return;
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
if(MCC_E_OK != Mount.getMountData(&mdata)){ WARNX("Can't get data"); continue;}
|
||||||
if(mdata.millis == millis) continue;
|
if(mdata.millis == millis) continue;
|
||||||
millis = mdata.millis;
|
millis = mdata.millis;
|
||||||
if(mdata.motXposition.val != xlast || mdata.motYposition.val != ylast){
|
if(mdata.motXposition.val != xlast || mdata.motYposition.val != ylast){
|
||||||
DBG("NEQ: old=%g, now=%g", RAD2DEG(ylast), RAD2DEG(mdata.motYposition.val));
|
//DBG("NEQ: old=%g, now=%g", RAD2DEG(ylast), RAD2DEG(mdata.motYposition.val));
|
||||||
xlast = mdata.motXposition.val;
|
xlast = mdata.motXposition.val;
|
||||||
ylast = mdata.motYposition.val;
|
ylast = mdata.motYposition.val;
|
||||||
ctr = 0;
|
ctr = 0;
|
||||||
}else{
|
}else{
|
||||||
DBG("EQ: old=%g, now=%g", RAD2DEG(ylast), RAD2DEG(mdata.motYposition.val));
|
//DBG("EQ: old=%g, now=%g", RAD2DEG(ylast), RAD2DEG(mdata.motYposition.val));
|
||||||
++ctr;
|
++ctr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,15 +110,28 @@ int main(int argc, char **argv){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(G.coordsoutput){
|
if(G.coordsoutput){
|
||||||
if(!(fcoords = fopen(G.coordsoutput, "w")))
|
if(!(fcoords = fopen(G.coordsoutput, "w"))){
|
||||||
ERRX("Can't open %s", G.coordsoutput);
|
WARNX("Can't open %s", G.coordsoutput);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}else fcoords = stdout;
|
}else fcoords = stdout;
|
||||||
if(G.Ncycles < 7) ERRX("Ncycles should be >7");
|
if(G.Ncycles < 2){
|
||||||
if(G.amplitude < 0.01 || G.amplitude > 45.)
|
WARNX("Ncycles should be >2");
|
||||||
ERRX("Amplitude should be from 0.01 to 45 degrees");
|
return 1;
|
||||||
if(G.period < 0.1 || G.period > 900.)
|
}
|
||||||
ERRX("Period should be from 0.1 to 900s");
|
double absamp = fabs(G.amplitude);
|
||||||
if(G.Nswings < 1) ERRX("Nswings should be more than 0");
|
if(absamp < 0.01 || absamp > 45.){
|
||||||
|
WARNX("Amplitude should be from 0.01 to 45 degrees");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(G.period < 0.1 || G.period > 900.){
|
||||||
|
WARNX("Period should be from 0.1 to 900s");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(G.Nswings < 1){
|
||||||
|
WARNX("Nswings should be more than 0");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
conf_t *Config = readServoConf(G.conffile);
|
conf_t *Config = readServoConf(G.conffile);
|
||||||
if(!Config){
|
if(!Config){
|
||||||
dumpConf();
|
dumpConf();
|
||||||
@@ -145,26 +158,30 @@ int main(int argc, char **argv){
|
|||||||
}else{
|
}else{
|
||||||
tagX = 0.; tagY = DEG2RAD(G.amplitude);
|
tagX = 0.; tagY = DEG2RAD(G.amplitude);
|
||||||
}
|
}
|
||||||
double t = Mount.currentT(), t0 = t;
|
double t = Mount.timeFromStart(), t0 = t;
|
||||||
coordpair_t tag = {.X = tagX, .Y = tagY}, rtag = {.X = -tagX, .Y = -tagY};
|
coordpair_t tag = {.X = tagX, .Y = tagY}, rtag = {.X = -tagX, .Y = -tagY};
|
||||||
double divide = 2.;
|
double divide = 2.;
|
||||||
for(int i = 0; i < G.Nswings; ++i){
|
for(int i = 0; i < G.Nswings; ++i){
|
||||||
Mount.moveTo(&tag);
|
Mount.moveTo(&tag);
|
||||||
DBG("CMD: %g", Mount.currentT()-t0);
|
DBG("CMD: %g", Mount.timeFromStart()-t0);
|
||||||
t += G.period / divide;
|
t += G.period / divide;
|
||||||
divide = 1.;
|
divide = 1.;
|
||||||
waithalf(t);
|
waithalf(t);
|
||||||
DBG("Moved to +, t=%g", t-t0);
|
DBG("Moved to +, t=%g", t-t0);
|
||||||
DBG("CMD: %g", Mount.currentT()-t0);
|
DBG("CMD: %g", Mount.timeFromStart()-t0);
|
||||||
Mount.moveTo(&rtag);
|
Mount.moveTo(&rtag);
|
||||||
t += G.period;
|
t += G.period;
|
||||||
waithalf(t);
|
waithalf(t);
|
||||||
DBG("Moved to -, t=%g", t-t0);
|
DBG("Moved to -, t=%g", t-t0);
|
||||||
DBG("CMD: %g", Mount.currentT()-t0);
|
DBG("CMD: %g", Mount.timeFromStart()-t0);
|
||||||
}
|
}
|
||||||
tag = (coordpair_t){.X = 0., .Y = 0.};
|
green("Move to zero @ %g\n", Mount.timeFromStart());
|
||||||
|
tag = (coordpair_t){0};
|
||||||
// be sure to move @ 0,0
|
// be sure to move @ 0,0
|
||||||
|
if(MCC_E_OK != Mount.moveTo(&tag)){
|
||||||
|
Mount.emergStop();
|
||||||
Mount.moveTo(&tag);
|
Mount.moveTo(&tag);
|
||||||
|
}
|
||||||
// wait moving ends
|
// wait moving ends
|
||||||
pthread_join(dthr, NULL);
|
pthread_join(dthr, NULL);
|
||||||
#undef SCMD
|
#undef SCMD
|
||||||
|
|||||||
@@ -61,12 +61,13 @@ static FILE* fcoords = NULL;
|
|||||||
static pthread_t dthr;
|
static pthread_t dthr;
|
||||||
|
|
||||||
void signals(int sig){
|
void signals(int sig){
|
||||||
pthread_cancel(dthr);
|
|
||||||
if(sig){
|
if(sig){
|
||||||
signal(sig, SIG_IGN);
|
signal(sig, SIG_IGN);
|
||||||
DBG("Get signal %d, quit.\n", sig);
|
DBG("Get signal %d, quit.\n", sig);
|
||||||
}
|
}
|
||||||
|
DBG("Quit");
|
||||||
Mount.quit();
|
Mount.quit();
|
||||||
|
DBG("close");
|
||||||
if(fcoords) fclose(fcoords);
|
if(fcoords) fclose(fcoords);
|
||||||
exit(sig);
|
exit(sig);
|
||||||
}
|
}
|
||||||
@@ -90,11 +91,10 @@ int main(int _U_ argc, char _U_ **argv){
|
|||||||
if(MCC_E_OK != Mount.init(Config)) ERRX("Can't init mount");
|
if(MCC_E_OK != Mount.init(Config)) ERRX("Can't init mount");
|
||||||
coordval_pair_t M, E;
|
coordval_pair_t M, E;
|
||||||
if(!getPos(&M, &E)) ERRX("Can't get current position");
|
if(!getPos(&M, &E)) ERRX("Can't get current position");
|
||||||
|
printf("Current time: %.10f\n", Mount.timeFromStart());
|
||||||
if(G.coordsoutput){
|
if(G.coordsoutput){
|
||||||
if(!G.wait) green("When logging I should wait until moving ends; added '-w'");
|
if(!G.wait) green("When logging I should wait until moving ends; added '-w'\n");
|
||||||
G.wait = 1;
|
G.wait = 1;
|
||||||
}
|
|
||||||
if(G.coordsoutput){
|
|
||||||
if(!(fcoords = fopen(G.coordsoutput, "w")))
|
if(!(fcoords = fopen(G.coordsoutput, "w")))
|
||||||
ERRX("Can't open %s", G.coordsoutput);
|
ERRX("Can't open %s", G.coordsoutput);
|
||||||
logmnt(fcoords, NULL);
|
logmnt(fcoords, NULL);
|
||||||
@@ -120,7 +120,11 @@ int main(int _U_ argc, char _U_ **argv){
|
|||||||
}
|
}
|
||||||
printf("Moving to X=%gdeg, Y=%gdeg\n", G.X, G.Y);
|
printf("Moving to X=%gdeg, Y=%gdeg\n", G.X, G.Y);
|
||||||
tag.X = DEG2RAD(G.X); tag.Y = DEG2RAD(G.Y);
|
tag.X = DEG2RAD(G.X); tag.Y = DEG2RAD(G.Y);
|
||||||
Mount.moveTo(&tag);
|
mcc_errcodes_t e = Mount.moveTo(&tag);
|
||||||
|
if(MCC_E_OK != e){
|
||||||
|
WARNX("Cant go to given coordinates: %s\n", EcodeStr(e));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
if(G.wait){
|
if(G.wait){
|
||||||
sleep(1);
|
sleep(1);
|
||||||
waitmoving(G.Ncycles);
|
waitmoving(G.Ncycles);
|
||||||
@@ -132,7 +136,9 @@ out:
|
|||||||
if(G.coordsoutput) pthread_join(dthr, NULL);
|
if(G.coordsoutput) pthread_join(dthr, NULL);
|
||||||
DBG("QUIT");
|
DBG("QUIT");
|
||||||
if(G.wait){
|
if(G.wait){
|
||||||
if(getPos(&M, NULL)) printf("Mount position: X=%g, Y=%g\n", RAD2DEG(M.X.val), RAD2DEG(M.Y.val));
|
usleep(250000); // pause to refresh coordinates
|
||||||
|
if(getPos(&M, &E)) printf("Mount position: X=%g, Y=%g; encoders: X=%g, Y=%g\n", RAD2DEG(M.X.val), RAD2DEG(M.Y.val),
|
||||||
|
RAD2DEG(E.X.val), RAD2DEG(E.Y.val));
|
||||||
Mount.quit();
|
Mount.quit();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int help;
|
int help;
|
||||||
|
int dumpconf;
|
||||||
int Ncycles; // n cycles to wait stop
|
int Ncycles; // n cycles to wait stop
|
||||||
double reqint; // requests interval (seconds)
|
double reqint; // requests interval (seconds)
|
||||||
double Xmax; // maximal X to stop
|
double Xmax; // maximal X to stop
|
||||||
@@ -38,11 +39,13 @@ typedef struct{
|
|||||||
double X0; // starting point of traectory (-30..30 degr)
|
double X0; // starting point of traectory (-30..30 degr)
|
||||||
double Y0; // -//-
|
double Y0; // -//-
|
||||||
char *coordsoutput; // dump file
|
char *coordsoutput; // dump file
|
||||||
|
char *errlog; // log with position errors
|
||||||
char *tfn; // traectory function name
|
char *tfn; // traectory function name
|
||||||
char *conffile;
|
char *conffile;
|
||||||
} parameters;
|
} parameters;
|
||||||
|
|
||||||
static FILE *fcoords = NULL;
|
static conf_t *Config = NULL;
|
||||||
|
static FILE *fcoords = NULL, *errlog = NULL;
|
||||||
static pthread_t dthr;
|
static pthread_t dthr;
|
||||||
static parameters G = {
|
static parameters G = {
|
||||||
.Ncycles = 40,
|
.Ncycles = 40,
|
||||||
@@ -61,21 +64,24 @@ static sl_option_t cmdlnopts[] = {
|
|||||||
{"coordsfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"output file with coordinates log"},
|
{"coordsfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.coordsoutput),"output file with coordinates log"},
|
||||||
{"reqinterval", NEED_ARG, NULL, 'i', arg_double, APTR(&G.reqint), "mount requests interval (default: 0.1 second)"},
|
{"reqinterval", NEED_ARG, NULL, 'i', arg_double, APTR(&G.reqint), "mount requests interval (default: 0.1 second)"},
|
||||||
{"traectory", NEED_ARG, NULL, 't', arg_string, APTR(&G.tfn), "used traectory function (default: sincos)"},
|
{"traectory", NEED_ARG, NULL, 't', arg_string, APTR(&G.tfn), "used traectory function (default: sincos)"},
|
||||||
{"xmax", NEED_ARG, NULL, 'X', arg_double, APTR(&G.Xmax), "maximal X coordinate for traectory (default: 45 degrees)"},
|
{"xmax", NEED_ARG, NULL, 'X', arg_double, APTR(&G.Xmax), "maximal abs X coordinate for traectory (default: 45 degrees)"},
|
||||||
{"ymax", NEED_ARG, NULL, 'Y', arg_double, APTR(&G.Ymax), "maximal X coordinate for traectory (default: 45 degrees)"},
|
{"ymax", NEED_ARG, NULL, 'Y', arg_double, APTR(&G.Ymax), "maximal abs Y coordinate for traectory (default: 45 degrees)"},
|
||||||
{"tmax", NEED_ARG, NULL, 'T', arg_double, APTR(&G.tmax), "maximal duration time of emulation (default: 300 seconds)"},
|
{"tmax", NEED_ARG, NULL, 'T', arg_double, APTR(&G.tmax), "maximal duration time of emulation (default: 300 seconds)"},
|
||||||
{"x0", NEED_ARG, NULL, '0', arg_double, APTR(&G.X0), "starting X-coordinate of traectory (default: 10 degrees)"},
|
{"x0", NEED_ARG, NULL, '0', arg_double, APTR(&G.X0), "starting X-coordinate of traectory (default: 10 degrees)"},
|
||||||
{"y0", NEED_ARG, NULL, '1', arg_double, APTR(&G.Y0), "starting Y-coordinate of traectory (default: 10 degrees)"},
|
{"y0", NEED_ARG, NULL, '1', arg_double, APTR(&G.Y0), "starting Y-coordinate of traectory (default: 10 degrees)"},
|
||||||
{"conffile", NEED_ARG, NULL, 'C', arg_string, APTR(&G.conffile), "configuration file name"},
|
{"conffile", NEED_ARG, NULL, 'C', arg_string, APTR(&G.conffile), "configuration file name"},
|
||||||
|
{"errlog", NEED_ARG, NULL, 'e', arg_string, APTR(&G.errlog), "file with errors log"},
|
||||||
|
{"dumpconf", NO_ARGS, NULL, 'D', arg_int, APTR(&G.dumpconf), "dump current configuration"},
|
||||||
end_option
|
end_option
|
||||||
};
|
};
|
||||||
|
|
||||||
void signals(int sig){
|
void signals(int sig){
|
||||||
pthread_cancel(dthr);
|
|
||||||
if(sig){
|
if(sig){
|
||||||
signal(sig, SIG_IGN);
|
signal(sig, SIG_IGN);
|
||||||
DBG("Get signal %d, quit.\n", sig);
|
DBG("Get signal %d, quit.\n", sig);
|
||||||
}
|
}
|
||||||
|
Mount.stop();
|
||||||
|
sleep(1);
|
||||||
Mount.quit();
|
Mount.quit();
|
||||||
if(fcoords) fclose(fcoords);
|
if(fcoords) fclose(fcoords);
|
||||||
exit(sig);
|
exit(sig);
|
||||||
@@ -90,22 +96,39 @@ static void *dumping(void _U_ *u){
|
|||||||
static void runtraectory(traectory_fn tfn){
|
static void runtraectory(traectory_fn tfn){
|
||||||
if(!tfn) return;
|
if(!tfn) return;
|
||||||
coordval_pair_t telXY;
|
coordval_pair_t telXY;
|
||||||
|
coordval_pair_t target;
|
||||||
coordpair_t traectXY;
|
coordpair_t traectXY;
|
||||||
double t0 = Mount.currentT();
|
double tlast = 0., tstart = Mount.timeFromStart();
|
||||||
double tlast = 0.;
|
long tlastXnsec = 0, tlastYnsec = 0;
|
||||||
|
struct timespec tcur, t0 = {0};
|
||||||
|
dumpt0(&t0);
|
||||||
while(1){
|
while(1){
|
||||||
if(!telpos(&telXY)){
|
if(!telpos(&telXY)){
|
||||||
WARNX("No next telescope position");
|
WARNX("No next telescope position");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(telXY.X.t == tlast && telXY.Y.t == tlast) continue; // last measure - don't mind
|
if(!Mount.currentT(&tcur)) continue;
|
||||||
tlast = (telXY.X.t + telXY.Y.t) / 2.;
|
if(telXY.X.t.tv_nsec == tlastXnsec && telXY.Y.t.tv_nsec == tlastYnsec) continue; // last measure - don't mind
|
||||||
double t = Mount.currentT();
|
DBG("\n\nTELPOS: %g'/%g' (%.6f/%.6f)", RAD2AMIN(telXY.X.val), RAD2AMIN(telXY.Y.val), RAD2DEG(telXY.X.val), RAD2DEG(telXY.Y.val));
|
||||||
if(telXY.X.val > G.Xmax || telXY.Y.val > G.Ymax || t - t0 > G.tmax) break;
|
tlastXnsec = telXY.X.t.tv_nsec; tlastYnsec = telXY.Y.t.tv_nsec;
|
||||||
|
double t = Mount.timeFromStart();
|
||||||
|
if(fabs(telXY.X.val) > G.Xmax || fabs(telXY.Y.val) > G.Ymax || t - tstart > G.tmax) break;
|
||||||
if(!traectory_point(&traectXY, t)) break;
|
if(!traectory_point(&traectXY, t)) break;
|
||||||
DBG("%g: dX=%.1f'', dY=%.1f''", t-t0, RAD2ASEC(traectXY.X-telXY.X.val), RAD2ASEC(traectXY.Y-telXY.Y.val));
|
target.X.val = traectXY.X; target.Y.val = traectXY.Y;
|
||||||
|
target.X.t = target.Y.t = tcur;
|
||||||
|
if(t0.tv_nsec == 0 && t0.tv_sec == 0) dumpt0(&t0);
|
||||||
|
else{
|
||||||
|
//DBG("target: %g'/%g'", RAD2AMIN(traectXY.X), RAD2AMIN(traectXY.Y));
|
||||||
|
DBG("%g: dX=%.4f'', dY=%.4f''", t-tstart, RAD2ASEC(traectXY.X-telXY.X.val), RAD2ASEC(traectXY.Y-telXY.Y.val));
|
||||||
|
//DBG("Correct to: %g/%g with EP %g/%g", RAD2DEG(target.X.val), RAD2DEG(target.Y.val), RAD2DEG(endpoint.X), RAD2DEG(endpoint.Y));
|
||||||
|
if(errlog)
|
||||||
|
fprintf(errlog, "%10.4f %10.4f %10.4f\n", Mount.timeDiff(&telXY.X.t, &t0), RAD2ASEC(traectXY.X-telXY.X.val), RAD2ASEC(traectXY.Y-telXY.Y.val));
|
||||||
}
|
}
|
||||||
WARNX("No next traectory point");
|
if(MCC_E_OK != Mount.correctTo(&target)) WARNX("Error of correction!");
|
||||||
|
while((t = Mount.timeFromStart()) - tlast < Config->PIDRefreshDt) usleep(500);
|
||||||
|
tlast = t;
|
||||||
|
}
|
||||||
|
WARNX("No next traectory point or emulation ends");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
@@ -118,12 +141,18 @@ int main(int argc, char **argv){
|
|||||||
G.Xmax = DEG2RAD(G.Xmax); G.Ymax = DEG2RAD(G.Ymax);
|
G.Xmax = DEG2RAD(G.Xmax); G.Ymax = DEG2RAD(G.Ymax);
|
||||||
if(G.X0 < -30. || G.X0 > 30. || G.Y0 < -30. || G.Y0 > 30.)
|
if(G.X0 < -30. || G.X0 > 30. || G.Y0 < -30. || G.Y0 > 30.)
|
||||||
ERRX("X0 and Y0 should be -30..30 degrees");
|
ERRX("X0 and Y0 should be -30..30 degrees");
|
||||||
|
if(G.errlog){
|
||||||
|
if(!(errlog = fopen(G.errlog, "w")))
|
||||||
|
ERRX("Can't open error log %s", G.errlog);
|
||||||
|
else
|
||||||
|
fprintf(errlog, "# time Xerr'' Yerr'' // target - real\n");
|
||||||
|
}
|
||||||
if(G.coordsoutput){
|
if(G.coordsoutput){
|
||||||
if(!(fcoords = fopen(G.coordsoutput, "w")))
|
if(!(fcoords = fopen(G.coordsoutput, "w")))
|
||||||
ERRX("Can't open %s", G.coordsoutput);
|
ERRX("Can't open %s", G.coordsoutput);
|
||||||
}else fcoords = stdout;
|
}else fcoords = stdout;
|
||||||
conf_t *Config = readServoConf(G.conffile);
|
Config = readServoConf(G.conffile);
|
||||||
if(!Config){
|
if(!Config || G.dumpconf){
|
||||||
dumpConf();
|
dumpConf();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,25 @@
|
|||||||
|
# Current configuration
|
||||||
MountDevPath=/dev/ttyUSB0
|
MountDevPath=/dev/ttyUSB0
|
||||||
MountDevSpeed=19200
|
MountDevSpeed=19200
|
||||||
|
EncoderDevPath=(null)
|
||||||
|
EncoderDevSpeed=1000000
|
||||||
|
MountReqInterval=0.1
|
||||||
|
EncoderReqInterval=0.001
|
||||||
|
SepEncoder=2
|
||||||
EncoderXDevPath=/dev/encoder_X0
|
EncoderXDevPath=/dev/encoder_X0
|
||||||
EncoderYDevPath=/dev/encoder_Y0
|
EncoderYDevPath=/dev/encoder_Y0
|
||||||
MountReqInterval=0.05
|
|
||||||
SepEncoder=2
|
|
||||||
EncoderReqInterval=0.001
|
|
||||||
EncoderDevSpeed=1000000
|
|
||||||
EncoderSpeedInterval=0.05
|
EncoderSpeedInterval=0.05
|
||||||
|
RunModel=1
|
||||||
|
XPIDCP=0.8
|
||||||
|
XPIDCI=0.0
|
||||||
|
XPIDCD=0.0
|
||||||
|
YPIDCP=0.5
|
||||||
|
YPIDCI=0.0
|
||||||
|
YPIDCD=0.0
|
||||||
|
XPIDVP=0.2
|
||||||
|
XPIDVI=0.1
|
||||||
|
XPIDVD=0.0
|
||||||
|
YPIDVP=0.2
|
||||||
|
YPIDVI=0.1
|
||||||
|
YPIDVD=0.0
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,10 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define DEG2RAD(d) (d/180.*M_PI)
|
#define DEG2RAD(d) ((d)/180.*M_PI)
|
||||||
#define ASEC2RAD(d) (d/180.*M_PI/3600.)
|
#define ASEC2RAD(d) ((d)/180.*M_PI/3600.)
|
||||||
#define AMIN2RAD(d) (d/180.*M_PI/60.)
|
#define AMIN2RAD(d) ((d)/180.*M_PI/60.)
|
||||||
#define RAD2DEG(r) (r/M_PI*180.)
|
#define RAD2DEG(r) ((r)/M_PI*180.)
|
||||||
#define RAD2ASEC(r) (r/M_PI*180.*3600.)
|
#define RAD2ASEC(r) ((r)/M_PI*180.*3600.)
|
||||||
#define RAD2AMIN(r) (r/M_PI*180.*60.)
|
#define RAD2AMIN(r) ((r)/M_PI*180.*60.)
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ static traectory_fn cur_traectory = NULL;
|
|||||||
// starting point of traectory
|
// starting point of traectory
|
||||||
static coordpair_t XYstart = {0};
|
static coordpair_t XYstart = {0};
|
||||||
static double tstart = 0.;
|
static double tstart = 0.;
|
||||||
// convert Xe/Ye to approximate motor coordinates:
|
|
||||||
// Xnew = Xcor+Xe; Ynew = Ycor+Ye; as Ye goes backwards to Ym, we have
|
|
||||||
// Xcor = Xm0 - Xe0; Ycor = Xm0 + Ye0
|
|
||||||
static coordval_pair_t XYcor = {0};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init_traectory - init traectory fn, sync starting positions of motor & encoders
|
* @brief init_traectory - init traectory fn, sync starting positions of motor & encoders
|
||||||
@@ -45,16 +41,13 @@ int init_traectory(traectory_fn f, coordpair_t *XY0){
|
|||||||
if(!f || !XY0) return FALSE;
|
if(!f || !XY0) return FALSE;
|
||||||
cur_traectory = f;
|
cur_traectory = f;
|
||||||
XYstart = *XY0;
|
XYstart = *XY0;
|
||||||
tstart = Mount.currentT();
|
tstart = Mount.timeFromStart();
|
||||||
mountdata_t mdata;
|
mountdata_t mdata;
|
||||||
int ntries = 0;
|
int ntries = 0;
|
||||||
for(; ntries < 10; ++ntries){
|
for(; ntries < 10; ++ntries){
|
||||||
if(MCC_E_OK == Mount.getMountData(&mdata)) break;
|
if(MCC_E_OK == Mount.getMountData(&mdata)) break;
|
||||||
}
|
}
|
||||||
if(ntries == 10) return FALSE;
|
if(ntries == 10) return FALSE;
|
||||||
XYcor.X.val = mdata.motXposition.val - mdata.encXposition.val;
|
|
||||||
XYcor.Y.val = mdata.motYposition.val - mdata.encYposition.val;
|
|
||||||
DBG("STARTING POINTS: x=%g, y=%g degrees", DEG2RAD(XYcor.X.val), DEG2RAD(XYcor.Y.val));
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +76,9 @@ int telpos(coordval_pair_t *curpos){
|
|||||||
}
|
}
|
||||||
if(ntries == 10) return FALSE;
|
if(ntries == 10) return FALSE;
|
||||||
coordval_pair_t pt;
|
coordval_pair_t pt;
|
||||||
pt.X.val = XYcor.X.val + mdata.encXposition.val;
|
//DBG("\n\nTELPOS: %g'/%g' measured @ %.6f", RAD2AMIN(mdata.encXposition.val), RAD2AMIN(mdata.encYposition.val), mdata.encXposition.t);
|
||||||
pt.Y.val = XYcor.Y.val + mdata.encYposition.val;
|
pt.X.val = mdata.encXposition.val;
|
||||||
|
pt.Y.val = mdata.encYposition.val;
|
||||||
pt.X.t = mdata.encXposition.t;
|
pt.X.t = mdata.encXposition.t;
|
||||||
pt.Y.t = mdata.encYposition.t;
|
pt.Y.t = mdata.encYposition.t;
|
||||||
if(curpos) *curpos = pt;
|
if(curpos) *curpos = pt;
|
||||||
@@ -94,7 +88,7 @@ int telpos(coordval_pair_t *curpos){
|
|||||||
// X=X0+1'/s, Y=Y0+15''/s
|
// X=X0+1'/s, Y=Y0+15''/s
|
||||||
int Linear(coordpair_t *nextpt, double t){
|
int Linear(coordpair_t *nextpt, double t){
|
||||||
coordpair_t pt;
|
coordpair_t pt;
|
||||||
pt.X = XYstart.X + ASEC2RAD(1.) * (t - tstart);
|
pt.X = XYstart.X + ASEC2RAD(0.1) * (t - tstart);
|
||||||
pt.Y = XYstart.Y + ASEC2RAD(15.)* (t - tstart);
|
pt.Y = XYstart.Y + ASEC2RAD(15.)* (t - tstart);
|
||||||
if(nextpt) *nextpt = pt;
|
if(nextpt) *nextpt = pt;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -103,8 +97,8 @@ int Linear(coordpair_t *nextpt, double t){
|
|||||||
// X=X0+5'*sin(t/30*2pi), Y=Y0+10'*cos(t/200*2pi)
|
// X=X0+5'*sin(t/30*2pi), Y=Y0+10'*cos(t/200*2pi)
|
||||||
int SinCos(coordpair_t *nextpt, double t){
|
int SinCos(coordpair_t *nextpt, double t){
|
||||||
coordpair_t pt;
|
coordpair_t pt;
|
||||||
pt.X = XYstart.X + AMIN2RAD(5.) * sin((t-tstart)/30.*2*M_PI);
|
pt.X = XYstart.X + ASEC2RAD(5.) * sin((t-tstart)/30.*2*M_PI);
|
||||||
pt.Y = XYstart.Y + AMIN2RAD(10.)* cos((t-tstart)/200.*2*M_PI);
|
pt.Y = XYstart.Y + AMIN2RAD(1.)* cos((t-tstart)/200.*2*M_PI);
|
||||||
if(nextpt) *nextpt = pt;
|
if(nextpt) *nextpt = pt;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -116,8 +110,8 @@ typedef struct{
|
|||||||
} tr_names;
|
} tr_names;
|
||||||
|
|
||||||
static tr_names names[] = {
|
static tr_names names[] = {
|
||||||
{Linear, "linear", "X=X0+1'/s, Y=Y0+15''/s"},
|
{Linear, "linear", "X=X0+0.1''/s, Y=Y0+15''/s"},
|
||||||
{SinCos, "sincos", "X=X0+5'*sin(t/30*2pi), Y=Y0+10'*cos(t/200*2pi)"},
|
{SinCos, "sincos", "X=X0+5''*sin(t/30*2pi), Y=Y0+10'*cos(t/200*2pi)"},
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Add predefined macros for your project here. For example:
|
// Add predefined macros for your project here. For example:
|
||||||
// #define THE_ANSWER 42
|
// #define THE_ANSWER 42
|
||||||
#define EBUG
|
#define EBUG
|
||||||
#define _POSIX_C_SOURCE 111
|
#define _POSIX_C_SOURCE 11111111
|
||||||
#define PACKAGE_VERSION "0.0.1"
|
#define PACKAGE_VERSION "0.0.1"
|
||||||
|
#define _XOPEN_SOURCE 666
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 17.0.0, 2025-07-23T22:48:05. -->
|
<!-- Written by QtCreator 18.0.0, 2026-03-11T12:36:26. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
|
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
<data>
|
||||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
@@ -40,9 +40,9 @@
|
|||||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
|
||||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||||
@@ -51,10 +51,10 @@
|
|||||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
|
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
@@ -75,19 +75,18 @@
|
|||||||
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey"/>
|
|
||||||
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
|
|
||||||
<valuemap type="QVariantMap" key="ClangTools">
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||||
<value type="int" key="ClangTools.ParallelJobs">8</value>
|
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||||
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
<value type="int" key="RcSync">0</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
<data>
|
||||||
@@ -97,12 +96,12 @@
|
|||||||
<value type="bool" key="HasPerBcDcs">true</value>
|
<value type="bool" key="HasPerBcDcs">true</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Big/Data/00__Small_tel/C-sources/erfa</value>
|
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/10micron/C-sources/erfa_functions</value>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||||
@@ -154,7 +153,9 @@
|
|||||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
@@ -164,6 +165,7 @@
|
|||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
@@ -186,7 +188,9 @@
|
|||||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
@@ -196,6 +200,7 @@
|
|||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||||
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||||
|
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
@@ -206,10 +211,6 @@
|
|||||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||||
<value type="qlonglong">1</value>
|
<value type="qlonglong">1</value>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
|
||||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
|
||||||
<value type="int">22</value>
|
|
||||||
</data>
|
|
||||||
<data>
|
<data>
|
||||||
<variable>Version</variable>
|
<variable>Version</variable>
|
||||||
<value type="int">22</value>
|
<value type="int">22</value>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
CMakeLists.txt
|
CMakeLists.txt
|
||||||
dbg.h
|
PID.c
|
||||||
|
PID.h
|
||||||
examples/SSIIconf.c
|
examples/SSIIconf.c
|
||||||
examples/conf.c
|
examples/conf.c
|
||||||
examples/conf.h
|
examples/conf.h
|
||||||
@@ -18,6 +19,12 @@ serial.c
|
|||||||
examples/CMakeLists.txt
|
examples/CMakeLists.txt
|
||||||
examples/traectories.c
|
examples/traectories.c
|
||||||
examples/traectories.h
|
examples/traectories.h
|
||||||
|
main.h
|
||||||
|
movingmodel.c
|
||||||
|
movingmodel.h
|
||||||
|
polltest/main.c
|
||||||
|
ramp.c
|
||||||
|
ramp.h
|
||||||
serial.h
|
serial.h
|
||||||
ssii.c
|
ssii.c
|
||||||
ssii.h
|
ssii.h
|
||||||
|
|||||||
@@ -16,28 +16,171 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main functions to fill struct `mount_t`
|
||||||
|
*/
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "dbg.h"
|
#include "main.h"
|
||||||
|
#include "movingmodel.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "ssii.h"
|
#include "ssii.h"
|
||||||
|
#include "PID.h"
|
||||||
|
|
||||||
|
// adder for monotonic time by realtime: inited any call of init()
|
||||||
|
static struct timespec timeadder = {0}, // adder of CLOCK_REALTIME to CLOCK_MONOTONIC
|
||||||
|
t0 = {0}, // curtime() for initstarttime() call
|
||||||
|
starttime = {0}; // starting time by monotonic (for timefromstart())
|
||||||
|
|
||||||
conf_t Conf = {0};
|
conf_t Conf = {0};
|
||||||
|
// parameters for model
|
||||||
|
static movemodel_t *Xmodel, *Ymodel;
|
||||||
|
// limits for model and/or real mount (in latter case data should be read from mount on init)
|
||||||
|
// radians, rad/sec, rad/sec^2
|
||||||
|
// max speeds (rad/s): xs=10 deg/s, ys=8 deg/s
|
||||||
|
// accelerations: xa=12.6 deg/s^2, ya= 9.5 deg/s^2
|
||||||
|
limits_t
|
||||||
|
Xlimits = {
|
||||||
|
.min = {.coord = -3.1241, .speed = 1e-10, .accel = 1e-6},
|
||||||
|
.max = {.coord = 3.1241, .speed = 0.174533, .accel = 0.219911}},
|
||||||
|
Ylimits = {
|
||||||
|
.min = {.coord = -3.1241, .speed = 1e-10, .accel = 1e-6},
|
||||||
|
.max = {.coord = 3.1241, .speed = 0.139626, .accel = 0.165806}}
|
||||||
|
;
|
||||||
static mcc_errcodes_t shortcmd(short_command_t *cmd);
|
static mcc_errcodes_t shortcmd(short_command_t *cmd);
|
||||||
|
static mcc_errcodes_t get_hwconf(hardware_configuration_t *hwConfig);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief curtime - monotonic time from first run
|
||||||
|
* @param t - struct timespec by CLOCK_MONOTONIC but with setpoint by CLOCK_REALTIME on observations start
|
||||||
|
* @return TRUE if all OK
|
||||||
|
* FIXME: double -> struct timespec; on init: init t0 by CLOCK_REALTIME
|
||||||
|
*/
|
||||||
|
int curtime(struct timespec *t){
|
||||||
|
struct timespec now;
|
||||||
|
if(clock_gettime(CLOCK_MONOTONIC, &now)) return FALSE;
|
||||||
|
now.tv_sec += timeadder.tv_sec;
|
||||||
|
now.tv_nsec += timeadder.tv_nsec;
|
||||||
|
if(now.tv_nsec > 999999999L){
|
||||||
|
++now.tv_sec;
|
||||||
|
now.tv_nsec -= 1000000000L;
|
||||||
|
}
|
||||||
|
if(t) *t = now;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// init starttime; @return TRUE if all OK
|
||||||
|
static int initstarttime(){
|
||||||
|
struct timespec start;
|
||||||
|
if(clock_gettime(CLOCK_MONOTONIC, &starttime)) return FALSE;
|
||||||
|
if(clock_gettime(CLOCK_REALTIME, &start)) return FALSE;
|
||||||
|
timeadder.tv_sec = start.tv_sec - starttime.tv_sec;
|
||||||
|
timeadder.tv_nsec = start.tv_nsec - starttime.tv_nsec;
|
||||||
|
if(timeadder.tv_nsec < 0){
|
||||||
|
--timeadder.tv_sec;
|
||||||
|
timeadder.tv_nsec += 1000000000L;
|
||||||
|
}
|
||||||
|
curtime(&t0);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return difference (in seconds) between time1 and time0
|
||||||
|
double timediff(const struct timespec *time1, const struct timespec *time0){
|
||||||
|
if(!time1 || !time0) return -1.;
|
||||||
|
return (time1->tv_sec - time0->tv_sec) + (time1->tv_nsec - time0->tv_nsec) / 1e9;
|
||||||
|
}
|
||||||
|
// difference between given time and last initstarttime() call
|
||||||
|
double timediff0(const struct timespec *time1){
|
||||||
|
return timediff(time1, &t0);
|
||||||
|
}
|
||||||
|
// time from last initstarttime() call
|
||||||
|
double timefromstart(){
|
||||||
|
struct timespec now;
|
||||||
|
if(clock_gettime(CLOCK_MONOTONIC, &now)) return -1.;
|
||||||
|
return (now.tv_sec - starttime.tv_sec) + (now.tv_nsec - starttime.tv_nsec) / 1e9;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief quit - close all opened and return to default state
|
* @brief quit - close all opened and return to default state
|
||||||
|
* TODO: close serial devices even in "model" mode
|
||||||
*/
|
*/
|
||||||
static void quit(){
|
static void quit(){
|
||||||
DBG("Close serial devices");
|
if(Conf.RunModel) return;
|
||||||
for(int i = 0; i < 10; ++i) if(SSstop(TRUE)) break;
|
for(int i = 0; i < 10; ++i) if(SSstop(TRUE)) break;
|
||||||
|
DBG("Close all serial devices");
|
||||||
closeSerial();
|
closeSerial();
|
||||||
DBG("Exit");
|
DBG("Exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getModData(coordpair_t *c, movestate_t *xst, movestate_t *yst){
|
||||||
|
if(!c || !Xmodel || !Ymodel) return;
|
||||||
|
double tnow = timefromstart();
|
||||||
|
moveparam_t Xp, Yp;
|
||||||
|
movestate_t Xst = Xmodel->get_state(Xmodel, &Xp);
|
||||||
|
//DBG("Xstate = %d", Xst);
|
||||||
|
if(Xst == ST_MOVE) Xst = Xmodel->proc_move(Xmodel, &Xp, tnow);
|
||||||
|
movestate_t Yst = Ymodel->get_state(Ymodel, &Yp);
|
||||||
|
if(Yst == ST_MOVE) Yst = Ymodel->proc_move(Ymodel, &Yp, tnow);
|
||||||
|
c->X = Xp.coord;
|
||||||
|
c->Y = Yp.coord;
|
||||||
|
if(xst) *xst = Xst;
|
||||||
|
if(yst) *yst = Yst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* less square calculations of speed
|
||||||
|
*/
|
||||||
|
less_square_t *LS_init(size_t Ndata){
|
||||||
|
if(Ndata < 5){
|
||||||
|
DBG("Ndata=%zd - TOO SMALL", Ndata);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
DBG("Init less squares: %zd", Ndata);
|
||||||
|
less_square_t *l = calloc(1, sizeof(less_square_t));
|
||||||
|
l->x = calloc(Ndata, sizeof(double));
|
||||||
|
l->t2 = calloc(Ndata, sizeof(double));
|
||||||
|
l->t = calloc(Ndata, sizeof(double));
|
||||||
|
l->xt = calloc(Ndata, sizeof(double));
|
||||||
|
l->arraysz = Ndata;
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
void LS_delete(less_square_t **l){
|
||||||
|
if(!l || !*l) return;
|
||||||
|
free((*l)->x); free((*l)->t2); free((*l)->t); free((*l)->xt);
|
||||||
|
free(*l);
|
||||||
|
*l = NULL;
|
||||||
|
}
|
||||||
|
// add next data portion and calculate current slope
|
||||||
|
double LS_calc_slope(less_square_t *l, double x, double t){
|
||||||
|
if(!l) return 0.;
|
||||||
|
size_t idx = l->idx;
|
||||||
|
double oldx = l->x[idx], oldt = l->t[idx], oldt2 = l->t2[idx], oldxt = l->xt[idx];
|
||||||
|
/*DBG("old: x=%g, t=%g, t2=%g, xt=%g; sum: %g, t=%g, t2=%g, xt=%g", oldx, oldt, oldt2, oldxt,
|
||||||
|
l->xsum, l->tsum, l->t2sum, l->xtsum);*/
|
||||||
|
double t2 = t * t, xt = x * t;
|
||||||
|
l->x[idx] = x; l->t2[idx] = t2;
|
||||||
|
l->t[idx] = t; l->xt[idx] = xt;
|
||||||
|
++idx;
|
||||||
|
l->idx = (idx >= l->arraysz) ? 0 : idx;
|
||||||
|
l->xsum += x - oldx;
|
||||||
|
l->t2sum += t2 - oldt2;
|
||||||
|
l->tsum += t - oldt;
|
||||||
|
l->xtsum += xt - oldxt;
|
||||||
|
double n = (double)l->arraysz;
|
||||||
|
double denominator = n * l->t2sum - l->tsum * l->tsum;
|
||||||
|
if(fabs(denominator) < 1e-7) return 0.;
|
||||||
|
double numerator = n * l->xtsum - l->xsum * l->tsum;
|
||||||
|
//DBG("x=%g, t=%g; idx=%zd, arrsz=%zd, den=%g; xsum=%g, num=%g", x, t, l->idx, l->arraysz, denominator, l->xsum, numerator);
|
||||||
|
// point: (sum_x - slope * sum_t) / n;
|
||||||
|
return (numerator / denominator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init - open serial devices and do other job
|
* @brief init - open serial devices and do other job
|
||||||
* @param c - initial configuration
|
* @param c - initial configuration
|
||||||
@@ -46,9 +189,20 @@ static void quit(){
|
|||||||
static mcc_errcodes_t init(conf_t *c){
|
static mcc_errcodes_t init(conf_t *c){
|
||||||
FNAME();
|
FNAME();
|
||||||
if(!c) return MCC_E_BADFORMAT;
|
if(!c) return MCC_E_BADFORMAT;
|
||||||
|
if(!initstarttime()) return MCC_E_FAILED;
|
||||||
Conf = *c;
|
Conf = *c;
|
||||||
mcc_errcodes_t ret = MCC_E_OK;
|
mcc_errcodes_t ret = MCC_E_OK;
|
||||||
if(!Conf.MountDevPath || Conf.MountDevSpeed < 1200){
|
Xmodel = model_init(&Xlimits);
|
||||||
|
Ymodel = model_init(&Ylimits);
|
||||||
|
if(Conf.MountReqInterval > 1. || Conf.MountReqInterval < 0.05){
|
||||||
|
DBG("Bad value of MountReqInterval");
|
||||||
|
ret = MCC_E_BADFORMAT;
|
||||||
|
}
|
||||||
|
if(Conf.RunModel){
|
||||||
|
if(!Xmodel || !Ymodel || !openMount()) return MCC_E_FAILED;
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
|
if(!Conf.MountDevPath || Conf.MountDevSpeed < MOUNT_BAUDRATE_MIN){
|
||||||
DBG("Define mount device path and speed");
|
DBG("Define mount device path and speed");
|
||||||
ret = MCC_E_BADFORMAT;
|
ret = MCC_E_BADFORMAT;
|
||||||
}else if(!openMount()){
|
}else if(!openMount()){
|
||||||
@@ -64,65 +218,61 @@ static mcc_errcodes_t init(conf_t *c){
|
|||||||
ret = MCC_E_ENCODERDEV;
|
ret = MCC_E_ENCODERDEV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Conf.MountReqInterval > 1. || Conf.MountReqInterval < 0.05){
|
// TODO: read hardware configuration on init
|
||||||
DBG("Bad value of MountReqInterval");
|
|
||||||
ret = MCC_E_BADFORMAT;
|
|
||||||
}
|
|
||||||
if(Conf.EncoderSpeedInterval < Conf.EncoderReqInterval * MCC_CONF_MIN_SPEEDC || Conf.EncoderSpeedInterval > MCC_CONF_MAX_SPEEDINT){
|
if(Conf.EncoderSpeedInterval < Conf.EncoderReqInterval * MCC_CONF_MIN_SPEEDC || Conf.EncoderSpeedInterval > MCC_CONF_MAX_SPEEDINT){
|
||||||
DBG("Wrong speed interval");
|
DBG("Wrong speed interval");
|
||||||
ret = MCC_E_BADFORMAT;
|
ret = MCC_E_BADFORMAT;
|
||||||
}
|
}
|
||||||
uint8_t buf[1024];
|
if(!SSrawcmd(CMD_EXITACM, NULL)) ret = MCC_E_FAILED;
|
||||||
data_t d = {.buf = buf, .len = 0, .maxlen = 1024};
|
|
||||||
// read input data as there may be some trash on start
|
|
||||||
if(!SSrawcmd(CMD_EXITACM, &d)) ret = MCC_E_FAILED;
|
|
||||||
if(ret != MCC_E_OK) return ret;
|
if(ret != MCC_E_OK) return ret;
|
||||||
mountdata_t md = {0};
|
// read HW config to update constants
|
||||||
ret = MCC_E_FATAL;
|
hardware_configuration_t HW;
|
||||||
double t0 = dtime(), t = 0.;
|
if(MCC_E_OK != get_hwconf(&HW)) return MCC_E_FAILED;
|
||||||
do{
|
// make a pause for actual encoder's values
|
||||||
t = dtime();
|
double t0 = timefromstart();
|
||||||
if(MCC_E_OK == getMD(&md)){
|
while(timefromstart() - t0 < Conf.EncoderReqInterval) usleep(1000);
|
||||||
if(fabs(md.encXposition.t - t) < 0.1 && fabs(md.encYposition.t - t) < 0.1){
|
mcc_errcodes_t e = updateMotorPos();
|
||||||
DBG("FIX motors position to encoders");
|
// and refresh data after updating
|
||||||
int32_t Xpos = X_RAD2MOT(md.encXposition.val), Ypos = Y_RAD2MOT(md.encYposition.val);
|
DBG("Wait for next mount reading");
|
||||||
if(SSsetterI(CMD_MOTXSET, Xpos) && SSsetterI(CMD_MOTYSET, Ypos)){
|
t0 = timefromstart();
|
||||||
DBG("All OK");
|
while(timefromstart() - t0 < Conf.MountReqInterval * 3.) usleep(1000);
|
||||||
ret = MCC_E_OK;
|
return e;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DBG("NO DATA; dt = %g", t - t0);
|
|
||||||
}while(t - t0 < 2.);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check coordinates (rad) and speeds (rad/s); return FALSE if failed
|
// check coordinates (rad) and speeds (rad/s); return FALSE if failed
|
||||||
// TODO fix to real limits!!!
|
// TODO fix to real limits!!!
|
||||||
static int chkX(double X){
|
static int chkX(double X){
|
||||||
if(X > 2.*M_PI || X < -2.*M_PI) return FALSE;
|
if(X > Xlimits.max.coord || X < Xlimits.min.coord) return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static int chkY(double Y){
|
static int chkY(double Y){
|
||||||
if(Y > 2.*M_PI || Y < -2.*M_PI) return FALSE;
|
if(Y > Ylimits.max.coord || Y < Ylimits.min.coord) return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static int chkXs(double s){
|
static int chkXs(double s){
|
||||||
if(s < 0. || s > MCC_MAX_X_SPEED) return FALSE;
|
if(s < Xlimits.min.speed || s > Xlimits.max.speed) return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static int chkYs(double s){
|
static int chkYs(double s){
|
||||||
if(s < 0. || s > MCC_MAX_Y_SPEED) return FALSE;
|
if(s < Ylimits.min.speed || s > Ylimits.max.speed) return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mcc_errcodes_t slew2(const coordpair_t *target, slewflags_t flags){
|
// set SLEWING state if axis was stopped
|
||||||
(void)target;
|
static void setslewingstate(){
|
||||||
(void)flags;
|
//FNAME();
|
||||||
return MCC_E_FAILED;
|
mountdata_t d;
|
||||||
|
if(MCC_E_OK == getMD(&d)){
|
||||||
|
axis_status_t newx = d.Xstate, newy = d.Ystate;
|
||||||
|
//DBG("old state: %d/%d", d.Xstate, d.Ystate);
|
||||||
|
if(d.Xstate == AXIS_STOPPED) newx = AXIS_SLEWING;
|
||||||
|
if(d.Ystate == AXIS_STOPPED) newy = AXIS_SLEWING;
|
||||||
|
if(newx != d.Xstate || newy != d.Ystate){
|
||||||
|
DBG("Started moving -> slew");
|
||||||
|
setStat(newx, newy);
|
||||||
|
}
|
||||||
|
}else DBG("CAN't GET MOUNT DATA!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief move2 - simple move to given point and stop
|
* @brief move2 - simple move to given point and stop
|
||||||
@@ -133,12 +283,17 @@ static mcc_errcodes_t slew2(const coordpair_t *target, slewflags_t flags){
|
|||||||
static mcc_errcodes_t move2(const coordpair_t *target){
|
static mcc_errcodes_t move2(const coordpair_t *target){
|
||||||
if(!target) return MCC_E_BADFORMAT;
|
if(!target) return MCC_E_BADFORMAT;
|
||||||
if(!chkX(target->X) || !chkY(target->Y)) return MCC_E_BADFORMAT;
|
if(!chkX(target->X) || !chkY(target->Y)) return MCC_E_BADFORMAT;
|
||||||
|
if(MCC_E_OK != updateMotorPos()) return MCC_E_FAILED;
|
||||||
short_command_t cmd = {0};
|
short_command_t cmd = {0};
|
||||||
DBG("x,y: %g, %g", target->X, target->Y);
|
DBG("x,y: %g, %g", target->X, target->Y);
|
||||||
cmd.Xmot = target->X;
|
cmd.Xmot = target->X;
|
||||||
cmd.Ymot = target->Y;
|
cmd.Ymot = target->Y;
|
||||||
cmd.Xspeed = MCC_MAX_X_SPEED;
|
cmd.Xspeed = Xlimits.max.speed;
|
||||||
cmd.Yspeed = MCC_MAX_Y_SPEED;
|
cmd.Yspeed = Ylimits.max.speed;
|
||||||
|
/*mcc_errcodes_t r = shortcmd(&cmd);
|
||||||
|
if(r != MCC_E_OK) return r;
|
||||||
|
setslewingstate();
|
||||||
|
return MCC_E_OK;*/
|
||||||
return shortcmd(&cmd);
|
return shortcmd(&cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +305,7 @@ static mcc_errcodes_t move2(const coordpair_t *target){
|
|||||||
*/
|
*/
|
||||||
static mcc_errcodes_t setspeed(const coordpair_t *tagspeed){
|
static mcc_errcodes_t setspeed(const coordpair_t *tagspeed){
|
||||||
if(!tagspeed || !chkXs(tagspeed->X) || !chkYs(tagspeed->Y)) return MCC_E_BADFORMAT;
|
if(!tagspeed || !chkXs(tagspeed->X) || !chkYs(tagspeed->Y)) return MCC_E_BADFORMAT;
|
||||||
|
if(Conf.RunModel) return MCC_E_FAILED;
|
||||||
int32_t spd = X_RS2MOTSPD(tagspeed->X);
|
int32_t spd = X_RS2MOTSPD(tagspeed->X);
|
||||||
if(!SSsetterI(CMD_SPEEDX, spd)) return MCC_E_FAILED;
|
if(!SSsetterI(CMD_SPEEDX, spd)) return MCC_E_FAILED;
|
||||||
spd = Y_RS2MOTSPD(tagspeed->Y);
|
spd = Y_RS2MOTSPD(tagspeed->Y);
|
||||||
@@ -167,12 +323,17 @@ static mcc_errcodes_t move2s(const coordpair_t *target, const coordpair_t *speed
|
|||||||
if(!target || !speed) return MCC_E_BADFORMAT;
|
if(!target || !speed) return MCC_E_BADFORMAT;
|
||||||
if(!chkX(target->X) || !chkY(target->Y)) return MCC_E_BADFORMAT;
|
if(!chkX(target->X) || !chkY(target->Y)) return MCC_E_BADFORMAT;
|
||||||
if(!chkXs(speed->X) || !chkYs(speed->Y)) return MCC_E_BADFORMAT;
|
if(!chkXs(speed->X) || !chkYs(speed->Y)) return MCC_E_BADFORMAT;
|
||||||
|
// updateMotorPos() here can make a problem; TODO: remove?
|
||||||
|
if(MCC_E_OK != updateMotorPos()) return MCC_E_FAILED;
|
||||||
short_command_t cmd = {0};
|
short_command_t cmd = {0};
|
||||||
cmd.Xmot = target->X;
|
cmd.Xmot = target->X;
|
||||||
cmd.Ymot = target->Y;
|
cmd.Ymot = target->Y;
|
||||||
cmd.Xspeed = speed->X;
|
cmd.Xspeed = speed->X;
|
||||||
cmd.Yspeed = speed->Y;
|
cmd.Yspeed = speed->Y;
|
||||||
return shortcmd(&cmd);
|
mcc_errcodes_t r = shortcmd(&cmd);
|
||||||
|
if(r != MCC_E_OK) return r;
|
||||||
|
setslewingstate();
|
||||||
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,11 +341,25 @@ static mcc_errcodes_t move2s(const coordpair_t *target, const coordpair_t *speed
|
|||||||
* @return errcode
|
* @return errcode
|
||||||
*/
|
*/
|
||||||
static mcc_errcodes_t emstop(){
|
static mcc_errcodes_t emstop(){
|
||||||
|
FNAME();
|
||||||
|
if(Conf.RunModel){
|
||||||
|
double curt = timefromstart();
|
||||||
|
Xmodel->emergency_stop(Xmodel, curt);
|
||||||
|
Ymodel->emergency_stop(Ymodel, curt);
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
if(!SSstop(TRUE)) return MCC_E_FAILED;
|
if(!SSstop(TRUE)) return MCC_E_FAILED;
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
// normal stop
|
// normal stop
|
||||||
static mcc_errcodes_t stop(){
|
static mcc_errcodes_t stop(){
|
||||||
|
FNAME();
|
||||||
|
if(Conf.RunModel){
|
||||||
|
double curt = timefromstart();
|
||||||
|
Xmodel->stop(Xmodel, curt);
|
||||||
|
Ymodel->stop(Ymodel,curt);
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
if(!SSstop(FALSE)) return MCC_E_FAILED;
|
if(!SSstop(FALSE)) return MCC_E_FAILED;
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
@@ -196,6 +371,16 @@ static mcc_errcodes_t stop(){
|
|||||||
*/
|
*/
|
||||||
static mcc_errcodes_t shortcmd(short_command_t *cmd){
|
static mcc_errcodes_t shortcmd(short_command_t *cmd){
|
||||||
if(!cmd) return MCC_E_BADFORMAT;
|
if(!cmd) return MCC_E_BADFORMAT;
|
||||||
|
if(Conf.RunModel){
|
||||||
|
double curt = timefromstart();
|
||||||
|
moveparam_t param = {0};
|
||||||
|
param.coord = cmd->Xmot; param.speed = cmd->Xspeed;
|
||||||
|
if(!model_move2(Xmodel, ¶m, curt)) return MCC_E_FAILED;
|
||||||
|
param.coord = cmd->Ymot; param.speed = cmd->Yspeed;
|
||||||
|
if(!model_move2(Ymodel, ¶m, curt)) return MCC_E_FAILED;
|
||||||
|
setslewingstate();
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
SSscmd s = {0};
|
SSscmd s = {0};
|
||||||
DBG("tag: xmot=%g rad, ymot=%g rad", cmd->Xmot, cmd->Ymot);
|
DBG("tag: xmot=%g rad, ymot=%g rad", cmd->Xmot, cmd->Ymot);
|
||||||
s.Xmot = X_RAD2MOT(cmd->Xmot);
|
s.Xmot = X_RAD2MOT(cmd->Xmot);
|
||||||
@@ -207,16 +392,27 @@ static mcc_errcodes_t shortcmd(short_command_t *cmd){
|
|||||||
s.YBits = cmd->YBits;
|
s.YBits = cmd->YBits;
|
||||||
DBG("X->%d, Y->%d, Xs->%d, Ys->%d", s.Xmot, s.Ymot, s.Xspeed, s.Yspeed);
|
DBG("X->%d, Y->%d, Xs->%d, Ys->%d", s.Xmot, s.Ymot, s.Xspeed, s.Yspeed);
|
||||||
if(!cmdS(&s)) return MCC_E_FAILED;
|
if(!cmdS(&s)) return MCC_E_FAILED;
|
||||||
|
setslewingstate();
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief shortcmd - send and receive long binary command
|
* @brief longcmd - send and receive long binary command
|
||||||
* @param cmd (io) - command
|
* @param cmd (io) - command
|
||||||
* @return errcode
|
* @return errcode
|
||||||
*/
|
*/
|
||||||
static mcc_errcodes_t longcmd(long_command_t *cmd){
|
static mcc_errcodes_t longcmd(long_command_t *cmd){
|
||||||
if(!cmd) return MCC_E_BADFORMAT;
|
if(!cmd) return MCC_E_BADFORMAT;
|
||||||
|
if(Conf.RunModel){
|
||||||
|
double curt = timefromstart();
|
||||||
|
moveparam_t param = {0};
|
||||||
|
param.coord = cmd->Xmot; param.speed = cmd->Xspeed;
|
||||||
|
if(!model_move2(Xmodel, ¶m, curt)) return MCC_E_FAILED;
|
||||||
|
param.coord = cmd->Ymot; param.speed = cmd->Yspeed;
|
||||||
|
if(!model_move2(Ymodel, ¶m, curt)) return MCC_E_FAILED;
|
||||||
|
setslewingstate();
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
SSlcmd l = {0};
|
SSlcmd l = {0};
|
||||||
l.Xmot = X_RAD2MOT(cmd->Xmot);
|
l.Xmot = X_RAD2MOT(cmd->Xmot);
|
||||||
l.Ymot = Y_RAD2MOT(cmd->Ymot);
|
l.Ymot = Y_RAD2MOT(cmd->Ymot);
|
||||||
@@ -227,12 +423,15 @@ static mcc_errcodes_t longcmd(long_command_t *cmd){
|
|||||||
l.Xatime = S2ADDER(cmd->Xatime);
|
l.Xatime = S2ADDER(cmd->Xatime);
|
||||||
l.Yatime = S2ADDER(cmd->Yatime);
|
l.Yatime = S2ADDER(cmd->Yatime);
|
||||||
if(!cmdL(&l)) return MCC_E_FAILED;
|
if(!cmdL(&l)) return MCC_E_FAILED;
|
||||||
|
setslewingstate();
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mcc_errcodes_t get_hwconf(hardware_configuration_t *hwConfig){
|
static mcc_errcodes_t get_hwconf(hardware_configuration_t *hwConfig){
|
||||||
if(!hwConfig) return MCC_E_BADFORMAT;
|
if(!hwConfig) return MCC_E_BADFORMAT;
|
||||||
|
if(Conf.RunModel) return MCC_E_FAILED;
|
||||||
SSconfig config;
|
SSconfig config;
|
||||||
|
DBG("Read HW configuration");
|
||||||
if(!cmdC(&config, FALSE)) return MCC_E_FAILED;
|
if(!cmdC(&config, FALSE)) return MCC_E_FAILED;
|
||||||
// Convert acceleration (ticks per loop^2 to rad/s^2)
|
// Convert acceleration (ticks per loop^2 to rad/s^2)
|
||||||
hwConfig->Xconf.accel = X_MOTACC2RS(config.Xconf.accel);
|
hwConfig->Xconf.accel = X_MOTACC2RS(config.Xconf.accel);
|
||||||
@@ -266,14 +465,14 @@ static mcc_errcodes_t get_hwconf(hardware_configuration_t *hwConfig){
|
|||||||
hwConfig->address = config.address;
|
hwConfig->address = config.address;
|
||||||
|
|
||||||
// TODO: What to do with eqrate, eqadj and trackgoal?
|
// TODO: What to do with eqrate, eqadj and trackgoal?
|
||||||
|
config.latitude = __bswap_16(config.latitude);
|
||||||
// Convert latitude (degrees * 100 to radians)
|
// Convert latitude (degrees * 100 to radians)
|
||||||
hwConfig->latitude = (double)config.latitude / 100.0 * M_PI / 180.0;
|
hwConfig->latitude = ((double)config.latitude) / 100.0 * M_PI / 180.0;
|
||||||
// Copy ticks per revolution
|
// Copy ticks per revolution
|
||||||
hwConfig->Xsetpr = config.Xsetpr;
|
hwConfig->Xsetpr = __bswap_32(config.Xsetpr);
|
||||||
hwConfig->Ysetpr = config.Ysetpr;
|
hwConfig->Ysetpr = __bswap_32(config.Ysetpr);
|
||||||
hwConfig->Xmetpr = config.Xmetpr;
|
hwConfig->Xmetpr = __bswap_32(config.Xmetpr); // as documentation said, real ticks are 4 times less
|
||||||
hwConfig->Ymetpr = config.Ymetpr;
|
hwConfig->Ymetpr = __bswap_32(config.Ymetpr);
|
||||||
// Convert slew rates (ticks per loop to rad/s)
|
// Convert slew rates (ticks per loop to rad/s)
|
||||||
hwConfig->Xslewrate = X_MOTSPD2RS(config.Xslewrate);
|
hwConfig->Xslewrate = X_MOTSPD2RS(config.Xslewrate);
|
||||||
hwConfig->Yslewrate = Y_MOTSPD2RS(config.Yslewrate);
|
hwConfig->Yslewrate = Y_MOTSPD2RS(config.Yslewrate);
|
||||||
@@ -291,11 +490,36 @@ static mcc_errcodes_t get_hwconf(hardware_configuration_t *hwConfig){
|
|||||||
hwConfig->locsspeed = (double)config.locsspeed * M_PI / (180.0 * 3600.0);
|
hwConfig->locsspeed = (double)config.locsspeed * M_PI / (180.0 * 3600.0);
|
||||||
// Convert backlash speed (ticks per loop to rad/s)
|
// Convert backlash speed (ticks per loop to rad/s)
|
||||||
hwConfig->backlspd = X_MOTSPD2RS(config.backlspd);
|
hwConfig->backlspd = X_MOTSPD2RS(config.backlspd);
|
||||||
|
// now read text commands
|
||||||
|
int64_t i64;
|
||||||
|
double Xticks, Yticks;
|
||||||
|
DBG("SERIAL");
|
||||||
|
// motor's encoder ticks per rev
|
||||||
|
if(!SSgetint(CMD_MEPRX, &i64)) return MCC_E_FAILED;
|
||||||
|
Xticks = ((double) i64); // divide by 4 as these values stored ???
|
||||||
|
if(!SSgetint(CMD_MEPRY, &i64)) return MCC_E_FAILED;
|
||||||
|
Yticks = ((double) i64);
|
||||||
|
X_ENC_ZERO = Conf.XEncZero;
|
||||||
|
Y_ENC_ZERO = Conf.YEncZero;
|
||||||
|
DBG("xyrev: %d/%d", config.xbits.motrev, config.ybits.motrev);
|
||||||
|
X_MOT_STEPSPERREV = hwConfig->Xconf.motor_stepsperrev = Xticks; // (config.xbits.motrev) ? -Xticks : Xticks;
|
||||||
|
Y_MOT_STEPSPERREV = hwConfig->Yconf.motor_stepsperrev = Yticks; //(config.ybits.motrev) ? -Yticks : Yticks;
|
||||||
|
DBG("zero: %d/%d; motsteps: %.10g/%.10g", X_ENC_ZERO, Y_ENC_ZERO, X_MOT_STEPSPERREV, Y_MOT_STEPSPERREV);
|
||||||
|
// axis encoder ticks per rev
|
||||||
|
if(!SSgetint(CMD_AEPRX, &i64)) return MCC_E_FAILED;
|
||||||
|
Xticks = (double) i64;
|
||||||
|
if(!SSgetint(CMD_AEPRY, &i64)) return MCC_E_FAILED;
|
||||||
|
Yticks = (double) i64;
|
||||||
|
DBG("xyencrev: %d/%d", config.xbits.encrev, config.ybits.encrev);
|
||||||
|
X_ENC_STEPSPERREV = hwConfig->Xconf.axis_stepsperrev = (config.xbits.encrev) ? -Xticks : Xticks;
|
||||||
|
Y_ENC_STEPSPERREV = hwConfig->Yconf.axis_stepsperrev = (config.ybits.encrev) ? -Yticks : Yticks;
|
||||||
|
DBG("encsteps: %.10g/%.10g", X_ENC_STEPSPERREV, Y_ENC_STEPSPERREV);
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mcc_errcodes_t write_hwconf(hardware_configuration_t *hwConfig){
|
static mcc_errcodes_t write_hwconf(hardware_configuration_t *hwConfig){
|
||||||
SSconfig config;
|
SSconfig config;
|
||||||
|
if(Conf.RunModel) return MCC_E_FAILED;
|
||||||
// Convert acceleration (rad/s^2 to ticks per loop^2)
|
// Convert acceleration (rad/s^2 to ticks per loop^2)
|
||||||
config.Xconf.accel = X_RS2MOTACC(hwConfig->Xconf.accel);
|
config.Xconf.accel = X_RS2MOTACC(hwConfig->Xconf.accel);
|
||||||
config.Yconf.accel = Y_RS2MOTACC(hwConfig->Yconf.accel);
|
config.Yconf.accel = Y_RS2MOTACC(hwConfig->Yconf.accel);
|
||||||
@@ -325,7 +549,7 @@ static mcc_errcodes_t write_hwconf(hardware_configuration_t *hwConfig){
|
|||||||
config.xbits = hwConfig->xbits;
|
config.xbits = hwConfig->xbits;
|
||||||
config.ybits = hwConfig->ybits;
|
config.ybits = hwConfig->ybits;
|
||||||
// Convert latitude (radians to degrees * 100)
|
// Convert latitude (radians to degrees * 100)
|
||||||
config.latitude = (uint16_t)(hwConfig->latitude * 180.0 / M_PI * 100.0);
|
config.latitude = __bswap_16((uint16_t)(hwConfig->latitude * 180.0 / M_PI * 100.0));
|
||||||
// Convert slew rates (rad/s to ticks per loop)
|
// Convert slew rates (rad/s to ticks per loop)
|
||||||
config.Xslewrate = X_RS2MOTSPD(hwConfig->Xslewrate);
|
config.Xslewrate = X_RS2MOTSPD(hwConfig->Xslewrate);
|
||||||
config.Yslewrate = Y_RS2MOTSPD(hwConfig->Yslewrate);
|
config.Yslewrate = Y_RS2MOTSPD(hwConfig->Yslewrate);
|
||||||
@@ -341,17 +565,41 @@ static mcc_errcodes_t write_hwconf(hardware_configuration_t *hwConfig){
|
|||||||
config.locsspeed = (uint32_t)(hwConfig->locsspeed * 180.0 * 3600.0 / M_PI);
|
config.locsspeed = (uint32_t)(hwConfig->locsspeed * 180.0 * 3600.0 / M_PI);
|
||||||
// Convert backlash speed (rad/s to ticks per loop)
|
// Convert backlash speed (rad/s to ticks per loop)
|
||||||
config.backlspd = X_RS2MOTSPD(hwConfig->backlspd);
|
config.backlspd = X_RS2MOTSPD(hwConfig->backlspd);
|
||||||
|
config.Xsetpr = __bswap_32(hwConfig->Xsetpr);
|
||||||
|
config.Ysetpr = __bswap_32(hwConfig->Ysetpr);
|
||||||
|
config.Xmetpr = __bswap_32(hwConfig->Xmetpr);
|
||||||
|
config.Ymetpr = __bswap_32(hwConfig->Ymetpr);
|
||||||
|
// todo - also write text params
|
||||||
// TODO - next
|
// TODO - next
|
||||||
(void) config;
|
(void) config;
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getters of max/min speed and acceleration
|
||||||
|
mcc_errcodes_t maxspeed(coordpair_t *v){
|
||||||
|
if(!v) return MCC_E_BADFORMAT;
|
||||||
|
v->X = Xlimits.max.speed;
|
||||||
|
v->Y = Ylimits.max.speed;
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
|
mcc_errcodes_t minspeed(coordpair_t *v){
|
||||||
|
if(!v) return MCC_E_BADFORMAT;
|
||||||
|
v->X = Xlimits.min.speed;
|
||||||
|
v->Y = Ylimits.min.speed;
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
|
mcc_errcodes_t acceleration(coordpair_t *a){
|
||||||
|
if(!a) return MCC_E_BADFORMAT;
|
||||||
|
a->X = Xlimits.max.accel;
|
||||||
|
a->Y = Ylimits.max.accel;
|
||||||
|
return MCC_E_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// init mount class
|
// init mount class
|
||||||
mount_t Mount = {
|
mount_t Mount = {
|
||||||
.init = init,
|
.init = init,
|
||||||
.quit = quit,
|
.quit = quit,
|
||||||
.getMountData = getMD,
|
.getMountData = getMD,
|
||||||
.slewTo = slew2,
|
|
||||||
.moveTo = move2,
|
.moveTo = move2,
|
||||||
.moveWspeed = move2s,
|
.moveWspeed = move2s,
|
||||||
.setSpeed = setspeed,
|
.setSpeed = setspeed,
|
||||||
@@ -361,5 +609,13 @@ mount_t Mount = {
|
|||||||
.longCmd = longcmd,
|
.longCmd = longcmd,
|
||||||
.getHWconfig = get_hwconf,
|
.getHWconfig = get_hwconf,
|
||||||
.saveHWconfig = write_hwconf,
|
.saveHWconfig = write_hwconf,
|
||||||
.currentT = dtime,
|
.currentT = curtime,
|
||||||
|
.timeFromStart = timefromstart,
|
||||||
|
.timeDiff = timediff,
|
||||||
|
.timeDiff0 = timediff0,
|
||||||
|
.correctTo = correct2,
|
||||||
|
.getMaxSpeed = maxspeed,
|
||||||
|
.getMinSpeed = minspeed,
|
||||||
|
.getAcceleration = acceleration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,37 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Almost all here used for debug purposes
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "movingmodel.h"
|
||||||
#include "sidservo.h"
|
#include "sidservo.h"
|
||||||
|
|
||||||
extern conf_t Conf;
|
extern conf_t Conf;
|
||||||
|
extern limits_t Xlimits, Ylimits;
|
||||||
|
int curtime(struct timespec *t);
|
||||||
|
double timediff(const struct timespec *time1, const struct timespec *time0);
|
||||||
|
double timediff0(const struct timespec *time1);
|
||||||
|
double timefromstart();
|
||||||
|
void getModData(coordpair_t *c, movestate_t *xst, movestate_t *yst);
|
||||||
|
typedef struct{
|
||||||
|
double *x, *t, *t2, *xt; // arrays of coord/time and multiply
|
||||||
|
double xsum, tsum, t2sum, xtsum; // sums of coord/time and their multiply
|
||||||
|
size_t idx; // index of current data in array
|
||||||
|
size_t arraysz; // size of arrays
|
||||||
|
} less_square_t;
|
||||||
|
|
||||||
|
less_square_t *LS_init(size_t Ndata);
|
||||||
|
void LS_delete(less_square_t **ls);
|
||||||
|
double LS_calc_slope(less_square_t *l, double x, double t);
|
||||||
|
|
||||||
// unused arguments of functions
|
// unused arguments of functions
|
||||||
#define _U_ __attribute__((__unused__))
|
#define _U_ __attribute__((__unused__))
|
||||||
// break absent in `case`
|
|
||||||
#define FALLTHRU __attribute__ ((fallthrough))
|
|
||||||
// and synonym for FALLTHRU
|
|
||||||
#define NOBREAKHERE __attribute__ ((fallthrough))
|
|
||||||
// weak functions
|
// weak functions
|
||||||
#define WEAK __attribute__ ((weak))
|
#define WEAK __attribute__ ((weak))
|
||||||
|
|
||||||
@@ -53,12 +70,12 @@ extern conf_t Conf;
|
|||||||
#define COLOR_OLD "\033[0;0;0m"
|
#define COLOR_OLD "\033[0;0;0m"
|
||||||
#define FNAME() do{ fprintf(stderr, COLOR_GREEN "\n%s " COLOR_OLD, __func__); \
|
#define FNAME() do{ fprintf(stderr, COLOR_GREEN "\n%s " COLOR_OLD, __func__); \
|
||||||
fprintf(stderr, "(%s, line %d)\n", __FILE__, __LINE__);} while(0)
|
fprintf(stderr, "(%s, line %d)\n", __FILE__, __LINE__);} while(0)
|
||||||
#define DBG(...) do{ fprintf(stderr, COLOR_RED "\n%s " COLOR_OLD, __func__); \
|
#define DBG(...) do{ fprintf(stderr, COLOR_RED "%s " COLOR_OLD, __func__); \
|
||||||
fprintf(stderr, "(%s, line %d): ", __FILE__, __LINE__); \
|
fprintf(stderr, "(%s, line %d): ", __FILE__, __LINE__); \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
fprintf(stderr, "\n");} while(0)
|
fprintf(stderr, "\n");} while(0)
|
||||||
|
|
||||||
#else // EBUG
|
#else // EBUG
|
||||||
#define FNAME() do{}while(0)
|
#define FNAME()
|
||||||
#define DBG(...) do{}while(0)
|
#define DBG(...)
|
||||||
#endif // EBUG
|
#endif // EBUG
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# configuration file for SSII driven equatorial mount
|
|
||||||
verbose = 5
|
|
||||||
mountpath = /dev/ttyS1
|
|
||||||
mountspeed = 19200
|
|
||||||
encoderpath = /dev/ttyUSB0
|
|
||||||
encoderspeed = 153000
|
|
||||||
|
|
||||||
73
LibSidServo/movingmodel.c
Normal file
73
LibSidServo/movingmodel.c
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "movingmodel.h"
|
||||||
|
#include "ramp.h"
|
||||||
|
|
||||||
|
extern movemodel_t trapez;
|
||||||
|
|
||||||
|
static void chkminmax(double *min, double *max){
|
||||||
|
if(*min <= *max) return;
|
||||||
|
double t = *min;
|
||||||
|
*min = *max;
|
||||||
|
*max = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t *model_init(limits_t *l){
|
||||||
|
if(!l) return FALSE;
|
||||||
|
movemodel_t *m = calloc(1, sizeof(movemodel_t));
|
||||||
|
// we can't use memcpy or assign as Times/Params would be common for all
|
||||||
|
*m = trapez;
|
||||||
|
m->Times = calloc(STAGE_AMOUNT, sizeof(double));
|
||||||
|
m->Params = calloc(STAGE_AMOUNT, sizeof(moveparam_t));
|
||||||
|
moveparam_t *max = &l->max, *min = &l->min;
|
||||||
|
if(min->speed < 0.) min->speed = -min->speed;
|
||||||
|
if(max->speed < 0.) max->speed = -max->speed;
|
||||||
|
if(min->accel < 0.) min->accel = -min->accel;
|
||||||
|
if(max->accel < 0.) max->accel = -max->accel;
|
||||||
|
chkminmax(&min->coord, &max->coord);
|
||||||
|
chkminmax(&min->speed, &max->speed);
|
||||||
|
chkminmax(&min->accel, &max->accel);
|
||||||
|
m->Min = l->min;
|
||||||
|
m->Max = l->max;
|
||||||
|
m->movingstage = STAGE_STOPPED;
|
||||||
|
m->state = ST_STOP;
|
||||||
|
pthread_mutex_init(&m->mutex, NULL);
|
||||||
|
DBG("model inited");
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
int model_move2(movemodel_t *model, moveparam_t *target, double t){
|
||||||
|
if(!target || !model) return FALSE;
|
||||||
|
DBG("MOVE to %g (deg) at speed %g (deg/s)", target->coord/M_PI*180., target->speed/M_PI*180.);
|
||||||
|
// only positive velocity
|
||||||
|
if(target->speed < 0.) target->speed = -target->speed;
|
||||||
|
if(fabs(target->speed) < model->Min.speed){
|
||||||
|
DBG("STOP");
|
||||||
|
model->stop(model, t);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// don't mind about acceleration - user cannot set it now
|
||||||
|
return model->calculate(model, target, t);
|
||||||
|
}
|
||||||
76
LibSidServo/movingmodel.h
Normal file
76
LibSidServo/movingmodel.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "sidservo.h"
|
||||||
|
|
||||||
|
// tolerance, time ticks
|
||||||
|
#define COORD_TOLERANCE_DEFAULT (1e-8)
|
||||||
|
#define COORD_TOLERANCE_MIN (1e-12)
|
||||||
|
#define COORD_TOLERANCE_MAX (10.)
|
||||||
|
#define TIME_TICK_DEFAULT (0.0001)
|
||||||
|
#define TIME_TICK_MIN (1e-9)
|
||||||
|
#define TIME_TICK_MAX (10.)
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
ST_STOP, // stopped
|
||||||
|
ST_MOVE, // moving
|
||||||
|
ST_AMOUNT
|
||||||
|
} movestate_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
double coord;
|
||||||
|
double speed;
|
||||||
|
double accel;
|
||||||
|
} moveparam_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
moveparam_t min;
|
||||||
|
moveparam_t max;
|
||||||
|
//double acceleration;
|
||||||
|
} limits_t;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
STAGE_ACCEL, // start from last speed and accelerate/decelerate to target speed
|
||||||
|
STAGE_MAXSPEED, // go with target speed
|
||||||
|
STAGE_DECEL, // go from target speed to zero
|
||||||
|
STAGE_STOPPED, // stop
|
||||||
|
STAGE_AMOUNT
|
||||||
|
} movingstage_t;
|
||||||
|
|
||||||
|
typedef struct movemodel{
|
||||||
|
moveparam_t Min;
|
||||||
|
moveparam_t Max;
|
||||||
|
movingstage_t movingstage;
|
||||||
|
movestate_t state;
|
||||||
|
double *Times;
|
||||||
|
moveparam_t *Params;
|
||||||
|
moveparam_t curparams; // init values of limits, jerk
|
||||||
|
int (*calculate)(struct movemodel *m, moveparam_t *target, double t); // calculate stages of traectory beginning from t
|
||||||
|
movestate_t (*proc_move)(struct movemodel *m, moveparam_t *next, double t); // calculate next model point for time t
|
||||||
|
movestate_t (*get_state)(struct movemodel *m, moveparam_t *cur); // get current moving state
|
||||||
|
void (*stop)(struct movemodel *m, double t); // stop by ramp
|
||||||
|
void (*emergency_stop)(struct movemodel *m, double t); // stop with highest acceleration
|
||||||
|
double (*stoppedtime)(struct movemodel *m); // time when moving will ends
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
} movemodel_t;
|
||||||
|
|
||||||
|
movemodel_t *model_init(limits_t *l);
|
||||||
|
int model_move2(movemodel_t *model, moveparam_t *target, double t);
|
||||||
197
LibSidServo/polltest/main.c
Normal file
197
LibSidServo/polltest/main.c
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libsidservo project.
|
||||||
|
* Copyright 2026 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
// suppose that we ONLY poll data
|
||||||
|
#define XYBUFSZ (128)
|
||||||
|
|
||||||
|
struct{
|
||||||
|
int help;
|
||||||
|
char *Xpath;
|
||||||
|
char *Ypath;
|
||||||
|
double dt;
|
||||||
|
} G = {
|
||||||
|
.Xpath = "/dev/encoder_X0",
|
||||||
|
.Ypath = "/dev/encoder_Y0",
|
||||||
|
.dt = 0.001,
|
||||||
|
};
|
||||||
|
|
||||||
|
sl_option_t options[] = {
|
||||||
|
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
|
||||||
|
{"Xpath", NEED_ARG, NULL, 'X', arg_string, APTR(&G.Xpath), "path to X encoder"},
|
||||||
|
{"Ypath", NEED_ARG, NULL, 'Y', arg_string, APTR(&G.Ypath), "path to Y encoder"},
|
||||||
|
{"dt", NEED_ARG, NULL, 'd', arg_double, APTR(&G.dt), "request interval (1e-4..10s)"},
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
char buf[XYBUFSZ+1];
|
||||||
|
int len;
|
||||||
|
} buf_t;
|
||||||
|
|
||||||
|
static int Xfd = -1, Yfd = -1;
|
||||||
|
|
||||||
|
void signals(int sig){
|
||||||
|
if(sig){
|
||||||
|
signal(sig, SIG_IGN);
|
||||||
|
DBG("Get signal %d, quit.\n", sig);
|
||||||
|
}
|
||||||
|
DBG("close");
|
||||||
|
if(Xfd > 0){ close(Xfd); Xfd = -1; }
|
||||||
|
if(Yfd > 0){ close(Yfd); Yfd = -1; }
|
||||||
|
exit(sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int op(const char *nm){
|
||||||
|
int fd = open(nm, O_RDWR|O_NOCTTY|O_NONBLOCK);
|
||||||
|
if(fd < 0) ERR("Can't open %s", nm);
|
||||||
|
struct termios2 tty;
|
||||||
|
if(ioctl(fd, TCGETS2, &tty)) ERR("Can't read TTY settings");
|
||||||
|
tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG)
|
||||||
|
tty.c_iflag = 0; // don't do any changes in input stream
|
||||||
|
tty.c_oflag = 0; // don't do any changes in output stream
|
||||||
|
tty.c_cflag = BOTHER | CS8 | CREAD | CLOCAL; // other speed, 8bit, RW, ignore line ctrl
|
||||||
|
tty.c_ispeed = 1000000;
|
||||||
|
tty.c_ospeed = 1000000;
|
||||||
|
if(ioctl(fd, TCSETS2, &tty)) ERR("Can't set TTY settings");
|
||||||
|
// try to set exclusive
|
||||||
|
if(ioctl(fd, TIOCEXCL)){DBG("Can't make exclusive");}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write to buffer next data portion; return FALSE in case of error
|
||||||
|
static int readstrings(buf_t *buf, int fd){
|
||||||
|
FNAME();
|
||||||
|
if(!buf){WARNX("Empty buffer"); return FALSE;}
|
||||||
|
int L = XYBUFSZ - buf->len;
|
||||||
|
if(L == 0){
|
||||||
|
DBG("buffer overfull!", buf->len);
|
||||||
|
char *lastn = strrchr(buf->buf, '\n');
|
||||||
|
if(lastn){
|
||||||
|
fprintf(stderr, "BUFOVR: _%s_", buf->buf);
|
||||||
|
++lastn;
|
||||||
|
buf->len = XYBUFSZ - (lastn - buf->buf);
|
||||||
|
DBG("Memmove %d", buf->len);
|
||||||
|
memmove(lastn, buf->buf, buf->len);
|
||||||
|
buf->buf[buf->len] = 0;
|
||||||
|
}else buf->len = 0;
|
||||||
|
L = XYBUFSZ - buf->len;
|
||||||
|
}
|
||||||
|
int got = read(fd, &buf->buf[buf->len], L);
|
||||||
|
if(got < 0){
|
||||||
|
WARN("read()");
|
||||||
|
return FALSE;
|
||||||
|
}else if(got == 0){ DBG("NO data"); return TRUE; }
|
||||||
|
buf->len += got;
|
||||||
|
buf->buf[buf->len] = 0;
|
||||||
|
DBG("buf[%d]: %s", buf->len, buf->buf);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// return TRUE if got, FALSE if no data found
|
||||||
|
static int getdata(buf_t *buf, long *out){
|
||||||
|
if(!buf || buf->len < 1) return FALSE;
|
||||||
|
// read record between last '\n' and previous (or start of string)
|
||||||
|
char *last = &buf->buf[buf->len - 1];
|
||||||
|
//DBG("buf: _%s_", buf->buf);
|
||||||
|
if(*last != '\n') return FALSE;
|
||||||
|
*last = 0;
|
||||||
|
//DBG("buf: _%s_", buf->buf);
|
||||||
|
char *prev = strrchr(buf->buf, '\n');
|
||||||
|
if(!prev) prev = buf->buf;
|
||||||
|
else{
|
||||||
|
fprintf(stderr, "MORETHANONE: _%s_", buf->buf);
|
||||||
|
++prev; // after last '\n'
|
||||||
|
}
|
||||||
|
if(out) *out = atol(prev);
|
||||||
|
// clear buffer
|
||||||
|
buf->len = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
// try to write '\n' asking new data portion; return FALSE if failed
|
||||||
|
static int asknext(int fd){
|
||||||
|
FNAME();
|
||||||
|
if(fd < 0) return FALSE;
|
||||||
|
int i = 0;
|
||||||
|
for(; i < 5; ++i){
|
||||||
|
int l = write(fd, "\n", 1);
|
||||||
|
//DBG("l=%d", l);
|
||||||
|
if(1 == l) return TRUE;
|
||||||
|
usleep(100);
|
||||||
|
}
|
||||||
|
DBG("5 tries... failed!");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
buf_t xbuf, ybuf;
|
||||||
|
long xlast, ylast;
|
||||||
|
double xtlast, ytlast;
|
||||||
|
sl_init();
|
||||||
|
sl_parseargs(&argc, &argv, options);
|
||||||
|
if(G.help) sl_showhelp(-1, options);
|
||||||
|
if(G.dt < 1e-4) ERRX("dx too small");
|
||||||
|
if(G.dt > 10.) ERRX("dx too big");
|
||||||
|
Xfd = op(G.Xpath);
|
||||||
|
Yfd = op(G.Ypath);
|
||||||
|
struct pollfd pfds[2];
|
||||||
|
pfds[0].fd = Xfd; pfds[0].events = POLLIN;
|
||||||
|
pfds[1].fd = Yfd; pfds[1].events = POLLIN;
|
||||||
|
double t0x, t0y, tstart;
|
||||||
|
asknext(Xfd); asknext(Yfd);
|
||||||
|
t0x = t0y = tstart = sl_dtime();
|
||||||
|
DBG("Start");
|
||||||
|
do{ // main cycle
|
||||||
|
if(poll(pfds, 2, 0) < 0){
|
||||||
|
WARN("poll()");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(pfds[0].revents && POLLIN){
|
||||||
|
DBG("got X");
|
||||||
|
if(!readstrings(&xbuf, Xfd)) break;
|
||||||
|
}
|
||||||
|
if(pfds[1].revents && POLLIN){
|
||||||
|
DBG("got Y");
|
||||||
|
if(!readstrings(&ybuf, Yfd)) break;
|
||||||
|
}
|
||||||
|
double curt = sl_dtime();
|
||||||
|
if(getdata(&xbuf, &xlast)) xtlast = curt;
|
||||||
|
if(curt - t0x >= G.dt){ // get last records
|
||||||
|
if(curt - xtlast < 1.5*G.dt)
|
||||||
|
printf("%-14.4fX=%ld\n", xtlast-tstart, xlast);
|
||||||
|
if(!asknext(Xfd)) break;
|
||||||
|
t0x = (curt - t0x < 2.*G.dt) ? t0x + G.dt : curt;
|
||||||
|
}
|
||||||
|
curt = sl_dtime();
|
||||||
|
if(getdata(&ybuf, &ylast)) ytlast = curt;
|
||||||
|
if(curt - t0y >= G.dt){ // get last records
|
||||||
|
if(curt - ytlast < 1.5*G.dt)
|
||||||
|
printf("%-14.4fY=%ld\n", ytlast-tstart, ylast);
|
||||||
|
if(!asknext(Yfd)) break;
|
||||||
|
t0y = (curt - t0y < 2.*G.dt) ? t0y + G.dt : curt;
|
||||||
|
}
|
||||||
|
}while(Xfd > 0 && Yfd > 0);
|
||||||
|
DBG("OOps: disconnected");
|
||||||
|
signals(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
259
LibSidServo/ramp.c
Normal file
259
LibSidServo/ramp.c
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// simplest trapezioidal ramp
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "ramp.h"
|
||||||
|
|
||||||
|
#ifdef EBUG
|
||||||
|
#undef DBG
|
||||||
|
#define DBG(...)
|
||||||
|
#undef FNAME
|
||||||
|
#define FNAME()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static double coord_tolerance = COORD_TOLERANCE_DEFAULT;
|
||||||
|
|
||||||
|
static void emstop(movemodel_t *m, double _U_ t){
|
||||||
|
FNAME();
|
||||||
|
pthread_mutex_lock(&m->mutex);
|
||||||
|
m->curparams.accel = 0.;
|
||||||
|
m->curparams.speed = 0.;
|
||||||
|
bzero(m->Times, sizeof(double) * STAGE_AMOUNT);
|
||||||
|
bzero(m->Params, sizeof(moveparam_t) * STAGE_AMOUNT);
|
||||||
|
m->state = ST_STOP;
|
||||||
|
m->movingstage = STAGE_STOPPED;
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(movemodel_t *m, double t){
|
||||||
|
FNAME();
|
||||||
|
pthread_mutex_lock(&m->mutex);
|
||||||
|
if(m->state == ST_STOP || m->movingstage == STAGE_STOPPED) goto ret;
|
||||||
|
m->movingstage = STAGE_DECEL;
|
||||||
|
m->state = ST_MOVE;
|
||||||
|
m->Times[STAGE_DECEL] = t;
|
||||||
|
m->Params[STAGE_DECEL].speed = m->curparams.speed;
|
||||||
|
if(m->curparams.speed > 0.) m->Params[STAGE_DECEL].accel = -m->Max.accel;
|
||||||
|
else m->Params[STAGE_DECEL].accel = m->Max.accel;
|
||||||
|
m->Params[STAGE_DECEL].coord = m->curparams.coord;
|
||||||
|
// speed: v=v2+a2(t-t2), v2 and a2 have different signs; t3: v3=0 -> t3=t2-v2/a2
|
||||||
|
m->Times[STAGE_STOPPED] = t - m->curparams.speed / m->Params[STAGE_DECEL].accel;
|
||||||
|
// coordinate: x=x2+v2(t-t2)+a2(t-t2)^2/2 -> x3=x2+v2(t3-t2)+a2(t3-t2)^2/2
|
||||||
|
double dt = m->Times[STAGE_STOPPED] - t;
|
||||||
|
m->Params[STAGE_STOPPED].coord = m->curparams.coord + m->curparams.speed * dt +
|
||||||
|
m->Params[STAGE_DECEL].accel * dt * dt / 2.;
|
||||||
|
ret:
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// inner part of `calc`, could be called recoursively for hard case
|
||||||
|
static void unlockedcalc(movemodel_t *m, moveparam_t *x, double t){
|
||||||
|
// signs
|
||||||
|
double sign_a01 = 0., sign_a23 = 0., sign_vset = 0.; // accelerations on stages ACCEL and DECEL, speed on maxspeed stage
|
||||||
|
// times
|
||||||
|
double dt01 = 0., dt12 = 0., dt23 = 0.;
|
||||||
|
// absolute speed at stage 23 (or in that point); absolute max acceleration
|
||||||
|
double abs_vset = x->speed, abs_a = m->Max.accel;
|
||||||
|
// absolute target movement
|
||||||
|
double abs_Dx = fabs(x->coord - m->curparams.coord);
|
||||||
|
if(m->state == ST_STOP && abs_Dx < coord_tolerance){
|
||||||
|
DBG("Movement too small -> stay at place");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// signs of Dx and current speed
|
||||||
|
double sign_Dx = (x->coord > m->curparams.coord) ? 1. : -1.;
|
||||||
|
double v0 = m->curparams.speed;
|
||||||
|
double sign_v0 = v0 < 0. ? -1 : 1., abs_v0 = fabs(v0);
|
||||||
|
if(v0 == 0.) sign_v0 = 0.;
|
||||||
|
// preliminary calculations (vset and dependent values could be changed)
|
||||||
|
dt01 = fabs(abs_v0 - abs_vset) / abs_a;
|
||||||
|
double abs_dx23 = abs_vset * abs_vset / 2. / abs_a;
|
||||||
|
dt23 = abs_vset / abs_a;
|
||||||
|
double abs_dx_stop = abs_v0 * abs_v0 / 2. / abs_a;
|
||||||
|
if(sign_Dx * sign_v0 >= 0. && abs_dx_stop < abs_Dx){ // we shouldn't change speed direction
|
||||||
|
if(fabs(abs_dx_stop - abs_Dx) <= coord_tolerance){ // simplest case: just stop
|
||||||
|
//DBG("Simplest case: stop");
|
||||||
|
dt01 = dt12 = 0.;
|
||||||
|
sign_a23 = -sign_v0;
|
||||||
|
dt23 = abs_v0 / abs_a;
|
||||||
|
}else if(abs_vset < abs_v0){ // move with smaller speed than now: very simple case
|
||||||
|
//DBG("Move with smaller speed");
|
||||||
|
sign_a01 = sign_a23 = -sign_v0;
|
||||||
|
sign_vset = sign_v0;
|
||||||
|
double abs_dx01 = abs_v0 * dt01 - abs_a * dt01 * dt01 / 2.;
|
||||||
|
double abs_dx12 = abs_Dx - abs_dx01 - abs_dx23;
|
||||||
|
dt12 = abs_dx12 / abs_vset;
|
||||||
|
}else{// move with larget speed
|
||||||
|
//DBG("Move with larger speed");
|
||||||
|
double abs_dx01 = abs_v0 * dt01 + abs_a * dt01 * dt01 / 2.;
|
||||||
|
if(abs_Dx < abs_dx01 + abs_dx23){ // recalculate target speed and other
|
||||||
|
abs_vset = sqrt(abs_a * abs_Dx + abs_v0 * abs_v0 / 2.);
|
||||||
|
dt01 = fabs(abs_v0 - abs_vset) / abs_a;
|
||||||
|
abs_dx01 = abs_v0 * dt01 + abs_a * dt01 * dt01 / 2.;
|
||||||
|
dt23 = abs_vset / abs_a;
|
||||||
|
abs_dx23 = abs_vset * abs_vset / 2. / abs_a;
|
||||||
|
DBG("Can't reach target speed %g, take %g instead", x->speed, abs_vset);
|
||||||
|
}
|
||||||
|
sign_a01 = sign_Dx; // sign_v0 could be ZERO!!!
|
||||||
|
sign_a23 = -sign_Dx;
|
||||||
|
sign_vset = sign_Dx;
|
||||||
|
double abs_dx12 = abs_Dx - abs_dx01 - abs_dx23;
|
||||||
|
dt12 = abs_dx12 / abs_vset;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// if we are here, we have the worst case: change speed direction
|
||||||
|
// DBG("Hardest case: change speed direction");
|
||||||
|
// now we should calculate coordinate at which model stops and biuld new trapezium from that point
|
||||||
|
double x0 = m->curparams.coord, v0 = m->curparams.speed;
|
||||||
|
double xstop = x0 + sign_v0 * abs_dx_stop, tstop = t + abs_v0 / abs_a;
|
||||||
|
m->state = ST_STOP;
|
||||||
|
m->curparams.accel = 0.; m->curparams.coord = xstop; m->curparams.speed = 0.;
|
||||||
|
unlockedcalc(m, x, tstop); // calculate new ramp
|
||||||
|
// and change started conditions
|
||||||
|
m->curparams.coord = x0; m->curparams.speed = v0;
|
||||||
|
m->Times[STAGE_ACCEL] = t;
|
||||||
|
m->Params[STAGE_ACCEL].coord = x0;
|
||||||
|
m->Params[STAGE_ACCEL].speed = v0;
|
||||||
|
// DBG("NOW t[0]=%g, X[0]=%g, V[0]=%g", t, x0, v0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m->state = ST_MOVE;
|
||||||
|
m->movingstage = STAGE_ACCEL;
|
||||||
|
// some knot parameters
|
||||||
|
double a01 = sign_a01 * abs_a, a23 = sign_a23 * abs_a;
|
||||||
|
double v1, v2, x0, x1, x2;
|
||||||
|
v2 = v1 = sign_vset * abs_vset;
|
||||||
|
x0 = m->curparams.coord;
|
||||||
|
x1 = x0 + v0 * dt01 + a01 * dt01 * dt01 / 2.;
|
||||||
|
x2 = x1 + v1 * dt12;
|
||||||
|
// fill knot parameters
|
||||||
|
moveparam_t *p = &m->Params[STAGE_ACCEL]; // 0-1 - change started speed
|
||||||
|
p->accel = a01;
|
||||||
|
p->speed = m->curparams.speed;
|
||||||
|
p->coord = x0;
|
||||||
|
m->Times[STAGE_ACCEL] = t;
|
||||||
|
p = &m->Params[STAGE_MAXSPEED]; // 1-2 - constant speed
|
||||||
|
p->accel = 0.;
|
||||||
|
p->speed = v1;
|
||||||
|
p->coord = x1;
|
||||||
|
m->Times[STAGE_MAXSPEED] = m->Times[STAGE_ACCEL] + dt01;
|
||||||
|
p = &m->Params[STAGE_DECEL]; // 2-3 - decrease speed
|
||||||
|
p->accel = a23;
|
||||||
|
p->speed = v2;
|
||||||
|
p->coord = x2;
|
||||||
|
m->Times[STAGE_DECEL] = m->Times[STAGE_MAXSPEED] + dt12;
|
||||||
|
p = &m->Params[STAGE_STOPPED]; // 3 - stop at target
|
||||||
|
p->accel = p->speed = 0.;
|
||||||
|
p->coord = x->coord;
|
||||||
|
m->Times[STAGE_STOPPED] = m->Times[STAGE_DECEL] + dt23;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief calc - moving calculation
|
||||||
|
* @param x - using max speed (>0!!!) and coordinate
|
||||||
|
* @param t - current time value
|
||||||
|
* @return FALSE if can't move with given parameters
|
||||||
|
*/
|
||||||
|
static int calc(movemodel_t *m, moveparam_t *x, double t) {
|
||||||
|
//DBG("target coord/speed: %g/%g; current: %g/%g", x->coord, x->speed, m->curparams.coord, m->curparams.speed);
|
||||||
|
if (!x || !m) return FALSE;
|
||||||
|
pthread_mutex_lock(&m->mutex);
|
||||||
|
int ret = FALSE;
|
||||||
|
// Validate input parameters
|
||||||
|
if(x->coord < m->Min.coord || x->coord > m->Max.coord){
|
||||||
|
DBG("Wrong coordinate [%g, %g]", m->Min.coord, m->Max.coord);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if(x->speed < m->Min.speed || x->speed > m->Max.speed){
|
||||||
|
DBG("Wrong speed [%g, %g]", m->Min.speed, m->Max.speed);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
ret = TRUE; // now there's no chanses to make error
|
||||||
|
unlockedcalc(m, x, t);
|
||||||
|
// Debug output
|
||||||
|
/*for(int i = 0; i < STAGE_AMOUNT; i++){
|
||||||
|
DBG("Stage %d: t=%.6f, coord=%.6f, speed=%.6f, accel=%.6f",
|
||||||
|
i, m->Times[i], m->Params[i].coord, m->Params[i].speed, m->Params[i].accel);
|
||||||
|
}*/
|
||||||
|
ret:
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t proc(movemodel_t *m, moveparam_t *next, double t){
|
||||||
|
pthread_mutex_lock(&m->mutex);
|
||||||
|
if(m->state == ST_STOP) goto ret;
|
||||||
|
for(movingstage_t s = STAGE_STOPPED; s >= 0; --s){
|
||||||
|
if(m->Times[s] <= t){ // check time for current stage
|
||||||
|
m->movingstage = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(m->movingstage == STAGE_STOPPED){
|
||||||
|
m->curparams.coord = m->Params[STAGE_STOPPED].coord;
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
/* DBG("REACHED STOPping stage @ t=%g", t);
|
||||||
|
for(int s = STAGE_STOPPED; s >= 0; --s){
|
||||||
|
DBG("T[%d]=%g, ", s, m->Times[s]);
|
||||||
|
}*/
|
||||||
|
emstop(m, t);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
// calculate current parameters
|
||||||
|
double dt = t - m->Times[m->movingstage];
|
||||||
|
double a = m->Params[m->movingstage].accel;
|
||||||
|
double v0 = m->Params[m->movingstage].speed;
|
||||||
|
double x0 = m->Params[m->movingstage].coord;
|
||||||
|
m->curparams.accel = a;
|
||||||
|
m->curparams.speed = v0 + a * dt;
|
||||||
|
m->curparams.coord = x0 + v0 * dt + a * dt * dt / 2.;
|
||||||
|
ret:
|
||||||
|
if(next) *next = m->curparams;
|
||||||
|
movestate_t st = m->state;
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
static movestate_t getst(movemodel_t *m, moveparam_t *cur){
|
||||||
|
pthread_mutex_lock(&m->mutex);
|
||||||
|
if(cur) *cur = m->curparams;
|
||||||
|
movestate_t st = m->state;
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double gettstop(movemodel_t *m){
|
||||||
|
pthread_mutex_lock(&m->mutex);
|
||||||
|
double r = m->Times[STAGE_STOPPED];
|
||||||
|
pthread_mutex_unlock(&m->mutex);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
movemodel_t trapez = {
|
||||||
|
.stop = stop,
|
||||||
|
.emergency_stop = emstop,
|
||||||
|
.get_state = getst,
|
||||||
|
.calculate = calc,
|
||||||
|
.proc_move = proc,
|
||||||
|
.stoppedtime = gettstop,
|
||||||
|
};
|
||||||
23
LibSidServo/ramp.h
Normal file
23
LibSidServo/ramp.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the moving_model project.
|
||||||
|
* Copyright 2025 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "movingmodel.h"
|
||||||
|
|
||||||
|
extern movemodel_t trapez;
|
||||||
@@ -20,25 +20,28 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "dbg.h"
|
#include "main.h"
|
||||||
|
#include "movingmodel.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
#include "ssii.h"
|
||||||
|
|
||||||
// serial devices FD
|
// serial devices FD
|
||||||
static int encfd[2] = {-1, -1}, mntfd = -1;
|
static int encfd[2] = {-1, -1}, mntfd = -1;
|
||||||
// main mount data
|
// main mount data
|
||||||
static mountdata_t mountdata = {0};
|
static mountdata_t mountdata = {0};
|
||||||
// last encoders time and last encoders data - for speed measurement
|
// last encoders time and last encoders data - for speed measurement
|
||||||
static coordval_t lastXenc = {0}, lastYenc = {0};
|
//static coordval_t lastXenc = {0}, lastYenc = {0};
|
||||||
|
|
||||||
// mutexes for RW operations with mount device and data
|
// mutexes for RW operations with mount device and data
|
||||||
static pthread_mutex_t mntmutex = PTHREAD_MUTEX_INITIALIZER,
|
static pthread_mutex_t mntmutex = PTHREAD_MUTEX_INITIALIZER,
|
||||||
@@ -46,7 +49,7 @@ static pthread_mutex_t mntmutex = PTHREAD_MUTEX_INITIALIZER,
|
|||||||
// encoders thread and mount thread
|
// encoders thread and mount thread
|
||||||
static pthread_t encthread, mntthread;
|
static pthread_t encthread, mntthread;
|
||||||
// max timeout for 1.5 bytes of encoder and 2 bytes of mount - for `select`
|
// max timeout for 1.5 bytes of encoder and 2 bytes of mount - for `select`
|
||||||
static struct timeval encRtmout = {0}, mntRtmout = {0};
|
static struct timeval encRtmout = {.tv_sec = 0, .tv_usec = 100}, mntRtmout = {.tv_sec = 0, .tv_usec = 50000};
|
||||||
// encoders raw data
|
// encoders raw data
|
||||||
typedef struct __attribute__((packed)){
|
typedef struct __attribute__((packed)){
|
||||||
uint8_t magick;
|
uint8_t magick;
|
||||||
@@ -55,46 +58,32 @@ typedef struct __attribute__((packed)){
|
|||||||
uint8_t CRC[4];
|
uint8_t CRC[4];
|
||||||
} enc_t;
|
} enc_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief dtime - UNIX time with microsecond
|
|
||||||
* @return value
|
|
||||||
*/
|
|
||||||
double dtime(){
|
|
||||||
double t;
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
t = tv.tv_sec + ((double)tv.tv_usec)/1e6;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
double tv2d(struct timeval *tv){
|
|
||||||
if(!tv) return 0.;
|
|
||||||
double t = tv->tv_sec + ((double)tv->tv_usec) / 1e6;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
// init start time
|
|
||||||
static void gttime(){
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
tv_sec_got = tv.tv_sec;
|
|
||||||
tv_usec_got = tv.tv_usec;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// calculate current X/Y speeds
|
// calculate current X/Y speeds
|
||||||
static void getXspeed(double t){
|
void getXspeed(){
|
||||||
mountdata.encXspeed.val = (mountdata.encXposition.val - lastXenc.val) / (t - lastXenc.t);
|
static less_square_t *ls = NULL;
|
||||||
mountdata.encXspeed.t = (lastXenc.t + t) / 2.;
|
if(!ls){
|
||||||
lastXenc.val = mountdata.encXposition.val;
|
ls = LS_init(Conf.EncoderSpeedInterval / Conf.EncoderReqInterval);
|
||||||
lastXenc.t = t;
|
if(!ls) return;
|
||||||
|
}
|
||||||
|
double dt = timediff0(&mountdata.encXposition.t);
|
||||||
|
double speed = LS_calc_slope(ls, mountdata.encXposition.val, dt);
|
||||||
|
if(fabs(speed) < 1.5 * Xlimits.max.speed){
|
||||||
|
mountdata.encXspeed.val = speed;
|
||||||
|
mountdata.encXspeed.t = mountdata.encXposition.t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void getYspeed(){
|
||||||
|
static less_square_t *ls = NULL;
|
||||||
|
if(!ls){
|
||||||
|
ls = LS_init(Conf.EncoderSpeedInterval / Conf.EncoderReqInterval);
|
||||||
|
if(!ls) return;
|
||||||
|
}
|
||||||
|
double dt = timediff0(&mountdata.encYposition.t);
|
||||||
|
double speed = LS_calc_slope(ls, mountdata.encYposition.val, dt);
|
||||||
|
if(fabs(speed) < 1.5 * Ylimits.max.speed){
|
||||||
|
mountdata.encYspeed.val = speed;
|
||||||
|
mountdata.encYspeed.t = mountdata.encYposition.t;
|
||||||
}
|
}
|
||||||
static void getYspeed(double t){
|
|
||||||
mountdata.encYspeed.val = (mountdata.encYposition.val - lastYenc.val) / (t - lastYenc.t);
|
|
||||||
mountdata.encYspeed.t = (lastYenc.t + t) / 2.;
|
|
||||||
lastYenc.val = mountdata.encYposition.val;
|
|
||||||
lastYenc.t = t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,7 +91,8 @@ static void getYspeed(double t){
|
|||||||
* @param databuf - input buffer with 13 bytes of data
|
* @param databuf - input buffer with 13 bytes of data
|
||||||
* @param t - time when databuf[0] got
|
* @param t - time when databuf[0] got
|
||||||
*/
|
*/
|
||||||
static void parse_encbuf(uint8_t databuf[ENC_DATALEN], double t){
|
static void parse_encbuf(uint8_t databuf[ENC_DATALEN], struct timespec *t){
|
||||||
|
if(!t) return;
|
||||||
enc_t *edata = (enc_t*) databuf;
|
enc_t *edata = (enc_t*) databuf;
|
||||||
/*
|
/*
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
@@ -137,17 +127,17 @@ static void parse_encbuf(uint8_t databuf[ENC_DATALEN], double t){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&datamutex);
|
pthread_mutex_lock(&datamutex);
|
||||||
mountdata.encXposition.val = X_ENC2RAD(edata->encX);
|
mountdata.encXposition.val = Xenc2rad(edata->encX);
|
||||||
mountdata.encYposition.val = Y_ENC2RAD(edata->encY);
|
mountdata.encYposition.val = Yenc2rad(edata->encY);
|
||||||
DBG("Got positions X/Y= %.6g / %.6g", mountdata.encXposition.val, mountdata.encYposition.val);
|
DBG("Got positions X/Y= %.6g / %.6g", mountdata.encXposition.val, mountdata.encYposition.val);
|
||||||
mountdata.encXposition.t = t;
|
mountdata.encXposition.t = *t;
|
||||||
mountdata.encYposition.t = t;
|
mountdata.encYposition.t = *t;
|
||||||
if(t - lastXenc.t > Conf.EncoderSpeedInterval) getXspeed(t);
|
getXspeed(); getYspeed();
|
||||||
if(t - lastYenc.t > Conf.EncoderSpeedInterval) getYspeed(t);
|
|
||||||
pthread_mutex_unlock(&datamutex);
|
pthread_mutex_unlock(&datamutex);
|
||||||
//DBG("time = %zd+%zd/1e6, X=%g deg, Y=%g deg", tv->tv_sec, tv->tv_usec, mountdata.encposition.X*180./M_PI, mountdata.encposition.Y*180./M_PI);
|
//DBG("time = %zd+%zd/1e6, X=%g deg, Y=%g deg", tv->tv_sec, tv->tv_usec, mountdata.encposition.X*180./M_PI, mountdata.encposition.Y*180./M_PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/**
|
/**
|
||||||
* @brief getencval - get uint64_t data from encoder
|
* @brief getencval - get uint64_t data from encoder
|
||||||
* @param fd - encoder fd
|
* @param fd - encoder fd
|
||||||
@@ -155,33 +145,53 @@ static void parse_encbuf(uint8_t databuf[ENC_DATALEN], double t){
|
|||||||
* @param t - measurement time
|
* @param t - measurement time
|
||||||
* @return amount of data read or 0 if problem
|
* @return amount of data read or 0 if problem
|
||||||
*/
|
*/
|
||||||
static int getencval(int fd, double *val, double *t){
|
static int getencval(int fd, double *val, struct timespec *t){
|
||||||
if(fd < 0) return FALSE;
|
if(fd < 0){
|
||||||
|
DBG("Encoder fd < 0!");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int got = 0, Lmax = 127;
|
int got = 0, Lmax = 127;
|
||||||
double t0 = dtime();
|
double t0 = timefromstart();
|
||||||
|
//DBG("start: %.6g", t0);
|
||||||
do{
|
do{
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(fd, &rfds);
|
FD_SET(fd, &rfds);
|
||||||
struct timeval tv = encRtmout;
|
struct timeval tv = encRtmout;
|
||||||
int retval = select(fd + 1, &rfds, NULL, NULL, &tv);
|
int retval = select(fd + 1, &rfds, NULL, NULL, &tv);
|
||||||
if(!retval) continue;
|
if(!retval){
|
||||||
|
//DBG("select()==0 - timeout, %.6g", timefromstart());
|
||||||
|
break;
|
||||||
|
}
|
||||||
if(retval < 0){
|
if(retval < 0){
|
||||||
if(errno == EINTR) continue;
|
if(errno == EINTR){
|
||||||
|
DBG("EINTR");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DBG("select() < 0");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(FD_ISSET(fd, &rfds)){
|
if(FD_ISSET(fd, &rfds)){
|
||||||
ssize_t l = read(fd, &buf[got], Lmax);
|
ssize_t l = read(fd, &buf[got], Lmax);
|
||||||
if(l < 1) return 0; // disconnected ??
|
if(l < 1){
|
||||||
|
DBG("read() < 0");
|
||||||
|
return 0; // disconnected ??
|
||||||
|
}
|
||||||
got += l; Lmax -= l;
|
got += l; Lmax -= l;
|
||||||
buf[got] = 0;
|
buf[got] = 0;
|
||||||
} else continue;
|
} else continue;
|
||||||
if(strchr(buf, '\n')) break;
|
if(buf[got-1] == '\n') break; // got EOL as last symbol
|
||||||
}while(Lmax && dtime() - t0 < Conf.EncoderReqInterval);
|
}while(Lmax && timefromstart() - t0 < Conf.EncoderReqInterval / 5.);
|
||||||
if(got == 0) return 0; // WTF?
|
if(got == 0){
|
||||||
|
//DBG("No data from encoder, tfs=%.6g", timefromstart());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
char *estr = strrchr(buf, '\n');
|
char *estr = strrchr(buf, '\n');
|
||||||
if(!estr) return 0;
|
if(!estr){
|
||||||
|
DBG("No EOL");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
*estr = 0;
|
*estr = 0;
|
||||||
char *bgn = strrchr(buf, '\n');
|
char *bgn = strrchr(buf, '\n');
|
||||||
if(bgn) ++bgn;
|
if(bgn) ++bgn;
|
||||||
@@ -193,9 +203,11 @@ static int getencval(int fd, double *val, double *t){
|
|||||||
return 0; // wrong number
|
return 0; // wrong number
|
||||||
}
|
}
|
||||||
if(val) *val = (double) data;
|
if(val) *val = (double) data;
|
||||||
if(t) *t = t0;
|
if(t){ if(!curtime(t)){ DBG("Can't get time"); return 0; }}
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// try to read 1 byte from encoder; return -1 if nothing to read or -2 if device seems to be disconnected
|
// try to read 1 byte from encoder; return -1 if nothing to read or -2 if device seems to be disconnected
|
||||||
static int getencbyte(){
|
static int getencbyte(){
|
||||||
if(encfd[0] < 0) return -1;
|
if(encfd[0] < 0) return -1;
|
||||||
@@ -243,19 +255,43 @@ static int getmntbyte(){
|
|||||||
if(FD_ISSET(mntfd, &rfds)){
|
if(FD_ISSET(mntfd, &rfds)){
|
||||||
ssize_t l = read(mntfd, &byte, 1);
|
ssize_t l = read(mntfd, &byte, 1);
|
||||||
//DBG("MNT read=%zd byte=0x%X", l, byte);
|
//DBG("MNT read=%zd byte=0x%X", l, byte);
|
||||||
if(l != 1) return -2; // disconnected ??
|
if(l != 1){
|
||||||
|
DBG("Mount disconnected?");
|
||||||
|
return -2; // disconnected ??
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else return -1;
|
} else return -1;
|
||||||
}while(1);
|
}while(1);
|
||||||
return (int)byte;
|
return (int)byte;
|
||||||
}
|
}
|
||||||
|
// clear data from input buffer
|
||||||
|
static void clrmntbuf(){
|
||||||
|
if(mntfd < 0) return;
|
||||||
|
uint8_t byte;
|
||||||
|
fd_set rfds;
|
||||||
|
do{
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(mntfd, &rfds);
|
||||||
|
struct timeval tv = {.tv_sec=0, .tv_usec=10};
|
||||||
|
int retval = select(mntfd + 1, &rfds, NULL, NULL, &tv);
|
||||||
|
if(retval < 0){
|
||||||
|
if(errno == EINTR) continue;
|
||||||
|
DBG("Error in select()");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(FD_ISSET(mntfd, &rfds)){
|
||||||
|
ssize_t l = read(mntfd, &byte, 1);
|
||||||
|
if(l != 1) break;
|
||||||
|
} else break;
|
||||||
|
}while(1);
|
||||||
|
}
|
||||||
|
|
||||||
// main encoder thread (for separate encoder): read next data and make parsing
|
// main encoder thread (for separate encoder): read next data and make parsing
|
||||||
static void *encoderthread1(void _U_ *u){
|
static void *encoderthread1(void _U_ *u){
|
||||||
if(Conf.SepEncoder != 1) return NULL;
|
if(Conf.SepEncoder != 1) return NULL;
|
||||||
uint8_t databuf[ENC_DATALEN];
|
uint8_t databuf[ENC_DATALEN];
|
||||||
int wridx = 0, errctr = 0;
|
int wridx = 0, errctr = 0;
|
||||||
double t = 0.;
|
struct timespec tcur;
|
||||||
while(encfd[0] > -1 && errctr < MAX_ERR_CTR){
|
while(encfd[0] > -1 && errctr < MAX_ERR_CTR){
|
||||||
int b = getencbyte();
|
int b = getencbyte();
|
||||||
if(b == -2) ++errctr;
|
if(b == -2) ++errctr;
|
||||||
@@ -266,15 +302,16 @@ static void *encoderthread1(void _U_ *u){
|
|||||||
if((uint8_t)b == ENC_MAGICK){
|
if((uint8_t)b == ENC_MAGICK){
|
||||||
// DBG("Got magic -> start filling packet");
|
// DBG("Got magic -> start filling packet");
|
||||||
databuf[wridx++] = (uint8_t) b;
|
databuf[wridx++] = (uint8_t) b;
|
||||||
t = dtime();
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}else databuf[wridx++] = (uint8_t) b;
|
}else databuf[wridx++] = (uint8_t) b;
|
||||||
if(wridx == ENC_DATALEN){
|
if(wridx == ENC_DATALEN){
|
||||||
parse_encbuf(databuf, t);
|
if(curtime(&tcur)){
|
||||||
|
parse_encbuf(databuf, &tcur);
|
||||||
wridx = 0;
|
wridx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(encfd[0] > -1){
|
if(encfd[0] > -1){
|
||||||
close(encfd[0]);
|
close(encfd[0]);
|
||||||
encfd[0] = -1;
|
encfd[0] = -1;
|
||||||
@@ -282,47 +319,138 @@ static void *encoderthread1(void _U_ *u){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define XYBUFSZ (128)
|
||||||
|
typedef struct{
|
||||||
|
char buf[XYBUFSZ+1];
|
||||||
|
int len;
|
||||||
|
} buf_t;
|
||||||
|
|
||||||
|
// write to buffer next data portion; return FALSE in case of error
|
||||||
|
static int readstrings(buf_t *buf, int fd){
|
||||||
|
if(!buf){DBG("Empty buffer"); return FALSE;}
|
||||||
|
int L = XYBUFSZ - buf->len;
|
||||||
|
if(L < 0){
|
||||||
|
DBG("buf not initialized!");
|
||||||
|
buf->len = 0;
|
||||||
|
}
|
||||||
|
if(L == 0){
|
||||||
|
DBG("buffer overfull: %d!", buf->len);
|
||||||
|
char *lastn = strrchr(buf->buf, '\n');
|
||||||
|
if(lastn){
|
||||||
|
fprintf(stderr, "BUFOVR: _%s_", buf->buf);
|
||||||
|
++lastn;
|
||||||
|
buf->len = XYBUFSZ - (lastn - buf->buf);
|
||||||
|
DBG("Memmove %d", buf->len);
|
||||||
|
memmove(lastn, buf->buf, buf->len);
|
||||||
|
buf->buf[buf->len] = 0;
|
||||||
|
}else buf->len = 0;
|
||||||
|
L = XYBUFSZ - buf->len;
|
||||||
|
}
|
||||||
|
//DBG("read %d bytes from %d", L, fd);
|
||||||
|
int got = read(fd, &buf->buf[buf->len], L);
|
||||||
|
if(got < 0){
|
||||||
|
DBG("read()");
|
||||||
|
return FALSE;
|
||||||
|
}else if(got == 0){ DBG("NO data"); return TRUE; }
|
||||||
|
buf->len += got;
|
||||||
|
buf->buf[buf->len] = 0;
|
||||||
|
//DBG("buf[%d]: %s", buf->len, buf->buf);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return TRUE if got, FALSE if no data found
|
||||||
|
static int getdata(buf_t *buf, long *out){
|
||||||
|
if(!buf || buf->len < 1 || buf->len > (XYBUFSZ+1)) return FALSE;
|
||||||
|
// read record between last '\n' and previous (or start of string)
|
||||||
|
char *last = &buf->buf[buf->len - 1];
|
||||||
|
//DBG("buf: _%s_", buf->buf);
|
||||||
|
if(*last != '\n') return FALSE;
|
||||||
|
*last = 0;
|
||||||
|
//DBG("buf: _%s_", buf->buf);
|
||||||
|
char *prev = strrchr(buf->buf, '\n');
|
||||||
|
if(!prev) prev = buf->buf;
|
||||||
|
else{
|
||||||
|
fprintf(stderr, "MORETHANONE: _%s_", buf->buf);
|
||||||
|
++prev; // after last '\n'
|
||||||
|
}
|
||||||
|
if(out) *out = atol(prev);
|
||||||
|
// clear buffer
|
||||||
|
buf->len = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to write '\n' asking new data portion; return FALSE if failed
|
||||||
|
static int asknext(int fd){
|
||||||
|
//FNAME();
|
||||||
|
if(fd < 0) return FALSE;
|
||||||
|
int i = 0;
|
||||||
|
for(; i < 5; ++i){
|
||||||
|
int l = write(fd, "\n", 1);
|
||||||
|
//DBG("l=%d", l);
|
||||||
|
if(1 == l) return TRUE;
|
||||||
|
usleep(100);
|
||||||
|
}
|
||||||
|
DBG("5 tries... failed!");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
// main encoder thread for separate encoders as USB devices /dev/encoder_X0 and /dev/encoder_Y0
|
// main encoder thread for separate encoders as USB devices /dev/encoder_X0 and /dev/encoder_Y0
|
||||||
static void *encoderthread2(void _U_ *u){
|
static void *encoderthread2(void _U_ *u){
|
||||||
if(Conf.SepEncoder != 2) return NULL;
|
if(Conf.SepEncoder != 2) return NULL;
|
||||||
DBG("Thread started");
|
DBG("Thread started");
|
||||||
|
struct pollfd pfds[2];
|
||||||
|
pfds[0].fd = encfd[0]; pfds[0].events = POLLIN;
|
||||||
|
pfds[1].fd = encfd[1]; pfds[1].events = POLLIN;
|
||||||
|
double t0[2], tstart;
|
||||||
|
buf_t strbuf[2] = {0};
|
||||||
|
long msrlast[2]; // last encoder data
|
||||||
|
double mtlast[2]; // last measurement time
|
||||||
|
asknext(encfd[0]); asknext(encfd[1]);
|
||||||
|
t0[0] = t0[1] = tstart = timefromstart();
|
||||||
int errctr = 0;
|
int errctr = 0;
|
||||||
double t0 = dtime();
|
do{ // main cycle
|
||||||
const char *req = "next\n";
|
if(poll(pfds, 2, 0) < 0){
|
||||||
int need2ask = 0; // need or not to ask encoder for new data
|
DBG("poll()");
|
||||||
while(encfd[0] > -1 && encfd[1] > -1 && errctr < MAX_ERR_CTR){
|
break;
|
||||||
if(need2ask){
|
|
||||||
if(5 != write(encfd[0], req, 5)) { ++errctr; continue; }
|
|
||||||
else if(5 != write(encfd[1], req, 5)) { ++errctr; continue; }
|
|
||||||
}
|
}
|
||||||
double v, t;
|
int got = 0;
|
||||||
if(getencval(encfd[0], &v, &t)){
|
for(int i = 0; i < 2; ++i){
|
||||||
mountdata.encXposition.val = X_ENC2RAD(v);
|
if(pfds[i].revents && POLLIN){
|
||||||
//DBG("encX(%g) = %g", t, mountdata.encXposition.val);
|
if(!readstrings(&strbuf[i], encfd[i])){
|
||||||
mountdata.encXposition.t = t;
|
++errctr;
|
||||||
if(t - lastXenc.t > Conf.EncoderSpeedInterval) getXspeed(t);
|
break;
|
||||||
if(getencval(encfd[1], &v, &t)){
|
}
|
||||||
mountdata.encYposition.val = Y_ENC2RAD(v);
|
}
|
||||||
//DBG("encY(%g) = %g", t, mountdata.encYposition.val);
|
double curt = timefromstart();
|
||||||
mountdata.encYposition.t = t;
|
if(getdata(&strbuf[i], &msrlast[i])) mtlast[i] = curt;
|
||||||
if(t - lastYenc.t > Conf.EncoderSpeedInterval) getYspeed(t);
|
if(curt - t0[i] >= Conf.EncoderReqInterval){ // get last records
|
||||||
errctr = 0;
|
if(curt - mtlast[i] < 1.5*Conf.EncoderReqInterval){
|
||||||
need2ask = 0;
|
pthread_mutex_lock(&datamutex);
|
||||||
|
if(i == 0){
|
||||||
|
mountdata.encXposition.val = Xenc2rad((double)msrlast[i]);
|
||||||
|
curtime(&mountdata.encXposition.t);
|
||||||
|
/*DBG("msrlast=%ld, Xpos.val=%g, t=%zd; XEzero=%d, SPR=%g",
|
||||||
|
msrlast[i], mountdata.encXposition.val, mountdata.encXposition.t.tv_sec,
|
||||||
|
X_ENC_ZERO, X_ENC_STEPSPERREV);*/
|
||||||
|
getXspeed();
|
||||||
}else{
|
}else{
|
||||||
if(need2ask) ++errctr;
|
mountdata.encYposition.val = Yenc2rad((double)msrlast[i]);
|
||||||
else need2ask = 1;
|
curtime(&mountdata.encYposition.t);
|
||||||
continue;
|
getYspeed();
|
||||||
}
|
}
|
||||||
} else {
|
pthread_mutex_unlock(&datamutex);
|
||||||
if(need2ask) ++errctr;
|
|
||||||
else need2ask = 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
while(dtime() - t0 < Conf.EncoderReqInterval){ usleep(10); }
|
if(!asknext(encfd[i])){
|
||||||
//DBG("DT=%g (RI=%g)", dtime()-t0, Conf.EncoderReqInterval);
|
++errctr;
|
||||||
t0 = dtime();
|
break;
|
||||||
}
|
}
|
||||||
DBG("ERRCTR=%d", errctr);
|
t0[i] = (curt - t0[i] < 2.*Conf.EncoderReqInterval) ? t0[i] + Conf.EncoderReqInterval : curt;
|
||||||
|
++got;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(got == 2) errctr = 0;
|
||||||
|
}while(encfd[0] > -1 && encfd[1] > -1 && errctr < MAX_ERR_CTR);
|
||||||
|
DBG("\n\nEXIT: ERRCTR=%d", errctr);
|
||||||
for(int i = 0; i < 2; ++i){
|
for(int i = 0; i < 2; ++i){
|
||||||
if(encfd[i] > -1){
|
if(encfd[i] > -1){
|
||||||
close(encfd[i]);
|
close(encfd[i]);
|
||||||
@@ -348,25 +476,78 @@ void data_free(data_t **x){
|
|||||||
*x = NULL;
|
*x = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void chkModStopped(double *prev, double cur, int *nstopped, axis_status_t *stat){
|
||||||
|
if(!prev || !nstopped || !stat) return;
|
||||||
|
if(isnan(*prev)){
|
||||||
|
*stat = AXIS_STOPPED;
|
||||||
|
DBG("START");
|
||||||
|
}else if(*stat != AXIS_STOPPED){
|
||||||
|
if(fabs(*prev - cur) < DBL_EPSILON && ++(*nstopped) > MOTOR_STOPPED_CNT){
|
||||||
|
*stat = AXIS_STOPPED;
|
||||||
|
DBG("AXIS stopped; prev=%g, cur=%g; nstopped=%d", *prev/M_PI*180., cur/M_PI*180., *nstopped);
|
||||||
|
}
|
||||||
|
}else if(*prev != cur){
|
||||||
|
DBG("AXIS moving");
|
||||||
|
*nstopped = 0;
|
||||||
|
}
|
||||||
|
*prev = cur;
|
||||||
|
}
|
||||||
|
|
||||||
// main mount thread
|
// main mount thread
|
||||||
static void *mountthread(void _U_ *u){
|
static void *mountthread(void _U_ *u){
|
||||||
int errctr = 0;
|
int errctr = 0;
|
||||||
uint8_t buf[2*sizeof(SSstat)];
|
uint8_t buf[2*sizeof(SSstat)];
|
||||||
SSstat *status = (SSstat*) buf;
|
SSstat *status = (SSstat*) buf;
|
||||||
|
bzero(&mountdata, sizeof(mountdata));
|
||||||
|
double t0 = timefromstart(), tstart = t0, tcur = t0;
|
||||||
|
double oldmt = -100.; // old `millis measurement` time
|
||||||
|
static uint32_t oldmillis = 0;
|
||||||
|
if(Conf.RunModel){
|
||||||
|
double Xprev = NAN, Yprev = NAN; // previous coordinates
|
||||||
|
int xcnt = 0, ycnt = 0;
|
||||||
|
while(1){
|
||||||
|
coordpair_t c;
|
||||||
|
movestate_t xst, yst;
|
||||||
|
// now change data
|
||||||
|
getModData(&c, &xst, &yst);
|
||||||
|
struct timespec tnow;
|
||||||
|
if(!curtime(&tnow) || (tcur = timefromstart()) < 0.) continue;
|
||||||
|
pthread_mutex_lock(&datamutex);
|
||||||
|
mountdata.encXposition.t = mountdata.encYposition.t = tnow;
|
||||||
|
mountdata.encXposition.val = c.X + (drand48() - 0.5)*1e-6; // .2arcsec error
|
||||||
|
mountdata.encYposition.val = c.Y + (drand48() - 0.5)*1e-6;
|
||||||
|
//DBG("t=%g, X=%g, Y=%g", tnow, c.X.val, c.Y.val);
|
||||||
|
if(tcur - oldmt > Conf.MountReqInterval){
|
||||||
|
oldmillis = mountdata.millis = (uint32_t)((tcur - tstart) * 1e3);
|
||||||
|
mountdata.motYposition.t = mountdata.motXposition.t = tnow;
|
||||||
|
if(xst == ST_MOVE)
|
||||||
|
mountdata.motXposition.val = c.X + (c.X - mountdata.motXposition.val)*(drand48() - 0.5)/100.;
|
||||||
|
//else
|
||||||
|
// mountdata.motXposition.val = c.X;
|
||||||
|
if(yst == ST_MOVE)
|
||||||
|
mountdata.motYposition.val = c.Y + (c.Y - mountdata.motYposition.val)*(drand48() - 0.5)/100.;
|
||||||
|
//else
|
||||||
|
// mountdata.motYposition.val = c.Y;
|
||||||
|
oldmt = tcur;
|
||||||
|
}else mountdata.millis = oldmillis;
|
||||||
|
chkModStopped(&Xprev, c.X, &xcnt, &mountdata.Xstate);
|
||||||
|
chkModStopped(&Yprev, c.Y, &ycnt, &mountdata.Ystate);
|
||||||
|
getXspeed(); getYspeed();
|
||||||
|
pthread_mutex_unlock(&datamutex);
|
||||||
|
while(timefromstart() - t0 < Conf.EncoderReqInterval) usleep(50);
|
||||||
|
t0 = timefromstart();
|
||||||
|
}
|
||||||
|
}
|
||||||
// data to get
|
// data to get
|
||||||
data_t d = {.buf = buf, .maxlen = sizeof(buf)};
|
data_t d = {.buf = buf, .maxlen = sizeof(buf)};
|
||||||
// cmd to send
|
// cmd to send
|
||||||
data_t *cmd_getstat = cmd2dat(CMD_GETSTAT);
|
data_t *cmd_getstat = cmd2dat(CMD_GETSTAT);
|
||||||
if(!cmd_getstat) goto failed;
|
if(!cmd_getstat) goto failed;
|
||||||
double t0 = dtime();
|
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
double t00 = t0;
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
while(mntfd > -1 && errctr < MAX_ERR_CTR){
|
while(mntfd > -1 && errctr < MAX_ERR_CTR){
|
||||||
// read data to status
|
// read data to status
|
||||||
double tgot = dtime();
|
struct timespec tcur;
|
||||||
|
if(!curtime(&tcur)) continue;
|
||||||
|
// 80 milliseconds to get answer on GETSTAT
|
||||||
if(!MountWriteRead(cmd_getstat, &d) || d.len != sizeof(SSstat)){
|
if(!MountWriteRead(cmd_getstat, &d) || d.len != sizeof(SSstat)){
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
DBG("Can't read SSstat, need %zd got %zd bytes", sizeof(SSstat), d.len);
|
DBG("Can't read SSstat, need %zd got %zd bytes", sizeof(SSstat), d.len);
|
||||||
@@ -382,13 +563,13 @@ static void *mountthread(void _U_ *u){
|
|||||||
errctr = 0;
|
errctr = 0;
|
||||||
pthread_mutex_lock(&datamutex);
|
pthread_mutex_lock(&datamutex);
|
||||||
// now change data
|
// now change data
|
||||||
SSconvstat(status, &mountdata, tgot);
|
SSconvstat(status, &mountdata, &tcur);
|
||||||
pthread_mutex_unlock(&datamutex);
|
pthread_mutex_unlock(&datamutex);
|
||||||
// allow writing & getters
|
// allow writing & getters
|
||||||
//DBG("t0=%g, tnow=%g", t0-t00, dtime()-t00);
|
do{
|
||||||
if(dtime() - t0 >= Conf.MountReqInterval) usleep(50);
|
usleep(500);
|
||||||
while(dtime() - t0 < Conf.MountReqInterval);
|
}while(timefromstart() - t0 < Conf.MountReqInterval);
|
||||||
t0 = dtime();
|
t0 = timefromstart();
|
||||||
}
|
}
|
||||||
data_free(&cmd_getstat);
|
data_free(&cmd_getstat);
|
||||||
failed:
|
failed:
|
||||||
@@ -404,8 +585,15 @@ static int ttyopen(const char *path, speed_t speed){
|
|||||||
int fd = -1;
|
int fd = -1;
|
||||||
struct termios2 tty;
|
struct termios2 tty;
|
||||||
DBG("Try to open %s @ %d", path, speed);
|
DBG("Try to open %s @ %d", path, speed);
|
||||||
if((fd = open(path, O_RDWR|O_NOCTTY)) < 0) return -1;
|
if((fd = open(path, O_RDWR|O_NOCTTY)) < 0){
|
||||||
if(ioctl(fd, TCGETS2, &tty)){ close(fd); return -1; }
|
DBG("Can't open device %s: %s", path, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(ioctl(fd, TCGETS2, &tty)){
|
||||||
|
DBG("Can't read TTY settings");
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG)
|
tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG)
|
||||||
tty.c_iflag = 0; // don't do any changes in input stream
|
tty.c_iflag = 0; // don't do any changes in input stream
|
||||||
tty.c_oflag = 0; // don't do any changes in output stream
|
tty.c_oflag = 0; // don't do any changes in output stream
|
||||||
@@ -414,7 +602,11 @@ static int ttyopen(const char *path, speed_t speed){
|
|||||||
tty.c_ospeed = speed;
|
tty.c_ospeed = speed;
|
||||||
//tty.c_cc[VMIN] = 0; // non-canonical mode
|
//tty.c_cc[VMIN] = 0; // non-canonical mode
|
||||||
//tty.c_cc[VTIME] = 5;
|
//tty.c_cc[VTIME] = 5;
|
||||||
if(ioctl(fd, TCSETS2, &tty)){ close(fd); return -1; }
|
if(ioctl(fd, TCSETS2, &tty)){
|
||||||
|
DBG("Can't set TTY settings");
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
DBG("Check speed: i=%d, o=%d", tty.c_ispeed, tty.c_ospeed);
|
DBG("Check speed: i=%d, o=%d", tty.c_ispeed, tty.c_ospeed);
|
||||||
if(tty.c_ispeed != (speed_t) speed || tty.c_ospeed != (speed_t)speed){ close(fd); return -1; }
|
if(tty.c_ispeed != (speed_t) speed || tty.c_ospeed != (speed_t)speed){ close(fd); return -1; }
|
||||||
// try to set exclusive
|
// try to set exclusive
|
||||||
@@ -424,6 +616,7 @@ static int ttyopen(const char *path, speed_t speed){
|
|||||||
|
|
||||||
// return FALSE if failed
|
// return FALSE if failed
|
||||||
int openEncoder(){
|
int openEncoder(){
|
||||||
|
if(Conf.RunModel) return TRUE;
|
||||||
if(!Conf.SepEncoder) return FALSE; // try to open separate encoder when it's absent
|
if(!Conf.SepEncoder) return FALSE; // try to open separate encoder when it's absent
|
||||||
if(Conf.SepEncoder == 1){ // only one device
|
if(Conf.SepEncoder == 1){ // only one device
|
||||||
DBG("One device");
|
DBG("One device");
|
||||||
@@ -431,7 +624,7 @@ int openEncoder(){
|
|||||||
encfd[0] = ttyopen(Conf.EncoderDevPath, (speed_t) Conf.EncoderDevSpeed);
|
encfd[0] = ttyopen(Conf.EncoderDevPath, (speed_t) Conf.EncoderDevSpeed);
|
||||||
if(encfd[0] < 0) return FALSE;
|
if(encfd[0] < 0) return FALSE;
|
||||||
encRtmout.tv_sec = 0;
|
encRtmout.tv_sec = 0;
|
||||||
encRtmout.tv_usec = 200000000 / Conf.EncoderDevSpeed; // 20 bytes
|
encRtmout.tv_usec = 100000000 / Conf.EncoderDevSpeed; // 10 bytes
|
||||||
if(pthread_create(&encthread, NULL, encoderthread1, NULL)){
|
if(pthread_create(&encthread, NULL, encoderthread1, NULL)){
|
||||||
close(encfd[0]);
|
close(encfd[0]);
|
||||||
encfd[0] = -1;
|
encfd[0] = -1;
|
||||||
@@ -446,7 +639,7 @@ int openEncoder(){
|
|||||||
if(encfd[i] < 0) return FALSE;
|
if(encfd[i] < 0) return FALSE;
|
||||||
}
|
}
|
||||||
encRtmout.tv_sec = 0;
|
encRtmout.tv_sec = 0;
|
||||||
encRtmout.tv_usec = 1000; // 1ms
|
encRtmout.tv_usec = 100000000 / Conf.EncoderDevSpeed;
|
||||||
if(pthread_create(&encthread, NULL, encoderthread2, NULL)){
|
if(pthread_create(&encthread, NULL, encoderthread2, NULL)){
|
||||||
for(int i = 0; i < 2; ++i){
|
for(int i = 0; i < 2; ++i){
|
||||||
close(encfd[i]);
|
close(encfd[i]);
|
||||||
@@ -461,6 +654,7 @@ int openEncoder(){
|
|||||||
|
|
||||||
// return FALSE if failed
|
// return FALSE if failed
|
||||||
int openMount(){
|
int openMount(){
|
||||||
|
if(Conf.RunModel) goto create_thread;
|
||||||
if(mntfd > -1) close(mntfd);
|
if(mntfd > -1) close(mntfd);
|
||||||
DBG("Open mount %s @ %d", Conf.MountDevPath, Conf.MountDevSpeed);
|
DBG("Open mount %s @ %d", Conf.MountDevPath, Conf.MountDevSpeed);
|
||||||
mntfd = ttyopen(Conf.MountDevPath, (speed_t) Conf.MountDevSpeed);
|
mntfd = ttyopen(Conf.MountDevPath, (speed_t) Conf.MountDevSpeed);
|
||||||
@@ -476,11 +670,14 @@ int openMount(){
|
|||||||
DBG("got %zd", l);
|
DBG("got %zd", l);
|
||||||
}while(1);*/
|
}while(1);*/
|
||||||
mntRtmout.tv_sec = 0;
|
mntRtmout.tv_sec = 0;
|
||||||
mntRtmout.tv_usec = 500000000 / Conf.MountDevSpeed; // 50 bytes
|
mntRtmout.tv_usec = 500000000 / Conf.MountDevSpeed; // 50 bytes * 10bits / speed
|
||||||
|
create_thread:
|
||||||
if(pthread_create(&mntthread, NULL, mountthread, NULL)){
|
if(pthread_create(&mntthread, NULL, mountthread, NULL)){
|
||||||
DBG("Can't create thread");
|
DBG("Can't create mount thread");
|
||||||
|
if(!Conf.RunModel){
|
||||||
close(mntfd);
|
close(mntfd);
|
||||||
mntfd = -1;
|
mntfd = -1;
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
DBG("Mount opened, thread started");
|
DBG("Mount opened, thread started");
|
||||||
@@ -489,24 +686,26 @@ int openMount(){
|
|||||||
|
|
||||||
// close all opened serial devices and quit threads
|
// close all opened serial devices and quit threads
|
||||||
void closeSerial(){
|
void closeSerial(){
|
||||||
|
// TODO: close devices in "model" mode too!
|
||||||
|
if(Conf.RunModel) return;
|
||||||
if(mntfd > -1){
|
if(mntfd > -1){
|
||||||
DBG("Kill mount thread");
|
DBG("Cancel mount thread");
|
||||||
pthread_cancel(mntthread);
|
pthread_cancel(mntthread);
|
||||||
DBG("join mount thread");
|
DBG("join mount thread");
|
||||||
pthread_join(mntthread, NULL);
|
pthread_join(mntthread, NULL);
|
||||||
DBG("close fd");
|
DBG("close mount fd");
|
||||||
close(mntfd);
|
close(mntfd);
|
||||||
mntfd = -1;
|
mntfd = -1;
|
||||||
}
|
}
|
||||||
if(encfd[0] > -1){
|
if(encfd[0] > -1){
|
||||||
DBG("Kill encoder thread");
|
DBG("Cancel encoder thread");
|
||||||
pthread_cancel(encthread);
|
pthread_cancel(encthread);
|
||||||
DBG("join encoder thread");
|
DBG("join encoder thread");
|
||||||
pthread_join(encthread, NULL);
|
pthread_join(encthread, NULL);
|
||||||
DBG("close fd");
|
DBG("close encoder's fd");
|
||||||
close(encfd[0]);
|
close(encfd[0]);
|
||||||
encfd[0] = -1;
|
encfd[0] = -1;
|
||||||
if(Conf.SepEncoder == 2){
|
if(Conf.SepEncoder == 2 && encfd[1] > -1){
|
||||||
close(encfd[1]);
|
close(encfd[1]);
|
||||||
encfd[1] = -1;
|
encfd[1] = -1;
|
||||||
}
|
}
|
||||||
@@ -519,33 +718,44 @@ mcc_errcodes_t getMD(mountdata_t *d){
|
|||||||
pthread_mutex_lock(&datamutex);
|
pthread_mutex_lock(&datamutex);
|
||||||
*d = mountdata;
|
*d = mountdata;
|
||||||
pthread_mutex_unlock(&datamutex);
|
pthread_mutex_unlock(&datamutex);
|
||||||
|
//DBG("ENCpos: %.10g/%.10g", d->encXposition.val, d->encYposition.val);
|
||||||
|
//DBG("millis: %u, encxt: %zd (time: %zd)", d->millis, d->encXposition.t.tv_sec, time(NULL));
|
||||||
return MCC_E_OK;
|
return MCC_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStat(axis_status_t Xstate, axis_status_t Ystate){
|
||||||
|
DBG("set x/y state to %d/%d", Xstate, Ystate);
|
||||||
|
pthread_mutex_lock(&datamutex);
|
||||||
|
mountdata.Xstate = Xstate;
|
||||||
|
mountdata.Ystate = Ystate;
|
||||||
|
pthread_mutex_unlock(&datamutex);
|
||||||
|
}
|
||||||
|
|
||||||
// write-read without locking mutex (to be used inside other functions)
|
// write-read without locking mutex (to be used inside other functions)
|
||||||
static int wr(const data_t *out, data_t *in, int needeol){
|
static int wr(const data_t *out, data_t *in, int needeol){
|
||||||
if((!out && !in) || mntfd < 0) return FALSE;
|
if((!out && !in) || mntfd < 0){
|
||||||
|
DBG("Wrong arguments or no mount fd");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
clrmntbuf();
|
||||||
if(out){
|
if(out){
|
||||||
if(out->len != (size_t)write(mntfd, out->buf, out->len)){
|
if(out->len != (size_t)write(mntfd, out->buf, out->len)){
|
||||||
DBG("written bytes not equal to need");
|
DBG("written bytes not equal to need");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
//DBG("Send to mount %zd bytes: %s", out->len, out->buf);
|
|
||||||
if(needeol){
|
if(needeol){
|
||||||
int g = write(mntfd, "\r", 1); // add EOL
|
int g = write(mntfd, "\r", 1); // add EOL
|
||||||
(void) g;
|
(void) g;
|
||||||
}
|
}
|
||||||
|
usleep(50000); // add little pause so that the idiot has time to swallow
|
||||||
}
|
}
|
||||||
uint8_t buf[256];
|
if(!in) return TRUE;
|
||||||
data_t dumb = {.buf = buf, .maxlen = 256};
|
|
||||||
if(!in) in = &dumb; // even if user don't ask for answer, try to read to clear trash
|
|
||||||
in->len = 0;
|
in->len = 0;
|
||||||
for(size_t i = 0; i < in->maxlen; ++i){
|
for(size_t i = 0; i < in->maxlen; ++i){
|
||||||
int b = getmntbyte();
|
int b = getmntbyte();
|
||||||
if(b < 0) break; // nothing to read -> go out
|
if(b < 0) break; // nothing to read -> go out
|
||||||
in->buf[in->len++] = (uint8_t) b;
|
in->buf[in->len++] = (uint8_t) b;
|
||||||
}
|
}
|
||||||
//DBG("Clear trashing input");
|
|
||||||
while(getmntbyte() > -1);
|
while(getmntbyte() > -1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -557,6 +767,7 @@ static int wr(const data_t *out, data_t *in, int needeol){
|
|||||||
* @return FALSE if failed
|
* @return FALSE if failed
|
||||||
*/
|
*/
|
||||||
int MountWriteRead(const data_t *out, data_t *in){
|
int MountWriteRead(const data_t *out, data_t *in){
|
||||||
|
if(Conf.RunModel) return -1;
|
||||||
pthread_mutex_lock(&mntmutex);
|
pthread_mutex_lock(&mntmutex);
|
||||||
int ret = wr(out, in, 1);
|
int ret = wr(out, in, 1);
|
||||||
pthread_mutex_unlock(&mntmutex);
|
pthread_mutex_unlock(&mntmutex);
|
||||||
@@ -564,6 +775,7 @@ int MountWriteRead(const data_t *out, data_t *in){
|
|||||||
}
|
}
|
||||||
// send binary data - without EOL
|
// send binary data - without EOL
|
||||||
int MountWriteReadRaw(const data_t *out, data_t *in){
|
int MountWriteReadRaw(const data_t *out, data_t *in){
|
||||||
|
if(Conf.RunModel) return -1;
|
||||||
pthread_mutex_lock(&mntmutex);
|
pthread_mutex_lock(&mntmutex);
|
||||||
int ret = wr(out, in, 0);
|
int ret = wr(out, in, 0);
|
||||||
pthread_mutex_unlock(&mntmutex);
|
pthread_mutex_unlock(&mntmutex);
|
||||||
@@ -587,28 +799,32 @@ static void loglcmd(SSlcmd *c){
|
|||||||
|
|
||||||
// send short/long binary command; return FALSE if failed
|
// send short/long binary command; return FALSE if failed
|
||||||
static int bincmd(uint8_t *cmd, int len){
|
static int bincmd(uint8_t *cmd, int len){
|
||||||
|
if(Conf.RunModel) return FALSE;
|
||||||
static data_t *dscmd = NULL, *dlcmd = NULL;
|
static data_t *dscmd = NULL, *dlcmd = NULL;
|
||||||
if(!dscmd) dscmd = cmd2dat(CMD_SHORTCMD);
|
if(!dscmd) dscmd = cmd2dat(CMD_SHORTCMD);
|
||||||
if(!dlcmd) dlcmd = cmd2dat(CMD_LONGCMD);
|
if(!dlcmd) dlcmd = cmd2dat(CMD_LONGCMD);
|
||||||
int ret = FALSE;
|
int ret = FALSE;
|
||||||
pthread_mutex_lock(&mntmutex);
|
pthread_mutex_lock(&mntmutex);
|
||||||
// dummy buffer to clear trash in input
|
// dummy buffer to clear trash in input
|
||||||
char ans[300];
|
//char ans[300];
|
||||||
data_t a = {.buf = (uint8_t*)ans, .maxlen=299};
|
//data_t a = {.buf = (uint8_t*)ans, .maxlen=299};
|
||||||
if(len == sizeof(SSscmd)){
|
if(len == sizeof(SSscmd)){
|
||||||
((SSscmd*)cmd)->checksum = SScalcChecksum(cmd, len-2);
|
((SSscmd*)cmd)->checksum = SScalcChecksum(cmd, len-2);
|
||||||
DBG("Short command");
|
DBG("Short command");
|
||||||
|
#ifdef EBUG
|
||||||
logscmd((SSscmd*)cmd);
|
logscmd((SSscmd*)cmd);
|
||||||
if(!wr(dscmd, &a, 1)) goto rtn;
|
#endif
|
||||||
|
if(!wr(dscmd, NULL, 1)) goto rtn;
|
||||||
}else if(len == sizeof(SSlcmd)){
|
}else if(len == sizeof(SSlcmd)){
|
||||||
((SSlcmd*)cmd)->checksum = SScalcChecksum(cmd, len-2);
|
((SSlcmd*)cmd)->checksum = SScalcChecksum(cmd, len-2);
|
||||||
DBG("Long command");
|
DBG("Long command");
|
||||||
|
#ifdef EBUG
|
||||||
loglcmd((SSlcmd*)cmd);
|
loglcmd((SSlcmd*)cmd);
|
||||||
if(!wr(dlcmd, &a, 1)) goto rtn;
|
#endif
|
||||||
|
if(!wr(dlcmd, NULL, 1)) goto rtn;
|
||||||
}else{
|
}else{
|
||||||
goto rtn;
|
goto rtn;
|
||||||
}
|
}
|
||||||
DBG("Write %d bytes and wait for ans", len);
|
|
||||||
data_t d;
|
data_t d;
|
||||||
d.buf = cmd;
|
d.buf = cmd;
|
||||||
d.len = d.maxlen = len;
|
d.len = d.maxlen = len;
|
||||||
@@ -619,6 +835,7 @@ rtn:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// short, long and config text-binary commands
|
||||||
// return TRUE if OK
|
// return TRUE if OK
|
||||||
int cmdS(SSscmd *cmd){
|
int cmdS(SSscmd *cmd){
|
||||||
return bincmd((uint8_t *)cmd, sizeof(SSscmd));
|
return bincmd((uint8_t *)cmd, sizeof(SSscmd));
|
||||||
@@ -628,6 +845,7 @@ int cmdL(SSlcmd *cmd){
|
|||||||
}
|
}
|
||||||
// rw == 1 to write, 0 to read
|
// rw == 1 to write, 0 to read
|
||||||
int cmdC(SSconfig *conf, int rw){
|
int cmdC(SSconfig *conf, int rw){
|
||||||
|
if(Conf.RunModel) return FALSE;
|
||||||
static data_t *wcmd = NULL, *rcmd = NULL;
|
static data_t *wcmd = NULL, *rcmd = NULL;
|
||||||
int ret = FALSE;
|
int ret = FALSE;
|
||||||
// dummy buffer to clear trash in input
|
// dummy buffer to clear trash in input
|
||||||
@@ -641,16 +859,23 @@ int cmdC(SSconfig *conf, int rw){
|
|||||||
}else{ // read
|
}else{ // read
|
||||||
data_t d;
|
data_t d;
|
||||||
d.buf = (uint8_t *) conf;
|
d.buf = (uint8_t *) conf;
|
||||||
|
d.len = 0; d.maxlen = 0;
|
||||||
|
ret = wr(rcmd, &d, 1);
|
||||||
|
DBG("write command: %s", ret ? "TRUE" : "FALSE");
|
||||||
|
if(!ret) goto rtn;
|
||||||
|
// make a huge pause for stupid SSII
|
||||||
|
usleep(100000);
|
||||||
d.len = 0; d.maxlen = sizeof(SSconfig);
|
d.len = 0; d.maxlen = sizeof(SSconfig);
|
||||||
ret = wr(rcmd, &d, 1);
|
ret = wr(rcmd, &d, 1);
|
||||||
DBG("wr returned %s; got %zd bytes of %zd", ret ? "TRUE" : "FALSE", d.len, d.maxlen);
|
DBG("wr returned %s; got %zd bytes of %zd", ret ? "TRUE" : "FALSE", d.len, d.maxlen);
|
||||||
if(d.len != d.maxlen) return FALSE;
|
if(d.len != d.maxlen){ ret = FALSE; goto rtn; }
|
||||||
// simplest checksum
|
// simplest checksum
|
||||||
uint16_t sum = 0;
|
uint16_t sum = 0;
|
||||||
for(uint32_t i = 0; i < sizeof(SSconfig)-2; ++i) sum += d.buf[i];
|
for(uint32_t i = 0; i < sizeof(SSconfig)-2; ++i) sum += d.buf[i];
|
||||||
if(sum != conf->checksum){
|
if(sum != conf->checksum){
|
||||||
DBG("got sum: %u, need: %u", conf->checksum, sum);
|
DBG("got sum: %u, need: %u", conf->checksum, sum);
|
||||||
return FALSE;
|
ret = FALSE;
|
||||||
|
goto rtn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rtn:
|
rtn:
|
||||||
|
|||||||
@@ -28,15 +28,17 @@
|
|||||||
// max error counter (when read() returns -1)
|
// max error counter (when read() returns -1)
|
||||||
#define MAX_ERR_CTR (100)
|
#define MAX_ERR_CTR (100)
|
||||||
|
|
||||||
double dtime();
|
|
||||||
data_t *cmd2dat(const char *cmd);
|
data_t *cmd2dat(const char *cmd);
|
||||||
void data_free(data_t **x);
|
void data_free(data_t **x);
|
||||||
int openEncoder();
|
int openEncoder();
|
||||||
int openMount();
|
int openMount();
|
||||||
void closeSerial();
|
void closeSerial();
|
||||||
mcc_errcodes_t getMD(mountdata_t *d);
|
mcc_errcodes_t getMD(mountdata_t *d);
|
||||||
|
void setStat(axis_status_t Xstate, axis_status_t Ystate);
|
||||||
int MountWriteRead(const data_t *out, data_t *in);
|
int MountWriteRead(const data_t *out, data_t *in);
|
||||||
int MountWriteReadRaw(const data_t *out, data_t *in);
|
int MountWriteReadRaw(const data_t *out, data_t *in);
|
||||||
int cmdS(SSscmd *cmd);
|
int cmdS(SSscmd *cmd);
|
||||||
int cmdL(SSlcmd *cmd);
|
int cmdL(SSlcmd *cmd);
|
||||||
int cmdC(SSconfig *conf, int rw);
|
int cmdC(SSconfig *conf, int rw);
|
||||||
|
void getXspeed();
|
||||||
|
void getYspeed();
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file contains all need for external usage
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -27,15 +32,14 @@ extern "C"
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
// max speeds (rad/s): xs=10 deg/s, ys=8 deg/s
|
// minimal serial speed of mount device
|
||||||
#define MCC_MAX_X_SPEED (0.174533)
|
#define MOUNT_BAUDRATE_MIN (1200)
|
||||||
#define MCC_MAX_Y_SPEED (0.139626)
|
|
||||||
|
|
||||||
// max speed interval, seconds
|
// max speed interval, seconds
|
||||||
#define MCC_CONF_MAX_SPEEDINT (2.)
|
#define MCC_CONF_MAX_SPEEDINT (2.)
|
||||||
// minimal speed interval in parts of EncoderReqInterval
|
// minimal speed interval in parts of EncoderReqInterval
|
||||||
#define MCC_CONF_MIN_SPEEDC (3.)
|
#define MCC_CONF_MIN_SPEEDC (3.)
|
||||||
|
|
||||||
|
|
||||||
// error codes
|
// error codes
|
||||||
typedef enum{
|
typedef enum{
|
||||||
MCC_E_OK = 0, // all OK
|
MCC_E_OK = 0, // all OK
|
||||||
@@ -44,8 +48,13 @@ typedef enum{
|
|||||||
MCC_E_ENCODERDEV, // encoder device error or can't open
|
MCC_E_ENCODERDEV, // encoder device error or can't open
|
||||||
MCC_E_MOUNTDEV, // mount device error or can't open
|
MCC_E_MOUNTDEV, // mount device error or can't open
|
||||||
MCC_E_FAILED, // failed to run command - protocol error
|
MCC_E_FAILED, // failed to run command - protocol error
|
||||||
|
MCC_E_AMOUNT // Just amount of errors
|
||||||
} mcc_errcodes_t;
|
} mcc_errcodes_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
double P, I, D;
|
||||||
|
} PIDpar_t;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
char* MountDevPath; // path to mount device
|
char* MountDevPath; // path to mount device
|
||||||
int MountDevSpeed; // serial speed
|
int MountDevSpeed; // serial speed
|
||||||
@@ -54,9 +63,23 @@ typedef struct{
|
|||||||
int SepEncoder; // ==1 if encoder works as separate serial device, ==2 if there's new version with two devices
|
int SepEncoder; // ==1 if encoder works as separate serial device, ==2 if there's new version with two devices
|
||||||
char* EncoderXDevPath; // paths to new controller devices
|
char* EncoderXDevPath; // paths to new controller devices
|
||||||
char* EncoderYDevPath;
|
char* EncoderYDevPath;
|
||||||
|
double EncodersDisagreement; // acceptable disagreement between motor and axis encoders
|
||||||
double MountReqInterval; // interval between subsequent mount requests (seconds)
|
double MountReqInterval; // interval between subsequent mount requests (seconds)
|
||||||
double EncoderReqInterval; // interval between subsequent encoder requests (seconds)
|
double EncoderReqInterval; // interval between subsequent encoder requests (seconds)
|
||||||
double EncoderSpeedInterval; // interval between speed calculations
|
double EncoderSpeedInterval; // interval between speed calculations
|
||||||
|
int RunModel; // == 1 if you want to use model instead of real mount
|
||||||
|
double PIDMaxDt; // maximal PID refresh time interval (if larger all old data will be cleared)
|
||||||
|
double PIDRefreshDt; // normal PID refresh interval
|
||||||
|
double PIDCycleDt; // PID I cycle time (analog of "RC" for PID on opamps)
|
||||||
|
PIDpar_t XPIDC; // gain parameters of PID for both axiss (C - coordinate driven, V - velocity driven)
|
||||||
|
PIDpar_t XPIDV;
|
||||||
|
PIDpar_t YPIDC;
|
||||||
|
PIDpar_t YPIDV;
|
||||||
|
double MaxPointingErr; // if angle < this, change state from "slewing" to "pointing" (coarse pointing): 8 degrees
|
||||||
|
double MaxFinePointingErr; // if angle < this, chane state from "pointing" to "guiding" (fine poinging): 1.5 deg
|
||||||
|
double MaxGuidingErr; // if error less than this value we suppose that target is captured and guiding is good (true guiding): 0.1''
|
||||||
|
int XEncZero; // encoders' zero position
|
||||||
|
int YEncZero;
|
||||||
} conf_t;
|
} conf_t;
|
||||||
|
|
||||||
// coordinates/speeds in degrees or d/s: X, Y
|
// coordinates/speeds in degrees or d/s: X, Y
|
||||||
@@ -67,7 +90,7 @@ typedef struct{
|
|||||||
// coordinate/speed and time of last measurement
|
// coordinate/speed and time of last measurement
|
||||||
typedef struct{
|
typedef struct{
|
||||||
double val;
|
double val;
|
||||||
double t;
|
struct timespec t;
|
||||||
} coordval_t;
|
} coordval_t;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
@@ -112,12 +135,21 @@ typedef struct{
|
|||||||
uint16_t ain1;
|
uint16_t ain1;
|
||||||
} extradata_t;
|
} extradata_t;
|
||||||
|
|
||||||
|
typedef enum{
|
||||||
|
AXIS_STOPPED,
|
||||||
|
AXIS_SLEWING,
|
||||||
|
AXIS_POINTING,
|
||||||
|
AXIS_GUIDING,
|
||||||
|
AXIS_ERROR,
|
||||||
|
} axis_status_t;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
|
axis_status_t Xstate;
|
||||||
|
axis_status_t Ystate;
|
||||||
coordval_t motXposition;
|
coordval_t motXposition;
|
||||||
coordval_t motYposition;
|
coordval_t motYposition;
|
||||||
coordval_t encXposition;
|
coordval_t encXposition;
|
||||||
coordval_t encYposition;
|
coordval_t encYposition;
|
||||||
// TODO: add speedX/Y
|
|
||||||
coordval_t encXspeed; // once per <config> s
|
coordval_t encXspeed; // once per <config> s
|
||||||
coordval_t encYspeed;
|
coordval_t encYspeed;
|
||||||
uint8_t keypad;
|
uint8_t keypad;
|
||||||
@@ -127,10 +159,6 @@ typedef struct{
|
|||||||
double voltage;
|
double voltage;
|
||||||
} mountdata_t;
|
} mountdata_t;
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
;
|
|
||||||
} mountstat_t;
|
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
double Xmot; // 0 X motor position (rad)
|
double Xmot; // 0 X motor position (rad)
|
||||||
double Xspeed; // 4 X speed (rad/s)
|
double Xspeed; // 4 X speed (rad/s)
|
||||||
@@ -152,7 +180,7 @@ typedef struct{
|
|||||||
double Yatime; // 28
|
double Yatime; // 28
|
||||||
} long_command_t; // long command
|
} long_command_t; // long command
|
||||||
|
|
||||||
// hardware axe configuration
|
// hardware axis configuration
|
||||||
typedef struct{
|
typedef struct{
|
||||||
double accel; // Default Acceleration, rad/s^2
|
double accel; // Default Acceleration, rad/s^2
|
||||||
double backlash; // Backlash (???)
|
double backlash; // Backlash (???)
|
||||||
@@ -163,13 +191,16 @@ typedef struct{
|
|||||||
double outplimit; // Output Limit, percent (0..100)
|
double outplimit; // Output Limit, percent (0..100)
|
||||||
double currlimit; // Current Limit (A)
|
double currlimit; // Current Limit (A)
|
||||||
double intlimit; // Integral Limit (???)
|
double intlimit; // Integral Limit (???)
|
||||||
} __attribute__((packed)) axe_config_t;
|
// these params are taken from mount by text commands (don't save negative values - better save these marks in xybits
|
||||||
|
double motor_stepsperrev;// encoder's steps per revolution: motor and axis
|
||||||
|
double axis_stepsperrev; // negative sign of these values means reverse direction
|
||||||
|
} __attribute__((packed)) axis_config_t;
|
||||||
|
|
||||||
// hardware configuration
|
// hardware configuration
|
||||||
typedef struct{
|
typedef struct{
|
||||||
axe_config_t Xconf;
|
axis_config_t Xconf;
|
||||||
xbits_t xbits;
|
xbits_t xbits;
|
||||||
axe_config_t Yconf;
|
axis_config_t Yconf;
|
||||||
ybits_t ybits;
|
ybits_t ybits;
|
||||||
uint8_t address;
|
uint8_t address;
|
||||||
double eqrate; // Equatorial Rate (???)
|
double eqrate; // Equatorial Rate (???)
|
||||||
@@ -192,21 +223,19 @@ typedef struct{
|
|||||||
double backlspd; // Backlash speed (rad/s)
|
double backlspd; // Backlash speed (rad/s)
|
||||||
} hardware_configuration_t;
|
} hardware_configuration_t;
|
||||||
|
|
||||||
// flags for slew function
|
/* flags for slew function
|
||||||
typedef struct{
|
typedef struct{
|
||||||
uint32_t slewNguide : 1; // ==1 to gude after slewing
|
uint32_t slewNguide : 1; // ==1 to guide after slewing
|
||||||
} slewflags_t;
|
} slewflags_t;
|
||||||
|
*/
|
||||||
// mount class
|
// mount class
|
||||||
typedef struct{
|
typedef struct{
|
||||||
// TODO: on init/quit clear all XY-bits to default`
|
// TODO: on init/quit clear all XY-bits to default`
|
||||||
mcc_errcodes_t (*init)(conf_t *c); // init device
|
mcc_errcodes_t (*init)(conf_t *c); // init device
|
||||||
void (*quit)(); // deinit
|
void (*quit)(); // deinit
|
||||||
mcc_errcodes_t (*getMountData)(mountdata_t *d); // get last data
|
mcc_errcodes_t (*getMountData)(mountdata_t *d); // get last data
|
||||||
// TODO: change (or add flags) switching slew-and-stop and slew-and-track
|
// mcc_errcodes_t (*slewTo)(const coordpair_t *target, slewflags_t flags);
|
||||||
// add mount state: stop/slew/guide
|
mcc_errcodes_t (*correctTo)(const coordval_pair_t *target);
|
||||||
mcc_errcodes_t (*slewTo)(const coordpair_t *target, slewflags_t flags);
|
|
||||||
mcc_errcodes_t (*correctBy)(coordpair_t *delta); // delta = Target - Real
|
|
||||||
mcc_errcodes_t (*moveTo)(const coordpair_t *target); // move to given position and stop
|
mcc_errcodes_t (*moveTo)(const coordpair_t *target); // move to given position and stop
|
||||||
mcc_errcodes_t (*moveWspeed)(const coordpair_t *target, const coordpair_t *speed); // move with given max speed
|
mcc_errcodes_t (*moveWspeed)(const coordpair_t *target, const coordpair_t *speed); // move with given max speed
|
||||||
mcc_errcodes_t (*setSpeed)(const coordpair_t *tagspeed); // set speed
|
mcc_errcodes_t (*setSpeed)(const coordpair_t *tagspeed); // set speed
|
||||||
@@ -216,12 +245,17 @@ typedef struct{
|
|||||||
mcc_errcodes_t (*longCmd)(long_command_t *cmd); // send/get long command
|
mcc_errcodes_t (*longCmd)(long_command_t *cmd); // send/get long command
|
||||||
mcc_errcodes_t (*getHWconfig)(hardware_configuration_t *c); // get hardware configuration
|
mcc_errcodes_t (*getHWconfig)(hardware_configuration_t *c); // get hardware configuration
|
||||||
mcc_errcodes_t (*saveHWconfig)(hardware_configuration_t *c); // save hardware configuration
|
mcc_errcodes_t (*saveHWconfig)(hardware_configuration_t *c); // save hardware configuration
|
||||||
double (*currentT)(); // current time
|
int (*currentT)(struct timespec *t); // current time
|
||||||
|
double (*timeFromStart)(); // amount of seconds from last init
|
||||||
|
double (*timeDiff)(const struct timespec *time1, const struct timespec *time0); // difference of times
|
||||||
|
double (*timeDiff0)(const struct timespec *time1); // difference between current time and last init time
|
||||||
|
mcc_errcodes_t (*getMaxSpeed)(coordpair_t *v); // maximal speed by both axis
|
||||||
|
mcc_errcodes_t (*getMinSpeed)(coordpair_t *v); // minimal -//-
|
||||||
|
mcc_errcodes_t (*getAcceleration)(coordpair_t *a); // acceleration/deceleration
|
||||||
} mount_t;
|
} mount_t;
|
||||||
|
|
||||||
extern mount_t Mount;
|
extern mount_t Mount;
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,12 +18,21 @@
|
|||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "dbg.h"
|
#include "main.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "ssii.h"
|
#include "ssii.h"
|
||||||
|
|
||||||
|
int X_ENC_ZERO = 0, Y_ENC_ZERO = 0;
|
||||||
|
// defaults until read from controller
|
||||||
|
double X_MOT_STEPSPERREV = 13312000.,
|
||||||
|
Y_MOT_STEPSPERREV = 17578668.,
|
||||||
|
X_ENC_STEPSPERREV = 67108864.,
|
||||||
|
Y_ENC_STEPSPERREV = 67108864.;
|
||||||
|
|
||||||
uint16_t SScalcChecksum(uint8_t *buf, int len){
|
uint16_t SScalcChecksum(uint8_t *buf, int len){
|
||||||
uint16_t checksum = 0;
|
uint16_t checksum = 0;
|
||||||
for(int i = 0; i < len; i++){
|
for(int i = 0; i < len; i++){
|
||||||
@@ -35,33 +44,50 @@ uint16_t SScalcChecksum(uint8_t *buf, int len){
|
|||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next three functions runs under locked mountdata_t mutex and shouldn't call locked it again!!
|
||||||
|
static void chkstopstat(int32_t *prev, int32_t cur, int *nstopped, axis_status_t *stat){
|
||||||
|
if(*prev == INT32_MAX){
|
||||||
|
*stat = AXIS_STOPPED;
|
||||||
|
DBG("START");
|
||||||
|
}else if(*stat != AXIS_STOPPED){
|
||||||
|
if(*prev == cur && ++(*nstopped) > MOTOR_STOPPED_CNT){
|
||||||
|
*stat = AXIS_STOPPED;
|
||||||
|
DBG("AXIS stopped");
|
||||||
|
}
|
||||||
|
}else if(*prev != cur){
|
||||||
|
DBG("AXIS moving");
|
||||||
|
*nstopped = 0;
|
||||||
|
}
|
||||||
|
*prev = cur;
|
||||||
|
}
|
||||||
|
// check for stopped/pointing states
|
||||||
|
static void ChkStopped(const SSstat *s, mountdata_t *m){
|
||||||
|
static int32_t Xmot_prev = INT32_MAX, Ymot_prev = INT32_MAX; // previous coordinates
|
||||||
|
static int Xnstopped = 0, Ynstopped = 0; // counters to get STOPPED state
|
||||||
|
chkstopstat(&Xmot_prev, s->Xmot, &Xnstopped, &m->Xstate);
|
||||||
|
chkstopstat(&Ymot_prev, s->Ymot, &Ynstopped, &m->Ystate);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SSconvstat - convert stat from SSII format to human
|
* @brief SSconvstat - convert stat from SSII format to human
|
||||||
* @param s (i) - just read data
|
* @param s (i) - just read data
|
||||||
* @param m (o) - output
|
* @param m (o) - output
|
||||||
* @param t - measurement time
|
* @param t - measurement time
|
||||||
*/
|
*/
|
||||||
void SSconvstat(const SSstat *s, mountdata_t *m, double t){
|
void SSconvstat(const SSstat *s, mountdata_t *m, struct timespec *t){
|
||||||
if(!s || !m) return;
|
if(!s || !m || !t) return;
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
static double t0 = -1.;
|
|
||||||
if(t0 < 0.) t0 = dtime();
|
|
||||||
#endif
|
|
||||||
DBG("Convert, t=%g", dtime()-t0);
|
|
||||||
*/
|
|
||||||
m->motXposition.val = X_MOT2RAD(s->Xmot);
|
m->motXposition.val = X_MOT2RAD(s->Xmot);
|
||||||
m->motYposition.val = Y_MOT2RAD(s->Ymot);
|
m->motYposition.val = Y_MOT2RAD(s->Ymot);
|
||||||
m->motXposition.t = m->motYposition.t = t;
|
ChkStopped(s, m);
|
||||||
|
m->motXposition.t = m->motYposition.t = *t;
|
||||||
// fill encoder data from here, as there's no separate enc thread
|
// fill encoder data from here, as there's no separate enc thread
|
||||||
if(!Conf.SepEncoder){
|
if(!Conf.SepEncoder){
|
||||||
m->encXposition.val = X_ENC2RAD(s->Xenc);
|
m->encXposition.val = Xenc2rad(s->Xenc);
|
||||||
m->encYposition.val = Y_ENC2RAD(s->Yenc);
|
DBG("encx: %g", m->encXposition.val);
|
||||||
m->encXposition.t = m->encYposition.t = t;
|
m->encYposition.val = Yenc2rad(s->Yenc);
|
||||||
|
m->encXposition.t = m->encYposition.t = *t;
|
||||||
|
getXspeed(); getYspeed();
|
||||||
}
|
}
|
||||||
//m->lastmotposition.X = X_MOT2RAD(s->XLast);
|
|
||||||
//m->lastmotposition.Y = Y_MOT2RAD(s->YLast);
|
|
||||||
//m->lastmotposition.msrtime = *tdat;
|
|
||||||
m->keypad = s->keypad;
|
m->keypad = s->keypad;
|
||||||
m->extradata.ExtraBits = s->ExtraBits;
|
m->extradata.ExtraBits = s->ExtraBits;
|
||||||
m->extradata.ain0 = s->ain0;
|
m->extradata.ain0 = s->ain0;
|
||||||
@@ -87,7 +113,7 @@ int SStextcmd(const char *cmd, data_t *answer){
|
|||||||
data_t d;
|
data_t d;
|
||||||
d.buf = (uint8_t*) cmd;
|
d.buf = (uint8_t*) cmd;
|
||||||
d.len = d.maxlen = strlen(cmd);
|
d.len = d.maxlen = strlen(cmd);
|
||||||
DBG("send %zd bytes: %s", d.len, d.buf);
|
//DBG("send %zd bytes: %s", d.len, d.buf);
|
||||||
return MountWriteRead(&d, answer);
|
return MountWriteRead(&d, answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +126,7 @@ int SSrawcmd(const char *cmd, data_t *answer){
|
|||||||
data_t d;
|
data_t d;
|
||||||
d.buf = (uint8_t*) cmd;
|
d.buf = (uint8_t*) cmd;
|
||||||
d.len = d.maxlen = strlen(cmd);
|
d.len = d.maxlen = strlen(cmd);
|
||||||
DBG("send %zd bytes: %s", d.len, d.buf);
|
//DBG("send %zd bytes: %s", d.len, d.buf);
|
||||||
return MountWriteReadRaw(&d, answer);
|
return MountWriteReadRaw(&d, answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,3 +180,50 @@ int SSstop(int emerg){
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update motors' positions due to encoders'
|
||||||
|
mcc_errcodes_t updateMotorPos(){
|
||||||
|
mountdata_t md = {0};
|
||||||
|
if(Conf.RunModel) return MCC_E_OK;
|
||||||
|
double t0 = timefromstart(), t = 0.;
|
||||||
|
struct timespec curt;
|
||||||
|
DBG("start @ %g", t0);
|
||||||
|
do{
|
||||||
|
t = timefromstart();
|
||||||
|
if(!curtime(&curt)){
|
||||||
|
usleep(10000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//DBG("XENC2RAD: %g (xez=%d, xesr=%.10g)", Xenc2rad(32424842), X_ENC_ZERO, X_ENC_STEPSPERREV);
|
||||||
|
if(MCC_E_OK == getMD(&md)){
|
||||||
|
if(md.encXposition.t.tv_sec == 0 || md.encYposition.t.tv_sec == 0){
|
||||||
|
DBG("Just started? t-t0 = %g!", t - t0);
|
||||||
|
usleep(10000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(md.Xstate != AXIS_STOPPED || md.Ystate != AXIS_STOPPED) return MCC_E_OK;
|
||||||
|
DBG("got; t pos x/y: %ld/%ld; tnow: %ld", md.encXposition.t.tv_sec, md.encYposition.t.tv_sec, curt.tv_sec);
|
||||||
|
mcc_errcodes_t OK = MCC_E_OK;
|
||||||
|
if(fabs(md.motXposition.val - md.encXposition.val) > Conf.EncodersDisagreement && md.Xstate == AXIS_STOPPED){
|
||||||
|
DBG("NEED to sync X: motors=%g, axis=%g", md.motXposition.val, md.encXposition.val);
|
||||||
|
DBG("new motsteps: %d", X_RAD2MOT(md.encXposition.val));
|
||||||
|
if(!SSsetterI(CMD_MOTXSET, X_RAD2MOT(md.encXposition.val))){
|
||||||
|
DBG("Xpos sync failed!");
|
||||||
|
OK = MCC_E_FAILED;
|
||||||
|
}else DBG("Xpos sync OK, Dt=%g", t - t0);
|
||||||
|
}
|
||||||
|
if(fabs(md.motYposition.val - md.encYposition.val) > Conf.EncodersDisagreement && md.Ystate == AXIS_STOPPED){
|
||||||
|
DBG("NEED to sync Y: motors=%g, axis=%g", md.motYposition.val, md.encYposition.val);
|
||||||
|
if(!SSsetterI(CMD_MOTYSET, Y_RAD2MOT(md.encYposition.val))){
|
||||||
|
DBG("Ypos sync failed!");
|
||||||
|
OK = MCC_E_FAILED;
|
||||||
|
}else DBG("Ypos sync OK, Dt=%g", t - t0);
|
||||||
|
}
|
||||||
|
if(MCC_E_OK == OK){
|
||||||
|
DBG("Encoders synced");
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBG("NO DATA; dt = %g", t - t0);
|
||||||
|
}while(t - t0 < 2.);
|
||||||
|
return MCC_E_FATAL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file contains stuff for sidereal-servo specific protocol
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -168,51 +172,75 @@
|
|||||||
// Loop freq
|
// Loop freq
|
||||||
#define SITECH_LOOP_FREQUENCY (1953.)
|
#define SITECH_LOOP_FREQUENCY (1953.)
|
||||||
|
|
||||||
|
// amount of consequent same coordinates to detect stop
|
||||||
|
#define MOTOR_STOPPED_CNT (19)
|
||||||
|
|
||||||
|
// replace macros with global variables inited when config read
|
||||||
|
extern int X_ENC_ZERO, Y_ENC_ZERO;
|
||||||
|
extern double X_MOT_STEPSPERREV, Y_MOT_STEPSPERREV, X_ENC_STEPSPERREV, Y_ENC_STEPSPERREV;
|
||||||
|
|
||||||
|
// TODO: take it from settings?
|
||||||
// steps per revolution (SSI - x4 - for SSI)
|
// steps per revolution (SSI - x4 - for SSI)
|
||||||
|
// -> hwconf.Xconf.mot/enc_stepsperrev
|
||||||
|
//#define X_MOT_STEPSPERREV_SSI (13312000.)
|
||||||
// 13312000 / 4 = 3328000
|
// 13312000 / 4 = 3328000
|
||||||
#define X_MOT_STEPSPERREV_SSI (13312000.)
|
//#define X_MOT_STEPSPERREV (3328000.)
|
||||||
//#define X_MOT_STEPSPERREV (3325952.)
|
//#define Y_MOT_STEPSPERREV_SSI (17578668.)
|
||||||
#define X_MOT_STEPSPERREV (3328000.)
|
|
||||||
// 17578668 / 4 = 4394667
|
// 17578668 / 4 = 4394667
|
||||||
#define Y_MOT_STEPSPERREV_SSI (17578668.)
|
//#define Y_MOT_STEPSPERREV (4394667.)
|
||||||
//#define Y_MOT_STEPSPERREV (4394960.)
|
|
||||||
#define Y_MOT_STEPSPERREV (4394667.)
|
|
||||||
|
|
||||||
// motor position to radians and back
|
|
||||||
#define X_MOT2RAD(n) (2. * M_PI * ((double)(n)) / X_MOT_STEPSPERREV)
|
|
||||||
#define Y_MOT2RAD(n) (2. * M_PI * ((double)(n)) / Y_MOT_STEPSPERREV)
|
|
||||||
#define X_RAD2MOT(r) ((int32_t)((r) / (2. * M_PI) * X_MOT_STEPSPERREV))
|
|
||||||
#define Y_RAD2MOT(r) ((int32_t)((r) / (2. * M_PI) * Y_MOT_STEPSPERREV))
|
|
||||||
// motor speed in rad/s and back
|
|
||||||
#define X_MOTSPD2RS(n) (X_MOT2RAD(n) / 65536. * SITECH_LOOP_FREQUENCY)
|
|
||||||
#define Y_MOTSPD2RS(n) (Y_MOT2RAD(n) / 65536. * SITECH_LOOP_FREQUENCY)
|
|
||||||
#define X_RS2MOTSPD(r) ((int32_t)(X_RAD2MOT(r) * 65536. / SITECH_LOOP_FREQUENCY))
|
|
||||||
#define Y_RS2MOTSPD(r) ((int32_t)(Y_RAD2MOT(r) * 65536. / SITECH_LOOP_FREQUENCY))
|
|
||||||
// motor acceleration -//-
|
|
||||||
#define X_MOTACC2RS(n) (X_MOT2RAD(n) / 65536. * SITECH_LOOP_FREQUENCY * SITECH_LOOP_FREQUENCY)
|
|
||||||
#define Y_MOTACC2RS(n) (Y_MOT2RAD(n) / 65536. * SITECH_LOOP_FREQUENCY * SITECH_LOOP_FREQUENCY)
|
|
||||||
#define X_RS2MOTACC(r) ((int32_t)(X_RAD2MOT(r) * 65536. / SITECH_LOOP_FREQUENCY / SITECH_LOOP_FREQUENCY))
|
|
||||||
#define Y_RS2MOTACC(r) ((int32_t)(Y_RAD2MOT(r) * 65536. / SITECH_LOOP_FREQUENCY / SITECH_LOOP_FREQUENCY))
|
|
||||||
|
|
||||||
// adder time to seconds vice versa
|
|
||||||
#define ADDER2S(a) ((a) / SITECH_LOOP_FREQUENCY)
|
|
||||||
#define S2ADDER(s) ((s) * SITECH_LOOP_FREQUENCY)
|
|
||||||
|
|
||||||
// encoder per revolution
|
// encoder per revolution
|
||||||
#define X_ENC_STEPSPERREV (67108864.)
|
//#define X_ENC_STEPSPERREV (67108864.)
|
||||||
#define Y_ENC_STEPSPERREV (67108864.)
|
//#define Y_ENC_STEPSPERREV (67108864.)
|
||||||
// encoder zero position
|
// encoder zero position
|
||||||
//#define X_ENC_ZERO (46033555)
|
// -> conf.XEncZero/YEncZero
|
||||||
#define X_ENC_ZERO (4603355)
|
//#define X_ENC_ZERO (61245239)
|
||||||
#define Y_ENC_ZERO (36674010)
|
//#define Y_ENC_ZERO (36999830)
|
||||||
// encoder reversed (no: +1)
|
// encoder reversed (no: +1) -> sign of ...stepsperrev
|
||||||
#define X_ENC_SIGN (-1.)
|
//#define X_ENC_SIGN (-1.)
|
||||||
#define Y_ENC_SIGN (-1.)
|
//#define Y_ENC_SIGN (-1.)
|
||||||
|
|
||||||
|
|
||||||
// encoder position to radians and back
|
// encoder position to radians and back
|
||||||
#define X_ENC2RAD(n) (X_ENC_SIGN * 2.*M_PI * ((double)(n-X_ENC_ZERO)) / X_ENC_STEPSPERREV)
|
#define Xenc2rad(n) ang2half(2.*M_PI * ((double)((n)-(X_ENC_ZERO))) / (X_ENC_STEPSPERREV))
|
||||||
#define Y_ENC2RAD(n) (Y_ENC_SIGN * 2.*M_PI * ((double)(n-Y_ENC_ZERO)) / Y_ENC_STEPSPERREV)
|
#define Yenc2rad(n) ang2half(2.*M_PI * ((double)((n)-(Y_ENC_ZERO))) / (Y_ENC_STEPSPERREV))
|
||||||
#define X_RAD2ENC(r) ((uint32_t)((r) / 2./M_PI * X_ENC_STEPSPERREV))
|
#define Xrad2enc(r) ((uint32_t)((r) / 2./M_PI * (X_ENC_STEPSPERREV)))
|
||||||
#define Y_RAD2ENC(r) ((uint32_t)((r) / 2./M_PI * Y_ENC_STEPSPERREV))
|
#define Yrad2enc(r) ((uint32_t)((r) / 2./M_PI * (Y_ENC_STEPSPERREV)))
|
||||||
|
|
||||||
|
// convert angle in radians to +-pi
|
||||||
|
static inline __attribute__((always_inline)) double ang2half(double ang){
|
||||||
|
ang = fmod(ang, 2.*M_PI);
|
||||||
|
if(ang < -M_PI) ang += 2.*M_PI;
|
||||||
|
else if(ang > M_PI) ang -= 2.*M_PI;
|
||||||
|
return ang;
|
||||||
|
}
|
||||||
|
// convert to only positive: 0..2pi
|
||||||
|
static inline __attribute__((always_inline)) double ang2full(double ang){
|
||||||
|
ang = fmod(ang, 2.*M_PI);
|
||||||
|
if(ang < 0.) ang += 2.*M_PI;
|
||||||
|
else if(ang > 2.*M_PI) ang -= 2.*M_PI;
|
||||||
|
return ang;
|
||||||
|
}
|
||||||
|
|
||||||
|
// motor position to radians and back
|
||||||
|
#define X_MOT2RAD(n) ang2half(2. * M_PI * ((double)(n)) / (X_MOT_STEPSPERREV))
|
||||||
|
#define Y_MOT2RAD(n) ang2half(2. * M_PI * ((double)(n)) / (Y_MOT_STEPSPERREV))
|
||||||
|
#define X_RAD2MOT(r) ((int32_t)((r) / (2. * M_PI) * (X_MOT_STEPSPERREV)))
|
||||||
|
#define Y_RAD2MOT(r) ((int32_t)((r) / (2. * M_PI) * (Y_MOT_STEPSPERREV)))
|
||||||
|
// motor speed in rad/s and back
|
||||||
|
#define X_MOTSPD2RS(n) (X_MOT2RAD(n) / 65536. * (SITECH_LOOP_FREQUENCY))
|
||||||
|
#define Y_MOTSPD2RS(n) (Y_MOT2RAD(n) / 65536. * (SITECH_LOOP_FREQUENCY))
|
||||||
|
#define X_RS2MOTSPD(r) ((int32_t)(X_RAD2MOT(r) * 65536. / (SITECH_LOOP_FREQUENCY)))
|
||||||
|
#define Y_RS2MOTSPD(r) ((int32_t)(Y_RAD2MOT(r) * 65536. / (SITECH_LOOP_FREQUENCY)))
|
||||||
|
// motor acceleration -//-
|
||||||
|
#define X_MOTACC2RS(n) (X_MOT2RAD(n) / 65536. * (SITECH_LOOP_FREQUENCY) * (SITECH_LOOP_FREQUENCY))
|
||||||
|
#define Y_MOTACC2RS(n) (Y_MOT2RAD(n) / 65536. * (SITECH_LOOP_FREQUENCY) * (SITECH_LOOP_FREQUENCY))
|
||||||
|
#define X_RS2MOTACC(r) ((int32_t)(X_RAD2MOT(r) * 65536. / (SITECH_LOOP_FREQUENCY) / (SITECH_LOOP_FREQUENCY)))
|
||||||
|
#define Y_RS2MOTACC(r) ((int32_t)(Y_RAD2MOT(r) * 65536. / (SITECH_LOOP_FREQUENCY) / (SITECH_LOOP_FREQUENCY)))
|
||||||
|
|
||||||
|
// adder time to seconds vice versa
|
||||||
|
#define ADDER2S(a) ((a) / (SITECH_LOOP_FREQUENCY))
|
||||||
|
#define S2ADDER(s) ((s) * (SITECH_LOOP_FREQUENCY))
|
||||||
|
|
||||||
// encoder's tolerance (ticks)
|
// encoder's tolerance (ticks)
|
||||||
#define YencTOL (25.)
|
#define YencTOL (25.)
|
||||||
@@ -313,10 +341,10 @@ typedef struct{
|
|||||||
} __attribute__((packed)) SSconfig;
|
} __attribute__((packed)) SSconfig;
|
||||||
|
|
||||||
uint16_t SScalcChecksum(uint8_t *buf, int len);
|
uint16_t SScalcChecksum(uint8_t *buf, int len);
|
||||||
void SSconvstat(const SSstat *status, mountdata_t *mountdata, double t);
|
void SSconvstat(const SSstat *status, mountdata_t *mountdata, struct timespec *t);
|
||||||
int SStextcmd(const char *cmd, data_t *answer);
|
int SStextcmd(const char *cmd, data_t *answer);
|
||||||
int SSrawcmd(const char *cmd, data_t *answer);
|
int SSrawcmd(const char *cmd, data_t *answer);
|
||||||
int SSgetint(const char *cmd, int64_t *ans);
|
int SSgetint(const char *cmd, int64_t *ans);
|
||||||
int SSsetterI(const char *cmd, int32_t ival);
|
int SSsetterI(const char *cmd, int32_t ival);
|
||||||
int SSstop(int emerg);
|
int SSstop(int emerg);
|
||||||
int SSshortCmd(SSscmd *cmd);
|
mcc_errcodes_t updateMotorPos();
|
||||||
|
|||||||
88
asibfm700/CMakeLists.txt
Normal file
88
asibfm700/CMakeLists.txt
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
|
||||||
|
# set(CMAKE_BUILD_TYPE Release)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
|
|
||||||
|
# find_package(ASIO QUIET CONFIG)
|
||||||
|
find_package(ASIO QUIET)
|
||||||
|
if (ASIO_FOUND)
|
||||||
|
message(STATUS "ASIO library was found in the host system")
|
||||||
|
else()
|
||||||
|
message(STATUS "ASIO library was not found! Try to download it!")
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
FetchContent_Declare(asio_lib
|
||||||
|
SOURCE_DIR ${CMAKE_BINARY_DIR}/asio_lib
|
||||||
|
BINARY_DIR ${CMAKE_BINARY_DIR}
|
||||||
|
GIT_REPOSITORY "https://github.com/chriskohlhoff/asio"
|
||||||
|
GIT_TAG "asio-1-32-0"
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
GIT_SUBMODULES ""
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(asio_lib)
|
||||||
|
# FetchContent_GetProperties(asio_lib SOURCE_DIR asio_SOURCE_DIR)
|
||||||
|
|
||||||
|
set(ASIO_INSTALL_DIR ${CMAKE_BINARY_DIR}/asio_lib/asio)
|
||||||
|
find_package(ASIO)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(cxxopts QUIET CONFIG)
|
||||||
|
if (cxxopts_FOUND)
|
||||||
|
message(STATUS "CXXOPTS library was found in the host system")
|
||||||
|
else()
|
||||||
|
message(STATUS "CXXOPTS library was not found! Try to download it!")
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
FetchContent_Declare(cxxopts_lib
|
||||||
|
PREFIX ${CMAKE_BINARY_DIR}/cxxopts_lib
|
||||||
|
# SOURCE_DIR ${CMAKE_BINARY_DIR}/cxxopts_lib
|
||||||
|
# BINARY_DIR ${CMAKE_BINARY_DIR}
|
||||||
|
GIT_REPOSITORY "https://github.com/jarro2783/cxxopts.git"
|
||||||
|
GIT_TAG "v3.3.1"
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
GIT_SUBMODULES ""
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
OVERRIDE_FIND_PACKAGE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(cxxopts_lib)
|
||||||
|
find_package(cxxopts CONFIG)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(ASIBFM700_LIB_SRC asibfm700_common.h asibfm700_servocontroller.h asibfm700_servocontroller.cpp)
|
||||||
|
|
||||||
|
set(ASIBFM700_LIB asibfm700mount)
|
||||||
|
add_library(${ASIBFM700_LIB} STATIC ${ASIBFM700_LIB_SRC}
|
||||||
|
asibfm700_mount.h asibfm700_mount.cpp
|
||||||
|
asibfm700_configfile.h
|
||||||
|
asibfm700_netserver.cpp
|
||||||
|
asibfm700_netserver.h
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${ASIBFM700_LIB} PUBLIC mcc spdlog ${ERFA_INCLUDE_DIR})
|
||||||
|
# target_link_libraries(${ASIBFM700_LIB} PUBLIC mcc spdlog ${ERFA_LIBFILE})
|
||||||
|
target_link_libraries(${ASIBFM700_LIB} PUBLIC mcc ASIO::ASIO spdlog ERFA_LIB bsplines sidservo)
|
||||||
|
|
||||||
|
|
||||||
|
set(ASIBFM700_NETSERVER_APP asibfm700_netserver)
|
||||||
|
add_executable(${ASIBFM700_NETSERVER_APP} asibfm700_netserver_main.cpp)
|
||||||
|
target_link_libraries(${ASIBFM700_NETSERVER_APP} PRIVATE cxxopts::cxxopts ${ASIBFM700_LIB})
|
||||||
|
|
||||||
|
option(WITH_TESTS "Build tests" ON)
|
||||||
|
|
||||||
|
if (WITH_TESTS)
|
||||||
|
set(CFG_TEST_APP cfg_test)
|
||||||
|
add_executable(${CFG_TEST_APP} tests/cfg_test.cpp)
|
||||||
|
target_link_libraries(${CFG_TEST_APP} PRIVATE mcc)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
endif()
|
||||||
30
asibfm700/asibfm700_common.h
Normal file
30
asibfm700/asibfm700_common.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* AstroSib FORK MOUNT FM-700 CONTROL LIBRARY */
|
||||||
|
|
||||||
|
|
||||||
|
/* COMMON LIBRARY DEFINITIONS */
|
||||||
|
|
||||||
|
|
||||||
|
#include <mcc_moving_model_common.h>
|
||||||
|
#include <mcc_pcm.h>
|
||||||
|
#include <mcc_pzone_container.h>
|
||||||
|
#include <mcc_spdlog.h>
|
||||||
|
|
||||||
|
#include "mcc_ccte_erfa.h"
|
||||||
|
#include "mcc_slewing_model.h"
|
||||||
|
#include "mcc_tracking_model.h"
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
static constexpr mcc::MccMountType asibfm700MountType = mcc::MccMountType::FORK_TYPE;
|
||||||
|
|
||||||
|
typedef mcc::ccte::erfa::MccCCTE_ERFA Asibfm700CCTE;
|
||||||
|
typedef mcc::MccDefaultPCM<asibfm700MountType> Asibfm700PCM;
|
||||||
|
typedef mcc::MccPZoneContainer<mcc::MccTimeDuration> Asibfm700PZoneContainer;
|
||||||
|
typedef mcc::utils::MccSpdlogLogger Asibfm700Logger;
|
||||||
|
typedef mcc::MccSimpleSlewingModel Asibfm700SlewingModel;
|
||||||
|
typedef mcc::MccSimpleTrackingModel Asibfm700TrackingModel;
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
860
asibfm700/asibfm700_configfile.h
Normal file
860
asibfm700/asibfm700_configfile.h
Normal file
@@ -0,0 +1,860 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**/
|
||||||
|
|
||||||
|
#include <expected>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <mcc_angle.h>
|
||||||
|
#include <mcc_moving_model_common.h>
|
||||||
|
#include <mcc_pcm.h>
|
||||||
|
#include <mcc_utils.h>
|
||||||
|
|
||||||
|
#include "asibfm700_common.h"
|
||||||
|
#include "asibfm700_servocontroller.h"
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/* A SIMPLE "KEYWORD - VALUE" HOLDER CLASS SUITABLE TO STORE SOME APPLICATION CONFIGURATION */
|
||||||
|
|
||||||
|
|
||||||
|
// to follow std::variant requirements (not references, not array, not void)
|
||||||
|
template <typename T>
|
||||||
|
concept config_record_valid_type_c = requires { !std::is_array_v<T> && !std::is_void_v<T> && !std::is_reference_v<T>; };
|
||||||
|
|
||||||
|
// simple minimal-requirement configuration record class
|
||||||
|
template <config_record_valid_type_c T>
|
||||||
|
struct simple_config_record_t {
|
||||||
|
std::string_view key;
|
||||||
|
T value;
|
||||||
|
std::vector<std::string_view> comment;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* ASTOROSIB FM700 MOUNT CONFIGURATION CLASS */
|
||||||
|
|
||||||
|
// configuration description and its defaults
|
||||||
|
static auto Asibfm700MountConfigDefaults = std::make_tuple(
|
||||||
|
// main cycle period in millisecs
|
||||||
|
simple_config_record_t{"hardwarePollingPeriod", std::chrono::milliseconds{100}, {"main cycle period in millisecs"}},
|
||||||
|
|
||||||
|
/* geographic coordinates of the observation site */
|
||||||
|
|
||||||
|
// site latitude in degrees
|
||||||
|
simple_config_record_t{"siteLatitude", mcc::MccAngle(43.646711_degs), {"site latitude in degrees"}},
|
||||||
|
|
||||||
|
// site longitude in degrees
|
||||||
|
simple_config_record_t{"siteLongitude", mcc::MccAngle(41.440732_degs), {"site longitude in degrees"}},
|
||||||
|
|
||||||
|
// site elevation in meters
|
||||||
|
simple_config_record_t{"siteElevation", 2070.0, {"site elevation in meters"}},
|
||||||
|
|
||||||
|
/* celestial coordinate transformation */
|
||||||
|
|
||||||
|
// wavelength at which refraction is calculated (in mkm)
|
||||||
|
simple_config_record_t{"refractWavelength", 0.55, {"wavelength at which refraction is calculated (in mkm)"}},
|
||||||
|
|
||||||
|
// an empty filename means default precompiled string
|
||||||
|
simple_config_record_t{"leapSecondFilename", std::string(), {"an empty filename means default precompiled string"}},
|
||||||
|
|
||||||
|
// an empty filename means default precompiled string
|
||||||
|
simple_config_record_t{"bulletinAFilename", std::string(), {"an empty filename means default precompiled string"}},
|
||||||
|
|
||||||
|
/* pointing correction model */
|
||||||
|
|
||||||
|
// PCM default type
|
||||||
|
simple_config_record_t{"pcmType",
|
||||||
|
mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY,
|
||||||
|
{"PCM type:", "GEOMETRY - 'classic' geometry-based correction coefficients",
|
||||||
|
"GEOMETRY-BSPLINE - previous one and additional 2D B-spline corrections",
|
||||||
|
"BSPLINE - pure 2D B-spline corrections"}},
|
||||||
|
|
||||||
|
// PCM geometrical coefficients
|
||||||
|
simple_config_record_t{"pcmGeomCoeffs",
|
||||||
|
std::vector<double>{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||||
|
{"PCM geometrical coefficients"}},
|
||||||
|
|
||||||
|
// PCM B-spline degrees
|
||||||
|
simple_config_record_t{"pcmBsplineDegree", std::vector<size_t>{3, 3}, {"PCM B-spline degrees"}},
|
||||||
|
|
||||||
|
// PCM B-spline knots along X-axis (HA-angle or azimuth). By default from 0 to 2*PI radians
|
||||||
|
// NOTE: The first and last values are interpretated as border knots!!!
|
||||||
|
// Thus the array length must be equal to or greater than 2!
|
||||||
|
simple_config_record_t{"pcmBsplineXknots",
|
||||||
|
std::vector<double>{0.0, 0.6981317, 1.3962634, 2.0943951, 2.7925268, 3.4906585, 4.1887902,
|
||||||
|
4.88692191, 5.58505361, 6.28318531},
|
||||||
|
{"PCM B-spline knots along X-axis (HA-angle or azimuth). By default from 0 to 2*PI radians",
|
||||||
|
"NOTE: The first and last values are interpretated as border knots!!!",
|
||||||
|
" Thus the array length must be equal to or greater than 2!"}},
|
||||||
|
|
||||||
|
// PCM B-spline knots along Y-axis (declination or zenithal distance). By default from -PI/6 to PI/2 radians
|
||||||
|
// NOTE: The first and last values are interpretated as border knots!!!
|
||||||
|
// Thus the array length must be equal to or greater than 2!
|
||||||
|
simple_config_record_t{
|
||||||
|
"pcmBsplineYknots",
|
||||||
|
std::vector<double>{-0.52359878, -0.29088821, -0.05817764, 0.17453293, 0.40724349, 0.63995406, 0.87266463,
|
||||||
|
1.10537519, 1.33808576, 1.57079633},
|
||||||
|
{"PCM B-spline knots along Y-axis (declination or zenithal distance). By default from -PI/6 to PI/2 radians",
|
||||||
|
"NOTE: The first and last values are interpretated as border knots!!!",
|
||||||
|
" Thus the array length must be equal to or greater than 2!"}},
|
||||||
|
|
||||||
|
// PCM B-spline coeffs for along X-axis (HA-angle or azimuth)
|
||||||
|
simple_config_record_t{"pcmBsplineXcoeffs",
|
||||||
|
std::vector<double>{},
|
||||||
|
{"PCM B-spline coeffs for along X-axis (HA-angle)"}},
|
||||||
|
|
||||||
|
// PCM B-spline coeffs for along Y-axis (declination or zenithal distance)
|
||||||
|
simple_config_record_t{"pcmBsplineYcoeffs",
|
||||||
|
std::vector<double>{},
|
||||||
|
{"PCM B-spline coeffs for along Y-axis (declination angle)"}},
|
||||||
|
|
||||||
|
|
||||||
|
/* slewing and tracking parameters */
|
||||||
|
|
||||||
|
// // arcseconds per second
|
||||||
|
// simple_config_record_t{"sideralRate", 15.0410686},
|
||||||
|
|
||||||
|
// timeout for telemetry updating in milliseconds
|
||||||
|
simple_config_record_t{"telemetryTimeout",
|
||||||
|
std::chrono::milliseconds(3000),
|
||||||
|
{"timeout for telemetry updating in milliseconds"}},
|
||||||
|
|
||||||
|
// minimal allowed time in seconds to prohibited zone
|
||||||
|
simple_config_record_t{"minTimeToPZone",
|
||||||
|
std::chrono::seconds(10),
|
||||||
|
{"minimal allowed time in seconds to prohibited zone"}},
|
||||||
|
|
||||||
|
// a time interval to update prohibited zones related quantities (millisecs)
|
||||||
|
simple_config_record_t{"updatingPZoneInterval",
|
||||||
|
std::chrono::milliseconds(5000),
|
||||||
|
{"a time interval to update prohibited zones related quantities (millisecs)"}},
|
||||||
|
|
||||||
|
// coordinates difference in arcsecs to stop slewing
|
||||||
|
simple_config_record_t{"slewToleranceRadius", 5.0, {"coordinates difference in arcsecs to stop slewing"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"slewingTelemetryInterval",
|
||||||
|
std::chrono::milliseconds(100),
|
||||||
|
{"telemetry request interval (in millisecs) in slewing mode"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"slewingPathFilename",
|
||||||
|
std::string(),
|
||||||
|
{"slewing trajectory filename", "if it is an empty - just skip saving"}},
|
||||||
|
|
||||||
|
// target-mount coordinate difference in arcsecs to start adjusting of slewing
|
||||||
|
simple_config_record_t{"adjustCoordDiff",
|
||||||
|
50.0,
|
||||||
|
{"target-mount coordinate difference in arcsecs to start adjusting of slewing"}},
|
||||||
|
|
||||||
|
// minimum time in millisecs between two successive adjustments
|
||||||
|
simple_config_record_t{"adjustCycleInterval",
|
||||||
|
std::chrono::milliseconds(300),
|
||||||
|
{"minimum time in millisecs between two successive adjustments"}},
|
||||||
|
|
||||||
|
// slew process timeout in seconds
|
||||||
|
simple_config_record_t{"slewTimeout", std::chrono::seconds(3600), {"slew process timeout in seconds"}},
|
||||||
|
|
||||||
|
// a time shift into future to compute target position in future (UT1-scale time duration, millisecs)
|
||||||
|
simple_config_record_t{
|
||||||
|
"timeShiftToTargetPoint",
|
||||||
|
std::chrono::milliseconds(10000),
|
||||||
|
{"a time shift into future to compute target position in future (UT1-scale time duration, millisecs)"}},
|
||||||
|
|
||||||
|
|
||||||
|
simple_config_record_t{"trackingTelemetryInterval",
|
||||||
|
std::chrono::milliseconds(100),
|
||||||
|
{"telemetry request interval (in millisecs) in tracking mode"}},
|
||||||
|
|
||||||
|
|
||||||
|
// minimum time in millisecs between two successive tracking corrections
|
||||||
|
simple_config_record_t{"trackingCycleInterval",
|
||||||
|
std::chrono::milliseconds(300),
|
||||||
|
{"minimum time in millisecs between two successive tracking corrections"}},
|
||||||
|
|
||||||
|
// maximal valid target-to-mount distance for tracking process (arcsecs)
|
||||||
|
// if current distance is greater than assume current mount coordinate as target point
|
||||||
|
simple_config_record_t{"trackingMaxCoordDiff",
|
||||||
|
20.0,
|
||||||
|
{"maximal valid target-to-mount distance for tracking process (arcsecs)",
|
||||||
|
"if current distance is greater than assume current mount coordinate as target point"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"trackingPathFilename",
|
||||||
|
std::string(),
|
||||||
|
{"tracking trajectory filename", "if it is an empty - just skip saving"}},
|
||||||
|
|
||||||
|
|
||||||
|
/* prohibited zones */
|
||||||
|
|
||||||
|
// minimal altitude
|
||||||
|
simple_config_record_t{"pzMinAltitude", mcc::MccAngle(10.0_degs), {"minimal altitude"}},
|
||||||
|
|
||||||
|
// HA-axis limit switch minimal value
|
||||||
|
simple_config_record_t{"pzLimitSwitchHAMin", mcc::MccAngle(-270.0_degs), {"HA-axis limit switch minimal value"}},
|
||||||
|
|
||||||
|
// HA-axis limit switch maximal value
|
||||||
|
simple_config_record_t{"pzLimitSwitchHAMax", mcc::MccAngle(270.0_degs), {"HA-axis limit switch maximal value"}},
|
||||||
|
|
||||||
|
// DEC-axis limit switch minimal value
|
||||||
|
simple_config_record_t{"pzLimitSwitchDecMin", mcc::MccAngle(-90.0_degs), {"DEC-axis limit switch minimal value"}},
|
||||||
|
|
||||||
|
// DEC-axis limit switch maximal value
|
||||||
|
simple_config_record_t{"pzLimitSwitchDecMax", mcc::MccAngle(90.0_degs), {"DEC-axis limit switch maximal value"}},
|
||||||
|
|
||||||
|
|
||||||
|
/* hardware-related */
|
||||||
|
|
||||||
|
// hardware mode: 1 - model mode, otherwise real mode
|
||||||
|
simple_config_record_t{"RunModel", 0, {"hardware mode: 1 - model mode, otherwise real mode"}},
|
||||||
|
|
||||||
|
// mount serial device paths
|
||||||
|
simple_config_record_t{"MountDevPath", std::string("/dev/ttyUSB0"), {"mount serial device paths"}},
|
||||||
|
|
||||||
|
// mount serial device speed
|
||||||
|
simple_config_record_t{"MountDevSpeed", 19200, {"mount serial device speed"}},
|
||||||
|
|
||||||
|
// motor encoders serial device path
|
||||||
|
simple_config_record_t{"EncoderDevPath", std::string(""), {"motor encoders serial device path"}},
|
||||||
|
|
||||||
|
// X-axis encoder serial device path
|
||||||
|
simple_config_record_t{"EncoderXDevPath", std::string("/dev/encoderX0"), {"X-axis encoder serial device path"}},
|
||||||
|
|
||||||
|
// Y-axis encoder serial device path
|
||||||
|
simple_config_record_t{"EncoderYDevPath", std::string("/dev/encoderY0"), {"Y-axis encoder serial device path"}},
|
||||||
|
|
||||||
|
// encoders serial device speed
|
||||||
|
simple_config_record_t{"EncoderDevSpeed", 153000, {"encoders serial device speed"}},
|
||||||
|
|
||||||
|
// ==1 if encoder works as separate serial device, ==2 if there's new version with two devices
|
||||||
|
simple_config_record_t{
|
||||||
|
"SepEncoder",
|
||||||
|
2,
|
||||||
|
{"==1 if encoder works as separate serial device, ==2 if there's new version with two devices"}},
|
||||||
|
|
||||||
|
|
||||||
|
// mount polling interval in millisecs
|
||||||
|
simple_config_record_t{"MountReqInterval", std::chrono::milliseconds(100), {"mount polling interval in millisecs"}},
|
||||||
|
|
||||||
|
// encoders polling interval in millisecs
|
||||||
|
simple_config_record_t{"EncoderReqInterval",
|
||||||
|
std::chrono::milliseconds(1),
|
||||||
|
{"encoders polling interval in millisecs"}},
|
||||||
|
|
||||||
|
// mount axes rate calculation interval in millisecs
|
||||||
|
simple_config_record_t{"EncoderSpeedInterval",
|
||||||
|
std::chrono::milliseconds(50),
|
||||||
|
{"mount axes rate calculation interval in millisecs"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"PIDMaxDt",
|
||||||
|
std::chrono::milliseconds(1000),
|
||||||
|
{"maximal PID refresh time interval in millisecs",
|
||||||
|
"NOTE: if PID data will be refreshed with interval longer than this value (e.g. user polls "
|
||||||
|
"encoder data too rarely)",
|
||||||
|
"then the PID 'expired' data will be cleared and new computing loop is started"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"PIDRefreshDt", std::chrono::milliseconds(100), {"PID refresh interval"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"PIDCycleDt",
|
||||||
|
std::chrono::milliseconds(5000),
|
||||||
|
{"PID I cycle time (analog of 'RC' for PID on opamps)"}},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// X-axis coordinate PID P,I,D-params
|
||||||
|
simple_config_record_t{"XPIDC", std::vector<double>{0.5, 0.1, 0.2}, {"X-axis coordinate PID P,I,D-params"}},
|
||||||
|
|
||||||
|
// X-axis rate PID P,I,D-params
|
||||||
|
simple_config_record_t{"XPIDV", std::vector<double>{0.09, 0.0, 0.05}, {"X-axis rate PID P,I,D-params"}},
|
||||||
|
|
||||||
|
// Y-axis coordinate PID P, I, D-params
|
||||||
|
simple_config_record_t{"YPIDC", std::vector<double>{0.5, 0.1, 0.2}, {"Y-axis coordinate PID P, I, D-params"}},
|
||||||
|
|
||||||
|
// Y-axis rate PID P,I,D-params
|
||||||
|
simple_config_record_t{"YPIDV", std::vector<double>{0.09, 0.0, 0.05}, {"Y-axis rate PID P,I,D-params"}},
|
||||||
|
|
||||||
|
|
||||||
|
// maximal moving rate (degrees per second) along HA-axis (Y-axis of Sidereal servo microcontroller)
|
||||||
|
simple_config_record_t{
|
||||||
|
"hwMaxRateHA",
|
||||||
|
mcc::MccAngle(8.0_degs),
|
||||||
|
{"maximal moving rate (degrees per second) along HA-axis (Y-axis of Sidereal servo microcontroller)"}},
|
||||||
|
|
||||||
|
// maximal moving rate (degrees per second) along DEC-axis (X-axis of Sidereal servo microcontroller)
|
||||||
|
simple_config_record_t{
|
||||||
|
"hwMaxRateDEC",
|
||||||
|
mcc::MccAngle(10.0_degs),
|
||||||
|
{"maximal moving rate (degrees per second) along DEC-axis (X-axis of Sidereal servo microcontroller)"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"MaxPointingErr",
|
||||||
|
mcc::MccAngle(8.0_degs),
|
||||||
|
{"slewing-to-pointing mode angular limit in degrees"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"MaxFinePointingErr",
|
||||||
|
mcc::MccAngle(1.5_degs),
|
||||||
|
{"pointing-to-guiding mode angular limit in degrees"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"MaxGuidingErr",
|
||||||
|
mcc::MccAngle(0.5_arcsecs),
|
||||||
|
{"guiding 'good'-flag error cirle radius (mount-to-target distance) in degrees"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"XEncZero", mcc::MccAngle(0.0_degs), {"X-axis encoder zero-point in degrees"}},
|
||||||
|
|
||||||
|
simple_config_record_t{"YEncZero", mcc::MccAngle(0.0_degs), {"Y-axis encoder zero-point in degrees"}}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
class Asibfm700MountConfig : public mcc::utils::KeyValueHolder<decltype(Asibfm700MountConfigDefaults)>
|
||||||
|
{
|
||||||
|
using base_t = mcc::utils::KeyValueHolder<decltype(Asibfm700MountConfigDefaults)>;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
inline static auto deserializer = []<typename VT>(std::string_view str, VT& value) {
|
||||||
|
std::error_code ec{};
|
||||||
|
|
||||||
|
mcc::utils::MccSimpleDeserializer deser;
|
||||||
|
deser.setRangeDelim(base_t::VALUE_ARRAY_DELIM);
|
||||||
|
|
||||||
|
if constexpr (std::is_arithmetic_v<VT> || mcc::traits::mcc_output_char_range<VT> || std::ranges::range<VT> ||
|
||||||
|
mcc::traits::mcc_time_duration_c<VT>) {
|
||||||
|
// ec = base_t::defaultDeserializeFunc(str, value);
|
||||||
|
ec = deser(str, value);
|
||||||
|
} else if constexpr (std::same_as<VT, mcc::MccAngle>) { // assume here all angles are in degrees
|
||||||
|
double vd;
|
||||||
|
// ec = base_t::defaultDeserializeFunc(str, vd);
|
||||||
|
ec = deser(str, vd);
|
||||||
|
if (!ec) {
|
||||||
|
value = mcc::MccAngle(vd, mcc::MccDegreeTag{});
|
||||||
|
}
|
||||||
|
} else if constexpr (std::same_as<VT, mcc::MccDefaultPCMType>) {
|
||||||
|
std::string vstr;
|
||||||
|
// ec = base_t::defaultDeserializeFunc(str, vstr);
|
||||||
|
ec = deser(str, vstr);
|
||||||
|
|
||||||
|
if (!ec) {
|
||||||
|
auto s = mcc::utils::trimSpaces(vstr);
|
||||||
|
|
||||||
|
if (s == mcc::MccDefaultPCMTypeString<mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY>) {
|
||||||
|
value = mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY;
|
||||||
|
} else if (s == mcc::MccDefaultPCMTypeString<mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY_BSPLINE>) {
|
||||||
|
value = mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY;
|
||||||
|
} else if (s == mcc::MccDefaultPCMTypeString<mcc::MccDefaultPCMType::PCM_TYPE_BSPLINE>) {
|
||||||
|
value = mcc::MccDefaultPCMType::PCM_TYPE_BSPLINE;
|
||||||
|
} else {
|
||||||
|
ec = std::make_error_code(std::errc::invalid_argument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ec = std::make_error_code(std::errc::invalid_argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ec;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
/* the most usefull config fields */
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_time_duration_c DT>
|
||||||
|
DT hardwarePollingPeriod() const
|
||||||
|
{
|
||||||
|
return std::chrono::duration_cast<DT>(
|
||||||
|
getValue<std::chrono::milliseconds>("hardwarePollingPeriod").value_or(std::chrono::milliseconds{}));
|
||||||
|
};
|
||||||
|
|
||||||
|
std::chrono::milliseconds hardwarePollingPeriod() const
|
||||||
|
{
|
||||||
|
return hardwarePollingPeriod<std::chrono::milliseconds>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::mcc_angle_c T>
|
||||||
|
T siteLatitude() const
|
||||||
|
{
|
||||||
|
return static_cast<double>(getValue<mcc::MccAngle>("siteLatitude").value_or(mcc::MccAngle{}));
|
||||||
|
};
|
||||||
|
|
||||||
|
mcc::MccAngle siteLatitude() const
|
||||||
|
{
|
||||||
|
return siteLatitude<mcc::MccAngle>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::mcc_angle_c T>
|
||||||
|
T siteLongitude() const
|
||||||
|
{
|
||||||
|
return static_cast<double>(getValue<mcc::MccAngle>("siteLongitude").value_or(mcc::MccAngle{}));
|
||||||
|
};
|
||||||
|
|
||||||
|
mcc::MccAngle siteLongitude() const
|
||||||
|
{
|
||||||
|
return siteLongitude<mcc::MccAngle>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T siteElevation() const
|
||||||
|
requires std::is_arithmetic_v<T>
|
||||||
|
{
|
||||||
|
return getValue<double>("siteElevation").value_or(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
double siteElevation() const
|
||||||
|
{
|
||||||
|
return getValue<double>("siteElevation").value_or(0.0);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T refractWavelength() const
|
||||||
|
requires std::is_arithmetic_v<T>
|
||||||
|
{
|
||||||
|
return getValue<double>("refractWavelength").value_or(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
double refractWavelength() const
|
||||||
|
{
|
||||||
|
return getValue<double>("refractWavelength").value_or(0.0);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_output_char_range R>
|
||||||
|
R leapSecondFilename() const
|
||||||
|
{
|
||||||
|
R r;
|
||||||
|
|
||||||
|
std::string val = getValue<std::string>("leapSecondFilename").value_or("");
|
||||||
|
std::ranges::copy(val, std::back_inserter(r));
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string leapSecondFilename() const
|
||||||
|
{
|
||||||
|
return leapSecondFilename<std::string>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_output_char_range R>
|
||||||
|
R bulletinAFilename() const
|
||||||
|
{
|
||||||
|
R r;
|
||||||
|
std::string val = getValue<std::string>("bulletinAFilename").value_or("");
|
||||||
|
std::ranges::copy(val, std::back_inserter(r));
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string bulletinAFilename() const
|
||||||
|
{
|
||||||
|
return bulletinAFilename<std::string>();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <mcc::mcc_angle_c T>
|
||||||
|
T pzMinAltitude() const
|
||||||
|
{
|
||||||
|
return static_cast<double>(getValue<mcc::MccAngle>("pzMinAltitude").value_or(mcc::MccAngle{}));
|
||||||
|
};
|
||||||
|
|
||||||
|
mcc::MccAngle pzMinAltitude() const
|
||||||
|
{
|
||||||
|
return pzMinAltitude<mcc::MccAngle>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::mcc_angle_c T>
|
||||||
|
T pzLimitSwitchHAMin() const
|
||||||
|
{
|
||||||
|
return static_cast<double>(getValue<mcc::MccAngle>("pzLimitSwitchHAMin").value_or(mcc::MccAngle{}));
|
||||||
|
};
|
||||||
|
|
||||||
|
mcc::MccAngle pzLimitSwitchHAMin() const
|
||||||
|
{
|
||||||
|
return pzLimitSwitchHAMin<mcc::MccAngle>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::mcc_angle_c T>
|
||||||
|
T pzLimitSwitchHAMax() const
|
||||||
|
{
|
||||||
|
return static_cast<double>(getValue<mcc::MccAngle>("pzLimitSwitchHAMax").value_or(mcc::MccAngle{}));
|
||||||
|
};
|
||||||
|
|
||||||
|
mcc::MccAngle pzLimitSwitchHAMax() const
|
||||||
|
{
|
||||||
|
return pzLimitSwitchHAMax<mcc::MccAngle>();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::hardware_config_t servoControllerConfig() const
|
||||||
|
{
|
||||||
|
AsibFM700ServoController::hardware_config_t hw_cfg;
|
||||||
|
|
||||||
|
hw_cfg.hwConfig = {};
|
||||||
|
|
||||||
|
hw_cfg.MountDevPath = getValue<std::string>("MountDevPath").value_or(std::string{});
|
||||||
|
hw_cfg.EncoderDevPath = getValue<std::string>("EncoderDevPath").value_or(std::string{});
|
||||||
|
hw_cfg.EncoderXDevPath = getValue<std::string>("EncoderXDevPath").value_or(std::string{});
|
||||||
|
hw_cfg.EncoderYDevPath = getValue<std::string>("EncoderYDevPath").value_or(std::string{});
|
||||||
|
|
||||||
|
hw_cfg.devConfig.MountDevPath = hw_cfg.MountDevPath.data();
|
||||||
|
hw_cfg.devConfig.EncoderDevPath = hw_cfg.EncoderDevPath.data();
|
||||||
|
hw_cfg.devConfig.EncoderXDevPath = hw_cfg.EncoderXDevPath.data();
|
||||||
|
hw_cfg.devConfig.EncoderYDevPath = hw_cfg.EncoderYDevPath.data();
|
||||||
|
|
||||||
|
hw_cfg.devConfig.RunModel = getValue<int>("RunModel").value_or(int{});
|
||||||
|
hw_cfg.devConfig.MountDevSpeed = getValue<int>("MountDevSpeed").value_or(int{});
|
||||||
|
hw_cfg.devConfig.EncoderDevSpeed = getValue<int>("EncoderDevSpeed").value_or(int{});
|
||||||
|
hw_cfg.devConfig.SepEncoder = getValue<int>("SepEncoder").value_or(int{});
|
||||||
|
|
||||||
|
std::chrono::duration<double> secs; // seconds as floating-point
|
||||||
|
|
||||||
|
secs = getValue<std::chrono::milliseconds>("MountReqInterval").value_or(std::chrono::milliseconds{});
|
||||||
|
hw_cfg.devConfig.MountReqInterval = secs.count();
|
||||||
|
|
||||||
|
secs = getValue<std::chrono::milliseconds>("EncoderReqInterval").value_or(std::chrono::milliseconds{});
|
||||||
|
hw_cfg.devConfig.EncoderReqInterval = secs.count();
|
||||||
|
|
||||||
|
secs = getValue<std::chrono::milliseconds>("EncoderSpeedInterval").value_or(std::chrono::milliseconds{});
|
||||||
|
hw_cfg.devConfig.EncoderSpeedInterval = secs.count();
|
||||||
|
|
||||||
|
secs = getValue<std::chrono::milliseconds>("PIDMaxDt").value_or(std::chrono::milliseconds{1000});
|
||||||
|
hw_cfg.devConfig.PIDMaxDt = secs.count();
|
||||||
|
|
||||||
|
secs = getValue<std::chrono::milliseconds>("PIDRefreshDt").value_or(std::chrono::milliseconds{100});
|
||||||
|
hw_cfg.devConfig.PIDRefreshDt = secs.count();
|
||||||
|
|
||||||
|
secs = getValue<std::chrono::milliseconds>("PIDCycleDt").value_or(std::chrono::milliseconds{5000});
|
||||||
|
hw_cfg.devConfig.PIDCycleDt = secs.count();
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<double> pid = getValue<std::vector<double>>("XPIDC").value_or(std::vector<double>{});
|
||||||
|
if (pid.size() > 2) {
|
||||||
|
hw_cfg.devConfig.XPIDC.P = pid[0];
|
||||||
|
hw_cfg.devConfig.XPIDC.I = pid[1];
|
||||||
|
hw_cfg.devConfig.XPIDC.D = pid[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = getValue<std::vector<double>>("XPIDV").value_or(std::vector<double>{});
|
||||||
|
if (pid.size() > 2) {
|
||||||
|
hw_cfg.devConfig.XPIDV.P = pid[0];
|
||||||
|
hw_cfg.devConfig.XPIDV.I = pid[1];
|
||||||
|
hw_cfg.devConfig.XPIDV.D = pid[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = getValue<std::vector<double>>("YPIDC").value_or(std::vector<double>{});
|
||||||
|
if (pid.size() > 2) {
|
||||||
|
hw_cfg.devConfig.YPIDC.P = pid[0];
|
||||||
|
hw_cfg.devConfig.YPIDC.I = pid[1];
|
||||||
|
hw_cfg.devConfig.YPIDC.D = pid[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = getValue<std::vector<double>>("YPIDV").value_or(std::vector<double>{});
|
||||||
|
if (pid.size() > 2) {
|
||||||
|
hw_cfg.devConfig.YPIDV.P = pid[0];
|
||||||
|
hw_cfg.devConfig.YPIDV.I = pid[1];
|
||||||
|
hw_cfg.devConfig.YPIDV.D = pid[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
double ang = getValue<mcc::MccAngle>("MaxPointingErr").value_or(mcc::MccAngle(8.0_degs));
|
||||||
|
hw_cfg.devConfig.MaxPointingErr = ang;
|
||||||
|
|
||||||
|
ang = getValue<mcc::MccAngle>("MaxFinePointingErr").value_or(mcc::MccAngle(1.5_degs));
|
||||||
|
hw_cfg.devConfig.MaxFinePointingErr = ang;
|
||||||
|
|
||||||
|
ang = getValue<mcc::MccAngle>("MaxGuidingErr").value_or(mcc::MccAngle(0.5_arcsecs));
|
||||||
|
hw_cfg.devConfig.MaxGuidingErr = ang;
|
||||||
|
|
||||||
|
ang = getValue<mcc::MccAngle>("XEncZero").value_or(mcc::MccAngle(0.0_degs));
|
||||||
|
hw_cfg.devConfig.XEncZero = ang;
|
||||||
|
|
||||||
|
|
||||||
|
ang = getValue<mcc::MccAngle>("YEncZero").value_or(mcc::MccAngle(0.0_degs));
|
||||||
|
hw_cfg.devConfig.YEncZero = ang;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return hw_cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mcc::MccSimpleMovingModelParams movingModelParams() const
|
||||||
|
{
|
||||||
|
static constexpr double arcsecs2rad = std::numbers::pi / 180.0 / 3600.0; // arcseconds to radians
|
||||||
|
|
||||||
|
mcc::MccSimpleMovingModelParams pars;
|
||||||
|
|
||||||
|
auto get_value = [&pars, this]<typename VT>(std::string_view name, VT& val) {
|
||||||
|
val = getValue<VT>(name).value_or(val);
|
||||||
|
};
|
||||||
|
|
||||||
|
pars.telemetryTimeout =
|
||||||
|
getValue<decltype(pars.telemetryTimeout)>("telemetryTimeout").value_or(pars.telemetryTimeout);
|
||||||
|
|
||||||
|
pars.minTimeToPZone = getValue<decltype(pars.minTimeToPZone)>("minTimeToPZone").value_or(pars.minTimeToPZone);
|
||||||
|
|
||||||
|
pars.updatingPZoneInterval = getValue<decltype(pars.updatingPZoneInterval)>("updatingPZoneInterval")
|
||||||
|
.value_or(pars.updatingPZoneInterval);
|
||||||
|
|
||||||
|
pars.slewToleranceRadius =
|
||||||
|
getValue<decltype(pars.slewToleranceRadius)>("slewToleranceRadius").value_or(pars.slewToleranceRadius) *
|
||||||
|
arcsecs2rad;
|
||||||
|
|
||||||
|
get_value("slewingTelemetryInterval", pars.slewingTelemetryInterval);
|
||||||
|
|
||||||
|
pars.slewRateX = getValue<decltype(pars.slewRateX)>("hwMaxRateHA").value_or(pars.slewRateX);
|
||||||
|
pars.slewRateY = getValue<decltype(pars.slewRateY)>("hwMaxRateDEC").value_or(pars.slewRateY);
|
||||||
|
|
||||||
|
pars.adjustCoordDiff =
|
||||||
|
getValue<decltype(pars.adjustCoordDiff)>("adjustCoordDiff").value_or(pars.adjustCoordDiff) * arcsecs2rad;
|
||||||
|
|
||||||
|
pars.adjustCycleInterval =
|
||||||
|
getValue<decltype(pars.adjustCycleInterval)>("adjustCycleInterval").value_or(pars.adjustCycleInterval);
|
||||||
|
|
||||||
|
pars.slewTimeout = getValue<decltype(pars.slewTimeout)>("slewTimeout").value_or(pars.slewTimeout);
|
||||||
|
|
||||||
|
pars.slewingPathFilename =
|
||||||
|
getValue<decltype(pars.slewingPathFilename)>("slewingPathFilename").value_or(std::string());
|
||||||
|
|
||||||
|
get_value("trackingTelemetryInterval", pars.trackingTelemetryInterval);
|
||||||
|
|
||||||
|
pars.timeShiftToTargetPoint = getValue<decltype(pars.timeShiftToTargetPoint)>("timeShiftToTargetPoint")
|
||||||
|
.value_or(pars.timeShiftToTargetPoint);
|
||||||
|
|
||||||
|
pars.trackingCycleInterval = getValue<decltype(pars.trackingCycleInterval)>("trackingCycleInterval")
|
||||||
|
.value_or(pars.trackingCycleInterval);
|
||||||
|
|
||||||
|
pars.trackingMaxCoordDiff =
|
||||||
|
getValue<decltype(pars.trackingMaxCoordDiff)>("trackingMaxCoordDiff").value_or(pars.trackingMaxCoordDiff) *
|
||||||
|
arcsecs2rad;
|
||||||
|
|
||||||
|
pars.trackingPathFilename =
|
||||||
|
getValue<decltype(pars.trackingPathFilename)>("trackingPathFilename").value_or(std::string());
|
||||||
|
|
||||||
|
return pars;
|
||||||
|
}
|
||||||
|
|
||||||
|
Asibfm700PCM::pcm_data_t pcmData() const
|
||||||
|
{
|
||||||
|
Asibfm700PCM::pcm_data_t pcm_data;
|
||||||
|
|
||||||
|
std::vector<double> empty_vec;
|
||||||
|
|
||||||
|
pcm_data.type = getValue<decltype(pcm_data.type)>("pcmType").value_or(pcm_data.type);
|
||||||
|
|
||||||
|
pcm_data.siteLatitude = getValue<mcc::MccAngle>("siteLatitude").value_or(pcm_data.siteLatitude);
|
||||||
|
|
||||||
|
std::vector<double> vec = getValue<std::vector<double>>("pcmGeomCoeffs").value_or(empty_vec);
|
||||||
|
if (vec.size() >= 9) { // must be 9 coefficients
|
||||||
|
pcm_data.geomCoefficients = {.zeroPointX = vec[0],
|
||||||
|
.zeroPointY = vec[1],
|
||||||
|
.collimationErr = vec[2],
|
||||||
|
.nonperpendErr = vec[3],
|
||||||
|
.misalignErr1 = vec[4],
|
||||||
|
.misalignErr2 = vec[5],
|
||||||
|
.tubeFlexure = vec[6],
|
||||||
|
.forkFlexure = vec[7],
|
||||||
|
.DECaxisFlexure = vec[8]};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<size_t> dd = getValue<decltype(dd)>("pcmBsplineDegree").value_or(dd);
|
||||||
|
if (dd.size() >= 2) {
|
||||||
|
pcm_data.bspline.bsplDegreeX = dd[0] > 0 ? dd[0] : 3;
|
||||||
|
pcm_data.bspline.bsplDegreeY = dd[1] > 0 ? dd[1] : 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec = getValue<std::vector<double>>("pcmBsplineXknots").value_or(empty_vec);
|
||||||
|
// pid must contains interior and border (single point for each border) knots so minimal length must be 2
|
||||||
|
if (vec.size() >= 2) {
|
||||||
|
// generate full knots array (with border knots)
|
||||||
|
size_t Nknots = vec.size() + pcm_data.bspline.bsplDegreeX * 2 - 2;
|
||||||
|
pcm_data.bspline.knotsX.resize(Nknots);
|
||||||
|
|
||||||
|
for (size_t i = 0; i <= pcm_data.bspline.bsplDegreeX; ++i) { // border knots
|
||||||
|
pcm_data.bspline.knotsX[i] = vec[0];
|
||||||
|
pcm_data.bspline.knotsX[Nknots - i - 1] = vec.back();
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < (vec.size() - 2); ++i) { // interior knots
|
||||||
|
pcm_data.bspline.knotsX[i + pcm_data.bspline.bsplDegreeX] = vec[1 + i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec = getValue<std::vector<double>>("pcmBsplineYknots").value_or(empty_vec);
|
||||||
|
// pid must contains interior and border (single point for each border) knots so minimal length must be 2
|
||||||
|
if (vec.size() >= 2) {
|
||||||
|
// generate full knots array (with border knots)
|
||||||
|
size_t Nknots = vec.size() + pcm_data.bspline.bsplDegreeY * 2 - 2;
|
||||||
|
pcm_data.bspline.knotsY.resize(Nknots);
|
||||||
|
|
||||||
|
for (size_t i = 0; i <= pcm_data.bspline.bsplDegreeY; ++i) { // border knots
|
||||||
|
pcm_data.bspline.knotsY[i] = vec[0];
|
||||||
|
pcm_data.bspline.knotsY[Nknots - i - 1] = vec.back();
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < (vec.size() - 2); ++i) { // interior knots
|
||||||
|
pcm_data.bspline.knotsY[i + pcm_data.bspline.bsplDegreeY] = vec[1 + i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// minimal allowed number of B-spline coefficients
|
||||||
|
size_t Ncoeffs = pcm_data.type == mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY
|
||||||
|
? 0
|
||||||
|
: (pcm_data.bspline.knotsX.size() - pcm_data.bspline.bsplDegreeX - 1) *
|
||||||
|
(pcm_data.bspline.knotsY.size() - pcm_data.bspline.bsplDegreeY - 1);
|
||||||
|
|
||||||
|
vec = getValue<std::vector<double>>("pcmBsplineXcoeffs").value_or(empty_vec);
|
||||||
|
|
||||||
|
if (vec.size() >= Ncoeffs) {
|
||||||
|
pcm_data.bspline.coeffsX.resize(Ncoeffs);
|
||||||
|
for (size_t i = 0; i < Ncoeffs; ++i) {
|
||||||
|
pcm_data.bspline.coeffsX[i] = vec[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec = getValue<std::vector<double>>("pcmBsplineYcoeffs").value_or(empty_vec);
|
||||||
|
|
||||||
|
if (vec.size() >= Ncoeffs) {
|
||||||
|
pcm_data.bspline.coeffsY.resize(Ncoeffs);
|
||||||
|
for (size_t i = 0; i < Ncoeffs; ++i) {
|
||||||
|
pcm_data.bspline.coeffsY[i] = vec[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pcm_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Asibfm700MountConfig() : base_t(Asibfm700MountConfigDefaults) {}
|
||||||
|
|
||||||
|
~Asibfm700MountConfig() = default;
|
||||||
|
|
||||||
|
std::error_code load(const std::filesystem::path& path)
|
||||||
|
{
|
||||||
|
std::string buffer;
|
||||||
|
|
||||||
|
std::error_code ec;
|
||||||
|
auto sz = std::filesystem::file_size(path, ec);
|
||||||
|
|
||||||
|
if (!ec && sz) {
|
||||||
|
std::ifstream fst(path);
|
||||||
|
|
||||||
|
try {
|
||||||
|
buffer.resize(sz);
|
||||||
|
|
||||||
|
fst.read(buffer.data(), sz);
|
||||||
|
|
||||||
|
fst.close();
|
||||||
|
|
||||||
|
ec = base_t::fromCharRange(buffer, deserializer);
|
||||||
|
if (!ec) {
|
||||||
|
// remove possible spaces in filenames
|
||||||
|
|
||||||
|
std::string val = getValue<std::string>("leapSecondFilename").value_or("");
|
||||||
|
auto fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("leapSecondFilename", fname);
|
||||||
|
|
||||||
|
|
||||||
|
val = getValue<std::string>("bulletinAFilename").value_or("");
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("bulletinAFilename", fname);
|
||||||
|
|
||||||
|
val = getValue<std::string>("MountDevPath").value_or(std::string{});
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("MountDevPath", fname);
|
||||||
|
|
||||||
|
val = getValue<std::string>("EncoderDevPath").value_or(std::string{});
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("EncoderDevPath", fname);
|
||||||
|
|
||||||
|
val = getValue<std::string>("EncoderXDevPath").value_or(std::string{});
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("EncoderXDevPath", fname);
|
||||||
|
|
||||||
|
val = getValue<std::string>("EncoderYDevPath").value_or(std::string{});
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("EncoderYDevPath", fname);
|
||||||
|
|
||||||
|
val = getValue<std::string>("slewingPathFilename").value_or(std::string{});
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("slewingPathFilename", fname);
|
||||||
|
|
||||||
|
val = getValue<std::string>("trackingPathFilename").value_or(std::string{});
|
||||||
|
fname = mcc::utils::trimSpaces(val);
|
||||||
|
setValue("trackingPathFilename", fname);
|
||||||
|
}
|
||||||
|
} catch (std::ios_base::failure const& ex) {
|
||||||
|
ec = ex.code();
|
||||||
|
} catch (std::length_error const& ex) {
|
||||||
|
ec = std::make_error_code(std::errc::no_buffer_space);
|
||||||
|
} catch (std::bad_alloc const& ex) {
|
||||||
|
ec = std::make_error_code(std::errc::not_enough_memory);
|
||||||
|
} catch (...) {
|
||||||
|
ec = std::make_error_code(std::errc::operation_canceled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ec;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dumpDefaultsToFile(const std::filesystem::path& path)
|
||||||
|
{
|
||||||
|
std::ofstream fst(path);
|
||||||
|
if (!fst.is_open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fst << "#\n";
|
||||||
|
fst << "# ASTROSIB FM-700 MOUNT CONFIGURATION\n" << "#\n";
|
||||||
|
fst << "# (created at " << std::format("{:%FT%T UTC}", std::chrono::system_clock::now()) << ")\n";
|
||||||
|
fst << "#\n";
|
||||||
|
|
||||||
|
auto wrec = [&fst, this]<size_t I>() {
|
||||||
|
fst << "\n";
|
||||||
|
for (size_t i = 0; i < std::get<I>(_keyValue).comment.size(); ++i) {
|
||||||
|
fst << "# " << std::get<I>(_keyValue).comment[i] << "\n";
|
||||||
|
}
|
||||||
|
fst << std::get<I>(_keyValue).key << " = ";
|
||||||
|
auto v = std::get<I>(_keyValue).value;
|
||||||
|
using v_t = std::remove_cvref_t<decltype(v)>;
|
||||||
|
|
||||||
|
if constexpr (std::is_arithmetic_v<v_t> || mcc::traits::mcc_char_range<v_t>) {
|
||||||
|
fst << std::format("{}", v);
|
||||||
|
} else if constexpr (mcc::traits::mcc_time_duration_c<v_t>) {
|
||||||
|
fst << std::format("{}", v.count());
|
||||||
|
} else if constexpr (mcc::mcc_angle_c<v_t>) {
|
||||||
|
fst << std::format("{}", mcc::MccAngle(static_cast<double>(v)).degrees());
|
||||||
|
} else if constexpr (std::same_as<v_t, mcc::MccDefaultPCMType>) {
|
||||||
|
if (v == mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY) {
|
||||||
|
fst << mcc::MccDefaultPCMTypeString<mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY>;
|
||||||
|
} else if (v == mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY_BSPLINE) {
|
||||||
|
fst << mcc::MccDefaultPCMTypeString<mcc::MccDefaultPCMType::PCM_TYPE_GEOMETRY_BSPLINE>;
|
||||||
|
} else if (v == mcc::MccDefaultPCMType::PCM_TYPE_BSPLINE) {
|
||||||
|
fst << mcc::MccDefaultPCMTypeString<mcc::MccDefaultPCMType::PCM_TYPE_BSPLINE>;
|
||||||
|
}
|
||||||
|
} else if constexpr (std::ranges::range<v_t> && std::formattable<std::ranges::range_value_t<v_t>, char>) {
|
||||||
|
size_t sz = std::ranges::size(v);
|
||||||
|
if (!sz) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
--sz;
|
||||||
|
|
||||||
|
auto it = v.begin();
|
||||||
|
for (size_t j = 0; j < sz; ++j, ++it) {
|
||||||
|
fst << std::format("{}", *it) << base_t::VALUE_ARRAY_DELIM;
|
||||||
|
}
|
||||||
|
fst << std::format("{}", *it);
|
||||||
|
} else if constexpr (std::formattable<v_t, char>) {
|
||||||
|
fst << std::format("{}", v);
|
||||||
|
} else {
|
||||||
|
static_assert(false, "INVALID TYPE!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fst << "\n";
|
||||||
|
};
|
||||||
|
|
||||||
|
[&wrec]<size_t... Is>(std::index_sequence<Is...>) {
|
||||||
|
(wrec.operator()<Is>(), ...);
|
||||||
|
}(std::make_index_sequence<std::tuple_size_v<decltype(Asibfm700MountConfigDefaults)>>());
|
||||||
|
|
||||||
|
fst.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
355
asibfm700/asibfm700_mount.cpp
Normal file
355
asibfm700/asibfm700_mount.cpp
Normal file
@@ -0,0 +1,355 @@
|
|||||||
|
#include "asibfm700_mount.h"
|
||||||
|
|
||||||
|
#include <mcc_pzone.h>
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/* CONSTRUCTOR AND DESTRUCTOR */
|
||||||
|
|
||||||
|
Asibfm700Mount::Asibfm700Mount(Asibfm700MountConfig const& config, std::shared_ptr<spdlog::logger> logger)
|
||||||
|
: mcc::ccte::erfa::MccCCTE_ERFA({.meteo{.temperature = 10.0, .humidity = 0.5, .pressure = 1010.0},
|
||||||
|
.wavelength = config.refractWavelength(),
|
||||||
|
.lat = config.siteLatitude(),
|
||||||
|
.lon = config.siteLongitude(),
|
||||||
|
.elev = config.siteElevation()}),
|
||||||
|
Asibfm700PCM(config.pcmData()),
|
||||||
|
gm_class_t(std::make_tuple(config.servoControllerConfig()),
|
||||||
|
std::make_tuple(this),
|
||||||
|
std::make_tuple(),
|
||||||
|
std::make_tuple(this, Asibfm700Logger{logger}),
|
||||||
|
std::make_tuple(this, Asibfm700Logger{logger}),
|
||||||
|
std::make_tuple(logger, Asibfm700Logger::LOGGER_DEFAULT_FORMAT)),
|
||||||
|
// base_gm_class_t(Asibfm700StartState{},
|
||||||
|
// std::make_tuple(config.servoControllerConfig()),
|
||||||
|
// std::make_tuple(this),
|
||||||
|
// std::make_tuple(),
|
||||||
|
// std::make_tuple(this),
|
||||||
|
// std::make_tuple(this),
|
||||||
|
// std::make_tuple(logger, Asibfm700Logger::LOGGER_DEFAULT_FORMAT)),
|
||||||
|
_mountConfig(config),
|
||||||
|
_mountConfigMutex(new std::mutex)
|
||||||
|
{
|
||||||
|
gm_class_t::addMarkToPatternIdx("[ASIB-MOUNT]");
|
||||||
|
|
||||||
|
logDebug("Create Asibfm700Mount class instance ({})", this->getThreadId());
|
||||||
|
|
||||||
|
initMount();
|
||||||
|
}
|
||||||
|
// Asibfm700Mount::Asibfm700Mount(Asibfm700MountConfig const& config, std::shared_ptr<spdlog::logger> logger)
|
||||||
|
// : mcc::ccte::erfa::MccCCTE_ERFA({.meteo{.temperature = 10.0, .humidity = 0.5, .pressure = 1010.0},
|
||||||
|
// .wavelength = config.refractWavelength(),
|
||||||
|
// .lat = config.siteLatitude(),
|
||||||
|
// .lon = config.siteLongitude(),
|
||||||
|
// .elev = config.siteElevation()}),
|
||||||
|
// Asibfm700PCM(config.pcmData()),
|
||||||
|
// base_gm_class_t(
|
||||||
|
// gm_class_t{AsibFM700ServoController{config.servoControllerConfig()}, mcc::MccTelemetry{this},
|
||||||
|
// Asibfm700PZoneContainer{}, mcc::MccSimpleSlewingModel{this}, mcc::MccSimpleTrackingModel{this},
|
||||||
|
// Asibfm700Logger{std::move(logger), Asibfm700Logger::LOGGER_DEFAULT_FORMAT}},
|
||||||
|
// Asibfm700StartState{}),
|
||||||
|
// _mountConfig(config),
|
||||||
|
// _mountConfigMutex(new std::mutex)
|
||||||
|
// {
|
||||||
|
// addMarkToPatternIdx("ASIB-MOUNT");
|
||||||
|
|
||||||
|
// logDebug("Create Asibfm700Mount class instance ({})", this->getThreadId());
|
||||||
|
|
||||||
|
// initMount();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
Asibfm700Mount::~Asibfm700Mount()
|
||||||
|
{
|
||||||
|
logDebug("Delete Asibfm700Mount class instance ({})", this->getThreadId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* PUBIC METHODS */
|
||||||
|
|
||||||
|
Asibfm700Mount::error_t Asibfm700Mount::initMount()
|
||||||
|
{
|
||||||
|
std::lock_guard lock{*_mountConfigMutex};
|
||||||
|
|
||||||
|
logInfo("Stop telemetry data updating");
|
||||||
|
stopInternalTelemetryDataUpdating();
|
||||||
|
|
||||||
|
logInfo("Init AstroSib FM-700 mount with configuration:");
|
||||||
|
logInfo(" site latitude: {}", _mountConfig.siteLatitude().sexagesimal());
|
||||||
|
logInfo(" site longitude: {}", _mountConfig.siteLongitude().sexagesimal());
|
||||||
|
logInfo(" site elevation: {} meters", _mountConfig.siteElevation());
|
||||||
|
logInfo(" refraction wavelength: {} mkm", _mountConfig.refractWavelength());
|
||||||
|
logInfo(" leap seconds filename: {}", _mountConfig.leapSecondFilename());
|
||||||
|
logInfo(" IERS Bulletin A filename: {}", _mountConfig.bulletinAFilename());
|
||||||
|
|
||||||
|
logInfo("");
|
||||||
|
logDebug("Delete previously defined prohobited zones");
|
||||||
|
clearPZones();
|
||||||
|
logInfo("Add prohibited zones ...");
|
||||||
|
|
||||||
|
logInfo(" Add MccAltLimitPZ zone: min alt = {}, lat = {} (pzone type: '{}')",
|
||||||
|
_mountConfig.pzMinAltitude().degrees(), _mountConfig.siteLatitude().degrees(),
|
||||||
|
"Minimal altitude prohibited zone");
|
||||||
|
addPZone(mcc::MccAltLimitPZ<mcc::MccAltLimitKind::MIN_ALT_LIMIT>{_mountConfig.pzMinAltitude(),
|
||||||
|
_mountConfig.siteLatitude(), this});
|
||||||
|
|
||||||
|
logInfo(" Add MccAxisLimitSwitchPZ zone: min value = {}, max value = {} (pzone type: '{}')",
|
||||||
|
_mountConfig.pzLimitSwitchHAMin().degrees(), _mountConfig.pzLimitSwitchHAMax().degrees(),
|
||||||
|
"HA-axis limit switch");
|
||||||
|
size_t pz_num = addPZone(mcc::MccAxisLimitSwitchPZ<mcc::MccCoordKind::COORDS_KIND_HA>{
|
||||||
|
_mountConfig.pzLimitSwitchHAMin(), _mountConfig.pzLimitSwitchHAMax(), this});
|
||||||
|
|
||||||
|
logInfo("{} prohibited zones were added successfully", pz_num);
|
||||||
|
|
||||||
|
auto mpars = _mountConfig.movingModelParams();
|
||||||
|
|
||||||
|
using secs_t = std::chrono::duration<double>;
|
||||||
|
auto to_msecs = [](double secs) {
|
||||||
|
auto s = secs_t{secs};
|
||||||
|
return std::chrono::duration_cast<std::chrono::milliseconds>(s);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto hw_cfg = _mountConfig.servoControllerConfig();
|
||||||
|
logInfo("");
|
||||||
|
logInfo("Hardware initialization ...");
|
||||||
|
logInfo(" set hardware configuration:");
|
||||||
|
logInfo(" RunModel: {}", hw_cfg.devConfig.RunModel == 1 ? "MODEL-MODE" : "REAL-MODE");
|
||||||
|
logInfo(" mount dev path: {}", hw_cfg.MountDevPath);
|
||||||
|
logInfo(" encoder dev path: {}", hw_cfg.EncoderDevPath);
|
||||||
|
logInfo(" encoder X-dev path: {}", hw_cfg.EncoderXDevPath);
|
||||||
|
logInfo(" encoder Y-dev path: {}", hw_cfg.EncoderYDevPath);
|
||||||
|
|
||||||
|
logInfo(" EncoderDevSpeed: {}", hw_cfg.devConfig.EncoderDevSpeed);
|
||||||
|
logInfo(" SepEncoder: {}", hw_cfg.devConfig.SepEncoder);
|
||||||
|
logInfo(" MountReqInterval: {}", to_msecs(hw_cfg.devConfig.MountReqInterval));
|
||||||
|
logInfo(" EncoderReqInterval: {}", to_msecs(hw_cfg.devConfig.EncoderReqInterval));
|
||||||
|
logInfo(" EncoderSpeedInterval: {}", to_msecs(hw_cfg.devConfig.EncoderSpeedInterval));
|
||||||
|
logInfo(" PIDMaxDt: {}", to_msecs(hw_cfg.devConfig.PIDMaxDt));
|
||||||
|
logInfo(" PIDRefreshDt: {}", to_msecs(hw_cfg.devConfig.PIDRefreshDt));
|
||||||
|
logInfo(" PIDCycleDt: {}", to_msecs(hw_cfg.devConfig.PIDCycleDt));
|
||||||
|
|
||||||
|
logInfo(" XPIDC: [P: {}, I: {}, D: {}]", hw_cfg.devConfig.XPIDC.P, hw_cfg.devConfig.XPIDC.I,
|
||||||
|
hw_cfg.devConfig.XPIDC.D);
|
||||||
|
logInfo(" XPIDV: [P: {}, I: {}, D: {}]", hw_cfg.devConfig.XPIDV.P, hw_cfg.devConfig.XPIDV.I,
|
||||||
|
hw_cfg.devConfig.XPIDV.D);
|
||||||
|
logInfo(" YPIDC: [P: {}, I: {}, D: {}]", hw_cfg.devConfig.YPIDC.P, hw_cfg.devConfig.YPIDC.I,
|
||||||
|
hw_cfg.devConfig.YPIDC.D);
|
||||||
|
logInfo(" YPIDV: [P: {}, I: {}, D: {}]", hw_cfg.devConfig.YPIDV.P, hw_cfg.devConfig.YPIDV.I,
|
||||||
|
hw_cfg.devConfig.YPIDV.D);
|
||||||
|
logInfo(" XEncZero: {}", hw_cfg.devConfig.XEncZero);
|
||||||
|
logInfo(" YEncZero: {}", hw_cfg.devConfig.YEncZero);
|
||||||
|
|
||||||
|
// actually, only set this->_hardwareConfig.devConfig part and paths!!!
|
||||||
|
this->_hardwareConfig = hw_cfg;
|
||||||
|
|
||||||
|
logInfo("");
|
||||||
|
logInfo(" EEPROM data:");
|
||||||
|
|
||||||
|
if (hw_cfg.devConfig.RunModel != 1) { // load EEPROM only in REAL HARDWARE mode
|
||||||
|
// load EEPROM part
|
||||||
|
auto cfg_err = this->hardwareUpdateConfig();
|
||||||
|
if (cfg_err) {
|
||||||
|
errorLogging("Cannot load EEPROM data:", cfg_err);
|
||||||
|
return cfg_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
mcc::MccAngle ang{_hardwareConfig.hwConfig.Yconf.accel}; // Sidereal defines HA-axis as Y-axis
|
||||||
|
|
||||||
|
logInfo(" HA-axis accel: {} degs/s^2", ang.degrees());
|
||||||
|
ang = _hardwareConfig.hwConfig.Xconf.accel; // Sidereal defines DEC-axis as X-axis
|
||||||
|
logInfo(" DEC-axis accel: {} degs/s^2", ang.degrees());
|
||||||
|
logInfo(" HA-axis backlash: {}", (double)_hardwareConfig.hwConfig.Yconf.backlash);
|
||||||
|
logInfo(" DEC-axis backlash: {}", (double)_hardwareConfig.hwConfig.Xconf.backlash);
|
||||||
|
|
||||||
|
logInfo(" HA-axis encoder ticks per revolution: {}",
|
||||||
|
_hardwareConfig.hwConfig.Ysetpr); // Sidereal defines HA-axis as Y-axis
|
||||||
|
logInfo(" DEC-axis encoder ticks per revolution: {}",
|
||||||
|
_hardwareConfig.hwConfig.Xsetpr); // Sidereal defines DEC-axis as X-axis
|
||||||
|
logInfo(" HA-motor encoder ticks per revolution: {}",
|
||||||
|
_hardwareConfig.hwConfig.Ymetpr); // Sidereal defines HA-axis as Y-axis
|
||||||
|
logInfo(" DEC-motor encoder ticks per revolution: {}",
|
||||||
|
_hardwareConfig.hwConfig.Xmetpr); // Sidereal defines DEC-axis as X-axis
|
||||||
|
|
||||||
|
ang = _hardwareConfig.hwConfig.Yslewrate; // Sidereal defines HA-axis as Y-axis
|
||||||
|
logInfo(" HA-axis slew rate: {} degs/s", ang.degrees());
|
||||||
|
ang = _hardwareConfig.hwConfig.Xslewrate; // Sidereal defines DEC-axis as X-axis
|
||||||
|
logInfo(" DEC-axis slew rate: {} degs/s", ang.degrees());
|
||||||
|
} else {
|
||||||
|
logWarn(" MODEL-MODE, no EEPROM data!");
|
||||||
|
}
|
||||||
|
|
||||||
|
logInfo("");
|
||||||
|
logInfo("Setup slewing and tracking parameters ...");
|
||||||
|
mpars.slewRateX = _mountConfig.getValue<mcc::MccAngle>("hwMaxRateHA").value_or(0.0);
|
||||||
|
mpars.slewRateY = _mountConfig.getValue<mcc::MccAngle>("hwMaxRateDEC").value_or(0.0);
|
||||||
|
if (hw_cfg.devConfig.RunModel != 1) {
|
||||||
|
mpars.brakingAccelX = _hardwareConfig.hwConfig.Yconf.accel; // Sidereal defines HA-axis as Y-axis
|
||||||
|
mpars.brakingAccelY = _hardwareConfig.hwConfig.Xconf.accel; // Sidereal defines DEC-axis as X-axis
|
||||||
|
} else {
|
||||||
|
mpars.brakingAccelX = 0.165806; // Sidereal defines HA-axis as Y-axis
|
||||||
|
mpars.brakingAccelY = 0.219911; // Sidereal defines DEC-axis as X-axis
|
||||||
|
}
|
||||||
|
|
||||||
|
auto max_dt_intvl = _mountConfig.getValue<std::chrono::milliseconds>("PIDMaxDt").value_or({});
|
||||||
|
auto min_dt_intvl = _mountConfig.getValue<std::chrono::milliseconds>("PIDRefreshDt").value_or({});
|
||||||
|
|
||||||
|
// check for polling interval consistency
|
||||||
|
auto intvl = mpars.slewingTelemetryInterval;
|
||||||
|
if (intvl > max_dt_intvl) {
|
||||||
|
mpars.slewingTelemetryInterval = max_dt_intvl;
|
||||||
|
logWarn(
|
||||||
|
" slewingTelemetryInterval user value ({} ms) is greater than allowed! Set it to maximal "
|
||||||
|
"allowed one: {} ms",
|
||||||
|
intvl.count(), max_dt_intvl.count());
|
||||||
|
}
|
||||||
|
if (intvl < min_dt_intvl) {
|
||||||
|
mpars.slewingTelemetryInterval = min_dt_intvl;
|
||||||
|
logWarn(
|
||||||
|
" slewingTelemetryInterval user value ({} ms) is lesser than allowed! Set it to minimal allowed "
|
||||||
|
"one: {} ms",
|
||||||
|
intvl.count(), min_dt_intvl.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
intvl = mpars.trackingTelemetryInterval;
|
||||||
|
if (intvl > max_dt_intvl) {
|
||||||
|
mpars.trackingTelemetryInterval = max_dt_intvl;
|
||||||
|
logWarn(
|
||||||
|
" trackingTelemetryInterval user value ({} ms) is greater than allowed! Set it to maximal "
|
||||||
|
"allowed one: {} ms",
|
||||||
|
intvl.count(), max_dt_intvl.count());
|
||||||
|
}
|
||||||
|
if (intvl < min_dt_intvl) {
|
||||||
|
mpars.trackingTelemetryInterval = min_dt_intvl;
|
||||||
|
logWarn(
|
||||||
|
" trackingTelemetryInterval user value ({} ms) is lesser than allowed! Set it to minimal "
|
||||||
|
"allowed one: {} ms",
|
||||||
|
intvl.count(), min_dt_intvl.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto st_err = setSlewingParams(mpars);
|
||||||
|
if (st_err) {
|
||||||
|
errorLogging(" An error occured while setting slewing parameters: ", st_err);
|
||||||
|
} else {
|
||||||
|
logInfo(" Max HA-axis speed: {} degs/s", mcc::MccAngle(mpars.slewRateX).degrees());
|
||||||
|
logInfo(" Max DEC-axis speed: {} degs/s", mcc::MccAngle(mpars.slewRateY).degrees());
|
||||||
|
logInfo(" HA-axis stop acceleration braking: {} degs/s^2", mcc::MccAngle(mpars.brakingAccelX).degrees());
|
||||||
|
logInfo(" DEC-axis stop acceleration braking: {} degs/s^2", mcc::MccAngle(mpars.brakingAccelY).degrees());
|
||||||
|
|
||||||
|
logInfo(" Slewing telemetry polling interval: {} millisecs", mpars.slewingTelemetryInterval.count());
|
||||||
|
}
|
||||||
|
st_err = setTrackingParams(_mountConfig.movingModelParams());
|
||||||
|
if (st_err) {
|
||||||
|
errorLogging(" An error occured while setting tracking parameters: ", st_err);
|
||||||
|
} else {
|
||||||
|
logInfo(" Tracking telemetry polling interval: {} millisecs", mpars.trackingTelemetryInterval.count());
|
||||||
|
}
|
||||||
|
logInfo("Slewing and tracking parameters have been set successfully");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// call base class initMount method
|
||||||
|
auto hw_err = gm_class_t::initMount();
|
||||||
|
// auto hw_err = base_gm_class_t::initMount();
|
||||||
|
if (hw_err) {
|
||||||
|
errorLogging("", hw_err);
|
||||||
|
return hw_err;
|
||||||
|
} else {
|
||||||
|
logInfo("Hardware initialization was performed sucessfully!");
|
||||||
|
}
|
||||||
|
|
||||||
|
logInfo("ERFA engine initialization ...");
|
||||||
|
|
||||||
|
|
||||||
|
// set ERFA state
|
||||||
|
Asibfm700CCTE::engine_state_t ccte_state{
|
||||||
|
.meteo = Asibfm700CCTE::_currentState.meteo, // just use of previous values
|
||||||
|
.wavelength = _mountConfig.refractWavelength(),
|
||||||
|
.lat = _mountConfig.siteLatitude(),
|
||||||
|
.lon = _mountConfig.siteLongitude(),
|
||||||
|
.elev = _mountConfig.siteElevation()};
|
||||||
|
|
||||||
|
|
||||||
|
if (_mountConfig.leapSecondFilename().size()) { // load leap seconds file
|
||||||
|
logInfo("Loading leap second file: '{}' ...", _mountConfig.leapSecondFilename());
|
||||||
|
bool ok = ccte_state._leapSeconds.load(_mountConfig.leapSecondFilename());
|
||||||
|
if (ok) {
|
||||||
|
logInfo("Leap second file was loaded successfully (expire date: {})", ccte_state._leapSeconds.expireDate());
|
||||||
|
} else {
|
||||||
|
logError("Leap second file loading failed! Using hardcoded defauls (expire date: {})",
|
||||||
|
ccte_state._leapSeconds.expireDate());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logInfo("Using hardcoded leap seconds defauls (expire date: {})", ccte_state._leapSeconds.expireDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_mountConfig.bulletinAFilename().size()) { // load IERS Bulletin A file
|
||||||
|
logInfo("Loading IERS Bulletin A file: '{}' ...", _mountConfig.bulletinAFilename());
|
||||||
|
bool ok = ccte_state._bulletinA.load(_mountConfig.bulletinAFilename());
|
||||||
|
if (ok) {
|
||||||
|
logInfo("IERS Bulletin A file was loaded successfully (date range: {} - {})",
|
||||||
|
ccte_state._bulletinA.dateRange().begin, ccte_state._bulletinA.dateRange().end);
|
||||||
|
} else {
|
||||||
|
logError("IERS Bulletin A file loading failed! Using hardcoded defauls (date range: {} - {})",
|
||||||
|
ccte_state._bulletinA.dateRange().begin, ccte_state._bulletinA.dateRange().end);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logInfo("Using hardcoded IERS Bulletin A defauls (date range: {} - {})",
|
||||||
|
ccte_state._bulletinA.dateRange().begin, ccte_state._bulletinA.dateRange().end);
|
||||||
|
}
|
||||||
|
|
||||||
|
setStateERFA(std::move(ccte_state));
|
||||||
|
|
||||||
|
// setTelemetryDataUpdateInterval(_mountConfig.hardwarePollingPeriod());
|
||||||
|
setTelemetryUpdateTimeout(_mountConfig.movingModelParams().telemetryTimeout);
|
||||||
|
startInternalTelemetryDataUpdating();
|
||||||
|
|
||||||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
|
bool ok = isInternalTelemetryDataUpdating();
|
||||||
|
if (ok) {
|
||||||
|
logInfo("Start updating telemetry data ...");
|
||||||
|
mcc::MccTelemetryData tdata;
|
||||||
|
auto err = waitForTelemetryData(&tdata, _mountConfig.movingModelParams().telemetryTimeout);
|
||||||
|
if (err) {
|
||||||
|
logError("Cannot update telemetry data (err = {} [{}, {}])!", err.message(), err.value(),
|
||||||
|
err.category().name());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto err = lastUpdateError();
|
||||||
|
logError("Cannot update telemetry data (err = {} [{}, {}])!", err.message(), err.value(),
|
||||||
|
err.category().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mcc::MccGenericMountErrorCode::ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Asibfm700Mount::error_t Asibfm700Mount::updateMountConfig(const Asibfm700MountConfig& cfg)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{*_mountConfigMutex};
|
||||||
|
|
||||||
|
_mountConfig = cfg;
|
||||||
|
|
||||||
|
auto hw_cfg = _mountConfig.servoControllerConfig();
|
||||||
|
hardwareUpdateConfig(hw_cfg.devConfig);
|
||||||
|
hardwareUpdateConfig(hw_cfg.hwConfig);
|
||||||
|
|
||||||
|
return AsibFM700ServoControllerErrorCode::ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* PROTECTED METHODS */
|
||||||
|
|
||||||
|
void Asibfm700Mount::errorLogging(const std::string& msg, const std::error_code& err)
|
||||||
|
{
|
||||||
|
if (msg.empty()) {
|
||||||
|
logError("{}::{} ({})", err.category().name(), err.value(), err.message());
|
||||||
|
} else {
|
||||||
|
logError("{}: {}::{} ({})", msg, err.category().name(), err.value(), err.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
189
asibfm700/asibfm700_mount.h
Normal file
189
asibfm700/asibfm700_mount.h
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include <mcc_generic_mount.h>
|
||||||
|
#include <mcc_pzone_container.h>
|
||||||
|
#include <mcc_slewing_model.h>
|
||||||
|
#include <mcc_spdlog.h>
|
||||||
|
#include <mcc_telemetry.h>
|
||||||
|
#include <mcc_tracking_model.h>
|
||||||
|
|
||||||
|
#include "asibfm700_common.h"
|
||||||
|
#include "asibfm700_configfile.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class Asibfm700Mount : public Asibfm700CCTE,
|
||||||
|
public Asibfm700PCM,
|
||||||
|
public mcc::MccGenericMount<AsibFM700ServoController,
|
||||||
|
mcc::MccTelemetry,
|
||||||
|
Asibfm700PZoneContainer,
|
||||||
|
Asibfm700SlewingModel,
|
||||||
|
Asibfm700TrackingModel,
|
||||||
|
Asibfm700Logger>
|
||||||
|
{
|
||||||
|
typedef mcc::MccGenericMount<AsibFM700ServoController,
|
||||||
|
mcc::MccTelemetry,
|
||||||
|
Asibfm700PZoneContainer,
|
||||||
|
Asibfm700SlewingModel,
|
||||||
|
Asibfm700TrackingModel,
|
||||||
|
Asibfm700Logger>
|
||||||
|
gm_class_t;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using gm_class_t::error_t;
|
||||||
|
|
||||||
|
using Asibfm700CCTE::setStateERFA;
|
||||||
|
using Asibfm700CCTE::updateBulletinA;
|
||||||
|
using Asibfm700CCTE::updateLeapSeconds;
|
||||||
|
using Asibfm700CCTE::updateMeteoERFA;
|
||||||
|
|
||||||
|
using gm_class_t::logCritical;
|
||||||
|
using gm_class_t::logDebug;
|
||||||
|
using gm_class_t::logError;
|
||||||
|
using gm_class_t::logInfo;
|
||||||
|
using gm_class_t::logWarn;
|
||||||
|
// using Asibfm700Logger::logCritical;
|
||||||
|
// using Asibfm700Logger::logDebug;
|
||||||
|
// using Asibfm700Logger::logError;
|
||||||
|
// using Asibfm700Logger::logInfo;
|
||||||
|
// using Asibfm700Logger::logWarn;
|
||||||
|
|
||||||
|
// using Asibfm700PZoneContainer::addPZone;
|
||||||
|
|
||||||
|
Asibfm700Mount(Asibfm700MountConfig const& config, std::shared_ptr<spdlog::logger> logger);
|
||||||
|
|
||||||
|
~Asibfm700Mount();
|
||||||
|
|
||||||
|
Asibfm700Mount(Asibfm700Mount&&) = default;
|
||||||
|
Asibfm700Mount& operator=(Asibfm700Mount&&) = default;
|
||||||
|
|
||||||
|
Asibfm700Mount(const Asibfm700Mount&) = delete;
|
||||||
|
Asibfm700Mount& operator=(const Asibfm700Mount&) = delete;
|
||||||
|
|
||||||
|
error_t initMount();
|
||||||
|
|
||||||
|
error_t updateMountConfig(Asibfm700MountConfig const&);
|
||||||
|
Asibfm700MountConfig currentMountConfig();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Asibfm700MountConfig _mountConfig;
|
||||||
|
std::unique_ptr<std::mutex> _mountConfigMutex;
|
||||||
|
|
||||||
|
void errorLogging(const std::string&, const std::error_code&);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
class Asibfm700Mount : public Asibfm700CCTE,
|
||||||
|
public Asibfm700PCM,
|
||||||
|
public mcc::MccGenericFsmMount<mcc::MccGenericMount<AsibFM700ServoController,
|
||||||
|
mcc::MccTelemetry,
|
||||||
|
Asibfm700PZoneContainer,
|
||||||
|
mcc::MccSimpleSlewingModel,
|
||||||
|
mcc::MccSimpleTrackingModel,
|
||||||
|
Asibfm700Logger>>
|
||||||
|
{
|
||||||
|
typedef mcc::MccGenericMount<AsibFM700ServoController,
|
||||||
|
mcc::MccTelemetry,
|
||||||
|
Asibfm700PZoneContainer,
|
||||||
|
mcc::MccSimpleSlewingModel,
|
||||||
|
mcc::MccSimpleTrackingModel,
|
||||||
|
Asibfm700Logger>
|
||||||
|
gm_class_t;
|
||||||
|
|
||||||
|
typedef mcc::MccGenericFsmMount<mcc::MccGenericMount<AsibFM700ServoController,
|
||||||
|
mcc::MccTelemetry,
|
||||||
|
Asibfm700PZoneContainer,
|
||||||
|
mcc::MccSimpleSlewingModel,
|
||||||
|
mcc::MccSimpleTrackingModel,
|
||||||
|
Asibfm700Logger>>
|
||||||
|
base_gm_class_t;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
struct Asibfm700ErrorState : base_gm_class_t::MccGenericFsmMountBaseState {
|
||||||
|
static constexpr std::string_view ID{"ASIBFM700-MOUNT-ERROR-STATE"};
|
||||||
|
|
||||||
|
// void exit(MccGenericFsmMountErrorEvent& event)
|
||||||
|
// {
|
||||||
|
// event.mount()->logWarn("The mount already in error state!");
|
||||||
|
// }
|
||||||
|
|
||||||
|
void enter(MccGenericFsmMountErrorEvent& event)
|
||||||
|
{
|
||||||
|
enterLog(event);
|
||||||
|
|
||||||
|
// event.mount()->logWarn("The mount already in error state!");
|
||||||
|
auto err = event.eventData();
|
||||||
|
event.mount()->logError("An error occured: {} [{} {}]", err.message(), err.value(), err.category().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit(mcc::fsm::traits::fsm_event_c auto& event)
|
||||||
|
{
|
||||||
|
exitLog(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enter(mcc::fsm::traits::fsm_event_c auto& event)
|
||||||
|
{
|
||||||
|
enterLog(event);
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
using transition_t = mcc::fsm::fsm_transition_table_t<
|
||||||
|
std::pair<MccGenericFsmMountErrorEvent, Asibfm700ErrorState>,
|
||||||
|
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState<Asibfm700ErrorState>>,
|
||||||
|
std::pair<MccGenericFsmMountIdleEvent, MccGenericFsmMountIdleState<Asibfm700ErrorState>>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef base_gm_class_t::MccGenericFsmMountStartState<Asibfm700ErrorState> Asibfm700StartState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using base_gm_class_t::error_t;
|
||||||
|
|
||||||
|
using Asibfm700CCTE::setStateERFA;
|
||||||
|
using Asibfm700CCTE::updateBulletinA;
|
||||||
|
using Asibfm700CCTE::updateLeapSeconds;
|
||||||
|
using Asibfm700CCTE::updateMeteoERFA;
|
||||||
|
|
||||||
|
using Asibfm700Logger::logCritical;
|
||||||
|
using Asibfm700Logger::logDebug;
|
||||||
|
using Asibfm700Logger::logError;
|
||||||
|
using Asibfm700Logger::logInfo;
|
||||||
|
using Asibfm700Logger::logWarn;
|
||||||
|
|
||||||
|
// using Asibfm700PZoneContainer::addPZone;
|
||||||
|
|
||||||
|
Asibfm700Mount(Asibfm700MountConfig const& config, std::shared_ptr<spdlog::logger> logger);
|
||||||
|
|
||||||
|
~Asibfm700Mount();
|
||||||
|
|
||||||
|
Asibfm700Mount(Asibfm700Mount&&) = default;
|
||||||
|
Asibfm700Mount& operator=(Asibfm700Mount&&) = default;
|
||||||
|
|
||||||
|
Asibfm700Mount(const Asibfm700Mount&) = delete;
|
||||||
|
Asibfm700Mount& operator=(const Asibfm700Mount&) = delete;
|
||||||
|
|
||||||
|
error_t initMount();
|
||||||
|
|
||||||
|
error_t updateMountConfig(Asibfm700MountConfig const&);
|
||||||
|
Asibfm700MountConfig currentMountConfig();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Asibfm700MountConfig _mountConfig;
|
||||||
|
std::unique_ptr<std::mutex> _mountConfigMutex;
|
||||||
|
|
||||||
|
void errorLogging(const std::string&, const std::error_code&);
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
static_assert(mcc::mcc_position_controls_c<Asibfm700Mount>, "");
|
||||||
|
static_assert(mcc::mcc_all_controls_c<Asibfm700Mount>, "");
|
||||||
|
|
||||||
|
static_assert(mcc::mcc_generic_mount_c<Asibfm700Mount>, "");
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
59
asibfm700/asibfm700_netserver.cpp
Normal file
59
asibfm700/asibfm700_netserver.cpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "asibfm700_netserver.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
Asibfm700MountNetServer::Asibfm700MountNetServer(asio::io_context& ctx,
|
||||||
|
Asibfm700Mount& mount,
|
||||||
|
std::shared_ptr<spdlog::logger> logger)
|
||||||
|
: base_t(ctx, mount, std::move(logger), Asibfm700Logger::LOGGER_DEFAULT_FORMAT)
|
||||||
|
{
|
||||||
|
addMarkToPatternIdx("[ASIB-NETSERVER]");
|
||||||
|
|
||||||
|
// to avoid possible compiler optimization (one needs to catch 'mount' strictly by reference)
|
||||||
|
auto* mount_ptr = &mount;
|
||||||
|
|
||||||
|
base_t::_handleMessageFunc = [mount_ptr, this](std::string_view command) {
|
||||||
|
// using mount_error_t = typename Asibfm700Mount::error_t;
|
||||||
|
std::error_code err{};
|
||||||
|
|
||||||
|
Asibfm700NetMessage input_msg;
|
||||||
|
using output_msg_t = Asibfm700NetMessage<handle_message_func_result_t>;
|
||||||
|
output_msg_t output_msg;
|
||||||
|
|
||||||
|
auto nn = std::this_thread::get_id();
|
||||||
|
|
||||||
|
auto ec = parseMessage(command, input_msg);
|
||||||
|
|
||||||
|
if (ec) {
|
||||||
|
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, ec);
|
||||||
|
} else {
|
||||||
|
if (input_msg.withKey(ASIBFM700_COMMPROTO_KEYWORD_METEO_STR)) {
|
||||||
|
// what is operation type (set or get)?
|
||||||
|
if (input_msg.paramSize()) { // set operation
|
||||||
|
auto vp = input_msg.paramValue<Asibfm700CCTE::meteo_t>(0);
|
||||||
|
if (vp) {
|
||||||
|
mount_ptr->updateMeteoERFA(vp.value());
|
||||||
|
|
||||||
|
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, input_msg.byteRepr());
|
||||||
|
} else {
|
||||||
|
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, vp.error());
|
||||||
|
}
|
||||||
|
} else { // get operation
|
||||||
|
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR,
|
||||||
|
ASIBFM700_COMMPROTO_KEYWORD_METEO_STR, mount_ptr->getStateERFA().meteo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// basic network message processing
|
||||||
|
output_msg = base_t::handleMessage<output_msg_t>(input_msg, mount_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output_msg.template byteRepr<typename base_t::handle_message_func_result_t>();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Asibfm700MountNetServer::~Asibfm700MountNetServer() {}
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
146
asibfm700/asibfm700_netserver.h
Normal file
146
asibfm700/asibfm700_netserver.h
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mcc_netserver.h>
|
||||||
|
#include <mcc_netserver_proto.h>
|
||||||
|
|
||||||
|
#include "asibfm700_common.h"
|
||||||
|
#include "asibfm700_mount.h"
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace details
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename VT, size_t N1, size_t N2>
|
||||||
|
static constexpr auto merge_arrays(const std::array<VT, N1>& arr1, const std::array<VT, N2>& arr2)
|
||||||
|
{
|
||||||
|
constexpr auto N = N1 + N2;
|
||||||
|
std::array<VT, N> res;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < N1; ++i) {
|
||||||
|
res[i] = arr1[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = N1; i < N; ++i) {
|
||||||
|
res[i] = arr2[i - N1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace details
|
||||||
|
|
||||||
|
constexpr static std::string_view ASIBFM700_COMMPROTO_KEYWORD_METEO_STR{"METEO"};
|
||||||
|
|
||||||
|
struct Asibfm700NetMessageValidKeywords {
|
||||||
|
static constexpr std::array NETMSG_VALID_KEYWORDS =
|
||||||
|
details::merge_arrays(mcc::network::MccNetMessageValidKeywords::NETMSG_VALID_KEYWORDS,
|
||||||
|
std::array{ASIBFM700_COMMPROTO_KEYWORD_METEO_STR});
|
||||||
|
|
||||||
|
// hashes of valid keywords
|
||||||
|
static constexpr std::array NETMSG_VALID_KEYWORD_HASHES = []<size_t... Is>(std::index_sequence<Is...>) {
|
||||||
|
return std::array{mcc::utils::FNV1aHash(NETMSG_VALID_KEYWORDS[Is])...};
|
||||||
|
}(std::make_index_sequence<NETMSG_VALID_KEYWORDS.size()>());
|
||||||
|
|
||||||
|
constexpr static const size_t* isKeywordValid(std::string_view key)
|
||||||
|
{
|
||||||
|
const auto hash = mcc::utils::FNV1aHash(key);
|
||||||
|
|
||||||
|
for (auto const& h : NETMSG_VALID_KEYWORD_HASHES) {
|
||||||
|
if (h == hash) {
|
||||||
|
return &h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_char_range BYTEREPR_T = std::string_view>
|
||||||
|
class Asibfm700NetMessage : public mcc::network::MccNetMessage<BYTEREPR_T, Asibfm700NetMessageValidKeywords>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
using base_t = mcc::network::MccNetMessage<BYTEREPR_T, Asibfm700NetMessageValidKeywords>;
|
||||||
|
|
||||||
|
class serializer_t : public base_t::DefaultSerializer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename T, mcc::traits::mcc_output_char_range OR>
|
||||||
|
void operator()(const T& value, OR& bytes)
|
||||||
|
{
|
||||||
|
if constexpr (std::same_as<T, Asibfm700CCTE::meteo_t>) {
|
||||||
|
// serialize just like a vector
|
||||||
|
std::vector<double> meteo{value.temperature, value.humidity, value.pressure};
|
||||||
|
base_t::DefaultSerializer::operator()(meteo, bytes);
|
||||||
|
} else {
|
||||||
|
base_t::DefaultSerializer::operator()(value, bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} _serializer;
|
||||||
|
|
||||||
|
|
||||||
|
class deserializer_t : public base_t::DefaultDeserializer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <mcc::traits::mcc_input_char_range IR, typename VT>
|
||||||
|
std::error_code operator()(IR&& bytes, VT& value) const
|
||||||
|
{
|
||||||
|
if constexpr (std::same_as<VT, Asibfm700CCTE::meteo_t>) {
|
||||||
|
// deserialize just like a vector
|
||||||
|
|
||||||
|
std::vector<double> v;
|
||||||
|
auto ec = base_t::DefaultDeserializer::operator()(std::forward<IR>(bytes), v);
|
||||||
|
if (ec) {
|
||||||
|
return ec;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v.size() < 3) {
|
||||||
|
return std::make_error_code(std::errc::invalid_argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
value.temperature = v[0];
|
||||||
|
value.humidity = v[1];
|
||||||
|
value.pressure = v[2];
|
||||||
|
|
||||||
|
return {};
|
||||||
|
} else {
|
||||||
|
return base_t::DefaultDeserializer::operator()(std::forward<IR>(bytes), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} _deserializer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
using base_t::base_t;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::expected<T, std::error_code> paramValue(size_t idx) const
|
||||||
|
{
|
||||||
|
return base_t::template paramValue<T>(idx, _deserializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_input_char_range KT, typename... PTs>
|
||||||
|
std::error_code construct(KT&& key, PTs&&... params)
|
||||||
|
requires mcc::traits::mcc_output_char_range<BYTEREPR_T>
|
||||||
|
{
|
||||||
|
return base_t::construct(_serializer, std::forward<KT>(key), std::forward<PTs>(params)...);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Asibfm700MountNetServer : public mcc::network::MccGenericMountNetworkServer<Asibfm700Logger>
|
||||||
|
{
|
||||||
|
using base_t = mcc::network::MccGenericMountNetworkServer<Asibfm700Logger>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Asibfm700MountNetServer(asio::io_context& ctx, Asibfm700Mount& mount, std::shared_ptr<spdlog::logger> logger);
|
||||||
|
|
||||||
|
~Asibfm700MountNetServer();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
507
asibfm700/asibfm700_netserver_endpoint.h
Normal file
507
asibfm700/asibfm700_netserver_endpoint.h
Normal file
@@ -0,0 +1,507 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <charconv>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <ranges>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include "mcc_traits.h"
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
|
||||||
|
static constexpr bool charSubrangeCompare(const mcc::traits::mcc_char_view auto& what,
|
||||||
|
const mcc::traits::mcc_char_view auto& where,
|
||||||
|
bool case_insensitive = false)
|
||||||
|
{
|
||||||
|
if (std::ranges::size(what) == std::ranges::size(where)) {
|
||||||
|
if (case_insensitive) {
|
||||||
|
auto f = std::ranges::search(where,
|
||||||
|
std::views::transform(what, [](const char& ch) { return std::tolower(ch); }));
|
||||||
|
return !f.empty();
|
||||||
|
} else {
|
||||||
|
auto f = std::ranges::search(where, what);
|
||||||
|
return !f.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Very simple various protocols endpoint parser and holder class
|
||||||
|
*
|
||||||
|
* endpoint: proto_mark://host_name:port_num/path
|
||||||
|
* where "part" is optional for all non-local protocol kinds;
|
||||||
|
*
|
||||||
|
* for local kind of protocols the endpoint must be given as:
|
||||||
|
* local://stream/PATH
|
||||||
|
* local://seqpacket/PATH
|
||||||
|
* local://serial/PATH
|
||||||
|
* where 'stream' and 'seqpacket' "host_name"-field marks the
|
||||||
|
* stream-type and seqpacket-type UNIX domain sockets protocols;
|
||||||
|
* 'serial' marks a serial (RS232/485) protocol.
|
||||||
|
* here, possible "port_num" field is allowed but ignored.
|
||||||
|
*
|
||||||
|
* NOTE: "proto_mark" and "host_name" (for local kind) fields are parsed in case-insensitive manner!
|
||||||
|
*
|
||||||
|
* EXAMPLES: tcp://192.168.70.130:3131
|
||||||
|
* local://serial/dev/ttyS1
|
||||||
|
* local://seqpacket/tmp/BM70_SERVER_SOCK
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class Asibfm700NetserverEndpoint
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr std::string_view protoHostDelim = "://";
|
||||||
|
static constexpr std::string_view hostPortDelim = ":";
|
||||||
|
static constexpr std::string_view portPathDelim = "/";
|
||||||
|
|
||||||
|
enum proto_id_t : uint8_t {
|
||||||
|
PROTO_ID_LOCAL,
|
||||||
|
PROTO_ID_SEQLOCAL,
|
||||||
|
PROTO_ID_SERLOCAL,
|
||||||
|
PROTO_ID_TCP,
|
||||||
|
PROTO_ID_TLS,
|
||||||
|
PROTO_ID_UNKNOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr std::string_view protoMarkLocal{"local"}; // UNIX domain
|
||||||
|
static constexpr std::string_view protoMarkTCP{"tcp"}; // TCP
|
||||||
|
static constexpr std::string_view protoMarkTLS{"tls"}; // TLS
|
||||||
|
|
||||||
|
static constexpr std::array validProtoMarks{protoMarkLocal, protoMarkTCP, protoMarkTLS};
|
||||||
|
|
||||||
|
|
||||||
|
static constexpr std::string_view localProtoTypeStream{"stream"}; // UNIX domain stream
|
||||||
|
static constexpr std::string_view localProtoTypeSeqpacket{"seqpacket"}; // UNIX domain seqpacket
|
||||||
|
static constexpr std::string_view localProtoTypeSerial{"serial"}; // serial (RS232/485)
|
||||||
|
|
||||||
|
static constexpr std::array validLocalProtoTypes{localProtoTypeStream, localProtoTypeSeqpacket,
|
||||||
|
localProtoTypeSerial};
|
||||||
|
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_input_char_range R>
|
||||||
|
Asibfm700NetserverEndpoint(const R& ept)
|
||||||
|
{
|
||||||
|
fromRange(ept);
|
||||||
|
}
|
||||||
|
|
||||||
|
Asibfm700NetserverEndpoint(const Asibfm700NetserverEndpoint& other)
|
||||||
|
{
|
||||||
|
copyInst(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
Asibfm700NetserverEndpoint(Asibfm700NetserverEndpoint&& other)
|
||||||
|
{
|
||||||
|
moveInst(std::move(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Asibfm700NetserverEndpoint() = default;
|
||||||
|
|
||||||
|
|
||||||
|
Asibfm700NetserverEndpoint& operator=(const Asibfm700NetserverEndpoint& other)
|
||||||
|
{
|
||||||
|
copyInst(other);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Asibfm700NetserverEndpoint& operator=(Asibfm700NetserverEndpoint&& other)
|
||||||
|
{
|
||||||
|
moveInst(std::move(other));
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_input_char_range R>
|
||||||
|
requires std::ranges::contiguous_range<R>
|
||||||
|
bool fromRange(const R& ept)
|
||||||
|
{
|
||||||
|
_isValid = false;
|
||||||
|
|
||||||
|
// at least 'ws://a' (proto, proto-host delimiter and at least a single character of hostname)
|
||||||
|
if (std::ranges::size(ept) < 6) {
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (std::is_array_v<std::remove_cvref_t<R>>) {
|
||||||
|
_endpoint = ept;
|
||||||
|
} else {
|
||||||
|
_endpoint.clear();
|
||||||
|
std::ranges::copy(ept, std::back_inserter(_endpoint));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto found = std::ranges::search(_endpoint, protoHostDelim);
|
||||||
|
if (found.empty()) {
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssize_t idx;
|
||||||
|
if ((idx = checkProtoMark(std::string_view{_endpoint.begin(), found.begin()})) < 0) {
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
_proto = validProtoMarks[idx];
|
||||||
|
|
||||||
|
_host = std::string_view{found.end(), _endpoint.end()};
|
||||||
|
|
||||||
|
auto f1 = std::ranges::search(_host, portPathDelim);
|
||||||
|
// std::string_view port_sv;
|
||||||
|
if (f1.empty() && isLocal()) { // no path, but it is mandatory for 'local'!
|
||||||
|
return _isValid;
|
||||||
|
} else {
|
||||||
|
_host = std::string_view(_host.begin(), f1.begin());
|
||||||
|
|
||||||
|
_path = std::string_view(f1.end(), &*_endpoint.end());
|
||||||
|
|
||||||
|
f1 = std::ranges::search(_host, hostPortDelim);
|
||||||
|
if (f1.empty() && !isLocal()) { // no port, but it is mandatory for non-local!
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
_portView = std::string_view(f1.end(), _host.end());
|
||||||
|
if (_portView.size()) {
|
||||||
|
_host = std::string_view(_host.begin(), f1.begin());
|
||||||
|
|
||||||
|
if (!isLocal()) {
|
||||||
|
// convert port string to int
|
||||||
|
auto end_ptr = _portView.data() + _portView.size();
|
||||||
|
|
||||||
|
auto [ptr, ec] = std::from_chars(_portView.data(), end_ptr, _port);
|
||||||
|
if (ec != std::errc() || ptr != end_ptr) {
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
} else { // ignore for local
|
||||||
|
_port = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_port = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLocal()) { // check for special values
|
||||||
|
idx = 0;
|
||||||
|
if (std::ranges::any_of(validLocalProtoTypes, [&idx, this](const auto& el) {
|
||||||
|
bool ok = utils::charSubrangeCompare(_host, el, true);
|
||||||
|
if (!ok) {
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
})) {
|
||||||
|
_host = validLocalProtoTypes[idx];
|
||||||
|
} else {
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_isValid = true;
|
||||||
|
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isValid() const
|
||||||
|
{
|
||||||
|
return _isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto endpoint() const
|
||||||
|
{
|
||||||
|
return _endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_view_or_output_char_range R>
|
||||||
|
R proto() const
|
||||||
|
{
|
||||||
|
return part<R>(PROTO_PART);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view proto() const
|
||||||
|
{
|
||||||
|
return proto<std::string_view>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_view_or_output_char_range R>
|
||||||
|
R host() const
|
||||||
|
{
|
||||||
|
return part<R>(HOST_PART);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view host() const
|
||||||
|
{
|
||||||
|
return host<std::string_view>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int port() const
|
||||||
|
{
|
||||||
|
return _port;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_view_or_output_char_range R>
|
||||||
|
R portView() const
|
||||||
|
{
|
||||||
|
return part<R>(PORT_PART);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view portView() const
|
||||||
|
{
|
||||||
|
return portView<std::string_view>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_output_char_range R, mcc::traits::mcc_input_char_range RR = std::string_view>
|
||||||
|
R path(RR&& root_path) const
|
||||||
|
{
|
||||||
|
if (_path.empty()) {
|
||||||
|
if constexpr (mcc::traits::mcc_output_char_range<R>) {
|
||||||
|
R res;
|
||||||
|
std::ranges::copy(std::forward<RR>(root_path), std::back_inserter(res));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} else { // can't add root path!!!
|
||||||
|
return part<R>(PATH_PART);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto N = std::ranges::distance(root_path.begin(), root_path.end());
|
||||||
|
|
||||||
|
if (N) {
|
||||||
|
R res;
|
||||||
|
std::filesystem::path pt(root_path.begin(), root_path.end());
|
||||||
|
|
||||||
|
if (isLocal() && _path[0] == '\0') {
|
||||||
|
std::ranges::copy(std::string_view(" "), std::back_inserter(res));
|
||||||
|
pt /= _path.substr(1);
|
||||||
|
std::ranges::copy(pt.string(), std::back_inserter(res));
|
||||||
|
*res.begin() = '\0';
|
||||||
|
} else {
|
||||||
|
pt /= _path;
|
||||||
|
std::ranges::copy(pt.string(), std::back_inserter(res));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
return part<R>(PATH_PART);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_input_char_range RR = std::string_view>
|
||||||
|
std::string path(RR&& root_path) const
|
||||||
|
{
|
||||||
|
return path<std::string, RR>(std::forward<RR>(root_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_view_or_output_char_range R>
|
||||||
|
R path() const
|
||||||
|
{
|
||||||
|
return part<R>(PATH_PART);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view path() const
|
||||||
|
{
|
||||||
|
return path<std::string_view>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isLocal() const
|
||||||
|
{
|
||||||
|
return proto() == protoMarkLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLocalStream() const
|
||||||
|
{
|
||||||
|
return host() == localProtoTypeStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLocalSerial() const
|
||||||
|
{
|
||||||
|
return host() == localProtoTypeSerial;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLocalSeqpacket() const
|
||||||
|
{
|
||||||
|
return host() == localProtoTypeSeqpacket;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isTCP() const
|
||||||
|
{
|
||||||
|
return proto() == protoMarkTCP;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTLS() const
|
||||||
|
{
|
||||||
|
return proto() == protoMarkTLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add '\0' char (or replace special-meaning char/char-sequence) to construct UNIX abstract namespace
|
||||||
|
// endpoint path
|
||||||
|
template <typename T = std::nullptr_t>
|
||||||
|
Asibfm700NetserverEndpoint& makeAbstract(const T& mark = nullptr)
|
||||||
|
requires(mcc::traits::mcc_input_char_range<T> || std::same_as<std::remove_cv_t<T>, char> ||
|
||||||
|
std::is_null_pointer_v<std::remove_cv_t<T>>)
|
||||||
|
{
|
||||||
|
if (!(isLocalStream() || isLocalSeqpacket())) { // only local proto is valid!
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (std::is_null_pointer_v<T>) { // just insert '\0'
|
||||||
|
auto it = _endpoint.insert(std::string::const_iterator(_path.begin()), '\0');
|
||||||
|
_path = std::string_view(it, _endpoint.end());
|
||||||
|
} else if constexpr (std::same_as<std::remove_cv_t<T>, char>) { // replace a character (mark)
|
||||||
|
auto pos = std::distance(_endpoint.cbegin(), std::string::const_iterator(_path.begin()));
|
||||||
|
if (_endpoint[pos] == mark) {
|
||||||
|
_endpoint[pos] = '\0';
|
||||||
|
}
|
||||||
|
} else { // replace a character range (mark)
|
||||||
|
if (std::ranges::equal(_path | std::views::take(std::ranges::size(mark), mark))) {
|
||||||
|
auto pos = std::distance(_endpoint.cbegin(), std::string::const_iterator(_path.begin()));
|
||||||
|
_endpoint.replace(pos, std::ranges::size(mark), 1, '\0');
|
||||||
|
_path = std::string_view(_endpoint.begin() + pos, _endpoint.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string _endpoint;
|
||||||
|
std::string_view _proto, _host, _path, _portView;
|
||||||
|
int _port;
|
||||||
|
bool _isValid;
|
||||||
|
|
||||||
|
|
||||||
|
virtual ssize_t checkProtoMark(std::string_view proto_mark)
|
||||||
|
{
|
||||||
|
ssize_t idx = 0;
|
||||||
|
|
||||||
|
// case-insensitive look-up
|
||||||
|
bool found =
|
||||||
|
std::ranges::any_of(Asibfm700NetserverEndpoint::validProtoMarks, [&idx, &proto_mark](const auto& el) {
|
||||||
|
bool ok = utils::charSubrangeCompare(proto_mark, el, true);
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
});
|
||||||
|
|
||||||
|
return found ? idx : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum EndpointPart { PROTO_PART, HOST_PART, PATH_PART, PORT_PART };
|
||||||
|
|
||||||
|
template <mcc::traits::mcc_view_or_output_char_range R>
|
||||||
|
R part(EndpointPart what) const
|
||||||
|
{
|
||||||
|
R res;
|
||||||
|
|
||||||
|
// if (!_isValid) {
|
||||||
|
// return res;
|
||||||
|
// }
|
||||||
|
|
||||||
|
auto part = _proto;
|
||||||
|
|
||||||
|
switch (what) {
|
||||||
|
case PROTO_PART:
|
||||||
|
part = _proto;
|
||||||
|
break;
|
||||||
|
case HOST_PART:
|
||||||
|
part = _host;
|
||||||
|
break;
|
||||||
|
case PATH_PART:
|
||||||
|
part = _path;
|
||||||
|
break;
|
||||||
|
case PORT_PART:
|
||||||
|
part = _portView;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (std::ranges::view<R>) {
|
||||||
|
return {part.begin(), part.end()};
|
||||||
|
} else {
|
||||||
|
std::ranges::copy(part, std::back_inserter(res));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void copyInst(const Asibfm700NetserverEndpoint& other)
|
||||||
|
{
|
||||||
|
if (&other != this) {
|
||||||
|
if (other._isValid) {
|
||||||
|
_isValid = other._isValid;
|
||||||
|
_endpoint = other._endpoint;
|
||||||
|
_proto = other._proto;
|
||||||
|
|
||||||
|
std::iterator_traits<const char*>::difference_type idx;
|
||||||
|
if (other.isLocal()) { // for 'local' host is one of static class constants
|
||||||
|
_host = other._host;
|
||||||
|
} else {
|
||||||
|
idx = std::distance(other._endpoint.c_str(), other._host.data());
|
||||||
|
_host = std::string_view(_endpoint.c_str() + idx, other._host.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
idx = std::distance(other._endpoint.c_str(), other._path.data());
|
||||||
|
_path = std::string_view(_endpoint.c_str() + idx, other._path.size());
|
||||||
|
|
||||||
|
idx = std::distance(other._endpoint.c_str(), other._portView.data());
|
||||||
|
_portView = std::string_view(_endpoint.c_str() + idx, other._portView.size());
|
||||||
|
|
||||||
|
_port = other._port;
|
||||||
|
} else {
|
||||||
|
_isValid = false;
|
||||||
|
_endpoint = std::string();
|
||||||
|
_proto = std::string_view();
|
||||||
|
_host = std::string_view();
|
||||||
|
_path = std::string_view();
|
||||||
|
_portView = std::string_view();
|
||||||
|
_port = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void moveInst(Asibfm700NetserverEndpoint&& other)
|
||||||
|
{
|
||||||
|
if (&other != this) {
|
||||||
|
if (other._isValid) {
|
||||||
|
_isValid = std::move(other._isValid);
|
||||||
|
_endpoint = std::move(other._endpoint);
|
||||||
|
_proto = other._proto;
|
||||||
|
_host = std::move(other._host);
|
||||||
|
_path = std::move(other._path);
|
||||||
|
_port = std::move(other._port);
|
||||||
|
_portView = std::move(other._portView);
|
||||||
|
} else {
|
||||||
|
_isValid = false;
|
||||||
|
_endpoint = std::string();
|
||||||
|
_proto = std::string_view();
|
||||||
|
_host = std::string_view();
|
||||||
|
_path = std::string_view();
|
||||||
|
_portView = std::string_view();
|
||||||
|
_port = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
172
asibfm700/asibfm700_netserver_main.cpp
Normal file
172
asibfm700/asibfm700_netserver_main.cpp
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
|
||||||
|
#include <cxxopts.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <asio/thread_pool.hpp>
|
||||||
|
|
||||||
|
#include <mcc_netserver_endpoint.h>
|
||||||
|
#include "asibfm700_netserver.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
/* COMMANDLINE OPTS */
|
||||||
|
cxxopts::Options options(argv[0], "Astrosib (c) BM700 mount server\n");
|
||||||
|
|
||||||
|
options.allow_unrecognised_options();
|
||||||
|
|
||||||
|
options.add_options()("h,help", "Print usage");
|
||||||
|
|
||||||
|
options.add_options()("D,daemon", "Demonize server");
|
||||||
|
|
||||||
|
options.add_options()("l,log", "Log filename (use stdout and stderr for standard output and error stream)",
|
||||||
|
cxxopts::value<std::string>()->default_value(""));
|
||||||
|
|
||||||
|
options.add_options()("level", "Log level (see SPDLOG package description for valid values)",
|
||||||
|
cxxopts::value<std::string>()->default_value("info"));
|
||||||
|
|
||||||
|
options.add_options()("c,config", "Mount configuration filename (by default use of hardcoded one)",
|
||||||
|
cxxopts::value<std::string>()->default_value(""));
|
||||||
|
|
||||||
|
options.add_options()("dump", "Dump mount default configuration to file and exit",
|
||||||
|
cxxopts::value<std::string>()->default_value(""));
|
||||||
|
|
||||||
|
options.add_options()(
|
||||||
|
"endpoints",
|
||||||
|
"endpoints server will be listening for. For 'local' endpoint the '@' symbol at the beginning of the path "
|
||||||
|
"means "
|
||||||
|
"abstract namespace socket.",
|
||||||
|
cxxopts::value<std::vector<std::string>>()->default_value("local://stream/@FM700_SERVER"));
|
||||||
|
|
||||||
|
|
||||||
|
options.positional_help("[endpoint0] [enpoint1] ... [endpointN]");
|
||||||
|
options.parse_positional({"endpoints"});
|
||||||
|
|
||||||
|
asio::io_context ctx(8);
|
||||||
|
// asio::io_context ctx;
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
auto opt_result = options.parse(argc, argv);
|
||||||
|
|
||||||
|
if (opt_result["help"].count()) {
|
||||||
|
std::cout << options.help();
|
||||||
|
std::cout << "\n";
|
||||||
|
std::cout << "[endpoint0] [enpoint1] ... [endpointN] - endpoints server will be listening for. For 'local' "
|
||||||
|
"endpoint the '@' symbol at the beginning of the path "
|
||||||
|
"means abstract namespace socket (e.g. local://stream/@ASIBFM700_SERVER)."
|
||||||
|
<< "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
asibfm700::Asibfm700MountConfig mount_cfg;
|
||||||
|
|
||||||
|
std::string fname = opt_result["dump"].as<std::string>();
|
||||||
|
if (fname.size()) {
|
||||||
|
bool ok = mount_cfg.dumpDefaultsToFile(fname);
|
||||||
|
if (!ok) {
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
// just ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
auto logname = opt_result["log"].as<std::string>();
|
||||||
|
|
||||||
|
auto logger = [&logname]() {
|
||||||
|
if (logname == "stdout") {
|
||||||
|
return spdlog::stdout_color_mt("console");
|
||||||
|
} else if (logname == "stderr") {
|
||||||
|
return spdlog::stderr_color_mt("stderr");
|
||||||
|
} else if (logname == "") {
|
||||||
|
return spdlog::null_logger_mt("FM700_SERVER_NULL_LOGGER");
|
||||||
|
} else {
|
||||||
|
return spdlog::basic_logger_mt(logname, logname);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
std::string level_str = opt_result["level"].as<std::string>();
|
||||||
|
std::ranges::transform(level_str, level_str.begin(), [](const char& c) { return std::tolower(c); });
|
||||||
|
|
||||||
|
auto log_level = spdlog::level::from_str(level_str);
|
||||||
|
logger->set_level(log_level);
|
||||||
|
logger->flush_on(spdlog::level::trace);
|
||||||
|
|
||||||
|
|
||||||
|
logger->set_pattern("%v");
|
||||||
|
int w = 90;
|
||||||
|
// const std::string fmt = std::format("{{:*^{}}}", w);
|
||||||
|
constexpr std::string_view fmt = "{:*^90}";
|
||||||
|
logger->info("\n\n\n");
|
||||||
|
logger->info(fmt, "");
|
||||||
|
logger->info(fmt, " ASTROSIB FM700 MOUNT SERVER ");
|
||||||
|
auto zt = std::chrono::zoned_time(std::chrono::current_zone(),
|
||||||
|
std::chrono::floor<std::chrono::seconds>(std::chrono::system_clock::now()));
|
||||||
|
logger->info(fmt, std::format(" {} ", zt));
|
||||||
|
logger->info(fmt, "");
|
||||||
|
logger->info("\n");
|
||||||
|
|
||||||
|
|
||||||
|
logger->set_pattern("[%Y-%m-%d %T.%e][%l]: %v");
|
||||||
|
std::string mount_cfg_fname = opt_result["config"].as<std::string>();
|
||||||
|
if (mount_cfg_fname.size()) {
|
||||||
|
logger->info("Try to load mount configuration from file: {}", mount_cfg_fname);
|
||||||
|
auto err = mount_cfg.load(mount_cfg_fname);
|
||||||
|
if (err) {
|
||||||
|
logger->error("Cannot load mount configuration (err = {})! Use of defaults!", err.message());
|
||||||
|
} else {
|
||||||
|
logger->info("Mount configuration was loaded successfully!");
|
||||||
|
}
|
||||||
|
logger->info("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
asibfm700::Asibfm700Mount mount(mount_cfg, logger);
|
||||||
|
asibfm700::Asibfm700MountNetServer server(ctx, mount, logger);
|
||||||
|
|
||||||
|
server.setupSignals();
|
||||||
|
|
||||||
|
if (opt_result["daemon"].count()) {
|
||||||
|
server.daemonize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// mcc::MccServerEndpoint epn(std::string_view("local://seqpacket/tmp/BM700_SERVER_SOCK"));
|
||||||
|
// mcc::MccServerEndpoint epn(std::string_view("local://stream/tmp/BM700_SERVER_SOCK"));
|
||||||
|
// mcc::MccServerEndpoint epn(std::string_view("local://stream/@tmp/BM700_SERVER_SOCK"));
|
||||||
|
// mcc::MccServerEndpoint epn(std::string_view("tcp://localhost:12345"));
|
||||||
|
|
||||||
|
// asio::co_spawn(ctx, server.listen(epn), asio::detached);
|
||||||
|
|
||||||
|
auto epnts = opt_result["endpoints"].as<std::vector<std::string>>();
|
||||||
|
|
||||||
|
for (auto& epnt : epnts) {
|
||||||
|
mcc::network::MccNetServerEndpoint ep(epnt);
|
||||||
|
|
||||||
|
if (ep.isValid()) {
|
||||||
|
ep.makeAbstract('@');
|
||||||
|
|
||||||
|
asio::co_spawn(ctx, server.listen(ep), asio::detached);
|
||||||
|
} else {
|
||||||
|
std::cerr << "Unrecognized endpoint: '" << epnt << "'! Ignore!\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// asio::thread_pool pool(5);
|
||||||
|
|
||||||
|
// asio::post(pool, [&ctx]() { ctx.run(); });
|
||||||
|
|
||||||
|
// pool.join();
|
||||||
|
ctx.run();
|
||||||
|
|
||||||
|
} catch (const std::system_error& ex) {
|
||||||
|
std::cerr << "An error occured: " << ex.code().message() << "\n";
|
||||||
|
return ex.code().value();
|
||||||
|
} catch (...) {
|
||||||
|
std::cerr << "Unhandled exceptions!\n";
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
292
asibfm700/asibfm700_servocontroller.cpp
Normal file
292
asibfm700/asibfm700_servocontroller.cpp
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
#include "asibfm700_servocontroller.h"
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
const char* AsibFM700ServoControllerErrorCategory::name() const noexcept
|
||||||
|
{
|
||||||
|
return "ASIBFM700-SERVOCONTROLLER-ERROR-CATEGORY";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AsibFM700ServoControllerErrorCategory::message(int ec) const
|
||||||
|
{
|
||||||
|
AsibFM700ServoControllerErrorCode err = static_cast<AsibFM700ServoControllerErrorCode>(ec);
|
||||||
|
|
||||||
|
switch (err) {
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_OK:
|
||||||
|
return "OK";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_FATAL:
|
||||||
|
return "LibSidServo fatal error";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_BADFORMAT:
|
||||||
|
return "LibSidServo wrong arguments of function";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_ENCODERDEV:
|
||||||
|
return "LibSidServo encoder device error or can't open";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_MOUNTDEV:
|
||||||
|
return "LibSidServo mount device error or can't open";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_FAILED:
|
||||||
|
return "LibSidServo failed to run command";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_NULLPTR:
|
||||||
|
return "nullptr argument";
|
||||||
|
case AsibFM700ServoControllerErrorCode::ERROR_POLLING_TIMEOUT:
|
||||||
|
return "polling timeout";
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const AsibFM700ServoControllerErrorCategory& AsibFM700ServoControllerErrorCategory::get()
|
||||||
|
{
|
||||||
|
static const AsibFM700ServoControllerErrorCategory constInst;
|
||||||
|
return constInst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::AsibFM700ServoController() : _hardwareConfig(), _setStateMutex(new std::mutex) {}
|
||||||
|
|
||||||
|
AsibFM700ServoController::AsibFM700ServoController(hardware_config_t config) : AsibFM700ServoController()
|
||||||
|
{
|
||||||
|
_hardwareConfig = std::move(config);
|
||||||
|
|
||||||
|
_hardwareConfig.devConfig.MountDevPath = const_cast<char*>(_hardwareConfig.MountDevPath.c_str());
|
||||||
|
_hardwareConfig.devConfig.EncoderDevPath = const_cast<char*>(_hardwareConfig.EncoderDevPath.c_str());
|
||||||
|
_hardwareConfig.devConfig.EncoderXDevPath = const_cast<char*>(_hardwareConfig.EncoderXDevPath.c_str());
|
||||||
|
_hardwareConfig.devConfig.EncoderYDevPath = const_cast<char*>(_hardwareConfig.EncoderYDevPath.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::~AsibFM700ServoController() {}
|
||||||
|
|
||||||
|
|
||||||
|
constexpr std::string_view AsibFM700ServoController::hardwareName() const
|
||||||
|
{
|
||||||
|
return "Sidereal-ServoControllerII";
|
||||||
|
}
|
||||||
|
|
||||||
|
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareStop()
|
||||||
|
{
|
||||||
|
error_t err = static_cast<AsibFM700ServoControllerErrorCode>(Mount.stop());
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
hardware_state_t hw_state;
|
||||||
|
|
||||||
|
auto start_tp = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
// poll hardware till stopped-state detected ...
|
||||||
|
while (true) {
|
||||||
|
err = hardwareGetState(&hw_state);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hw_state.moving_state == hardware_moving_state_t::HW_MOVE_STOPPED) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((std::chrono::steady_clock::now() - start_tp) > _hardwareConfig.pollingTimeout) {
|
||||||
|
err = AsibFM700ServoControllerErrorCode::ERROR_POLLING_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(_hardwareConfig.pollingInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareInit()
|
||||||
|
{
|
||||||
|
return static_cast<AsibFM700ServoControllerErrorCode>(Mount.init(&_hardwareConfig.devConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareSetState(hardware_state_t state)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{*_setStateMutex};
|
||||||
|
|
||||||
|
if (state.moving_state == hardware_moving_state_t::HW_MOVE_STOPPED) { // stop!
|
||||||
|
error_t err = static_cast<AsibFM700ServoControllerErrorCode>(Mount.stop());
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
hardware_state_t hw_state;
|
||||||
|
|
||||||
|
auto start_tp = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
// poll hardware till stopped-state detected ...
|
||||||
|
while (true) {
|
||||||
|
err = hardwareGetState(&hw_state);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hw_state.moving_state == hardware_moving_state_t::HW_MOVE_STOPPED) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((std::chrono::steady_clock::now() - start_tp) > _hardwareConfig.pollingTimeout) {
|
||||||
|
err = AsibFM700ServoControllerErrorCode::ERROR_POLLING_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(_hardwareConfig.pollingInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static thread_local coordval_pair_t cvalpair{.X{0.0, 0.0}, .Y{0.0, 0.0}};
|
||||||
|
// static thread_local coordpair_t cpair{.X = 0.0, .Y = 0.0};
|
||||||
|
|
||||||
|
// cvalpair.X = {.val = state.Y, .t = tp};
|
||||||
|
// cvalpair.Y = {.val = state.X, .t = tp};
|
||||||
|
|
||||||
|
// cpair.X = state.tagY;
|
||||||
|
// cpair.Y = state.tagX;
|
||||||
|
|
||||||
|
// time point from sidservo library is 'double' number represented UNIXTIME with
|
||||||
|
// microseconds/nanoseconds precision
|
||||||
|
// double tp = std::chrono::duration<double>(state.time_point.time_since_epoch()).count();
|
||||||
|
|
||||||
|
|
||||||
|
// 2025-12-04: coordval_pair_t.X.t is now of type struct timespec
|
||||||
|
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(state.time_point.time_since_epoch());
|
||||||
|
auto secs = std::chrono::floor<std::chrono::seconds>(ns);
|
||||||
|
ns -= secs;
|
||||||
|
std::timespec tp{.tv_sec = secs.count(), .tv_nsec = ns.count()};
|
||||||
|
|
||||||
|
// according to"SiTech protocol notes" X is DEC-axis and Y is HA-axis
|
||||||
|
coordval_pair_t cvalpair{.X{.val = state.Y, .t = tp}, .Y{.val = state.X, .t = tp}};
|
||||||
|
// coordpair_t cpair{.X = state.endptY, .Y = state.endptX};
|
||||||
|
|
||||||
|
|
||||||
|
// correctTo is asynchronous function!!!
|
||||||
|
//
|
||||||
|
// according to the Eddy's implementation of the LibSidServo library it is safe
|
||||||
|
// to pass the addresses of 'cvalpair' and 'cpair' automatic variables
|
||||||
|
// auto err = static_cast<AsibFM700ServoControllerErrorCode>(Mount.correctTo(&cvalpair, &cpair));
|
||||||
|
auto err = static_cast<AsibFM700ServoControllerErrorCode>(Mount.correctTo(&cvalpair));
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareGetState(hardware_state_t* state)
|
||||||
|
{
|
||||||
|
if (state == nullptr) {
|
||||||
|
return AsibFM700ServoControllerErrorCode::ERROR_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
using tp_t = decltype(hardware_state_t::time_point);
|
||||||
|
|
||||||
|
mountdata_t mdata;
|
||||||
|
|
||||||
|
error_t err = static_cast<AsibFM700ServoControllerErrorCode>(Mount.getMountData(&mdata));
|
||||||
|
if (!err) {
|
||||||
|
// time point from sidservo library is 'double' number represented UNIXTIME with
|
||||||
|
// microseconds/nanoseconds precision (must be equal for encXposition and encYposition)
|
||||||
|
|
||||||
|
// using secs_t = std::chrono::duration<double>;
|
||||||
|
|
||||||
|
// secs_t secs = secs_t{mdata.encXposition.t};
|
||||||
|
// state->time_point = tp_t{std::chrono::duration_cast<tp_t::duration>(secs)};
|
||||||
|
|
||||||
|
// 2025-12-04: coordval_pair_t.X.t is now of type struct timespec
|
||||||
|
auto dr = std::chrono::duration_cast<decltype(state->time_point)::duration>(
|
||||||
|
std::chrono::seconds(mdata.encXposition.t.tv_sec) + std::chrono::nanoseconds(mdata.encXposition.t.tv_nsec));
|
||||||
|
state->time_point = decltype(state->time_point){dr};
|
||||||
|
|
||||||
|
|
||||||
|
// if (mcc::utils::isEqual(secs.count(), 0.0)) { // model mode?
|
||||||
|
// state->time_point = decltype(state->time_point)::clock::now();
|
||||||
|
// } else {
|
||||||
|
// state->time_point = tp_t{std::chrono::duration_cast<tp_t::duration>(secs)};
|
||||||
|
// }
|
||||||
|
// WARNING: TEMPORARY (WAIT FOR Eddy fix its implementation of LibSidServo)!!!
|
||||||
|
// state->time_point = decltype(state->time_point)::clock::now();
|
||||||
|
|
||||||
|
// according to "SiTech protocol notes" X is DEC-axis and Y is HA-axis
|
||||||
|
state->X = mdata.encYposition.val;
|
||||||
|
state->Y = mdata.encXposition.val;
|
||||||
|
|
||||||
|
state->speedX = mdata.encYspeed.val;
|
||||||
|
state->speedY = mdata.encXspeed.val;
|
||||||
|
|
||||||
|
state->stateX = mdata.Ystate;
|
||||||
|
state->stateY = mdata.Xstate;
|
||||||
|
|
||||||
|
if (mdata.Xstate == AXIS_ERROR || mdata.Ystate == AXIS_ERROR) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_ERROR;
|
||||||
|
} else {
|
||||||
|
if (mdata.Xstate == AXIS_STOPPED) {
|
||||||
|
if (mdata.Ystate == AXIS_STOPPED) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_STOPPED;
|
||||||
|
} else if (mdata.Ystate == AXIS_SLEWING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_SLEWING;
|
||||||
|
} else if (mdata.Ystate == AXIS_POINTING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_ADJUSTING;
|
||||||
|
} else if (mdata.Ystate == AXIS_GUIDING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_GUIDING;
|
||||||
|
} else {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_UNKNOWN;
|
||||||
|
}
|
||||||
|
} else if (mdata.Xstate == AXIS_SLEWING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_SLEWING;
|
||||||
|
} else if (mdata.Xstate == AXIS_POINTING) {
|
||||||
|
if (mdata.Ystate == AXIS_SLEWING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_SLEWING;
|
||||||
|
} else {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_ADJUSTING;
|
||||||
|
}
|
||||||
|
} else if (mdata.Xstate == AXIS_GUIDING) {
|
||||||
|
if (mdata.Ystate == AXIS_SLEWING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_SLEWING;
|
||||||
|
} else if (mdata.Ystate == AXIS_POINTING) {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_ADJUSTING;
|
||||||
|
} else {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_GUIDING;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
state->moving_state = hardware_moving_state_t::HW_MOVE_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AsibFM700ServoController::hardwareUpdateConfig(conf_t cfg)
|
||||||
|
{
|
||||||
|
_hardwareConfig.devConfig = std::move(cfg);
|
||||||
|
|
||||||
|
_hardwareConfig.devConfig.MountDevPath = const_cast<char*>(_hardwareConfig.MountDevPath.c_str());
|
||||||
|
_hardwareConfig.devConfig.EncoderDevPath = const_cast<char*>(_hardwareConfig.EncoderDevPath.c_str());
|
||||||
|
_hardwareConfig.devConfig.EncoderXDevPath = const_cast<char*>(_hardwareConfig.EncoderXDevPath.c_str());
|
||||||
|
_hardwareConfig.devConfig.EncoderYDevPath = const_cast<char*>(_hardwareConfig.EncoderYDevPath.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareUpdateConfig(hardware_configuration_t cfg)
|
||||||
|
{
|
||||||
|
_hardwareConfig.hwConfig = std::move(cfg);
|
||||||
|
return static_cast<AsibFM700ServoControllerErrorCode>(Mount.saveHWconfig(&_hardwareConfig.hwConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::error_t AsibFM700ServoController::hardwareUpdateConfig()
|
||||||
|
{
|
||||||
|
return static_cast<AsibFM700ServoControllerErrorCode>(Mount.getHWconfig(&_hardwareConfig.hwConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AsibFM700ServoController::hardware_config_t AsibFM700ServoController::getHardwareConfig() const
|
||||||
|
{
|
||||||
|
return _hardwareConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
144
asibfm700/asibfm700_servocontroller.h
Normal file
144
asibfm700/asibfm700_servocontroller.h
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mcc_defaults.h>
|
||||||
|
#include <mcc_generics.h>
|
||||||
|
|
||||||
|
#include "../LibSidServo/sidservo.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
/* error codes enum definition */
|
||||||
|
|
||||||
|
enum class AsibFM700ServoControllerErrorCode : int {
|
||||||
|
// error codes from sidservo library
|
||||||
|
ERROR_OK = MCC_E_OK,
|
||||||
|
ERROR_FATAL = MCC_E_FATAL,
|
||||||
|
ERROR_BADFORMAT = MCC_E_BADFORMAT,
|
||||||
|
ERROR_ENCODERDEV = MCC_E_ENCODERDEV,
|
||||||
|
ERROR_MOUNTDEV = MCC_E_MOUNTDEV,
|
||||||
|
ERROR_FAILED = MCC_E_FAILED,
|
||||||
|
// my codes ...
|
||||||
|
ERROR_POLLING_TIMEOUT,
|
||||||
|
ERROR_NULLPTR
|
||||||
|
};
|
||||||
|
|
||||||
|
// error category
|
||||||
|
struct AsibFM700ServoControllerErrorCategory : public std::error_category {
|
||||||
|
const char* name() const noexcept;
|
||||||
|
std::string message(int ec) const;
|
||||||
|
|
||||||
|
static const AsibFM700ServoControllerErrorCategory& get();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static inline std::error_code make_error_code(AsibFM700ServoControllerErrorCode ec)
|
||||||
|
{
|
||||||
|
return std::error_code(static_cast<int>(ec), AsibFM700ServoControllerErrorCategory::get());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
|
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class is_error_code_enum<asibfm700::AsibFM700ServoControllerErrorCode> : public true_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
|
||||||
|
namespace asibfm700
|
||||||
|
{
|
||||||
|
|
||||||
|
class AsibFM700ServoController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::error_code error_t;
|
||||||
|
|
||||||
|
enum class hardware_moving_state_t : int {
|
||||||
|
HW_MOVE_ERROR = -1,
|
||||||
|
HW_MOVE_STOPPED = 0,
|
||||||
|
HW_MOVE_SLEWING,
|
||||||
|
HW_MOVE_ADJUSTING,
|
||||||
|
HW_MOVE_TRACKING,
|
||||||
|
HW_MOVE_GUIDING,
|
||||||
|
HW_MOVE_UNKNOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hardware_state_t {
|
||||||
|
static constexpr mcc::MccCoordPairKind pair_kind = mcc::MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||||
|
mcc::MccTimePoint time_point;
|
||||||
|
|
||||||
|
double X, Y, speedX, speedY;
|
||||||
|
axis_status_t stateX, stateY; // Eddy's LibSidServo axis state
|
||||||
|
|
||||||
|
hardware_moving_state_t moving_state;
|
||||||
|
|
||||||
|
// endpoint: a point on the trajectory of movement behind the guidance point (X,Y), taking into account
|
||||||
|
// the movement vector (i.e. sign of movement speed)
|
||||||
|
// this point is needed as Sidereal controller commands require not only moving speed but
|
||||||
|
// also 'target' point (point at which mount will stop)
|
||||||
|
// double endptX, endptY;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct hardware_config_t {
|
||||||
|
// the 'char*' fields from conf_t:
|
||||||
|
// wrap it to std::string
|
||||||
|
std::string MountDevPath;
|
||||||
|
std::string EncoderDevPath;
|
||||||
|
std::string EncoderXDevPath;
|
||||||
|
std::string EncoderYDevPath;
|
||||||
|
|
||||||
|
conf_t devConfig; // devices paths and PIDs parameters
|
||||||
|
hardware_configuration_t hwConfig; // EEPROM-located configuration
|
||||||
|
|
||||||
|
std::chrono::milliseconds pollingInterval{300}; // hardware polling interval
|
||||||
|
std::chrono::milliseconds pollingTimeout{30000}; // hardware polling timeout
|
||||||
|
};
|
||||||
|
|
||||||
|
/* constructors and destructor */
|
||||||
|
|
||||||
|
AsibFM700ServoController();
|
||||||
|
|
||||||
|
AsibFM700ServoController(hardware_config_t config);
|
||||||
|
|
||||||
|
AsibFM700ServoController(const AsibFM700ServoController&) = delete;
|
||||||
|
AsibFM700ServoController& operator=(const AsibFM700ServoController&) = delete;
|
||||||
|
|
||||||
|
AsibFM700ServoController(AsibFM700ServoController&&) = default;
|
||||||
|
AsibFM700ServoController& operator=(AsibFM700ServoController&&) = default;
|
||||||
|
|
||||||
|
virtual ~AsibFM700ServoController();
|
||||||
|
|
||||||
|
/* public methods */
|
||||||
|
|
||||||
|
constexpr std::string_view hardwareName() const;
|
||||||
|
|
||||||
|
error_t hardwareSetState(hardware_state_t state);
|
||||||
|
error_t hardwareGetState(hardware_state_t* state);
|
||||||
|
|
||||||
|
error_t hardwareStop();
|
||||||
|
error_t hardwareInit();
|
||||||
|
|
||||||
|
void hardwareUpdateConfig(conf_t cfg);
|
||||||
|
|
||||||
|
// save config to EEPROM
|
||||||
|
error_t hardwareUpdateConfig(hardware_configuration_t cfg);
|
||||||
|
// load config from EEPROM
|
||||||
|
error_t hardwareUpdateConfig();
|
||||||
|
|
||||||
|
hardware_config_t getHardwareConfig() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
hardware_config_t _hardwareConfig;
|
||||||
|
|
||||||
|
std::unique_ptr<std::mutex> _setStateMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace asibfm700
|
||||||
69
asibfm700/tests/cfg_test.cpp
Normal file
69
asibfm700/tests/cfg_test.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "../asibfm700_configfile.h"
|
||||||
|
|
||||||
|
template <typename VT>
|
||||||
|
struct rec_t {
|
||||||
|
std::string_view key;
|
||||||
|
VT value;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::string_view cfg_str = R"--(A = 11
|
||||||
|
B=3.3
|
||||||
|
# this is comment
|
||||||
|
C = WWWWWeeeWWWW
|
||||||
|
|
||||||
|
E = 10,20, 40, 32
|
||||||
|
)--";
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
auto desc = std::make_tuple(rec_t{"A", 1}, rec_t{"B", 2.2}, rec_t{"C", std::string("EEE")}, rec_t{"D", 3.3},
|
||||||
|
rec_t{"E", std::vector<int>{1, 2, 3}});
|
||||||
|
|
||||||
|
std::error_code err;
|
||||||
|
|
||||||
|
asibfm700::Asibfm700MountConfig acfg;
|
||||||
|
bool ok = acfg.dumpDefaultsToFile("/tmp/cfg.cfg");
|
||||||
|
if (!ok) {
|
||||||
|
std::cerr << "Cannot dump default configuration!\n";
|
||||||
|
exit(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ec = acfg.load("/tmp/cfg.cfg");
|
||||||
|
std::cout << "EC (load) = " << ec.message() << "\n";
|
||||||
|
|
||||||
|
std::cout << "refr w: " << acfg.refractWavelength() << "\n";
|
||||||
|
|
||||||
|
acfg.setValue("refractWavelength", 0.3);
|
||||||
|
|
||||||
|
auto e = acfg.getValue<double>("refractWavelength");
|
||||||
|
std::cout << "refr w: " << e.value_or(0.0) << "\n";
|
||||||
|
std::cout << "refr w: " << acfg.refractWavelength() << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
mcc::utils::KeyValueHolder kvh(desc);
|
||||||
|
err = kvh.setValue("C", "ewlkjfde");
|
||||||
|
if (err) {
|
||||||
|
std::cout << "cannot set value: " << err.message() << "\n";
|
||||||
|
} else {
|
||||||
|
auto vs = kvh.getValue<std::string>("C");
|
||||||
|
std::cout << "kvh[C] = " << vs.value_or("<no value>") << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
ec = kvh.fromCharRange(cfg_str);
|
||||||
|
if (ec) {
|
||||||
|
std::cout << "EC = " << ec.message() << "\n";
|
||||||
|
} else {
|
||||||
|
auto v3 = kvh.getValue<std::vector<int>>("E");
|
||||||
|
std::cout << "[";
|
||||||
|
for (auto& el : v3.value_or(std::vector<int>{0, 0, 0})) {
|
||||||
|
std::cout << el << " ";
|
||||||
|
}
|
||||||
|
std::cout << "]\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -6,13 +6,22 @@ set(ASIO_FOUND FALSE)
|
|||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
set(ASIO_INSTALL_DIR "" CACHE STRING "ASIO install dir")
|
||||||
|
set(ASIO_INSTALL_DIR_INTERNAL "" CACHE STRING "ASIO install dir")
|
||||||
|
if(NOT "${ASIO_INSTALL_DIR}" STREQUAL "${ASIO_INSTALL_DIR_INTERNAL}") # ASIO_INSTALL_DIR is given in command-line
|
||||||
|
unset(ASIO_INCLUDE_DIR CACHE)
|
||||||
find_path(ASIO_DIR asio.hpp HINTS ${ASIO_INSTALL_DIR} PATH_SUFFIXES include)
|
find_path(ASIO_DIR asio.hpp HINTS ${ASIO_INSTALL_DIR} PATH_SUFFIXES include)
|
||||||
|
else() # in system path
|
||||||
|
find_path(ASIO_DIR asio.hpp PATH_SUFFIXES include)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT ASIO_DIR)
|
if (NOT ASIO_DIR)
|
||||||
message(WARNING "Cannot find ASIO library headers!")
|
message(WARNING "Cannot find ASIO library headers!")
|
||||||
set(ASIO_FOUND FALSE)
|
set(ASIO_FOUND FALSE)
|
||||||
else()
|
else()
|
||||||
message(STATUS "Found ASIO: TRUE (${ASIO_DIR})")
|
message(STATUS "Found ASIO: (${ASIO_DIR})")
|
||||||
|
|
||||||
# ASIO is header-only library so it is IMPORTED target
|
# ASIO is header-only library so it is IMPORTED target
|
||||||
add_library(ASIO::ASIO INTERFACE IMPORTED GLOBAL)
|
add_library(ASIO::ASIO INTERFACE IMPORTED GLOBAL)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user