Skip to content

Commit

Permalink
Merge pull request #36 from nexdome/feature/holding-torque
Browse files Browse the repository at this point in the history
Feature/holding-torque
  • Loading branch information
NameOfTheDragon authored Jan 6, 2021
2 parents c158244 + fd0f0cf commit 8c1dc59
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
6 changes: 4 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.209\\**",
"F:\\Arduino\\hardware\\arduino\\avr\\**",
"F:\\Arduino\\tools\\**",
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\**"
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\**",
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.1\\**"
],
"forcedInclude": [
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.21\\cores\\arduino\\Arduino.h",
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.209\\cores\\arduino\\Arduino.h",
"F:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h",
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\cores\\arduino\\Arduino.h"
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.6.23\\cores\\arduino\\Arduino.h",
"C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.1\\cores\\arduino\\Arduino.h"
],
"intelliSenseMode": "msvc-x64"
}
Expand Down
5 changes: 3 additions & 2 deletions AdvancedStepper/MicrosteppingMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void MicrosteppingMotor::energizeMotor() const
// Disables the motor coils (releases holding torque).
void MicrosteppingMotor::releaseMotor()
{
digitalWrite(enablePin, HIGH); // active low, so de-energize the coils
digitalWrite(enablePin, HIGH); // active low
digitalWrite(stepPin, LOW); // active high, so ensure we are not commanding a step.
}

Expand Down Expand Up @@ -267,7 +267,8 @@ void MicrosteppingMotor::hardStop()
currentAcceleration = 0;
currentVelocity = 0;
direction = 0;
releaseMotor();
if (!configuration->useHoldingTorque)
releaseMotor();
if (stopHandler != nullptr)
stopHandler();
}
Expand Down
1 change: 1 addition & 0 deletions AdvancedStepper/MicrosteppingMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct MotorSettings
uint16_t rampTimeMilliseconds; // milliseconds to ramp from minSpeed to maxSpeed
uint16_t maxSpeed; // maximum number of steps per second
bool directionReversed; // If true, reverses the rotation direction with respect to the step position
bool useHoldingTorque; // Apply holding torque after motor stops (otherwise de-energize the coils)
};

typedef void (*StopHandler) ();
Expand Down
2 changes: 1 addition & 1 deletion SharedCode/NexDome.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ constexpr int32_t MinStepPosition = -2000000000L;
#define ROTATOR_FULL_REVOLUTION_MICROSTEPS (440640)
#define ROTATOR_MAX_POSITION (MaxStepPosition)
#define ROTATOR_HOME_POSITION (0)
#define ROTATOR_DEFAULT_DEADZONE (300 * MICROSTEPS_PER_STEP) // default dead-zone in microsteps
#define ROTATOR_DEFAULT_DEADZONE (75 * MICROSTEPS_PER_STEP) // default dead-zone in microsteps (~0.5°)

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

Expand Down
3 changes: 2 additions & 1 deletion TA.NexDome.Rotator/PersistentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ PersistentSettings::PersistentSettings() :
ROTATOR_HOME_POSITION, // Current position in microsteps
MOTOR_RAMP_TIME, // Ramp time to full speed in milliseconds
ROTATOR_DEFAULT_SPEED, // Maximum speed in microsteps per second
true // Direction sense reversed?
true, // Direction sense reversed?
true, // Use holding torque?
}),
home(0, 500, ROTATOR_FULL_REVOLUTION_MICROSTEPS),
deadZone(ROTATOR_DEFAULT_DEADZONE)
Expand Down
9 changes: 9 additions & 0 deletions TA.NexDome.Rotator/TA.NexDome.Rotator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
#include <SafeSerial.h>
#include <AdvancedStepper.h>
#include <XBeeApi.h>
#include <Timer.h>
#include "RainSensor.h"
#include "NexDome.h"
#include "PersistentSettings.h"
#include "HomeSensor.h"
#include "CommandProcessor.h"
#include "XBeeStartupState.h"

constexpr Duration SerialInactivityTimeout = Timer::Minutes(10);

// Forward declarations
void onXbeeFrameReceived(FrameType type, std::vector<byte> &payload);
void onMotorStopped();
Expand All @@ -32,6 +35,7 @@ auto machine = XBeeStateMachine(xbeeSerial, xbeeApi);
auto commandProcessor = CommandProcessor(stepper, settings, machine);
auto home = HomeSensor(&stepper, &settings.home, HOME_INDEX_PIN, commandProcessor);
Timer periodicTasks;
Timer serialInactivityTimer;
auto rain = RainSensor(RAIN_SENSOR_PIN);

// cin and cout for ArduinoSTL
Expand All @@ -58,6 +62,8 @@ void HandleSerialCommunications()
const auto rx = host.read();
if (rx < 0)
return; // No data available.

serialInactivityTimer.SetDuration(SerialInactivityTimeout);
const char rxChar = char(rx);
switch (rxChar)
{
Expand Down Expand Up @@ -161,6 +167,9 @@ void loop()
std::cout << "P" << std::dec << commandProcessor.getPositionInWholeSteps() << std::endl;
ProcessManualControls();
rain.loop();
// Release stepper holding torque if there has been no serial communication for "a long time".
if (serialInactivityTimer.Expired())
stepper.releaseMotor();
}
}

Expand Down
3 changes: 2 additions & 1 deletion TA.NexDome.Shutter/PersistentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ PersistentSettings::PersistentSettings() :
0, // Current position in microsteps
MOTOR_RAMP_TIME, // Ramp time to full speed in milliseconds
SHUTTER_DEFAULT_SPEED, // Maximum speed in microsteps per second
true // Direction reversed
true, // Direction reversed
false, // Use holding torque? (not for shutter - preserve battery)
}),
batteryMonitor(BatteryMonitorSettings{})
{}
Expand Down
2 changes: 1 addition & 1 deletion TA.NexDome.Shutter/TA.NexDome.Shutter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties arduino.upload.port="COM10" config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.AnalogPins="1" debug.view.FreeMemory="" VM_ADDITIONAL_PREPROC="" />
<UserProperties arduino.upload.port="COM7" config.Debug.customdebug_leonardo_debugger_type="universal" debug.view.AnalogPins="1" debug.view.FreeMemory="" VM_ADDITIONAL_PREPROC="" />
</VisualStudio>
</ProjectExtensions>
</Project>
14 changes: 0 additions & 14 deletions TA.Nexdome.VSCodeWorkspace.code-workspace

This file was deleted.

0 comments on commit 8c1dc59

Please sign in to comment.