Skip to content

Commit 8c1dc59

Browse files
Merge pull request #36 from nexdome/feature/holding-torque
Feature/holding-torque
2 parents c158244 + fd0f0cf commit 8c1dc59

File tree

9 files changed

+23
-22
lines changed

9 files changed

+23
-22
lines changed

.vscode/c_cpp_properties.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.209\\**",
1111
"F:\\Arduino\\hardware\\arduino\\avr\\**",
1212
"F:\\Arduino\\tools\\**",
13-
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\**"
13+
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\**",
14+
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.1\\**"
1415
],
1516
"forcedInclude": [
1617
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.21\\cores\\arduino\\Arduino.h",
1718
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.209\\cores\\arduino\\Arduino.h",
1819
"F:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h",
19-
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\cores\\arduino\\Arduino.h"
20+
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\cores\\arduino\\Arduino.h",
21+
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.1\\cores\\arduino\\Arduino.h"
2022
],
2123
"intelliSenseMode": "msvc-x64"
2224
}

AdvancedStepper/MicrosteppingMotor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void MicrosteppingMotor::energizeMotor() const
7474
// Disables the motor coils (releases holding torque).
7575
void MicrosteppingMotor::releaseMotor()
7676
{
77-
digitalWrite(enablePin, HIGH); // active low, so de-energize the coils
77+
digitalWrite(enablePin, HIGH); // active low
7878
digitalWrite(stepPin, LOW); // active high, so ensure we are not commanding a step.
7979
}
8080

@@ -267,7 +267,8 @@ void MicrosteppingMotor::hardStop()
267267
currentAcceleration = 0;
268268
currentVelocity = 0;
269269
direction = 0;
270-
releaseMotor();
270+
if (!configuration->useHoldingTorque)
271+
releaseMotor();
271272
if (stopHandler != nullptr)
272273
stopHandler();
273274
}

AdvancedStepper/MicrosteppingMotor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct MotorSettings
1919
uint16_t rampTimeMilliseconds; // milliseconds to ramp from minSpeed to maxSpeed
2020
uint16_t maxSpeed; // maximum number of steps per second
2121
bool directionReversed; // If true, reverses the rotation direction with respect to the step position
22+
bool useHoldingTorque; // Apply holding torque after motor stops (otherwise de-energize the coils)
2223
};
2324

2425
typedef void (*StopHandler) ();

SharedCode/NexDome.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ constexpr int32_t MinStepPosition = -2000000000L;
2929
#define ROTATOR_FULL_REVOLUTION_MICROSTEPS (440640)
3030
#define ROTATOR_MAX_POSITION (MaxStepPosition)
3131
#define ROTATOR_HOME_POSITION (0)
32-
#define ROTATOR_DEFAULT_DEADZONE (300 * MICROSTEPS_PER_STEP) // default dead-zone in microsteps
32+
#define ROTATOR_DEFAULT_DEADZONE (75 * MICROSTEPS_PER_STEP) // default dead-zone in microsteps (~0.5°)
3333

3434
#define HOST_SERIAL_RX_BUFFER_SIZE (16) // Receive buffer for PC/USB communications
3535

TA.NexDome.Rotator/PersistentSettings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ PersistentSettings::PersistentSettings() :
1313
ROTATOR_HOME_POSITION, // Current position in microsteps
1414
MOTOR_RAMP_TIME, // Ramp time to full speed in milliseconds
1515
ROTATOR_DEFAULT_SPEED, // Maximum speed in microsteps per second
16-
true // Direction sense reversed?
16+
true, // Direction sense reversed?
17+
true, // Use holding torque?
1718
}),
1819
home(0, 500, ROTATOR_FULL_REVOLUTION_MICROSTEPS),
1920
deadZone(ROTATOR_DEFAULT_DEADZONE)

TA.NexDome.Rotator/TA.NexDome.Rotator.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
#include <SafeSerial.h>
99
#include <AdvancedStepper.h>
1010
#include <XBeeApi.h>
11+
#include <Timer.h>
1112
#include "RainSensor.h"
1213
#include "NexDome.h"
1314
#include "PersistentSettings.h"
1415
#include "HomeSensor.h"
1516
#include "CommandProcessor.h"
1617
#include "XBeeStartupState.h"
1718

19+
constexpr Duration SerialInactivityTimeout = Timer::Minutes(10);
20+
1821
// Forward declarations
1922
void onXbeeFrameReceived(FrameType type, std::vector<byte> &payload);
2023
void onMotorStopped();
@@ -32,6 +35,7 @@ auto machine = XBeeStateMachine(xbeeSerial, xbeeApi);
3235
auto commandProcessor = CommandProcessor(stepper, settings, machine);
3336
auto home = HomeSensor(&stepper, &settings.home, HOME_INDEX_PIN, commandProcessor);
3437
Timer periodicTasks;
38+
Timer serialInactivityTimer;
3539
auto rain = RainSensor(RAIN_SENSOR_PIN);
3640

3741
// cin and cout for ArduinoSTL
@@ -58,6 +62,8 @@ void HandleSerialCommunications()
5862
const auto rx = host.read();
5963
if (rx < 0)
6064
return; // No data available.
65+
66+
serialInactivityTimer.SetDuration(SerialInactivityTimeout);
6167
const char rxChar = char(rx);
6268
switch (rxChar)
6369
{
@@ -161,6 +167,9 @@ void loop()
161167
std::cout << "P" << std::dec << commandProcessor.getPositionInWholeSteps() << std::endl;
162168
ProcessManualControls();
163169
rain.loop();
170+
// Release stepper holding torque if there has been no serial communication for "a long time".
171+
if (serialInactivityTimer.Expired())
172+
stepper.releaseMotor();
164173
}
165174
}
166175

TA.NexDome.Shutter/PersistentSettings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ PersistentSettings::PersistentSettings() :
1111
0, // Current position in microsteps
1212
MOTOR_RAMP_TIME, // Ramp time to full speed in milliseconds
1313
SHUTTER_DEFAULT_SPEED, // Maximum speed in microsteps per second
14-
true // Direction reversed
14+
true, // Direction reversed
15+
false, // Use holding torque? (not for shutter - preserve battery)
1516
}),
1617
batteryMonitor(BatteryMonitorSettings{})
1718
{}

TA.NexDome.Shutter/TA.NexDome.Shutter.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
</ImportGroup>
158158
<ProjectExtensions>
159159
<VisualStudio>
160-
<UserProperties arduino.upload.port="COM10" config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.AnalogPins="1" debug.view.FreeMemory="" VM_ADDITIONAL_PREPROC="" />
160+
<UserProperties arduino.upload.port="COM7" config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.AnalogPins="1" debug.view.FreeMemory="" VM_ADDITIONAL_PREPROC="" />
161161
</VisualStudio>
162162
</ProjectExtensions>
163163
</Project>

TA.Nexdome.VSCodeWorkspace.code-workspace

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)