Skip to content

Commit

Permalink
Updated with new files. Currently too big for a duemilanove!
Browse files Browse the repository at this point in the history
  • Loading branch information
euphy committed Apr 19, 2013
1 parent b2308d8 commit 7e2d4f0
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 98 deletions.
32 changes: 20 additions & 12 deletions comms.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ String comms_waitForNextCommand()
// this also sets usingCrc AND commandConfirmed
// to true or false
inS = comms_readCommand();

// if it's using the CRC check, then confirmation is easy
if (usingCrc && !commandConfirmed)
{
comms_requestResend();
inS = "";
}
}

// if it's using the CRC check, then confirmation is easy
if (usingCrc && !commandConfirmed)
{
comms_requestResend();
return "";
}

// CRC was ok, or we aren't using one
idleTime = millis();
Expand Down Expand Up @@ -76,7 +77,7 @@ String comms_readCommand()
while (Serial.available() > 0)
{
char ch = Serial.read(); // get it
delay(15);
delay(1);
inString[inCount] = ch;
if (ch == INTERMINATOR)
{
Expand All @@ -87,7 +88,7 @@ String comms_readCommand()
}
inString[inCount] = 0; // null terminate the string
String inS = inString;

// check the CRC for this command
// and set commandConfirmed true or false
int colonPos = inS.lastIndexOf(":");
Expand All @@ -106,10 +107,13 @@ String comms_readCommand()
}
else
{
Serial.print(F("I got "));
Serial.println(inString);
Serial.print(F("Checksum not matched!:"));
Serial.println(calcCrc);
commandConfirmed = false;
}

}
else
{
Expand All @@ -127,14 +131,18 @@ void comms_parseAndExecuteCommand(String &in)
if (commandParsed)
{
impl_processCommand(lastCommand);
in = "";
commandConfirmed = false;
comms_ready();
}
else
{
Serial.println(F("Command not parsed."));
Serial.print(F("Command ("));
Serial.print(in);
Serial.println(F(") not parsed."));
}
in = "";
commandConfirmed = false;
comms_ready();
inNoOfParams = 0;

}


Expand Down
36 changes: 22 additions & 14 deletions eeprom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void eeprom_resetEeprom()
}
void eeprom_dumpEeprom()
{
for (int i = 0; i <20; i++)
for (int i = 0; i <40; i++)
{
Serial.print(i);
Serial.print(". ");
Expand Down Expand Up @@ -76,15 +76,15 @@ void eeprom_loadSpoolSpec()
void eeprom_loadPenLiftRange()
{
EEPROM_readAnything(EEPROM_PENLIFT_DOWN, downPosition);
if (downPosition < 1)
if (downPosition < 0)
{
downPosition = DEFAULT_DOWN_POSITION;
}
Serial.print(F("Loaded down pos:"));
Serial.println(downPosition);

EEPROM_readAnything(EEPROM_PENLIFT_UP, upPosition);
if (upPosition < 1)
if (upPosition < 0)
{
upPosition = DEFAULT_UP_POSITION;
}
Expand Down Expand Up @@ -120,6 +120,24 @@ void eeprom_loadStepMultiplier()
Serial.println(stepMultiplier);
}

void eeprom_loadSpeed()
{
// load speed, acceleration
EEPROM_readAnything(EEPROM_MACHINE_MOTOR_SPEED, currentMaxSpeed);

// not sure why this requires a cast to int for the comparision, but a
// if (currentMaxSpeed < 1.0) wasn't catching cases where
// currentMaxSpeed == 0.00, ODD.
if (int(currentMaxSpeed) < 1) {
currentMaxSpeed = 800.0;
}

EEPROM_readAnything(EEPROM_MACHINE_MOTOR_ACCEL, currentAcceleration);
if (int(currentAcceleration) < 1) {
currentAcceleration = 800.0;
}
}

void eeprom_loadMachineSpecFromEeprom()
{
impl_loadMachineSpecFromEeprom();
Expand All @@ -129,22 +147,12 @@ void eeprom_loadMachineSpecFromEeprom()
eeprom_loadStepMultiplier();
eeprom_loadMachineName();
eeprom_loadPenLiftRange();
eeprom_loadSpeed();


// load speed, acceleration
EEPROM_readAnything(EEPROM_MACHINE_MOTOR_SPEED, currentMaxSpeed);
if (currentMaxSpeed < 1)
currentMaxSpeed = 800.0;

EEPROM_readAnything(EEPROM_MACHINE_MOTOR_ACCEL, currentAcceleration);
if (currentAcceleration < 1)
currentAcceleration = 800.0;

// load penwidth
EEPROM_readAnything(EEPROM_MACHINE_PEN_WIDTH, penWidth);
if (penWidth < 0.0001)
penWidth = 0.8;


mmPerStep = mmPerRev / multiplier(motorStepsPerRev);
stepsPerMM = multiplier(motorStepsPerRev) / mmPerRev;
Expand Down
102 changes: 68 additions & 34 deletions exec.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ boolean exec_executeBasicCommand(String &com)
exec_changeLengthDirect();
else if (com.startsWith(CMD_CHANGEPENWIDTH))
exec_changePenWidth();
else if (com.startsWith(CMD_CHANGEMOTORSPEED))
exec_changeMotorSpeed();
else if (com.startsWith(CMD_CHANGEMOTORACCEL))
exec_changeMotorAcceleration();
else if (com.startsWith(CMD_SETMOTORSPEED))
exec_setMotorSpeed();
else if (com.startsWith(CMD_SETMOTORACCEL))
Expand All @@ -39,8 +35,6 @@ boolean exec_executeBasicCommand(String &com)
pixel_drawSquarePixel();
else if (com.startsWith(CMD_DRAWSCRIBBLEPIXEL))
pixel_drawScribblePixel();
// else if (com.startsWith(CMD_DRAWRECT))
// drawRectangle();
else if (com.startsWith(CMD_CHANGEDRAWINGDIRECTION))
exec_changeDrawingDirection();
else if (com.startsWith(CMD_SETPOSITION))
Expand Down Expand Up @@ -77,10 +71,10 @@ void exec_changeDrawingDirection()
{
globalDrawDirectionMode = asInt(inParam1);
globalDrawDirection = asInt(inParam2);
Serial.print(F("Changed draw direction mode to be "));
Serial.print(globalDrawDirectionMode);
Serial.print(F(" and direction is "));
Serial.println(globalDrawDirection);
// Serial.print(F("Changed draw direction mode to be "));
// Serial.print(globalDrawDirectionMode);
// Serial.print(F(" and direction is "));
// Serial.println(globalDrawDirection);
}


Expand Down Expand Up @@ -109,6 +103,18 @@ void exec_reportMachineSpec()
Serial.print(stepMultiplier);
Serial.println(CMD_END);

Serial.print(F("PGLIFT,"));
Serial.print(downPosition);
Serial.print(COMMA);
Serial.print(upPosition);
Serial.println(CMD_END);

Serial.print(F("PGSPEED,"));
Serial.print(currentMaxSpeed);
Serial.print(COMMA);
Serial.print(currentAcceleration);
Serial.println(CMD_END);

}

void exec_setMachineSizeFromCommand()
Expand All @@ -135,6 +141,8 @@ void exec_setMachineSizeFromCommand()
// reload
eeprom_loadMachineSize();
}


void exec_setMachineNameFromCommand()
{
String name = inParam1;
Expand Down Expand Up @@ -165,18 +173,45 @@ void exec_setMachineStepMultiplierFromCommand()
EEPROM_writeAnything(EEPROM_MACHINE_STEP_MULTIPLIER, asInt(inParam1));
eeprom_loadMachineSpecFromEeprom();
}

void exec_setPenLiftRange()
{
int down = asInt(inParam1);
int up = asInt(inParam2);
EEPROM_writeAnything(EEPROM_PENLIFT_DOWN, down);
EEPROM_writeAnything(EEPROM_PENLIFT_UP, up);
eeprom_loadPenLiftRange();

Serial.print(F("Down: "));
Serial.println(down);
Serial.print(F("Up: "));
Serial.println(up);

if (inNoOfParams == 4)
{
// 4 params (C45,<downpos>,<uppos>,1,END) means save values to EEPROM
EEPROM_writeAnything(EEPROM_PENLIFT_DOWN, down);
EEPROM_writeAnything(EEPROM_PENLIFT_UP, up);
eeprom_loadPenLiftRange();
}
else if (inNoOfParams == 3)
{
// 3 params (C45,<downpos>,<uppos>,END) means just do a range test
penlift_movePen(down, up, penLiftSpeed);
delay(200);
penlift_movePen(up, down, penLiftSpeed);
delay(200);
penlift_movePen(down, up, penLiftSpeed);
delay(200);
penlift_movePen(up, down, penLiftSpeed);
delay(200);
}
}

/* Single parameter to set max speed, add a second parameter of "1" to make it persist.
*/
void exec_setMotorSpeed()
{
exec_setMotorSpeed(asFloat(inParam1));
if (inNoOfParams == 3 && asInt(inParam2) == 1)
EEPROM_writeAnything(EEPROM_MACHINE_MOTOR_SPEED, currentMaxSpeed);
}

void exec_setMotorSpeed(float speed)
Expand All @@ -188,18 +223,13 @@ void exec_setMotorSpeed(float speed)
Serial.println(currentMaxSpeed);
}

void exec_changeMotorSpeed()
{
float speedChange = asFloat(inParam1);
float newSpeed = currentMaxSpeed + speedChange;
exec_setMotorSpeed(newSpeed);
}



/* Single parameter to set acceleration, add a second parameter of "1" to make it persist.
*/
void exec_setMotorAcceleration()
{
exec_setMotorAcceleration(asFloat(inParam1));
if (inNoOfParams == 3 && asInt(inParam2) == 1)
EEPROM_writeAnything(EEPROM_MACHINE_MOTOR_ACCEL, currentAcceleration);
}
void exec_setMotorAcceleration(float accel)
{
Expand All @@ -209,12 +239,6 @@ void exec_setMotorAcceleration(float accel)
Serial.print(F("New acceleration: "));
Serial.println(currentAcceleration);
}
void exec_changeMotorAcceleration()
{
float speedChange = asFloat(inParam1);
float newAccel = currentAcceleration + speedChange;
exec_setMotorAcceleration(newAccel);
}

void exec_changePenWidth()
{
Expand Down Expand Up @@ -269,7 +293,6 @@ void exec_changeLengthDirect()
}
else
{
Serial.println("dr.5");
exec_drawBetweenPoints(startA, startB, endA, endB, maxSegmentLength);
}
}
Expand All @@ -295,8 +318,19 @@ void exec_drawBetweenPoints(float p1a, float p1b, float p2a, float p2b, int maxS
float c2y = getCartesianYFP(c2x, p2a);

// test to see if it's on the page
if (c2x > 20 && c2x<pageWidth-20 && c2y > 20 && c2y <pageHeight-20)
{
// AND ALSO TO see if the current position is on the page.
// Remember, the native system can easily specify points that can't exist,
// particularly up at the top.
if (c2x > 20
&& c2x<pageWidth-20
&& c2y > 20
&& c2y <pageHeight-20
&& c1x > 20
&& c1x<pageWidth-20
&& c1y > 20
&& c1y <pageHeight-20
)
{
reportingPosition = false;
float deltaX = c2x-c1x; // distance each must move (signed)
float deltaY = c2y-c1y;
Expand Down Expand Up @@ -330,6 +364,8 @@ void exec_drawBetweenPoints(float p1a, float p1b, float p2a, float p2b, int maxS
usingAcceleration = false;
while (linesegs > 0)
{
// Serial.print("Line segment: " );
// Serial.println(linesegs);
// compute next new location
c1x = c1x + deltaX;
c1y = c1y + deltaY;
Expand All @@ -341,7 +377,7 @@ void exec_drawBetweenPoints(float p1a, float p1b, float p2a, float p2b, int maxS
// do the move
runSpeed = desiredSpeed(linesegs, runSpeed, currentAcceleration*4);

// Serial.print("Runspeed:");
// Serial.print("Setting speed:");
// Serial.println(runSpeed);

motorA.setSpeed(runSpeed);
Expand All @@ -353,8 +389,6 @@ void exec_drawBetweenPoints(float p1a, float p1b, float p2a, float p2b, int maxS
}

// do the end point in case theres been some rounding errors etc
motorA.setSpeed(0);
motorB.setSpeed(0);
reportingPosition = true;
changeLength(p2a, p2b);

Expand Down
Loading

0 comments on commit 7e2d4f0

Please sign in to comment.