Skip to content

Commit

Permalink
Add initial implementation for rotator safety limits. By default GOTO…
Browse files Browse the repository at this point in the history
…s requested 90 degrees from starting position are rejected
  • Loading branch information
knro committed Jan 16, 2024
1 parent 01d5c9c commit c2e87c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion drivers/rotator/rotator_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ IPState RotatorSimulator::MoveRotator(double angle)

bool RotatorSimulator::SyncRotator(double angle)
{
INDI_UNUSED(angle);
GotoRotatorN[0].value = angle;
IDSetNumber(&GotoRotatorNP, nullptr);
return true;
}

Expand Down
42 changes: 38 additions & 4 deletions libs/indibase/indirotatorinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ void RotatorInterface::initProperties(const char *groupName)
IUFillNumberVector(&RotatorBacklashNP, RotatorBacklashN, 1, m_defaultDevice->getDeviceName(), "ROTATOR_BACKLASH_STEPS",
"Backlash",
groupName, IP_RW, 60, IPS_OK);


// Rotator Limits
RotatorLimitsNP[0].fill("ROTATOR_LIMITS_VALUE", "Max Range (degrees)", "%.f", 10, 180, 10, 90);
RotatorLimitsNP.fill(m_defaultDevice->getDeviceName(), "ROTATOR_LIMITS", "Limits", groupName, IP_RW, 60, IPS_IDLE);
}

bool RotatorInterface::processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Expand All @@ -95,10 +100,21 @@ bool RotatorInterface::processNumber(const char *dev, const char *name, double v
return true;
}

GotoRotatorNP.s = MoveRotator(values[0]);
IDSetNumber(&GotoRotatorNP, nullptr);
if (GotoRotatorNP.s == IPS_BUSY)
DEBUGFDEVICE(m_defaultDevice->getDeviceName(), Logger::DBG_SESSION, "Rotator moving to %.2f degrees...", values[0]);
// If value is outside safe zone, then prevent motion
if ( (values[0] < 180 && (std::abs(values[0] - m_RotatorOffset)) > RotatorLimitsNP[0].getValue()) ||
(values[0] > 180 && (std::abs(values[0] - m_RotatorOffset)) < (360 - RotatorLimitsNP[0].getValue())))
{
GotoRotatorNP.s = IPS_ALERT;
DEBUGFDEVICE(m_defaultDevice->getDeviceName(), Logger::DBG_ERROR, "Rotator target %.2f exceeds safe limits of %.2f degrees...", values[0], RotatorLimitsNP[0].getValue());
IDSetNumber(&GotoRotatorNP, nullptr);
}
else
{
GotoRotatorNP.s = MoveRotator(values[0]);
IDSetNumber(&GotoRotatorNP, nullptr);
if (GotoRotatorNP.s == IPS_BUSY)
DEBUGFDEVICE(m_defaultDevice->getDeviceName(), Logger::DBG_SESSION, "Rotator moving to %.2f degrees...", values[0]);
}
return true;
}
////////////////////////////////////////////
Expand All @@ -116,7 +132,11 @@ bool RotatorInterface::processNumber(const char *dev, const char *name, double v
bool rc = SyncRotator(values[0]);
SyncRotatorNP.s = rc ? IPS_OK : IPS_ALERT;
if (rc)
{
SyncRotatorN[0].value = values[0];
// Always reset offset after a sync
m_RotatorOffset = values[0];
}

IDSetNumber(&SyncRotatorNP, nullptr);
return true;
Expand Down Expand Up @@ -145,6 +165,17 @@ bool RotatorInterface::processNumber(const char *dev, const char *name, double v
IDSetNumber(&RotatorBacklashNP, nullptr);
return true;
}
////////////////////////////////////////////
// Limits
////////////////////////////////////////////
else if (RotatorLimitsNP.isNameMatch(name))
{
RotatorLimitsNP.update(values, names, n);
RotatorLimitsNP.setState(IPS_OK);
RotatorLimitsNP.apply();
m_RotatorOffset = GotoRotatorN[0].value;
return true;
}
}

return false;
Expand Down Expand Up @@ -264,6 +295,7 @@ bool RotatorInterface::updateProperties()
m_defaultDevice->defineProperty(&RotatorBacklashSP);
m_defaultDevice->defineProperty(&RotatorBacklashNP);
}
m_defaultDevice->defineProperty(RotatorLimitsNP);
}
else
{
Expand All @@ -282,6 +314,7 @@ bool RotatorInterface::updateProperties()
m_defaultDevice->deleteProperty(RotatorBacklashSP.name);
m_defaultDevice->deleteProperty(RotatorBacklashNP.name);
}
m_defaultDevice->deleteProperty(RotatorLimitsNP);
}

return true;
Expand Down Expand Up @@ -340,6 +373,7 @@ bool RotatorInterface::saveConfigItems(FILE *fp)
IUSaveConfigSwitch(fp, &RotatorBacklashSP);
IUSaveConfigNumber(fp, &RotatorBacklashNP);
}
RotatorLimitsNP.save(fp);

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions libs/indibase/indirotatorinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include "indibase.h"
#include "indipropertynumber.h"
#include <stdint.h>

using RI = INDI::RotatorInterface;
Expand Down Expand Up @@ -217,6 +218,10 @@ class RotatorInterface
INumberVectorProperty RotatorBacklashNP;
INumber RotatorBacklashN[1];

// Rotator Limits
INDI::PropertyNumber RotatorLimitsNP {1};
double m_RotatorOffset {0};

uint32_t rotatorCapability = 0;
DefaultDevice *m_defaultDevice { nullptr };
};
Expand Down

0 comments on commit c2e87c2

Please sign in to comment.