Skip to content

Commit

Permalink
Add fixes to make it alive
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio1990 committed Mar 14, 2023
1 parent a927f29 commit 87f22fd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
44 changes: 24 additions & 20 deletions ArduinoFirmware/sh-simple-focuser.ino/sh-simple-focuser.ino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(MotorInterfaceType, 2, 4, 3, 5);

bool isEnabled = false;
bool isMoving = false;
bool isConnected = false;

void setup() {
Serial.begin(9600);
Serial.setTimeout(10);
Serial.begin(57600, SERIAL_8N1);
Serial.setTimeout(100);
while (!Serial);
Serial.println("INITIALIZED#");

myStepper.setCurrentPosition(0);
myStepper.setMaxSpeed(200.0);
Expand All @@ -26,9 +28,11 @@ void loop() {
Serial.println(response);
}

if(isEnabled) {
if(isMoving) {
if (myStepper.distanceToGo() != 0) {
myStepper.runSpeed();
} else {
isMoving = false;
}
}
}
Expand All @@ -44,45 +48,45 @@ String processCommand(String command) {
case 'C':
myStepper.enableOutputs();
isConnected = true;
return "OK";
return "OK#";
// DISCONNECT
case 'D':
if(isEnabled) {
isEnabled = false;
if(isMoving) {
isMoving = false;
myStepper.stop();
myStepper.move(0);
myStepper.runToPosition();
}
isConnected = false;
myStepper.disableOutputs();
return "OK";
return "OK#";
// FORWARD steps
case 'F':
if(!isConnected) { return "NOK"; }
isEnabled = true;
if(!isConnected) { return "NOK#"; }
isMoving = true;
myStepper.move(stepsNumber);
myStepper.setSpeed(200);
return "OK";
return "OK#";
// BACKWARD steps
case 'B':
if(!isConnected) { return "NOK"; }
isEnabled = true;
if(!isConnected) { return "NOK#"; }
isMoving = true;
myStepper.move(-stepsNumber);
myStepper.setSpeed(-200);
return "OK";
return "OK#";
// STOP
case 'S':
if(!isConnected) { return "NOK"; }
isEnabled = false;
if(!isConnected) { return "NOK#"; }
isMoving = false;
myStepper.stop();
myStepper.move(0);
myStepper.runToPosition();
return "OK";
return "OK#";
// STATUS (aka WHAT)
case 'W':
if(!isConnected) { return "NOK"; }
return myStepper.isRunning() && isEnabled ? "MOVING" : "IDLE";
if(!isConnected) { return "NOK#"; }
return myStepper.isRunning() && isMoving ? "MOVING#" : "IDLE#";
default:
return "UNKNOWN";
return "UNKNOWN#";
}
}
Binary file modified SHSimpleFocuser/.vs/SHSimpleFocuser/v17/.suo
Binary file not shown.
6 changes: 6 additions & 0 deletions SHSimpleFocuser/SHSimpleFocuser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SHSimpleFocuser", "SHSimple
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x64.ActiveCfg = Debug|x64
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x64.Build.0 = Debug|x64
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x86.ActiveCfg = Debug|x86
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x86.Build.0 = Debug|x86
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x64.ActiveCfg = Release|x64
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x64.Build.0 = Release|x64
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x86.ActiveCfg = Release|x86
{64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x86.Build.0 = Release|x86
EndGlobalSection
Expand Down
19 changes: 10 additions & 9 deletions SHSimpleFocuser/SHSimpleFocuser/DeviceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public void Connect(String comPort)
{
traceLogger.LogMessage("Connected Set", "Connecting to port " + comPort);
serialConnection.PortName = comPort;
serialConnection.Speed = SerialSpeed.ps9600;
serialConnection.Speed = SerialSpeed.ps57600;
serialConnection.Parity = SerialParity.None;
serialConnection.StopBits = SerialStopBits.One;
serialConnection.DataBits = 8;
serialConnection.ReceiveTimeout = 5;
serialConnection.ReceiveTimeout = 10;
serialConnection.Connected = true;
_ = ReadResponse();
connected = CommandBool(Commands.Connect);
if(!connected)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public void Move(int position)
CommandString(Commands.Forward(position));
} else
{
CommandString(Commands.Backward(position));
CommandString(Commands.Backward(Math.Abs(position)));
}
}

Expand Down Expand Up @@ -135,19 +136,19 @@ public void Dispose()

class Commands
{
public static String Connect { get { return "C#"; } }
public static String Disconnect { get { return "D#"; } }
public static String Status { get { return "W#"; } }
public static String Stop { get { return "S#"; } }
public static String Connect { get { return "C"; } }
public static String Disconnect { get { return "D"; } }
public static String Status { get { return "W"; } }
public static String Stop { get { return "S"; } }

public static String Forward(int position)
{
return "F" + position.ToString() + "#";
return "F" + position.ToString();
}

public static String Backward(int position)
{
return "B" + position.ToString() + "#";
return "B" + position.ToString();
}
}
}
19 changes: 19 additions & 0 deletions SHSimpleFocuser/SHSimpleFocuser/SHSimpleFocuser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@
<RegisterForComInterop>false</RegisterForComInterop>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<RegisterForComInterop>true</RegisterForComInterop>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="ASCOM.Astrometry, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL" />
<Reference Include="ASCOM.Attributes, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL" />
Expand Down

0 comments on commit 87f22fd

Please sign in to comment.