Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leadshine drive fixes and improvements for low-speed motion #830

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ private void CalculateCallDuration()
var et = Environment.TickCount - start;

_usPerCall = et * 1000 / (float)calls;

Resolver.Log.Info($"us per call: {calls} / {et} = {_usPerCall}");
}

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
Expand Down Expand Up @@ -129,22 +127,38 @@ public void Step(int steps, RotationDirection direction, Frequency rate)
_enablePort.State = !InverseLogic;
}

var targetus = (int)(1000000d / rate.Hertz);
var targetus = (int)(500000d / rate.Hertz); // we divide by 2 because this is the half-wave length

if (targetus < MinimumMicrosecondDelayRequiredByDrive) throw new ArgumentOutOfRangeException(
"Rate cannot have pulses shorter than 5us. Use 200KHz or less.");
"Rate cannot have pulses shorter than 5us. Use 100KHz or less.");

var us = targetus < MinimumStartupDwellMicroseconds ? MinimumStartupDwellMicroseconds : targetus;

for (var step = 0; step < steps; step++)
{
_pulsePort.State = InverseLogic; // low means "step"

MicrosecondSleep(us);
if (us > 1000)
{
Thread.Sleep(us / 1000);
MicrosecondSleep(us % 1000);
}
else
{
MicrosecondSleep(us);
}

_pulsePort.State = !InverseLogic;

MicrosecondSleep(us);
if (us > 1000)
{
Thread.Sleep(us / 1000);
MicrosecondSleep(us % 1000);
}
else
{
MicrosecondSleep(us);
}

// DEV NOTE:
// naive linear acceleration tested only with STP-MTR-34066 motor
Expand Down
Loading