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

Make spindle speed sticky … #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
25 changes: 17 additions & 8 deletions src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,11 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
break;

case 3: // Spin spindle clockwise
if (gb.Seen('S'))
{
switch (machineType)
{
case MachineType::cnc:
{
const float rpm = gb.GetFValue();
const uint32_t slot = gb.Seen('P') ? gb.GetUIValue() : 0;
if (slot >= MaxSpindles)
{
Expand All @@ -408,18 +406,25 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
}
else
{
platform.AccessSpindle(slot).SetRpm(rpm);
if (gb.Seen('S'))
{
const float rpm = gb.GetFValue();
platform.AccessSpindle(slot).SetRpm(rpm);
}
platform.AccessSpindle(slot).TurnOn();
}
}
break;

case MachineType::laser:
platform.SetLaserPwm(ConvertLaserPwm(gb.GetFValue()));
if (gb.Seen('S')) {
platform.SetLaserPwm(ConvertLaserPwm(gb.GetFValue()));
}
break;

default:
#if SUPPORT_ROLAND
if (reprap.GetRoland()->Active())
if (gb.Seen('S') && reprap.GetRoland()->Active())
{
result = reprap.GetRoland()->ProcessSpindle(gb.GetFValue());
}
Expand All @@ -434,11 +439,9 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
break;

case 4: // Spin spindle counter clockwise
if (gb.Seen('S'))
{
if (machineType == MachineType::cnc)
{
const float rpm = gb.GetFValue();
const uint32_t slot = gb.Seen('P') ? gb.GetUIValue() : 0;
if (slot >= MaxSpindles)
{
Expand All @@ -447,7 +450,13 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply)
}
else
{
platform.AccessSpindle(slot).SetRpm(-rpm);
if (gb.Seen('S'))
{
const float rpm = gb.GetFValue();
platform.AccessSpindle(slot).SetRpm(-rpm);
}
platform.AccessSpindle(slot).TurnOn();

}
}
else
Expand Down
13 changes: 10 additions & 3 deletions src/Spindle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ void Spindle::SetPwmFrequency(float freq)

void Spindle::SetRpm(float rpm)
{
const float pwm = abs(rpm / maxRpm);
if (rpm >= 0.0)
configuredRpm = rpm;
}

void Spindle::TurnOn()
{
const float pwm = abs(configuredRpm / maxRpm);
if (configuredRpm >= 0.0)
{
spindleReversePort.WriteAnalog(0.0);
spindleForwardPort.WriteAnalog(pwm);
Expand All @@ -44,7 +49,7 @@ void Spindle::SetRpm(float rpm)
spindleReversePort.WriteAnalog(pwm);
spindleForwardPort.WriteAnalog(0.0);
}
currentRpm = configuredRpm = rpm;
currentRpm = configuredRpm;
}

void Spindle::TurnOff()
Expand All @@ -54,4 +59,6 @@ void Spindle::TurnOff()
currentRpm = 0.0;
}



// End
1 change: 1 addition & 0 deletions src/Spindle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Spindle
float GetRpm() const { return configuredRpm; }
void SetRpm(float rpm);

void TurnOn();
void TurnOff();
};

Expand Down