Created
April 8, 2016 12:02
-
-
Save Craigson/41a44b6f1816b6261fb93638120b33dd to your computer and use it in GitHub Desktop.
Some test code for sending commands to the EBB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Hi Brian | |
| //I'm running into those same issues, hopefully you might be able to point out something basic I'm doing wrong. | |
| //To give you an overview, during this testing phase I've created a container that will hold a list of the string commands I want to execute, it's called mCommandStack. Pressing any of the arrow keys pushes the corresponding command onto the stack. | |
| //This is the code in my keyDown method: | |
| case 273: | |
| cout << "Moving up!" << endl; | |
| //mSerial->writeString("SM,1000,0,3000\r"); | |
| addCommand("SM,1000,0,3000\n\r"); | |
| break; | |
| case 274: | |
| cout << "Moving down!" << endl; | |
| //mSerial->writeString("SM,1000,0,-3000\r"); | |
| addCommand("SM,1000,0,-3000\n\r"); | |
| break; | |
| case 275: | |
| cout << "Moving right!" << endl; | |
| // mSerial->writeString("SM,1000,3000,0\r"); | |
| addCommand("SM,1000,3000,0\n\r"); | |
| break; | |
| case 276: | |
| cout << "Moving left!" << endl; | |
| //mSerial->writeString("SM,1000,-3000,0\r"); | |
| addCommand("SM,1000,-3000,0\n\r"); | |
| break; | |
| //where my addCommand() method is as follows: | |
| void DrawBotTestApp::addCommand(string _command) | |
| { | |
| mCommandStack.push_back(_command); | |
| cout << "number of commands in stack: " << mCommandStack.size() << endl; | |
| } | |
| Once I've cued up the desired number of moves, I invoke the executeStack() method, which looks like this: | |
| void DrawBotTestApp::executeStack() | |
| { | |
| cout << "executing " << mCommandStack.size() << " commands" << endl; | |
| for (int i = 0; i < mCommandStack.size(); i++) | |
| { | |
| mSerial->writeString(mCommandStack[i]); | |
| cout << "sending: " << mCommandStack[i] << endl; | |
| } | |
| cout << "flushing serial buffer" << endl; | |
| mSerial->flush(); | |
| cout << "clearing stack" << endl; | |
| mCommandStack.clear(); | |
| cout << mCommandStack.size() << " commands left in stack" << endl; | |
| } | |
| //If for example I'd like to "draw a square", I hit the arrow keys in this order: Up, Right, Down, Left, then press the 'e' key to invoke the executeStack() method. | |
| //The issue is that sometimes the board only executes three commands, or two, or only one. It seems to be random, although I will say that it never seems to execute all four. The debug console messages look like this: | |
| executing 4 commands | |
| sending: SM,1000,0,-3000 | |
| sending: SM,1000,-3000,0 | |
| sending: SM,1000,0,3000 | |
| sending: SM,1000,3000,0 | |
| flushing serial buffer | |
| clearing stack | |
| 0 commands left in stack | |
| //Another interesting thing that happens is that often when I close the application, my "printhead" moves, almost as if it is executing a lost command stored internally somewhere on the board.. | |
| //any thoughts? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment