Skip to content

Commit

Permalink
Implement configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCyberBrick committed Dec 21, 2023
1 parent 4b18b7d commit 4a076c9
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 42 deletions.
10 changes: 10 additions & 0 deletions AutoPolarAlign.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="packages\ILMerge.3.0.41\build\ILMerge.props" Condition="Exists('packages\ILMerge.3.0.41\build\ILMerge.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -17,6 +18,8 @@
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -47,6 +50,9 @@
<Reference Include="ASCOM.Utilities, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<Private>True</Private>
</Reference>
<Reference Include="CommandLine, Version=2.9.1.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>packages\CommandLineParser.2.9.1\lib\net40\CommandLine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand Down Expand Up @@ -77,6 +83,10 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<MakeDir Directories="publish\$(Configuration)\" />
<Exec Command="&quot;$(ILMergeConsolePath)&quot; &quot;bin\$(Configuration)\$(AssemblyName).exe&quot; /out:&quot;publish\$(Configuration)\$(AssemblyName).exe&quot; bin\$(Configuration)\CommandLine.dll" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
38 changes: 30 additions & 8 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
using AutoPolarAlign;
using CommandLine;
using System;
using System.IO;

class MountInitializer
{
public static void Main(string[] args)
public static int Main(string[] args)
{
var settings = new Settings();
AutoPolarAlign(settings);
return Parser.Default.ParseArguments<Settings>(args).MapResult(opts => Run(opts), errs => 3);
}

private static void AutoPolarAlign(Settings settings)
private static int Run(Settings settings)
{
try
{
if (!AutoPolarAlign(settings))
{
return 1;
}
}
catch (Exception ex)
{
Console.WriteLine("Aborting due to an error: " + ex.Message);
Console.WriteLine(ex.ToString());
return 2;
}
return 0;
}

private static bool AutoPolarAlign(Settings settings)
{
using (var mount = new StarGoMount())
using (var solver = new OptronIPolarSolver())
{
mount.ReverseAltitude = settings.ReverseAltitude;
mount.ReverseAzimuth = settings.ReverseAzimuth;

Console.WriteLine("Connecting to mount...");

try
Expand All @@ -22,7 +44,7 @@ private static void AutoPolarAlign(Settings settings)
}
catch (Exception ex)
{
throw new Exception("Failed to connect to mount", ex);
throw new Exception("Failed connecting to mount", ex);
}

Console.WriteLine("Connecting to plate solver...");
Expand All @@ -33,12 +55,12 @@ private static void AutoPolarAlign(Settings settings)
}
catch (Exception ex)
{
throw new Exception("Failed to connect to solver", ex);
throw new Exception("Failed connecting to solver", ex);
}

var alignment = new AutoPolarAlignment(mount, solver, settings);
alignment.Run();
}

return alignment.Run();
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.0.1.0")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
72 changes: 68 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

# Auto Polar Align

A simple command line tool for automated polar alignment with Avalon mounts and iOptron iPolar.

Get the application [here](https://github.com/TheCyberBrick/Auto-Polar-Align/releases).

[![AutoPolarAlign Youtube Video](http://img.youtube.com/vi/LklTLXXU3LY/0.jpg)](http://www.youtube.com/watch?v=LklTLXXU3LY "AutoPolarAlign Youtube Video")
[![AutoPolarAlign Youtube Video](http://img.youtube.com/vi/hSZZqV73a8I/0.jpg)](https://youtu.be/hSZZqV73a8I "AutoPolarAlign Youtube Video")

## Requirements
- [ASCOM Platform](https://ascom-standards.org/)
- Avalon mount with StarGo and Motorized Polar Alignment upgrade
- StarGo ASCOM driver
- iOptron iPolar installed at `%LocalAppData%/iOptron iPolar/iOptron iPolar.exe`
Expand All @@ -16,10 +18,72 @@ Get the application [here](https://github.com/TheCyberBrick/Auto-Polar-Align/rel
Simply start AutoPolarAlign.exe and watch it do its thing.
If everything is working properly it will connect to StarGo, start and connect iPolar, do a short calibration and then home in towards the pole.

Note: If StarGo was installed with admin privileges then you must also run AutoPolarAlign with admin privileges, otherwise it will not be able to connect to StarGo.
**Important: If StarGo was installed with admin privileges then you must also run AutoPolarAlign with admin privileges, otherwise it will not be able to connect to StarGo.**

```
$ AutoPolarAlign.exe --help
Auto Polar Align 1.0.0.0
Copyright © TheCyberBrick 2023
--az-backlash (Default: 80) Azimuth backlash. Must be greater or equal the actual backlash amount or the exact backlash amount if backlash calibration is disabled.
--alt-backlash (Default: 40) Altitude backlash. Must be greater or equal the actual backlash amount or the exact backlash amount if backlash calibration is disabled.
--az-calibration-distance (Default: 60) Azimuth calibration distance
--alt-calibration-distance (Default: 60) Altitude calibration distance
--az-backlash-calibration (Default: yes) Azimuth backlash calibration
--alt-backlash-calibration (Default: yes) Altitude backlash calibration
--az-limit (Default: 600) Azimuth limit
--alt-limit (Default: 600) Altitude limit
--reverse-az (Default: no) Reverse azimuth axis
--reverse-alt (Default: no) Reverse altitude axis
--resist-direction-change (Default: yes) Resist changing direction when alignment is already close enough
--start-at-low-alt (Default: yes) Start altitude alignment at a position below pole
--start-at-opposite-az (Default: yes) Start azîmuth alignment at opposite position of pole
--samples-per-calibration (Default: 1) Samples taken per axis calibration
--samples-per-measurement (Default: 6) Samples taken per polar alignment measurement
--max-alignment-iterations (Default: 32) Maximum number of alignment iterations
--max-positioning-attempts (Default: 3) Maximum positioning attempts
--target-alignment (Default: 0.5) Target polar alignment
--acceptance-threshold (Default: 3) Alignment acceptance threshold in multiples of target alignment
--accept-best-effort (Default: no) Shorthand for infinite acceptance threshold
--start-aggressiveness (Default: 0.95) Start correction aggressiveness
--end-aggressiveness (Default: 0.5) End correction aggressiveness
--wait-until-consecutive-solving (Default: 5) Wait with alignment until the specified number of platesolves succeed consecutively
--wait-seconds-between-solving (Default: 1) Number of seconds to wait between each platesolve
--max-wait-seconds (Default: 3600) Maximum number of seconds to wait for consecutive platesolves before aborting
--settling-seconds (Default: 1) Number of seconds to wait after each move
--help Display this help screen.
--version Display version information.
```

There are many settings that can be changed but the default values should work just fine.

## TODOs
- Configuration
- Determine backlash automatically
- Integrate with Starkeeper Voyager (DragScript), N.I.N.A (TPPA?)
- Maybe QHY PoleMaster support
151 changes: 126 additions & 25 deletions Settings.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,131 @@
namespace AutoPolarAlign
using CommandLine;

namespace AutoPolarAlign
{
public enum YesNo
{
no,
yes
}

public class Settings
{
public double AzimuthBacklash = 80;
public double AltitudeBacklash = 40;
public double AzimuthCalibrationDistance = 60;
public double AltitudeCalibrationDistance = 60;
public bool AzimuthBacklashCalibration = true;
public bool AltitudeBacklashCalibration = true;
public double AzimuthLimit = 600;
public double AltitudeLimit = 600;
public bool ResistDirectionChange = true;
public bool StartAtLowAltitude = true;
public bool StartAtOppositeAzimuth = true;
public int SamplesPerCalibration = 1;
public int SamplesPerMeasurement = 6;
public int MaxAlignmentIterations = 32;
public int MaxPositioningAttempts = 3;
public double TargetAlignment = 0.5;
public double AcceptanceThreshold = 3;
public bool AcceptBestEffort = false;
public double StartAggressiveness = 0.95;
public double EndAggressiveness = 0.5;
public int WaitUntilConsecutiveSolving = 5;
public double WaitSecondsBetweenSolving = 1;
public double MaxWaitSeconds = 3600;
public double SettlingSeconds = 1;
[Option("az-backlash", Required = false, Default = 80, HelpText = "Azimuth backlash. Must be greater or equal the actual backlash amount or the exact backlash amount if backlash calibration is disabled.")]
public double AzimuthBacklash { get; set; }

[Option("alt-backlash", Required = false, Default = 40, HelpText = "Altitude backlash. Must be greater or equal the actual backlash amount or the exact backlash amount if backlash calibration is disabled.")]
public double AltitudeBacklash { get; set; }

[Option("az-calibration-distance", Required = false, Default = 60, HelpText = "Azimuth calibration distance")]
public double AzimuthCalibrationDistance { get; set; }

[Option("alt-calibration-distance", Required = false, Default = 60, HelpText = "Altitude calibration distance")]
public double AltitudeCalibrationDistance { get; set; }

[Option("az-backlash-calibration", Required = false, Default = YesNo.yes, HelpText = "Azimuth backlash calibration")]
public YesNo AzimuthBacklashCalibrationYesNo { get; set; }
public bool AzimuthBacklashCalibration
{
get => AzimuthBacklashCalibrationYesNo == YesNo.yes;
set => AzimuthBacklashCalibrationYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("alt-backlash-calibration", Required = false, Default = YesNo.yes, HelpText = "Altitude backlash calibration")]
public YesNo AltitudeBacklashCalibrationYesNo { get; set; }
public bool AltitudeBacklashCalibration
{
get => AltitudeBacklashCalibrationYesNo == YesNo.yes;
set => AltitudeBacklashCalibrationYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("az-limit", Required = false, Default = 600, HelpText = "Azimuth limit")]
public double AzimuthLimit { get; set; }

[Option("alt-limit", Required = false, Default = 600, HelpText = "Altitude limit")]
public double AltitudeLimit { get; set; }

[Option("reverse-az", Required = false, Default = YesNo.no, HelpText = "Reverse azimuth axis")]
public YesNo ReverseAzimuthYesNo { get; set; }
public bool ReverseAzimuth
{
get => ReverseAzimuthYesNo == YesNo.yes;
set => ReverseAzimuthYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("reverse-alt", Required = false, Default = YesNo.no, HelpText = "Reverse altitude axis")]
public YesNo ReverseAltitudeYesNo { get; set; }
public bool ReverseAltitude
{
get => ReverseAltitudeYesNo == YesNo.yes;
set => ReverseAltitudeYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("resist-direction-change", Required = false, Default = YesNo.yes, HelpText = "Resist changing direction when alignment is already close enough")]
public YesNo ResistDirectionChangeYesNo { get; set; }
public bool ResistDirectionChange
{
get => ResistDirectionChangeYesNo == YesNo.yes;
set => ResistDirectionChangeYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("start-at-low-alt", Required = false, Default = YesNo.yes, HelpText = "Start altitude alignment at a position below pole")]
public YesNo StartAtLowAltitudeYesNo { get; set; }
public bool StartAtLowAltitude
{
get => StartAtLowAltitudeYesNo == YesNo.yes;
set => StartAtLowAltitudeYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("start-at-opposite-az", Required = false, Default = YesNo.yes, HelpText = "Start azîmuth alignment at opposite position of pole")]
public YesNo StartAtOppositeAzimuthYesNo { get; set; }
public bool StartAtOppositeAzimuth
{
get => StartAtOppositeAzimuthYesNo == YesNo.yes;
set => StartAtOppositeAzimuthYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("samples-per-calibration", Required = false, Default = 1, HelpText = "Samples taken per axis calibration")]
public int SamplesPerCalibration { get; set; }

[Option("samples-per-measurement", Required = false, Default = 6, HelpText = "Samples taken per polar alignment measurement")]
public int SamplesPerMeasurement { get; set; }

[Option("max-alignment-iterations", Required = false, Default = 32, HelpText = "Maximum number of alignment iterations")]
public int MaxAlignmentIterations { get; set; }

[Option("max-positioning-attempts", Required = false, Default = 3, HelpText = "Maximum positioning attempts")]
public int MaxPositioningAttempts { get; set; }

[Option("target-alignment", Required = false, Default = 0.5, HelpText = "Target polar alignment")]
public double TargetAlignment { get; set; }

[Option("acceptance-threshold", Required = false, Default = 3, HelpText = "Alignment acceptance threshold in multiples of target alignment")]
public double AcceptanceThreshold { get; set; }

[Option("accept-best-effort", Required = false, Default = YesNo.no, HelpText = "Shorthand for infinite acceptance threshold")]
public YesNo AcceptBestEffortYesNo { get; set; }
public bool AcceptBestEffort
{
get => AcceptBestEffortYesNo == YesNo.yes;
set => AcceptBestEffortYesNo = value ? YesNo.yes : YesNo.no;
}

[Option("start-aggressiveness", Required = false, Default = 0.95, HelpText = "Start correction aggressiveness")]
public double StartAggressiveness { get; set; }

[Option("end-aggressiveness", Required = false, Default = 0.5, HelpText = "End correction aggressiveness")]
public double EndAggressiveness { get; set; }

[Option("wait-until-consecutive-solving", Required = false, Default = 5, HelpText = "Wait with alignment until the specified number of platesolves succeed consecutively")]
public int WaitUntilConsecutiveSolving { get; set; }

[Option("wait-seconds-between-solving", Required = false, Default = 1, HelpText = "Number of seconds to wait between each platesolve")]
public double WaitSecondsBetweenSolving { get; set; }

[Option("max-wait-seconds", Required = false, Default = 3600, HelpText = "Maximum number of seconds to wait for consecutive platesolves before aborting")]
public double MaxWaitSeconds { get; set; }

[Option("settling-seconds", Required = false, Default = 1, HelpText = "Number of seconds to wait after each move")]
public double SettlingSeconds { get; set; }
}
}
9 changes: 6 additions & 3 deletions StarGoMount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class StarGoMount : IPolarAlignmentMount

public bool SetAuxSpeed { get; set; } = true;

public bool ReverseAltitude { get; set; } = true;
public bool ReverseAltitude { get; set; } = false;

public bool ReverseAzimuth { get; set; } = false;

Expand Down Expand Up @@ -45,12 +45,15 @@ public void Connect()

public void Disconnect()
{
telescope.Connected = false;
if (telescope != null)
{
telescope.Connected = false;
}
}

public void Dispose()
{
telescope.Dispose();
telescope?.Dispose();
}

private double EstimateDurationForMove(double amount, int auxsteps, int auxspeed)
Expand Down
2 changes: 2 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="2.9.1" targetFramework="net40-client" />
<package id="ILMerge" version="3.0.41" targetFramework="net40-client" />
<package id="Microsoft.PowerShell.5.ReferenceAssemblies" version="1.1.0" targetFramework="net40-client" />
</packages>

0 comments on commit 4a076c9

Please sign in to comment.