Skip to content

Commit f0061c8

Browse files
V1.13.6 - Autohoming Updates (#247)
1 parent 053b20e commit f0061c8

7 files changed

Lines changed: 210 additions & 38 deletions

File tree

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
**V1.13.6 - Updates**
2+
- Added ability to query homing status during autohoming (:XGAH#)
3+
- Fixed a bug in autohoming that would make it fail if it did not pass over the sensor during the initial 30 degree search
4+
- Added debounce function to detection of sensor state changes. There were single false sensor trigger spikes that incorrectly detected sensor transitions.
5+
16
**V1.13.5 - Updates**
27
- Updated ThingPulse OLED library to 4.6.1
38

Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// Also, numbers are interpreted as simple numbers. _ __ _
44
// So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/
55

6-
#define VERSION "V1.13.5"
6+
#define VERSION "V1.13.6"

src/HallSensorHoming.cpp

Lines changed: 139 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,39 @@ HomingState HallSensorHoming::getHomingState() const
4343
return _homingData.state;
4444
}
4545

46+
/////////////////////////////////
47+
//
48+
// getLastResult
49+
//
50+
/////////////////////////////////
51+
String HallSensorHoming::getLastResult() const
52+
{
53+
MappedDict<int, String>::DictEntry_t lookupTable[] = {
54+
{HOMING_RESULT_SUCCEEDED, F("SUCCEEDED")},
55+
{HOMING_RESULT_HOMING_NEVER_RUN, F("NEVER RUN")},
56+
{HOMING_RESULT_HOMING_IN_PROGRESS, F("IN PROGRESS")},
57+
{HOMING_RESULT_CANT_MOVE_OFF_SENSOR, F("CANT MOVE OFF SENSOR")},
58+
{HOMING_RESULT_CANT_FIND_SENSOR_ON_REVERSE, F("CANT FIND SENSOR BEGIN")},
59+
{HOMING_RESULT_CANT_FIND_SENSOR_END, F("CANT FIND SENSOR END")},
60+
};
61+
62+
auto strLookup = MappedDict<int, String>(lookupTable, ARRAY_SIZE(lookupTable));
63+
String rtnStr;
64+
if (strLookup.tryGet(_lastResult, &rtnStr))
65+
{
66+
return rtnStr;
67+
}
68+
return F("WTF_RESULT");
69+
}
70+
4671
/////////////////////////////////
4772
//
4873
// findHomeByHallSensor
4974
//
5075
/////////////////////////////////
5176
bool HallSensorHoming::findHomeByHallSensor(int initialDirection, int searchDistance)
5277
{
78+
_lastResult = HOMING_RESULT_HOMING_IN_PROGRESS;
5379
_homingData.startPos = _pMount->getCurrentStepperPosition(_axis);
5480
_homingData.savedRate = _pMount->getSlewRate();
5581
_homingData.initialDir = initialDirection;
@@ -149,6 +175,7 @@ void HallSensorHoming::processHomingProgress()
149175
"[HOMING]: Stepper was unable to move off sensor... homing failed! Advance to %s",
150176
getHomingState(HomingState::HOMING_FAILED).c_str());
151177
_homingData.state = HomingState::HOMING_FAILED;
178+
_lastResult = HOMING_RESULT_CANT_MOVE_OFF_SENSOR;
152179
}
153180
}
154181
break;
@@ -179,14 +206,41 @@ void HallSensorHoming::processHomingProgress()
179206
int homingPinState = digitalRead(_sensorPin);
180207
if (_homingData.lastPinState != homingPinState)
181208
{
182-
LOG(DEBUG_STEPPERS,
183-
"[HOMING]: Found start of sensor at %l, continuing until end is found. Advance to %s",
184-
_pMount->getCurrentStepperPosition(_axis),
185-
getHomingState(HomingState::HOMING_FINDING_END).c_str());
186-
// Found the start of the sensor, keep going until we find the end
187-
_homingData.position[HOMING_START_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis);
188-
_homingData.lastPinState = homingPinState;
189-
_homingData.state = HomingState::HOMING_FINDING_END;
209+
if (_homingData.pinChangeCount == 0)
210+
{
211+
// First time the pin has triggered, record that position
212+
_homingData.position[HOMING_START_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis);
213+
LOG(DEBUG_STEPPERS,
214+
"[HOMING]: Potentially found start of sensor at %l",
215+
_homingData.position[HOMING_START_PIN_POSITION]);
216+
}
217+
218+
// Keep track of how many times the pin has been triggered
219+
_homingData.pinChangeCount++;
220+
221+
if (_homingData.pinChangeCount > 4)
222+
{
223+
// If we have seen this pin stay triggered for 5 cycles, assume we've found the start of the sensor, now
224+
// change state to keep going until we find the end
225+
LOG(DEBUG_STEPPERS,
226+
"[HOMING]: Found start of sensor at %l, continuing until end is found. Advance to %s",
227+
_homingData.position[HOMING_START_PIN_POSITION],
228+
getHomingState(HomingState::HOMING_FINDING_END).c_str());
229+
230+
// Make sure we continue moving far enough to reach end
231+
long distance = _homingData.initialDir * _stepsPerDegree * _homingData.searchDistance;
232+
_pMount->moveStepperBy(_axis, distance);
233+
234+
_homingData.lastPinState = homingPinState;
235+
_homingData.pinChangeCount = 0;
236+
_homingData.state = HomingState::HOMING_FINDING_END;
237+
}
238+
}
239+
else
240+
{
241+
// The pin is not triggered, so clear the recorded position and change count
242+
_homingData.position[HOMING_START_PIN_POSITION] = 0;
243+
_homingData.pinChangeCount = 0;
190244
}
191245
}
192246
else
@@ -211,13 +265,41 @@ void HallSensorHoming::processHomingProgress()
211265
int homingPinState = digitalRead(_sensorPin);
212266
if (_homingData.lastPinState != homingPinState)
213267
{
214-
LOG(DEBUG_STEPPERS,
215-
"[HOMING]: Found start of sensor in reverse at %l, continuing until end is found. Advance to %s",
216-
_pMount->getCurrentStepperPosition(_axis),
217-
getHomingState(HomingState::HOMING_FINDING_END).c_str());
218-
_homingData.position[HOMING_START_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis);
219-
_homingData.lastPinState = homingPinState;
220-
_homingData.state = HomingState::HOMING_FINDING_END;
268+
if (_homingData.pinChangeCount == 0)
269+
{
270+
// First time the pin has triggered, record that position
271+
_homingData.position[HOMING_START_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis);
272+
LOG(DEBUG_STEPPERS,
273+
"[HOMING]: Potentially found start of sensor in reverse pass at %l",
274+
_homingData.position[HOMING_START_PIN_POSITION]);
275+
}
276+
277+
// Keep track of how many times the pin has been triggered
278+
_homingData.pinChangeCount++;
279+
280+
if (_homingData.pinChangeCount > 4)
281+
{
282+
// If we have seen this pin stay triggered for 5 cycles, assume we've found the start of the sensor, now
283+
// change state to keep going until we find the end
284+
LOG(DEBUG_STEPPERS,
285+
"[HOMING]: Found start of sensor in reverse at %l, continuing until end is found. Advance to %s",
286+
_homingData.position[HOMING_START_PIN_POSITION],
287+
getHomingState(HomingState::HOMING_FINDING_END).c_str());
288+
289+
// Make sure we continue moving far enough to reach end
290+
long distance = -_homingData.initialDir * _stepsPerDegree * _homingData.searchDistance;
291+
_pMount->moveStepperBy(_axis, distance);
292+
293+
_homingData.lastPinState = homingPinState;
294+
_homingData.pinChangeCount = 0;
295+
_homingData.state = HomingState::HOMING_FINDING_END;
296+
}
297+
}
298+
else
299+
{
300+
// The pin is not triggered, so clear the recorded position and change count
301+
_homingData.position[HOMING_START_PIN_POSITION] = 0;
302+
_homingData.pinChangeCount = 0;
221303
}
222304
}
223305
else
@@ -227,6 +309,7 @@ void HallSensorHoming::processHomingProgress()
227309
"[HOMING]: Sensor not found on reverse pass either. Homing Failed. Advance to %s",
228310
getHomingState(HomingState::HOMING_FAILED).c_str());
229311
_homingData.state = HomingState::HOMING_FAILED;
312+
_lastResult = HOMING_RESULT_CANT_FIND_SENSOR_ON_REVERSE;
230313
}
231314
}
232315
break;
@@ -238,15 +321,36 @@ void HallSensorHoming::processHomingProgress()
238321
int homingPinState = digitalRead(_sensorPin);
239322
if (_homingData.lastPinState != homingPinState)
240323
{
241-
LOG(DEBUG_STEPPERS,
242-
"[HOMING]: Found end of sensor at %l, stopping... Advance to %s",
243-
_pMount->getCurrentStepperPosition(_axis),
244-
getHomingState(HomingState::HOMING_WAIT_FOR_STOP).c_str());
245-
_homingData.position[HOMING_END_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis);
246-
_homingData.lastPinState = homingPinState;
247-
_homingData.state = HomingState::HOMING_WAIT_FOR_STOP;
248-
_homingData.nextState = HomingState::HOMING_RANGE_FOUND;
249-
_pMount->stopSlewing(_axis);
324+
if (_homingData.pinChangeCount == 0)
325+
{
326+
_homingData.position[HOMING_END_PIN_POSITION] = _pMount->getCurrentStepperPosition(_axis);
327+
LOG(DEBUG_STEPPERS,
328+
"[HOMING]: Potentially found end of sensor at %l",
329+
_homingData.position[HOMING_END_PIN_POSITION]);
330+
}
331+
332+
// Keep track of how many times the pin has been triggered
333+
_homingData.pinChangeCount++;
334+
335+
if (_homingData.pinChangeCount > 4)
336+
{
337+
// If we have seen this pin stay triggered for 5 cycles, assume we've found the start of the sensor, now
338+
// change state to keep going until we find the end
339+
LOG(DEBUG_STEPPERS,
340+
"[HOMING]: Found end of sensor at %l, stopping... Advance to %s",
341+
_homingData.position[HOMING_END_PIN_POSITION],
342+
getHomingState(HomingState::HOMING_WAIT_FOR_STOP).c_str());
343+
_homingData.lastPinState = homingPinState;
344+
_homingData.pinChangeCount = 0;
345+
_homingData.state = HomingState::HOMING_WAIT_FOR_STOP;
346+
_homingData.nextState = HomingState::HOMING_RANGE_FOUND;
347+
_pMount->stopSlewing(_axis);
348+
}
349+
}
350+
else
351+
{
352+
_homingData.position[HOMING_END_PIN_POSITION] = 0;
353+
_homingData.pinChangeCount = 0;
250354
}
251355
}
252356
else
@@ -255,19 +359,21 @@ void HallSensorHoming::processHomingProgress()
255359
"[HOMING]: End of sensor not found! Advance to %s",
256360
getHomingState(HomingState::HOMING_FAILED).c_str());
257361
_homingData.state = HomingState::HOMING_FAILED;
362+
_lastResult = HOMING_RESULT_CANT_FIND_SENSOR_END;
258363
}
259364
}
260365
break;
261366

262367
case HomingState::HOMING_RANGE_FOUND:
263368
{
369+
long midPos = (_homingData.position[HOMING_START_PIN_POSITION] + _homingData.position[HOMING_END_PIN_POSITION]) / 2;
370+
264371
LOG(DEBUG_STEPPERS,
265-
"[HOMING]: Stepper stopped, Hall sensor found! Range: [%l to %l] size: %l",
372+
"[HOMING]: Stepper stopped, Hall sensor found! Range: [%l to %l] size: %l, MidPos: %l",
266373
_homingData.position[HOMING_START_PIN_POSITION],
267374
_homingData.position[HOMING_END_PIN_POSITION],
268-
_homingData.position[HOMING_START_PIN_POSITION] - _homingData.position[HOMING_END_PIN_POSITION]);
269-
270-
long midPos = (_homingData.position[HOMING_START_PIN_POSITION] + _homingData.position[HOMING_END_PIN_POSITION]) / 2;
375+
_homingData.position[HOMING_START_PIN_POSITION] - _homingData.position[HOMING_END_PIN_POSITION],
376+
midPos);
271377

272378
LOG(DEBUG_STEPPERS,
273379
"[HOMING]: Moving home by %l - (%l) - (%l), so %l steps. Advance to %s",
@@ -289,10 +395,15 @@ void HallSensorHoming::processHomingProgress()
289395
LOG(DEBUG_STEPPERS,
290396
"[HOMING]: Successfully homed! Setting home and restoring Rate setting. Advance to %s",
291397
getHomingState(HomingState::HOMING_NOT_ACTIVE).c_str());
398+
_lastResult = HOMING_RESULT_SUCCEEDED;
292399
_homingData.state = HomingState::HOMING_NOT_ACTIVE;
293400
_pMount->setHome(false);
294401
_pMount->setSlewRate(_homingData.savedRate);
295402
_pMount->clearStatusFlag(STATUS_FINDING_HOME);
403+
if (_wasTracking)
404+
{
405+
_pMount->startSlewing(TRACKING);
406+
}
296407
}
297408
break;
298409

src/HallSensorHoming.hpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#include "Types.hpp"
55
#include "Mount.hpp"
66

7+
#define HOMING_RESULT_SUCCEEDED 1
8+
#define HOMING_RESULT_HOMING_NEVER_RUN 0
9+
#define HOMING_RESULT_HOMING_IN_PROGRESS -1
10+
#define HOMING_RESULT_CANT_MOVE_OFF_SENSOR -2
11+
#define HOMING_RESULT_CANT_FIND_SENSOR_ON_REVERSE -3
12+
#define HOMING_RESULT_CANT_FIND_SENSOR_END -4
13+
714
class Mount;
815

916
enum HomingState
@@ -28,6 +35,7 @@ struct HomingData {
2835
HomingState nextState;
2936
int pinState;
3037
int lastPinState;
38+
int pinChangeCount;
3139
int savedRate;
3240
int initialDir;
3341
long searchDistance;
@@ -51,24 +59,30 @@ class HallSensorHoming
5159
long _stepsPerDegree;
5260
int _sensorPin;
5361
int _activeState;
62+
int _lastResult;
63+
bool _wasTracking;
5464

5565
public:
5666
HallSensorHoming(Mount *mount, StepperAxis axis, long stepsPerDegree, int sensorPin, int activeState, int32_t offset)
5767
{
58-
_homingData.state = HomingState::HOMING_NOT_ACTIVE;
59-
_homingData.offset = offset;
60-
_pMount = mount;
61-
_axis = axis;
62-
_stepsPerDegree = stepsPerDegree;
63-
_sensorPin = sensorPin;
64-
_activeState = activeState;
68+
_homingData.state = HomingState::HOMING_NOT_ACTIVE;
69+
_homingData.offset = offset;
70+
_homingData.pinChangeCount = 0;
71+
_pMount = mount;
72+
_axis = axis;
73+
_stepsPerDegree = stepsPerDegree;
74+
_sensorPin = sensorPin;
75+
_activeState = activeState;
76+
_lastResult = HOMING_RESULT_HOMING_NEVER_RUN;
77+
_wasTracking = mount->isSlewingTRK();
6578
}
6679

6780
bool findHomeByHallSensor(int initialDirection, int searchDistanceDegrees);
6881
void processHomingProgress();
6982
String getHomingState(HomingState state) const;
7083
HomingState getHomingState() const;
7184
bool isIdleOrComplete() const;
85+
String getLastResult() const;
7286
};
7387

7488
#endif

src/MeadeCommandProcessor.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,16 @@ bool gpsAqcuisitionComplete(int &indicator); // defined in c72_menuHA_GPS.hpp
710710
// "1#" if succsessful
711711
// "0#" if there is no Digital Level
712712
//
713+
// :XGAH#
714+
// Description:
715+
// Get auto homing state
716+
// Information:
717+
// Get the current state of RA and DEC Autohoming status. Only valid when at least
718+
// one Hall sensor based autohoming axis is enabled.
719+
// Returns:
720+
// "rastate|decstate#" if either axis is enabled
721+
// "|" if no autohoming is enabled
722+
//
713723
// :XGB#
714724
// Description:
715725
// Get Backlash correction steps
@@ -1579,7 +1589,7 @@ String MeadeCommandProcessor::handleMeadeMovement(String inCmd)
15791589
int distance = RA_HOMING_SENSOR_SEARCH_DEGREES;
15801590
if (inCmd.length() > 3)
15811591
{
1582-
distance = clamp((int) inCmd.substring(3).toInt(), 15, 75);
1592+
distance = clamp((int) inCmd.substring(3).toInt(), 5, 75);
15831593
LOG(DEBUG_MEADE, "[MEADE]: RA AutoHome by %dh", distance);
15841594
}
15851595

@@ -1600,7 +1610,7 @@ String MeadeCommandProcessor::handleMeadeMovement(String inCmd)
16001610
int decDistance = DEC_HOMING_SENSOR_SEARCH_DEGREES;
16011611
if (inCmd.length() > 3)
16021612
{
1603-
decDistance = clamp((int) inCmd.substring(3).toInt(), 15, 75);
1613+
decDistance = clamp((int) inCmd.substring(3).toInt(), 5, 75);
16041614
LOG(DEBUG_MEADE, "[MEADE]: DEC AutoHome by %dh", decDistance);
16051615
}
16061616

@@ -1747,6 +1757,10 @@ String MeadeCommandProcessor::handleMeadeExtraCommands(String inCmd)
17471757
{
17481758
return String(_mount->getBacklashCorrection()) + "#";
17491759
}
1760+
else if ((inCmd[1] == 'A') && (inCmd.length() > 2) && (inCmd[2] == 'H')) // :XGAH#
1761+
{
1762+
return _mount->getAutoHomingStates() + "#";
1763+
}
17501764
else if (inCmd[1] == 'C') // :XGCn.nn*m.mm#
17511765
{
17521766
String coords = inCmd.substring(2);

src/Mount.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,33 @@ void Mount::processHomingProgress()
26322632
}
26332633
#endif
26342634

2635+
String Mount::getAutoHomingStates() const
2636+
{
2637+
String state;
2638+
#if USE_HALL_SENSOR_RA_AUTOHOME == 1
2639+
if ((_raHoming != nullptr) && (!_raHoming->isIdleOrComplete()))
2640+
{
2641+
state += _raHoming->getHomingState(_raHoming->getHomingState());
2642+
}
2643+
else
2644+
{
2645+
state += _raHoming->getLastResult();
2646+
}
2647+
#endif
2648+
state += "|";
2649+
#if USE_HALL_SENSOR_DEC_AUTOHOME == 1
2650+
if ((_decHoming != nullptr) && (!_decHoming->isIdleOrComplete()))
2651+
{
2652+
state += _decHoming->getHomingState(_decHoming->getHomingState());
2653+
}
2654+
else
2655+
{
2656+
state += _decHoming->getLastResult();
2657+
}
2658+
#endif
2659+
return state;
2660+
}
2661+
26352662
#if (USE_RA_END_SWITCH == 1 || USE_DEC_END_SWITCH == 1)
26362663
/////////////////////////////////
26372664
//

0 commit comments

Comments
 (0)