/** "TP" — Toggle Pen Command: TP[,duration]<CR> Response: OK<NL><CR> Firmware versions: v1.9 and newer Execution: Immediate Arguments: duration: (Optional) an integer in the range of 1 to 65535, giving an delay in milliseconds. Description: This command toggles the state of the pen (up->down and down->up). EBB firmware resets with pen in 'up' (servo_min) state. Note that conventionally, we have used the servo_min ("SC,4") value as the 'Pen up position', and the servo_max ("SC,5") value as the 'Pen down position'. The optional duration argument is in milliseconds. It represents the total length of time between when the pen move is started, and when the next command will be executed. Note that this is not related to how fast the pen moves, which is set with the SC command. Rather, it is an intentional delay of a given duration, to force the EBB not to execute the next command (often an SM) for some length of time, which allows the pen move to complete and possibly some extra settling time before moving the other motors. If no duration argument is specified, a value of 0 milliseconds is used internally. */ void EBBParser::parseTP(const char* arg) { sendAck(); const short delayMs = (arg != NULL) ? atoi(arg) : 0; setPenState(!getPenState(), delayMs); }
/** "SP" — Set Pen State Command: SP,value[,duration[,portBpin]]<CR> Response: OK<NL><CR> Firmware versions: all (with changes) Execution: Added to FIFO motion queue Arguments: value is either 0 or 1, indicating to raise or lower the pen. duration (optional) is an integer from 1 to 65535, which gives a delay in milliseconds. portBpin (optional) is an integer from 0 through 7. Description: This command instructs the pen to go up or down. When a value of 1 is used, the servo will be moved to the servo_min value (as set by the "SC,4" command). When a value of 0 is used, the servo will be moved to the servo_max value (as set by the "SC,5" command below). Note that conventionally, we have used the servo_min ("SC,4") value as the 'Pen up position', and the servo_max ("SC,5") value as the 'Pen down position'. The duration argument is in milliseconds. It represents the total length of time between when the pen move is started, and when the next command will be executed. Note that this is not related to how fast the pen moves, which is set with the SC command. Rather, it is an intentional delay of a given duration, to force the EBB not to execute the next command (often an SM) for some length of time, which allows the pen move to complete and possibly some extra settling time before moving the other motors. If no duration argument is specified, a value of 0 milliseconds is used internally. The optional portBpin argument allows one to specify which portB pin of the MCU the output will use. If none is specified, pin 1 (the default) will be used. Default positions:The default position for the RC servo output (RB1) on reset is the 'Pen up position' (servo_min), and at boot servo_min is set to 12000 which results in a pulse width of 1.0 ms on boot. servo_max is set to 16000 on boot, so the down position will be 1.33 ms unless changed with the "SC,5" Command. Digital outputs: On older EBB hardware versions 1.1, 1.2 and 1.3, this command will make the solenoid output turn on and off. On all EBB versions it will make the RC servo output on RB1 move to the up or down position. Also, by default, it will turn on RB4 or turn off RB4 as a simple digital output, so that you could use this to trigger a laser for example. Example: SP,1<CR> Move pen-lift servo motor to servo_min position. */ void EBBParser::parseSP(const char* arg1, const char* arg2, const char* arg3) { if (arg1 == NULL) { sendError(); return; } int cmd = atoi(arg1); if (cmd != 0 && cmd != 1) { sendError(); return; } sendAck(); const short delayMs = (arg2 != NULL) ? atoi(arg2) : 0; setPenState(cmd == 0 ? false : true, delayMs); }
void Mirobot::begin(unsigned char v){ version(v); #ifdef AVR // Initialise the steppers HotStepper::begin(); // Set up the collision sensor inputs and state pinMode(LEFT_COLLIDE_SENSOR, INPUT_PULLUP); pinMode(RIGHT_COLLIDE_SENSOR, INPUT_PULLUP); // Set up the status LED pinMode(STATUS_LED_PIN, OUTPUT); #endif //AVR #ifdef ESP8266 // Set up the status LED pin pinMode(STATUS_LED_PIN, OUTPUT); // Set up the ADC on I2C Wire.begin(I2C_DATA, I2C_CLOCK); // Initialise the steppers ShiftStepper::setup(SHIFT_REG_DATA, SHIFT_REG_CLOCK, SHIFT_REG_LATCH); // Set up the line follower LED enable pin and turn it off pinMode(LINE_LED_ENABLE, OUTPUT); digitalWrite(LINE_LED_ENABLE, HIGH); // Set up the EEPROM EEPROM.begin(sizeof(MarceauSettings) + sizeof(settings)+4); #endif //ESP8266 // Set up the pen arm servo pinMode(SERVO_PIN, OUTPUT); _collideStatus = NORMAL; // Initialise the pen arm into the up position setPenState(UP); // Start the serial if(serialEnabled) beginSerial(); // Start the WiFi #ifdef ESP8266 if(wifiEnabled) beginWifi(); #endif // Pull the settings out of memory initSettings(); // Start marceau processing commands marcel.begin(); }
void Mirobot::pendown(){ setPenState(DOWN); wait(); }
void Mirobot::penup(){ setPenState(UP); wait(); }