Skip to content

Commit

Permalink
Merge pull request #444 from MaslowCNC/make-it-possible-to-measure-ei…
Browse files Browse the repository at this point in the history
…ther-chain

Make it possible to measure either chain
  • Loading branch information
MaslowCommunityGardenRobot authored May 5, 2018
2 parents 0bc78a3 + 5beedf6 commit abe3b0e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
17 changes: 12 additions & 5 deletions cnc_ctrl_v1/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ byte executeBcodeLine(const String& gcodeLine){
if(gcodeLine.substring(0, 3) == "B10"){
//measure the left axis chain length
Serial.print(F("[Measure: "));
Serial.print(leftAxis.read());
if (gcodeLine.indexOf('L') != -1){
Serial.print(leftAxis.read());
}
else{
Serial.print(rightAxis.read());
}
Serial.println(F("]"));
return STATUS_OK;
}
Expand All @@ -247,15 +252,17 @@ byte executeBcodeLine(const String& gcodeLine){

int i = 0;
while (millis() - begin < ms){
leftAxis.motorGearboxEncoder.motor.directWrite(speed);
if (i % 10000 == 0){
Serial.println(F("pulling")); //Keep the connection from timing out
if (gcodeLine.indexOf('L') != -1){
leftAxis.motorGearboxEncoder.motor.directWrite(speed);
}
else{
rightAxis.motorGearboxEncoder.motor.directWrite(speed);
}

i++;
execSystemRealtime();
if (sys.stop){return STATUS_OK;}
}
leftAxis.set(leftAxis.read());
return STATUS_OK;
}

Expand Down
22 changes: 4 additions & 18 deletions cnc_ctrl_v1/Motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ void Motor::additiveWrite(int speed){
write(_lastSpeed + speed);
}

void Motor::write(int speed){
void Motor::write(int speed, bool force){
/*
Sets motor speed from input. Speed = 0 is stopped, -255 is full reverse, 255 is full ahead.
Sets motor speed from input. Speed = 0 is stopped, -255 is full reverse, 255 is full ahead. If force is true the motor attached state will be ignored
*/
if (_attachedState == 1){
if (_attachedState == 1 or force){
speed = constrain(speed, -255, 255);
_lastSpeed = speed; //saves speed for use in additive write
bool forward = (speed > 0);
Expand Down Expand Up @@ -134,21 +134,7 @@ void Motor::directWrite(int voltage){
/*
Write directly to the motor, ignoring if the axis is attached or any applied calibration.
*/
bool forward = (voltage >= 0);
if (forward) {
if (voltage > 0) {
digitalWrite(_pin1 , HIGH );
analogWrite(_pin2 , 255 - abs(voltage)); // invert drive signals - don't alter speed
} else {
digitalWrite(_pin1 , LOW );
digitalWrite(_pin2 , LOW );
}
}
else{
analogWrite(_pin1 , 255 - abs(voltage)); // invert drive signals - don't alter speed
digitalWrite(_pin2 , HIGH );
}
digitalWrite(_pwmPin, HIGH);
write(voltage, true);
}

int Motor::attached(){
Expand Down
2 changes: 1 addition & 1 deletion cnc_ctrl_v1/Motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
void attach();
int setupMotor(const int& pwmPin, const int& pin1, const int& pin2);
void detach();
void write(int speed);
void write(int speed, bool force = false);
int lastSpeed();
void additiveWrite(int speed);
int attached();
Expand Down
1 change: 1 addition & 0 deletions cnc_ctrl_v1/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ byte settingsStoreGlobalSetting(const byte& parameter,const float& value){
sysSettings.chainSagCorrection = value;
break;
case 38:
settingsSaveStepstoEEprom();
sysSettings.chainOverSprocket = value;
setupAxes();
settingsLoadStepsFromEEprom();
Expand Down

0 comments on commit abe3b0e

Please sign in to comment.