Skip to content

Commit

Permalink
Merge pull request #532 from blurfl/tighten-up-FAKE_SERVO-access-control
Browse files Browse the repository at this point in the history
tighten up FAKE_SERVO access
  • Loading branch information
MaslowCommunityGardenRobot authored Sep 1, 2019
2 parents ad381bc + 5d351a3 commit 768524c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cnc_ctrl_v1/Axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void Axis::setSteps(const long& steps){

void Axis::computePID(){

if (FAKE_SERVO_STATE != 0) {
if (FAKE_SERVO_STATE == FAKE_SERVO_PERMITTED) {
if (motorGearboxEncoder.motor.attached()){
// Adds up to 10% error just to simulate servo noise
double rpm = (-1 * _pidOutput) * random(90, 110) / 100;
Expand Down
3 changes: 2 additions & 1 deletion cnc_ctrl_v1/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// LOOPINTERVAL tuning
#define KINEMATICSDBG 0 // set to 1 for additional kinematics debug messaging

#define FAKE_SERVO 4095 // store the state of FAKE_SERVO in EEPROM[ 4095 ] to preserve
#define FAKE_SERVO_PERMITTED 42 // store this value
#define FAKE_SERVO 4095 // in EEPROM[ 4095 ] to preserve
// the state of FAKE_SERVO mode over resets.
// Use 'B99 ON' to turn FAKE_SERVO mode on and set EEPROM[ 4095 ] to '1',
// 'B99' with no parameter, or any parameter other than 'ON'
Expand Down
12 changes: 6 additions & 6 deletions cnc_ctrl_v1/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,23 @@ byte executeBcodeLine(const String& gcodeLine){
// updating the encoder steps even if no servo is connected.
// Useful for testing on an arduino only (e.g. without motors).
// The status of FAKE_SERVO mode is stored in EEPROM[ 4095 ]
// to persist between resets. Tthat byte is set to '1' when FAKE_SERVO
// to persist between resets. That byte is set to 'FAKE_SERVO_PERMITTED' when FAKE_SERVO
// is on, '0' when off. settingsWipe(SETTINGS_RESTORE_ALL) clears the
// EEPROM to '0', sothat stores '0' at EEPROM[ 4095 ] as well.
if(gcodeLine.substring(0, 3) == "B99") {
int letterO = gcodeLine.indexOf('O');
int letterN = gcodeLine.indexOf('N');
if ((letterO != -1) && (letterN != -1)) {
EEPROM[ FAKE_SERVO ] = 1;
FAKE_SERVO_STATE = 1;
EEPROM[ FAKE_SERVO ] = FAKE_SERVO_PERMITTED;
FAKE_SERVO_STATE = FAKE_SERVO_PERMITTED;
} else {
EEPROM[ FAKE_SERVO ] = 0;
FAKE_SERVO_STATE = 0;
}
if (FAKE_SERVO_STATE == 0) {
Serial.println(F("FAKE_SERVO off"));
} else {
if (FAKE_SERVO_STATE == FAKE_SERVO_PERMITTED) {
Serial.println(F("FAKE_SERVO on"));
} else {
Serial.println(F("FAKE_SERVO off"));
}
return(STATUS_OK);
}
Expand Down
2 changes: 1 addition & 1 deletion cnc_ctrl_v1/Motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Motor::write(int speed, bool force){
/*
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 or force) and (FAKE_SERVO_STATE == 0)){
if ((_attachedState == 1 or force) and (FAKE_SERVO_STATE != FAKE_SERVO_PERMITTED)){
speed = constrain(speed, -255, 255);
_lastSpeed = speed; //saves speed for use in additive write
bool forward = (speed > 0);
Expand Down
13 changes: 7 additions & 6 deletions cnc_ctrl_v1/cnc_ctrl_v1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ void setup(){
Serial.println(F(" Detected"));
sys.inchesToMMConversion = 1;
sys.writeStepsToEEPROM = false;
FAKE_SERVO_STATE = EEPROM[ FAKE_SERVO ] & B00000001;
if (FAKE_SERVO_STATE == 0) {
Serial.println(F("FAKE_SERVO off"));
} else {
Serial.println(F("FAKE_SERVO on"));
}
FAKE_SERVO_STATE = EEPROM[ FAKE_SERVO ];
if (FAKE_SERVO_STATE == FAKE_SERVO_PERMITTED) { // only this value is accepted
Serial.println(F("FAKE_SERVO on")); // to turn this on
} else {
Serial.println(F("FAKE_SERVO off")); // otherwise
EEPROM[ FAKE_SERVO ] = 0; // force it to the 'off' value
}
settingsLoadFromEEprom();
sys.feedrate = sysSettings.maxFeed / 2.0;
setupAxes();
Expand Down

0 comments on commit 768524c

Please sign in to comment.