crash reports really should have motor id in them

--- arduino/motor_driver/motor_driver.ino
+++ arduino/motor_driver/motor_driver.ino
@@ -294,6 +294,7 @@

 void setupWatchdog() {
   OscMessage msg("/crashreport");
+  msg.add(MOTOR_ID);
   ApplicationMonitor.Dump(msg);
   ApplicationMonitor.EnableWatchdog(Watchdog::CApplicationMonitor::Timeout_4s);
   etherOSC.send(msg, destination);


Simplify boolean check in car_system

Simplify boolean check in car_system

--- arduino/src/car_system/car_system.ino
+++ arduino/src/car_system/car_system.ino
@@ -101,11 +101,8 @@

     if(ppad.available()) {
       String in = ppad.readStringUntil('\n');
-      if(in.charAt(0) == '1') {
-        alertSensorEssential = true;
-      }
-      if(in.charAt(1) == '1') {
-        alertSensorGeneral = true;
+      alertSensorEssential = (in.charAt(0) == '1');
+      alertSensorGeneral = (in.charAt(1) == '1');
       }
     }
   }


no used onboard led to show charge status

--- autonomo_lorabee/autonomo_lorabee.ino
+++ autonomo_lorabee/autonomo_lorabee.ino
@@ -51,6 +51,8 @@
 void setup() {
   digitalWrite(BEE_VCC, HIGH); // turn on lora module
   pinMode(13, OUTPUT);
+
+  pinMode(1, INPUT);

   debugSerial.begin(57600);
   rfidSerial.begin(9600);
@@ -67,6 +69,8 @@

 void loop() {
   while ((!SerialUSB) && (millis() < 5000)); // wait for usb serial monitor for 5 seconds
+
+  boolean value = digitalRead(1);

   debugSerial.println("Sleeping for 5 seconds");
   for (uint8_t i = 5; i > 0; i--) {


retab

retab

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -180,70 +180,70 @@
 }

 void fft_phase(float fs, float f1, float f2, uint16_t samples, const float data[],
-						float mag[], float phase[], uint16_t &startIndex, uint16_t &endIndex)
+                                                float mag[], float phase[], uint16_t &startIndex, uint16_t &endIndex)
 {
-	//changes f1 and f2 to indices
-	//fs/samples gives the increments of frequency on the x-axis
-	startIndex = f1/(fs/samples);
-	endIndex = f2/(fs/samples);
-
-
-	for (uint16_t i = startIndex; i < endIndex; i++)
-	{
-		float real = 0;
-		float imag = 0;
-
-
-		//Euler's Identity
-		for (uint16_t j = 0; j < samples; j++)
-		{
-			//uses lookup tables for trigonometric
-			//functions to save compputing power
-			switch(samples)
-			{
-				case 512:
-					real += intcosine512[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					imag += intsine512[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					break;
-
-				case 256:
-					real += intcosine256[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					imag += intsine256[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					break;
-
-				case 128:
-					real += intcosine128[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					imag += intsine128[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					break;
-
-				case 64:
-					real += intcosine64[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					imag += intsine64[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					break;
-
-				case 32:
-					real += intcosine32[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					imag += intsine32[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
-					break;
-
-				default:
-					break;
-			}
-		}
-
-
-		//dividing each number by 1000 to prevent each number from getting too large
-		//Also adjusts for the fact that the trigonometric values were multiplied
-		//by 1000 as well to make them integers instead of decimal values
-		real = real / 1000 / samples;
-		imag = imag / 1000 / samples;
-
+        //changes f1 and f2 to indices
+        //fs/samples gives the increments of frequency on the x-axis
+        startIndex = f1/(fs/samples);
+        endIndex = f2/(fs/samples);
+
+
+        for (uint16_t i = startIndex; i < endIndex; i++)
+        {
+                float real = 0;
+                float imag = 0;
+
+
+                //Euler's Identity
+                for (uint16_t j = 0; j < samples; j++)
+                {
+                        //uses lookup tables for trigonometric
+                        //functions to save compputing power
+                        switch(samples)
+                        {
+                                case 512:
+                                        real += intcosine512[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        imag += intsine512[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        break;
+
+                                case 256:
+                                        real += intcosine256[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        imag += intsine256[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        break;
+
+                                case 128:
+                                        real += intcosine128[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        imag += intsine128[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        break;
+
+                                case 64:
+                                        real += intcosine64[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        imag += intsine64[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        break;
+
+                                case 32:
+                                        real += intcosine32[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        imag += intsine32[ (i*j) - (samples*((i*j)/samples)) ] * data[j];
+                                        break;
+
+                                default:
+                                        break;
+                        }
+                }
+
+
+                //dividing each number by 1000 to prevent each number from getting too large
+                //Also adjusts for the fact that the trigonometric values were multiplied
+                //by 1000 as well to make them integers instead of decimal values
+                real = real / 1000 / samples;
+                imag = imag / 1000 / samples;
+
                 float phaseRad = atan2(imag, real);
-
+
                 // mag[i] = log2(sqrt(real * real + imag * imag));
                 mag[i] = sqrt(real * real + imag * imag);
-		phase[i] = phaseRad;
-	}
+                phase[i] = phaseRad;
+        }
 }

 float prevPhase[END_INDEX];
@@ -268,7 +268,7 @@

         float phase = phases[i];
         float old_phase = prevPhase[i];
-	prevPhase[i] = phase;
+        prevPhase[i] = phase;

         // Add the rate to our phase even in the case where we don't update the rate.
         phaseAvg[i] += phaseRateAverage[i];


fixing test.

fixing test.

--- test_VALVEMODEL/test_VALVEMODEL.ino
+++ test_VALVEMODEL/test_VALVEMODEL.ino
@@ -196,15 +196,16 @@

   // FIRST POLL(S) AFTER POWER_UP; RETRACTING THE PIN.
   csvmd1.poll();
-  // Whitebox test of internal state: should be valvePinWithdrawing.
-  AssertIsEqual(OTRadValve::CurrentSenseValveMotorDirect::valvePinWithdrawing, csvmd1.getState());
-  // More polls shouldn't make any difference initially.
-  csvmd1.poll();
-  // Whitebox test of internal state: should be valvePinWithdrawing.
-  AssertIsEqual(OTRadValve::CurrentSenseValveMotorDirect::valvePinWithdrawing, csvmd1.getState());
-  csvmd1.poll();
-  // Whitebox test of internal state: should be valvePinWithdrawing.
-  AssertIsEqual(OTRadValve::CurrentSenseValveMotorDirect::valvePinWithdrawing, csvmd1.getState());
+  // DHD20160123: now waits randomised number of ticks before starting to withdraw.
+//  // Whitebox test of internal state: should be valvePinWithdrawing.
+//  AssertIsEqual(OTRadValve::CurrentSenseValveMotorDirect::valvePinWithdrawing, csvmd1.getState());
+//  // More polls shouldn't make any difference initially.
+//  csvmd1.poll();
+//  // Whitebox test of internal state: should be valvePinWithdrawing.
+//  AssertIsEqual(OTRadValve::CurrentSenseValveMotorDirect::valvePinWithdrawing, csvmd1.getState());
+//  csvmd1.poll();
+//  // Whitebox test of internal state: should be valvePinWithdrawing.
+//  AssertIsEqual(OTRadValve::CurrentSenseValveMotorDirect::valvePinWithdrawing, csvmd1.getState());
 //  // Simulate hitting end-stop (high current).
 //  dhw.currentHigh = true;
 //  AssertIsTrue(dhw.isCurrentHigh());


Switch Config & Vicon Trigger

Switch Config & Vicon Trigger

Set pin 6 to output PWM square wave at 200 duty cycle to trigger vicon,
and goes back down to 20 afterwards.

--- LEDguide_actual/LEDguide_actual.ino
+++ LEDguide_actual/LEDguide_actual.ino
@@ -23,7 +23,7 @@
 #include "WS2812_Definitions.h"

 #define PIN 4
-#define LED_COUNT 30
+#define LED_COUNT 48

 // Create an instance of the Adafruit_NeoPixel class called "leds".
 // That'll be what we refer to from here on...
@@ -32,6 +32,7 @@
 //Variable for the other side of the switch
 int switchPin = A0;
 int switchValue = 0;
+int viconTriggerPin = 6;

 void setup()
 {
@@ -44,38 +45,25 @@

 void loop()
 {
-  /*
-  // Ride the Rainbow Road
-  for (int i=0; i<LED_COUNT*10; i++)
-  {
-    rainbow(i);
-    delay(100);  // Delay between rainbow slides
-  }
-
-  // Indigo cylon
-  // Do a cylon (larson scanner) cycle 10 times
-  for (int i=0; i<10; i++)
-  {
-    // cylon function: first param is color, second is time (in ms) between cycles
-    cylon(INDIGO, 500);  // Indigo cylon eye!
-  }
-  */
   clearLEDs();
   leds.show();
-  // A light shower of spring green rain
-  // This will run the cascade from top->bottom 20 times
   switchValue = analogRead(switchPin);
   Serial.println(switchValue);
   if(switchValue < 100){
+    analogWrite(viconTriggerPin, 20);
     digitalWrite(13, HIGH);
     clearLEDs();
     leds.show();
   }else{
-  //whenever signal detected to be shut off, reset leds?
+    analogWrite(viconTriggerPin, 200);
     digitalWrite(13,LOW);
       readySetGo(1500);
       // First parameter is the color, second is direction, third is ms between falls
       cascade(MEDIUMSPRINGGREEN, TOP_DOWN, 100);
+      clearLEDs();
+      leds.show();
+      analogWrite(viconTriggerPin, 20);
+      delay(3000);
     }
 }


motor command returns the distance to go also.

M0 100# returns M0 50# if only half of distance was traversed. Otherwise
it returns M0 0#

--- jenny5-firmware/jenny5-firmware.ino
+++ jenny5-firmware/jenny5-firmware.ino
@@ -22,7 +22,7 @@

 char is_command_running;

-char firmware_version[] = "2015.12.26.1";// year.month.day.build number
+char firmware_version[] = "2015.12.26.2";// year.month.day.build number

 char current_buffer[65];

@@ -40,11 +40,11 @@
   Serial.println();

   Serial.println(F("Commands are:"));
-  Serial.println(F("Mx y# // Moves motor x with y steps. If y is negative the motor runs in the opposite direction. The motor remains locked at the end of the movement. Outputs Mx# when motor rotation is over."));
+  Serial.println(F("Mx y# // Moves motor x with y steps. If y is negative the motor runs in the opposite direction. The motor remains locked at the end of the movement. Outputs Mx d# when motor rotation is over. If movement was complete, then d is 0, otherwise is the distance to go."));
   Serial.println(F("Dx#  // Disables motor x."));
   Serial.println(F("Lx#  // Lock motor x."));
   Serial.println(F("SMx s a# // Sets speed of motor x to s and the acceleration to a."));
-  Serial.println(F("SPx min max home# // Sets the parameters of a potentiometer. Min and Max are the limits where it can move and home is from where we start."));
+  Serial.println(F("SPx min max home# // Sets the parameters of a potentiometer. Min and max are the limits where it can move and home is from where we bring the robot when we start."));
   Serial.println(F("Ax n Py Bz ... # // Attach to motor x a list of n sensors (like Potentiometer y, Button z etc)."));
   Serial.println(F("Ux# // Gets the distance as measured by the ultrasonic sensor x. Outputs Ux d#."));
   Serial.println(F("Bx# // Gets the status of the button x. Outputs Bx s#"));
@@ -302,11 +302,13 @@
         is_one_motor_running = true;
       }
       else{
+        Serial.write("M");
+        Serial.print(m);
+        Serial.write(' ');
+        Serial.print(motors_control.steppers[m]->distanceToGo());
+        Serial.write('#');
         motors_control.steppers[m]->setCurrentPosition(0);
         motors_control.set_motor_running(m, 0);
-        Serial.write("M");
-        Serial.print(m);
-        Serial.write('#');
       }
     }
     else{
@@ -316,7 +318,7 @@
         motors_control.set_motor_running(m, 0);
         Serial.write("M");
         Serial.print(m);
-        Serial.write('#');
+        Serial.write(" 0#");
       }
     }
   }


now sweeps from one side to the other

now sweeps from one side to the other

--- sweep.ino
+++ sweep.ino
@@ -14,6 +14,8 @@
 int dir = 12;  // connect pin 12 to dir
 int a = 0;     //  gen counter

+int distance = 2300;
+
 void setup()
 {
   pinMode(stp, OUTPUT);
@@ -23,24 +25,24 @@

 void loop()
 {
-  if (a <  200)  //sweep 200 step in dir 1
+  if (a < distance)  //sweep 200 step in dir 1
    {
     a++;
     digitalWrite(stp, HIGH);
-    delay(10);
+    delay(1);
     digitalWrite(stp, LOW);
-    delay(10);
+    delay(1);
    }
   else
    {
     digitalWrite(dir, HIGH);
     a++;
     digitalWrite(stp, HIGH);
-    delay(10);
+    delay(1);
     digitalWrite(stp, LOW);
-    delay(10);
+    delay(1);

-    if (a>400)    //sweep 200 in dir 2
+    if (a>distance*2)    //sweep 200 in dir 2
      {
       a = 0;
       digitalWrite(dir, LOW);


Wrote a simple serial control method to test each motor

--- executer/executer.ino
+++ executer/executer.ino
@@ -13,21 +13,21 @@
 int steps_per_quarter_turn = 100;

 char get_nybble(char* arr, int i) {
-  if (i%2==0)
-    return arr[i]>>4;
+  if (i % 2 == 0)
+    return arr[i] >> 4;
   else
-    return arr[i]%16;
+    return arr[i] % 16;
 }

 char get_cmd_stepper_index(char cmd) {
-  return cmd%8;
+  return cmd % 8;
 }

 char get_cmd_direction(char cmd) {
-  return cmd>>3;
+  return cmd >> 3;
 }

-void enable_stepper(short* stepper) {
+void init_stepper(short* stepper) {
   pinMode(stepper[0], OUTPUT);
   pinMode(stepper[1], OUTPUT);
   pinMode(stepper[2], OUTPUT);
@@ -37,35 +37,56 @@
   digitalWrite(stepper[3], HIGH);
 }

+void enable_stepper(short* stepper) {
+  digitalWrite(stepper[2], HIGH);
+}
+
+void disable_stepper(short* stepper) {
+  digitalWrite(stepper[2], LOW);
+}
+
 void step_stepper(short* stepper, int steps, int d) {
-  digitalWrite(stepper[1], ((steps < 0)?HIGH:LOW));
+  digitalWrite(stepper[1], ((steps < 0) ? HIGH : LOW));
   for (int i = 0; i < abs(steps); i++) {
-    digitalWrite(stepper[0],HIGH);
+    digitalWrite(stepper[0], HIGH);
     delayMicroseconds(d);
-    digitalWrite(stepper[0],LOW);
+    digitalWrite(stepper[0], LOW);
+    delayMicroseconds(d);
+  }
+}
+
+void simul_step_steppers(short* stepper1, int steps1, short* stepper2, int steps2, int d) {
+  digitalWrite(stepper1[1], ((steps1 < 0) ? HIGH : LOW));
+  digitalWrite(stepper2[1], ((steps2 < 0) ? HIGH : LOW));
+  for (int i = 0; i < max(abs(steps1), abs(steps2)); i++) {
+    if (i < steps1) digitalWrite(stepper1[0], HIGH);
+    if (i < steps2) digitalWrite(stepper2[0], HIGH);
+    delayMicroseconds(d);
+    if (i < steps1) digitalWrite(stepper1[0], LOW);
+    if (i < steps2) digitalWrite(stepper2[0], LOW);
     delayMicroseconds(d);
   }
 }

 void setup() {
   for (int i = 0; i < 6; i++) {
-    enable_stepper(steppers[i]);
+    init_stepper(steppers[i]);
   }
   Serial.begin(9600);
 }

 void loop() {
   int n;
-  if (n=Serial.available()) {
+  if (n = Serial.available()) {
     char buf[2];

-    Serial.readBytes(buf,2);
+    Serial.readBytes(buf, 2);
     char command = buf[0];
     char dir = buf[1];

     Serial.print(command);
     Serial.println(dir);
-
+
     int stepper_i = -1;
     switch (command) {
       case 'f'://front
@@ -91,7 +112,12 @@
     }

     if (stepper_i != -1) {
-      step_stepper(steppers[stepper_i], ((dir=='+')?1:-1)*100, 250);
+      if (dir == '+' || dir == '-')
+        step_stepper(steppers[stepper_i], ((dir == '+') ? 1 : -1) * 100, 275);
+      else if (dir == 'd')
+        disable_stepper(steppers[stepper_i]);
+      else if (dir == 'e')
+        enable_stepper(steppers[stepper_i]);
     }
   }
 }


mark pin 11 and 12 as PIXY

mark pin 11 and 12 as PIXY

--- examples/RoseBot/RoseBotFirmata/RoseBotFirmata.ino
+++ examples/RoseBot/RoseBotFirmata/RoseBotFirmata.ino
@@ -28,7 +28,7 @@

   Last updated by Jeff Hoefs: April 11, 2015
         Alan Yorinks August 5, 2015
-        David Fisher Oct 2, 2015
+        David Fisher Oct 22, 2015
 */

 #include <Servo.h>
@@ -74,6 +74,10 @@
 #define PIXY_SET_BRIGHTNESS 2
 #define PIXY_SET_LED 3

+#define PIN_PIXY_MOSI 11
+#define PIN_PIXY_MISO 12
+
+
 /*==============================================================================
  * GLOBAL VARIABLES
  *============================================================================*/
@@ -141,6 +145,7 @@

 /* Pixy Support */
 Pixy pixy;
+boolean pixyIsInitialized = false;  // Flag to store if pixy.init() has been called.
 boolean pixyIsReporting = false;  // Determines if Pixy data will be sent.
 byte pixyMaxBlocks = 5;  // Sets the maximum number of Pixy blocks to report.

@@ -473,8 +478,7 @@
  */
 //void FirmataClass::setAnalogPinReporting(byte pin, byte state) {
 //}
-void reportAnalogCallback(byte analogPin, int value)
-{
+void reportAnalogCallback(byte analogPin, int value) {
   if (analogPin < TOTAL_ANALOG_PINS) {
     if (value == 0) {
       analogInputsToReport = analogInputsToReport & ~ (1 << analogPin);
@@ -493,8 +497,7 @@
   // TODO: save status to EEPROM here, if changed
 }

-void reportDigitalCallback(byte port, int value)
-{
+void reportDigitalCallback(byte port, int value) {
   if (port < TOTAL_PORTS) {
     reportPINs[port] = (byte)value;
     // Send port value immediately. This is helpful when connected via
@@ -514,8 +517,7 @@
  * SYSEX-BASED commands
  *============================================================================*/

-void sysexCallback(byte command, byte argc, byte *argv)
-{
+void sysexCallback(byte command, byte argc, byte *argv) {
   byte mode;
   byte stopTX;
   byte slaveAddress;
@@ -543,10 +545,8 @@
         stopTX = I2C_RESTART_TX; // default
       }
       else {
-
         stopTX = I2C_STOP_TX;
       }
-

       switch (mode) {
         case I2C_WRITE:
@@ -756,20 +756,32 @@
     case PIXY_CONFIG:
       if (argv[0] == PIXY_INIT) {
         pixy.init();
-        pinConfig[encoderPin1] = PIXY;
+        pixyIsInitialized = true;
+        // mark pins as Pixy so they are ignore in non Pixy data requests
+        setPinModeCallback(PIN_PIXY_MOSI, PIXY);
+        setPinModeCallback(PIN_PIXY_MISO, PIXY);
         pixyIsReporting = true;
         pixyMaxBlocks = argv[1];
         if (pixyMaxBlocks == 0) {
           pixyIsReporting = false;
         }
       } else if (argv[0] == PIXY_SET_SERVOS) {
+        if (!pixyIsInitialized) {
+          return;
+        }
         int s0 = argv[1] + (argv[2] << 7);
         int s1 = argv[3] + (argv[4] << 7);
         pixy.setServos(s0, s1);
       } else if (argv[0] == PIXY_SET_BRIGHTNESS) {
+        if (!pixyIsInitialized) {
+          return;
+        }
         int brightness = argv[1] + (argv[2] << 7);
         pixy.setBrightness(brightness);
       } else if (argv[0] == PIXY_SET_LED) {
+        if (!pixyIsInitialized) {
+          return;
+        }
         int r = argv[1] + (argv[2] << 7);
         int g = argv[3] + (argv[4] << 7);
         int b = argv[5] + (argv[6] << 7);
@@ -1139,12 +1151,12 @@
  * Writes a Pixy block of data using Firmata.write.
  */
 void writePixyBlock(byte pixyBlockIndex) {
-//pixy.blocks[i].signature The signature number of the detected object (1-7 for normal signatures)
-//pixy.blocks[i].x The x location of the center of the detected object (0 to 319)
-//pixy.blocks[i].y The y location of the center of the detected object (0 to 199)
-//pixy.blocks[i].width The width of the detected object (1 to 320)
-//pixy.blocks[i].height The height of the detected object (1 to 200)
-//pixy.blocks[i].angle The angle of the object detected object if the detected object is a color code.
+  // signature - The signature number of the detected object (1-7 for normal signatures)
+  // x - The x location of the center of the detected object (0 to 319)
+  // y - The y location of the center of the detected object (0 to 199)
+  // width - The width of the detected object (1 to 320)
+  // height - The height of the detected object (1 to 200)
+  // angle - The angle of the object detected object if the detected object is a color code.
   Firmata.write(pixy.blocks[pixyBlockIndex].signature & 0x7f);
   Firmata.write((pixy.blocks[pixyBlockIndex].signature >> 7) & 0x7f);
   Firmata.write(pixy.blocks[pixyBlockIndex].x & 0x7f);
@@ -1159,11 +1171,8 @@
   Firmata.write((pixy.blocks[pixyBlockIndex].angle >> 7) & 0x7f);
 }

-
-void printData(char * id,  long data)
-{
+void printData(char * id,  long data) {
   char myArray[64];
-
   String myString = String(data);
   myString.toCharArray(myArray, 64);
   Firmata.sendString(id);


Hand control changes in firmware.

Hand control changes in firmware.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -219,23 +219,36 @@
                   break;
                 case '2':
                   {
-                    int speed_percent = input_buffer.substring(2, 4).toInt();
-                    int speed = map(speed_percent, 0, 200, SERV_L_BACK, SERV_L_FORW);
-                    servo_left.write(speed);
-                    speed = map(speed_percent, 0, 200, SERV_R_BACK, SERV_R_FORW);
-                    servo_right.write(speed);
+                    int speed_percent = input_buffer.substring(2, 5).toInt();
+                    Serial.print(speed_percent);
+                    if (speed_percent == 100) { robotStop(); }
+                    else if( speed_percent > 100) {
+                      motorForwardLeft(speed_percent - 100);
+                      motorForwardRight(speed_percent - 100);
+                    }
+                    else if(speed_percent < 100) {
+                      motorBackwardLeft(100 - speed_percent);
+                      motorBackwardRight(100 - speed_percent);
+                    }
                   }
                   break;
                 case '3':
                   {
-                    int speed_percent = input_buffer.substring(2, 4).toInt();
-                    int speed = map(speed_percent, 0, 200, SERV_L_BACK, SERV_L_FORW);
-                    servo_left.write(speed);
-                    speed = map(speed_percent, 0, 200, SERV_R_FORW, SERV_R_BACK);
-                    servo_right.write(speed);
+                    int speed_percent = input_buffer.substring(2, 5).toInt();
+                    Serial.print(speed_percent);
+                    if (speed_percent == 100) { robotStop(); }
+                    else if( speed_percent > 100) {
+                      motorBackwardLeft(speed_percent - 100);
+                      motorForwardRight(speed_percent - 100);
+                    }
+                    else if(speed_percent < 100) {
+                      motorForwardLeft(100 - speed_percent);
+                      motorBackwardRight(100 - speed_percent);
+                    }
                   }
                   break;
               }
+              break;
             }
           case 'C': // calibration call
             {


Changed control line pins

Changed control line pins

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -2,10 +2,10 @@

 const int AddressLatchPin = 10;

-const int snesCartPin = A4; //Cart pin 49 - aka /CS, /ROMSEL, /Cart - Goes low when reading ROM
-const int snesReadPin = A3; //Cart pin 23 - aka /RD - Address bus read
+const int snesReadPin = A1; //Cart pin 23 - aka /RD - Address bus read
 const int snesWritePin = A2; //Cart pin 54 - aka /WR - Address bus write
-const int snesResetPin = A1; //Cart pin 26 - SNES reset pin. Goes high when reading cart
+const int snesCartPin = A3; //Cart pin 49 - aka /CS, /ROMSEL, /Cart - Goes low when reading ROM
+const int snesResetPin = A4; //Cart pin 26 - SNES reset pin. Goes high when reading cart

 typedef enum COMMANDS {
   CTRL,
@@ -23,7 +23,7 @@
   //begin spi
   SPI.begin();
   SPI.setClockDivider(SPI_CLOCK_DIV2); //8MHz
-
+
   setDataBusDir(INPUT);

   //setup cart control pins
@@ -36,7 +36,7 @@
   //readHeader();

   //Write byte to indicate device ready
-  Serial.write(0x00);
+  Serial.write(0x00);
 }

 void loop() {
@@ -48,7 +48,7 @@
       setCtrlLines(serialReadBlocking());
     }
     break;
-
+
     // read a section of data from the cart
     case READSECTION:
     {
@@ -67,7 +67,7 @@
         Serial.write(readDataBus());

         /* We must break out of the loop this way because of the potential case
-         * where addresses 0x0000 - 0xffff (inclusive) must be used. A standard
+         * where addresses 0x0000 - 0xffff (inclusive) must be used. A standard
          * loop won't work because it will overflow the 16 bit unsigned int.
          */
         if (addr == endAddr) {
@@ -78,7 +78,7 @@
       Serial.flush();
     }
     break;
-
+
     case WRITESECTION:
     {
       byte bank = serialReadBlocking();
@@ -90,13 +90,13 @@
       unsigned int addr = bytesToInt(startAddrHi, startAddrLow);
       unsigned int endAddr = bytesToInt(endAddrHi, endAddrLow);
       setDataBusDir(OUTPUT);
-
+
       while (true) {
         writeAddrBus(bank, addr);
         writeDataBus(serialReadBlocking());

         /* We must break out of the loop this way because of the potential case
-         * where addresses 0x0000 - 0xffff (inclusive) must be used. A standard
+         * where addresses 0x0000 - 0xffff (inclusive) must be used. A standard
          * loop won't work because it will overflow the 16 bit unsigned int.
          */
         if (addr == endAddr) {
@@ -156,7 +156,7 @@
 }

 //Set the data bus to output or input
-// false => INPUT, true => OUTPUT
+// false => INPUT, true => OUTPUT
 void setDataBusDir(bool dir) {
   for (int p = 2; p <=9; p++){
     pinMode(p, dir);


Tweak patterns and add a couple new ones

--- UselessBox.ino
+++ UselessBox.ino
@@ -15,7 +15,6 @@
 const int MODE_ADJUST_SWITCH = 2;
 int mode = 0;

-const int EEPROM_SEQUENCE = 0;
 const int EEPROM_LID_FROM = 10;
 const int EEPROM_SWITCH_TO = 20;

@@ -38,8 +37,6 @@
 int switchTo = 1100; // adjustable
 int switchRange = switchFrom - switchTo;

-int sequence = 0;
-
 void setup()
 {
   pinMode(6, OUTPUT);  // turn off motor power for startup
@@ -51,13 +48,11 @@
   int schema = EEPROM.read(511);
   if (schema == 87)
   {
-    EEPROM.get(EEPROM_SEQUENCE, sequence);
     EEPROM.get(EEPROM_LID_FROM, lidFrom);
     EEPROM.get(EEPROM_SWITCH_TO, switchTo);
   }
   else
   {
-    sequence = 0;
     // If we haven't run on the MCP before, set the end points
     // of the motor travel equal to the start point and the user
     // will need to do the adjust routine to set them so there's motion.
@@ -75,9 +70,11 @@

   pinMode(buttonPin, INPUT_PULLUP);
   modeButton.attach(buttonPin);
-  modeButton.interval(200);
+  modeButton.interval(100);

   digitalWrite(6, HIGH);  // turn on motor power
+
+  randomSeed(analogRead(A5));
 }

 void loop()
@@ -131,28 +128,19 @@

 void RunSequence()
 {
-  //sequence = ++sequence % 18;
-  sequence = 2;
-  EEPROM.write(EEPROM_SEQUENCE, sequence);
-
+  int sequence = random(0, 20);
+
   if (sequence == 0) Sequence0();
   if (sequence == 1) Sequence1();
-  if (sequence == 2) Sequence0();
-  if (sequence == 3) Sequence9();
-  if (sequence == 4) Sequence0();
+  if (sequence == 2) Sequence2();
+  if (sequence == 3) Sequence3();
+  if (sequence == 4) Sequence4();
   if (sequence == 5) Sequence5();
-  if (sequence == 6) Sequence0();
+  if (sequence == 6) Sequence6();
   if (sequence == 7) Sequence7();
-  if (sequence == 8) Sequence0();
-  if (sequence == 9) Sequence2();
-  if (sequence == 10) Sequence0();
-  if (sequence == 11) Sequence10();
-  if (sequence == 12) Sequence0();
-  if (sequence == 13) Sequence8();
-  if (sequence == 14) Sequence0();
-  if (sequence == 15) Sequence6();
-  if (sequence == 16) Sequence0();
-  if (sequence == 17) Sequence4();
+  if (sequence == 8) Sequence8();
+  if (sequence == 10) Sequence10();
+  if (sequence > 10) DefaultSequence();

   delay(3000);
 }
@@ -170,26 +158,26 @@
 }

 // Plain old open the lid, press the switch, close the lid
+void DefaultSequence()
+{
+  delay(50);
+  Sweep(lidServo, lidFrom, lidTo, 1);
+  delay(200);
+  Sweep(switchServo, switchFrom, switchTo, 1);
+  delay(300);
+  Sweep(switchServo, switchTo, switchFrom, 1);
+  delay(150);
+  Sweep(lidServo, lidTo, lidFrom, 1);
+  delay(400);
+}
+
 void Sequence0()
-{
-  delay(50);
-  Sweep(lidServo, lidFrom, lidTo, 1);
-  delay(200);
-  Sweep(switchServo, switchFrom, switchTo, 1);
-  delay(300);
-  Sweep(switchServo, switchTo, switchFrom, 1);
-  delay(150);
-  Sweep(lidServo, lidTo, lidFrom, 1);
-  delay(400);
-}
-
-void Sequence1()
 {
   int lidMid = lidFrom  + lidRange * 0.80;
   int lidMid4 = lidFrom  + lidRange * 0.60;
   int switchMid = switchTo + switchRange * 0.57;

-  delay(700);
+  delay(50);
   Sweep(lidServo, lidFrom, lidMid, 3000);
   delay(1000);
   Sweep(lidServo, lidMid, lidMid4, 500);
@@ -202,7 +190,7 @@
   Sweep(lidServo, lidTo, lidFrom, 500);
 }

-void Sequence2()
+void Sequence1()
 {
   int lidMid = lidFrom  + lidRange * 0.90;
   int lidMid2 = lidFrom + lidRange * 0.68;
@@ -210,7 +198,7 @@
   int lidMid4 = lidFrom  + lidRange * 0.60;
   int switchMid = switchTo + switchRange * 0.57;

-  delay(800);
+  delay(50);
   Sweep(lidServo, lidFrom, lidMid2, 3000);
   Sweep(lidServo, lidMid2, lidMid3, 1);
   delay(120);
@@ -235,11 +223,11 @@
   Sweep(lidServo, lidTo, lidFrom, 500);
 }

-void Sequence4()
+void Sequence2()
 {
   int switchMid2 = switchTo + switchRange * 0.28;   // Almost on the switch

-  delay(500);
+  delay(50);
   Sweep(lidServo, lidFrom, lidTo, 1);
   delay(1);
   Sweep(switchServo, switchFrom, switchMid2, 1);
@@ -252,40 +240,56 @@
   delay(400);
 }

-void Sequence5()
-{
-  int switchMid2 = switchTo + switchRange * 0.28;   // Almost on the switch
-
-  delay(1000);
+void Sequence3()
+{
+  int switchMid2 = switchTo + switchRange * 0.05;   // Almost on the switch
+
+  delay(50);
   Sweep(lidServo, lidFrom, lidTo, 1);
-  delay(1);
-  Sweep(switchServo, switchFrom, switchTo, 1);
-  delay(450);
-  Sweep(switchServo, switchTo, switchMid2, 1);
-  delay(110);
-  Sweep(switchServo, switchMid2, switchTo, 1);
-  delay(110);
-  Sweep(switchServo, switchTo, switchMid2, 1);
-  delay(110);
-  Sweep(switchServo, switchMid2, switchTo, 1);
-  delay(110);
-  Sweep(switchServo, switchTo, switchMid2, 1);
-  delay(110);
-  Sweep(switchServo, switchMid2, switchTo, 1);
-  delay(110);
-  Sweep(switchServo, switchTo, switchFrom, 1);
-  delay(200);
-  Sweep(lidServo, lidTo, lidFrom, 1);
-  delay(400);
-}
-
-void Sequence6()
-{
-  int lidMid4 = lidFrom  + lidRange * 0.28;
-
-  delay(1500);
+  delay(200);
+  Sweep(switchServo, switchFrom, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(50);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(50);
+  Sweep(switchServo, switchTo, switchFrom, 1);
+  delay(200);
+  Sweep(lidServo, lidTo, lidFrom, 1);
+  delay(400);
+}
+
+void Sequence4()
+{
+  int lidMid4 = lidFrom  + lidRange * 0.85;
+
+  delay(50);
   Sweep(lidServo, lidFrom, lidTo, 1);
-  delay(1);
+  delay(200);
   Sweep(switchServo, switchFrom, switchTo, 1);
   delay(450);
   Sweep(lidServo, lidTo, lidMid4, 1000);
@@ -298,13 +302,13 @@
   delay(400);
 }

-void Sequence7()
-{
-  int lidMid = lidTo;
+void Sequence5()
+{
+  int lidMid = lidFrom + lidRange * 0.90;
   int lidMid2 = lidFrom + lidRange * 0.68;
-  int lidMid4 = lidFrom  + lidRange * 0.28;
-
-  delay(500);
+  int lidMid4 = lidFrom  + lidRange * 0.50;
+
+  delay(50);
   Sweep(lidServo, lidFrom, lidMid, 1);
   delay(200);
   Sweep(lidServo, lidMid, lidMid2, 1);
@@ -327,14 +331,14 @@
   delay(400);
 }

-void Sequence8()
+void Sequence6()
 {
   int lidMid = lidTo;
   int lidMid2 = lidFrom + lidRange * 0.68;
   int lidMid3 = lidFrom + lidRange * 0.77;
-  int lidMid4 = lidFrom  + lidRange * 0.28;
-
-  delay(200);
+  int lidMid4 = lidFrom  + lidRange * 0.50;
+
+  delay(50);
   Sweep(lidServo, lidFrom, lidMid, 1);
   delay(200);
   Sweep(lidServo, lidMid, lidMid2, 1);
@@ -379,13 +383,13 @@
   delay(400);
 }

-void Sequence9()
+void Sequence7()
 {
   int lidMid = lidTo;
   int lidMid2 = lidFrom + lidRange * 0.68;
   int lidMid3 = lidFrom + lidRange * 0.77;

-  delay(1000);
+  delay(50);
   Sweep(lidServo, lidFrom, lidMid, 2000);
   delay(500);
   Sweep(lidServo, lidMid, lidMid2, 1000);
@@ -434,21 +438,63 @@
   delay(400);
 }

+void Sequence8()
+{
+  delay(1000);
+  Sweep(lidServo, lidFrom, lidTo, 30000);
+  delay(1);
+  Sweep(switchServo, switchFrom, switchTo, 5000);
+  delay(1);
+  Sweep(switchServo, switchTo, switchFrom, 5000);
+  delay(500);
+  Sweep(lidServo, lidTo, lidFrom, 1);
+  delay(300);
+}
+
+void Sequence9()
+{
+  int switchMid2 = switchTo + switchRange * 0.28;
+
+  delay(100);
+  Sweep(lidServo, lidFrom, lidTo, 1);
+  delay(200);
+  Sweep(switchServo, switchFrom, switchTo, 1);
+  delay(1000);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(110);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(500);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(110);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(500);
+  Sweep(switchServo, switchTo, switchMid2, 1);
+  delay(110);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(110);
+  Sweep(switchServo, switchTo, switchFrom, 1);
+  delay(200);
+  Sweep(lidServo, lidTo, lidFrom, 1);
+  delay(400);
+}
+
 void Sequence10()
 {
-  int lidMid = lidTo;
-
-  delay(800);
-  Sweep(lidServo, lidFrom, lidTo, 30000);
-  delay(1);
-  Sweep(switchServo, switchFrom, switchTo, 3000);
-  delay(1);
-  Sweep(switchServo, switchTo, switchFrom, 3000);
-  delay(1);
-  Sweep(lidServo, lidTo, lidMid, 30000);
-  delay(1);
-  Sweep(lidServo, lidMid, lidFrom, 1);
-  delay(300);
+  int switchMid2 = switchTo + switchRange * 0.35;
+
+  delay(100);
+  Sweep(lidServo, lidFrom, lidTo, 1);
+  delay(200);
+  Sweep(switchServo, switchFrom, switchTo, 1);
+  delay(2000);
+  Sweep(switchServo, switchTo, switchMid2, 6000);
+  delay(500);
+  Sweep(switchServo, switchMid2, switchTo, 1);
+  delay(2000);
+  Sweep(switchServo, switchTo, switchFrom, 2000);
+  delay(200);
+  Sweep(lidServo, lidTo, lidFrom, 1);
+  delay(400);
 }

 void Sweep(Servo& servo, int from, int to, int usec)
@@ -463,7 +509,7 @@
   }
   else
   {
-    for (int pos = from; pos>=to; pos--)
+    for (int pos = from; pos >= to; pos--)
     {
       servo.writeMicroseconds(pos);
       delayMicroseconds(usec);


Adding comment to ignore SSL in sample code. (#7994)

--- libraries/ESP8266HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino
+++ libraries/ESP8266HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino
@@ -44,6 +44,8 @@
     std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);

     client->setFingerprint(fingerprint);
+    // Or, if you happy to ignore the SSL certificate, then use the following line instead:
+    // client->setInsecure();

     HTTPClient https;


LoRa beacon: disable header and CRC.

LoRa beacon: disable header and CRC.

--- microcontrollers/arduino-esp32/lora32-morse-beacon/lora32-morse-beacon.ino
+++ microcontrollers/arduino-esp32/lora32-morse-beacon/lora32-morse-beacon.ino
@@ -56,6 +56,7 @@
     //LoRa.setSignalBandwidth(62500);
     LoRa.setCodingRate4(5);
     LoRa.setSpreadingFactor(6);
+    LoRa.disableCrc();

     Serial.println("init ok");

@@ -80,9 +81,9 @@
     // turn the LED on (HIGH is the voltage level)
     digitalWrite(LED, HIGH);

-    LoRa.setPreambleLength(plen);
-    LoRa.beginPacket();
-    LoRa.write(' ');
+    LoRa.setPreambleLength(plen);   // preamble length
+    LoRa.beginPacket(true);         // no header
+    LoRa.write(0);                  // data 1 byte
     LoRa.endPacket();

     // turn the LED off by making the voltage LOW


added CAN proxy code

added CAN proxy code

--- uartpilot_proxy/uartpilot_proxy.ino
+++ uartpilot_proxy/uartpilot_proxy.ino
@@ -5,14 +5,17 @@
  * Licensed under MIT license, see included file LICENSE or
  * http://opensource.org/licenses/MIT
  *
- * Arduino application which proxies/modifies CAN messages based on commands
+ * Arduino application which proxies/modifies CAN messages based on commands
  * received on the serial interface.
  */

 #include <UARTPilot.h>
+#include <due_can.h>

 UARTPilot::Parser parser;
-UARTPilot::Msg_COD_t* p_msg;
+UARTPilot::Msg_COD_t* p_cod;
+
+CAN_FRAME frame;

 /**
  * Standard arduino setup(), initialize things
@@ -20,7 +23,13 @@
 void setup() {
   Serial.begin(115200);
   Serial1.begin(115200);
-  p_msg = (UARTPilot::Msg_COD_t*) malloc(sizeof(p_msg));
+
+  Can0.begin(CAN_BPS_250K);
+  Can1.begin(CAN_BPS_250K);
+
+  p_cod = (UARTPilot::Msg_COD_t*) malloc(sizeof(p_cod));
+  p_cod->speed = 0;
+  p_cod->steerangle = 0;
 }

 /**
@@ -33,9 +42,36 @@
     msg_len = parser.parse(Serial1.read());
   }

-  if (msg_len > 0 && parser.isChecksumCorrect() && parser.getMsgCOD(p_msg)) {
-    Serial.print(p_msg->speed);
-    Serial.println(p_msg->steerangle);
+  if (msg_len > 0 && parser.isChecksumCorrect()) parser.getMsgCOD(p_cod);
+
+  if (Can0.rx_avail()) {
+    Can0.get_rx_buff(frame);
+
+    switch (frame.id) {
+      case 0x382:
+        frame.data.bytes[3] = p_cod->steerangle;
+        break;
+      case 0x282:
+        frame.data.bytes[1] = p_cod->steerangle != 0 ? 0xC0 : 0;
+        break;
+    }
+
+    Can1.sendFrame(frame);
+  }
+
+  if (Can1.rx_avail()) {
+    Can1.get_rx_buff(frame);
+
+    switch (frame.id) {
+      case 0x382:
+        frame.data.bytes[3] = p_cod->steerangle;
+        break;
+      case 0x282:
+        frame.data.bytes[1] = p_cod->steerangle != 0 ? 0xC0 : 0;
+        break;
+    }
+
+    Can0.sendFrame(frame);
   }
 }


enabled to control servo with ros

enabled to control servo with ros

--- jsk_2016_01_baxter_apc/firmware/arm_manager.ino
+++ jsk_2016_01_baxter_apc/firmware/arm_manager.ino
@@ -43,7 +43,12 @@

 void servoCb(const std_msgs::Int16& angle_msg)
 {
-    myservo.write(angle_msg.data);
+    int angle;
+    angle = angle_msg.data;
+    if (angle < 0) angle = 0;
+    if (angle > 180) angle = 180;
+
+    myservo.write(angle);
 }

 ros::Subscriber<std_msgs::Int16> servo_sub("vacuum_gripper/limb/right/servo", &servoCb);
@@ -89,7 +94,7 @@

 void init_servo()
 {
-    myservo.attach(9);
+    myservo.attach(5);
 }

 void initBME()


General tweaks & fixes

General tweaks & fixes

--- apollo/apolloClient/apolloClient.ino
+++ apollo/apolloClient/apolloClient.ino
@@ -56,7 +56,6 @@

 char byteStream() {
-  //Serial.println("byteStream called");
   char a = client.read();
   Serial.print(a);
   return a;
@@ -104,7 +103,6 @@
 }

 void loop() {
-  //Serial.println(F("THIS PROGRAM HAS BEEN UPDATED!!!!"));
   // Leave this here
   apolloUpdate();

@@ -120,7 +118,7 @@
   if (updateNow) {
     resetEthernet(A5);
     delay(2000);
-    Serial.println(F("apollo update Initialized"));
+    Serial.println(F("Apollo init"));

     // Init SD Card
     // initialize the SD card
@@ -128,7 +126,6 @@

     // initialize a FAT16 volume
     Fat16::init(&card);
-

     // create a new file
     Fat16 file;
@@ -144,7 +141,6 @@
       client.println(); //end of get request

       // Wait for http reponse and remove header
-      Serial.println(F("waiting for data"));
       while (client.connected()) {
         while (client.available()) {
           if (checkBytes(crnl, byteStream)) {
@@ -153,7 +149,6 @@
         }
       }
 end:
-      Serial.println(F("done waiting for data"));
       Serial.println();
       Serial.print(F("File size = "));

@@ -194,21 +189,19 @@
       computedChecksum |= sum2;

       Serial.println();
-      Serial.print(F("Computed Checksum = "));
-      Serial.println(computedChecksum);
-
+      Serial.print(F("File check: "));
       if (prependedSize == bytesReceived && checksum == computedChecksum) {
-        Serial.println(F("File check: OK"));
+        Serial.println(F("OK"));
       }
       else if (checksum != computedChecksum) {
-        Serial.println(F("File check: CHECKSUM ERROR!"));
+        Serial.println(F("CHECKSUM ERROR!"));
       }
       else if (prependedSize != bytesReceived) {
-        Serial.println(F("File check: FILE SIZE ERROR!"));
+        Serial.println(F("SIZE ERROR!"));
       }

       if (!client.connected()) {
-        Serial.println(F("Disconecting from update server"));
+        Serial.println(F("Disconecting"));
         client.stop();
       }

@@ -223,7 +216,7 @@

     }
     else {
-      Serial.println(F("connection failed")); //error message if no client connect
+      Serial.println(F("Connection failed")); //error message if no client connect
       Serial.println();
       Serial.println(F("Resetting..."));
       delay(200);


docs: fix typo in example sketch

docs: fix typo in example sketch

--- examples/advertising/setBeanName.ino
+++ examples/advertising/setBeanName.ino
@@ -8,7 +8,7 @@

   // Build a new name for Bean using the temperature
   String name = "Temp is ";
-  name += temp;
+  name += temperature;
   name += " C";

   // Set Bean's new name


Small improvements to the demo tune.

Small improvements to the demo tune.

--- examples/DemoTune/DemoTune.ino
+++ examples/DemoTune/DemoTune.ino
@@ -43,7 +43,7 @@
 };

 const String tuneData[3] = {
-  "t150m200o5l8egredgrdcercer<ba>aragdefefedr4.regredgrdcercer<ba>aragdedcr4.c<g>cea>cr<ag>cr<gfarfearedgrdcfrc<bagab>cdfegredgrdcercer<ba>aragdedcr4.cro3c2",
+  "t150m200o5l8egredgrdcercer<ba>aagdefefedr4.regredgrdcercer<ba>aagdedcr4.c<g>cea>cr<ag>cr<gfarfearedgrdcfrc<bagab>cdfegredgrdcercer<ba>aagdedcr4.cro3c2",
   "m85o3l8crer
dr<ar>cr<grbrfr>cr<grbr>crer<gb>dgcrer
dr<ar>cr<grbrfr>cr<grbr>ceger4.rfrafergedrfdcrec
d<bar>c<agrgd<gr4.o4crer
dr<ar>cr<grbrfr>cr<grbr>cege",
   "m85o3l8r4gr4.gr4.er4.err4fr4.gr4.gr4.grr4gr4.er4.er4.frr4gr4>ccr4ccr4<aarraar4ggr4ffr4.ro4gab>dr4.r<gr4.gr4.err4er4.fr4.g"
 };


add: completed adaptive modifiers (untested)

--- mods/AdaptiveMod/mod_AdaptiveMod.ino
+++ mods/AdaptiveMod/mod_AdaptiveMod.ino
@@ -17,6 +17,8 @@

 const int AdaptiveModMinAddr = 801;
 const int MaxAdaptiveMod = 18;
+
+const int AMMods[14] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, KEY_LEFT_CTRL, KEY_LEFT_SHIFT, KEY_LEFT_ALT, KEY_LEFT_GUI]

 #define modMethod(str) conca(mod_modname, str)

@@ -47,10 +49,19 @@
   {
     if (type == 8)
     {
-      byte switchLay = val & 0xf; // splits byte and get first 4 bits as number
+      byte switchID = val & 0xf; // splits byte and get first 4 bits as number

       PressedKey = false;
-      TempLayer = switchLay; // switches layer when key is held
+      if (switchID > 10)
+      {
+        Keyboard.press(AMMods[switchID]);
+
+      }
+      else
+      {
+
+        TempLayer = switchID; // switches layer when key is held
+      }
       ReleaseAllKey();

     }
@@ -73,7 +84,18 @@
       {
         Keyboard.write(modMethod(GetEEPROM)(AdapterID)); // outputs key from EEPROM
       }
-      TempLayer = KeyLayer; // resets layer back to default
+
+      if (switchID > 10)
+      {
+        // do nothing
+
+      }
+      else
+      {
+
+        TempLayer = KeyLayer; // resets layer back to default
+      }
+
       ReleaseAllKey(); // DEPRECIATED END
     }
   }
@@ -97,13 +119,13 @@
     input = input.substring(input.indexOf('(')+1);
     byte z = input.substring(0, input.indexOf('(')).toInt();
     input = input.substring(input.indexOf('(')+1);
-    byte lay = input.substring(0, input.indexOf('(')).toInt();
+    byte key = input.substring(0, input.indexOf('(')).toInt();
     input = input.substring(input.indexOf('(')+1);
     byte id = input.substring(0, input.indexOf('(')).toInt();
     input = input.substring(input.indexOf('(')+1);
     byte type = input.toInt();

-    byte val = (lay << 4) | id;
+    byte val = (key << 4) | id;

     SetEEPROM(x, y, z, val, type);
     Serial.print("set key(");
@@ -130,11 +152,12 @@
   }
   else if (input.startsWith("uniqueksetadaptivechar"))
   {
-
     input = input.substring(input.indexOf('(')+1);
     byte id = input.substring(0, input.indexOf('(')).toInt();
     input = input.substring(input.indexOf('(')+1);
     byte val = input.toInt();
+
+

     if (id < MaxAdaptiveMod)
     {


Remove unused constants and functions in firm

--- jsk_arc2017_baxter/firmware/gripper_v6/sensor_manager_right/sensor_manager_right.ino
+++ jsk_arc2017_baxter/firmware/gripper_v6/sensor_manager_right/sensor_manager_right.ino
@@ -9,8 +9,6 @@
 #define NSENSORS 5
 #define PCA9547D_RESET 32
 #define VCNL4010_ADDRESS 0x13
-#define COMMAND_0 0x80  // starts measurements, relays data ready info
-#define PRODUCT_ID 0x81  // product ID/revision ID, should read 0x21
 #define IR_CURRENT 0x83  // sets IR current in steps of 10mA 0-200mA
 #define IR_CURRENT_VALUE 8  // range = [0, 20]. current = value * 10 mA
 #define AMBIENT_PARAMETER 0x84  // Configures ambient light measures
@@ -56,7 +54,7 @@
   WIRE.beginTransmission(VCNL4010_ADDRESS);
   WIRE.write(address);

-  debug_endTransmission(WIRE.endTransmission());
+  WIRE.endTransmission();
   WIRE.requestFrom(VCNL4010_ADDRESS, 1);

   while (!WIRE.available());
@@ -70,19 +68,7 @@
   WIRE.beginTransmission(VCNL4010_ADDRESS);
   WIRE.write(address);
   WIRE.write(data);
-  return debug_endTransmission(WIRE.endTransmission());
-}
-
-unsigned int readAmbient()
-{
-  byte temp = readByte(0x80);
-  writeByte(0x80, temp | 0x10);  // command the sensor to perform ambient measure
-
-  while (!(readByte(0x80) & 0x40)); // wait for the proximity data ready bit to be set
-  unsigned int data = readByte(0x85) << 8;
-  data |= readByte(0x86);
-
-  return data;
+  return WIRE.endTransmission();
 }

 unsigned int readProximity()
@@ -97,31 +83,6 @@

   return data;
 }
-
-byte debug_endTransmission(int errcode)
-{
-  switch (errcode)
-  {
-      // https://www.arduino.cc/en/Reference/WireEndTransmission
-    case 0:
-      //Serial.println("CAVOK");
-      break;
-    case 1:
-      //Serial.println("data too long to fit in transmit buffer ");
-      break;
-    case 2:
-      //Serial.println("received NACK on transmit of address ");
-      break;
-    case 3:
-      //Serial.println("received NACK on transmit of data");
-      break;
-    case 4:
-      //Serial.println("other error");
-      break;
-  }
-  return errcode;
-}
-

 void measure_proximity()
 {


begin converting to serial lcd

begin converting to serial lcd

--- main/main.ino
+++ main/main.ino
@@ -1,10 +1,12 @@
 #include <mcp_can.h>
 #include <mcp_can_dfs.h>
-#include <LiquidCrystal.h>
+//#include <LiquidCrystal.h>
+#include <SoftwareSerial.h>

 // SET UP PINS ///////////////////////////////////////////

-LiquidCrystal lcd(14, 3, 4, 5, 6, 7); //RS,EN,DB4,DB5,DB6,DB7
+//LiquidCrystal lcd(14, 3, 4, 5, 6, 7); //RS,EN,DB4,DB5,DB6,DB7
+SoftwareSerial lcd(0,3);
 const byte LED_PIN = 15;
 const byte SPI_CS_PIN = 10;

@@ -183,12 +185,27 @@
   pinMode(GAUGE_PIN, INPUT_PULLUP);
   //digitalWrite(MODE_PIN, INPUT_PULLUP);

-  lcd.createChar(0, fill1);
-  lcd.createChar(1, fill2);
-  lcd.createChar(2, fill3);
-  lcd.createChar(3, fill4);
-  lcd.createChar(4, fill5);
-  lcd.createChar(5, fillMiddle);
+  // create a custom character
+  lcd.write(0xFE);
+  lcd.write(0x4E);
+  lcd.write((uint8_t)0);     // location #0
+  lcd.write((uint8_t)0x00);  // 8 bytes of character data
+  lcd.write(0x0A);
+  lcd.write(0x15);
+  lcd.write(0x11);
+  lcd.write(0x11);
+  lcd.write(0x0A);
+  lcd.write(0x04);
+  lcd.write((uint8_t)0x00);
+
+
+
+  //lcd.createChar(0, fill1);
+  //lcd.createChar(1, fill2);
+  //lcd.createChar(2, fill3);
+  //lcd.createChar(3, fill4);
+  //lcd.createChar(4, fill5);
+  //lcd.createChar(5, fillMiddle);

   octoModeGauges[0][0] = &engine_rpm;
   octoModeGauges[0][1] = &engine_map;
@@ -241,18 +258,47 @@
   allGauges[18] = &engine_tcr;
   allGauges[19] = &engine_lct;

-  lcd.begin(20, 4);
-
+  lcd.begin(9600);
+  // set the size of the display
+  lcd.write(0xFE);
+  lcd.write(0xD1);
+  lcd.write(20);
+  lcd.write(4);
+
+  // set the contrast
+  lcd.write(0xFE);
+  lcd.write(0x50);
+  lcd.write(240);
+  delay(10);
+
+  // set the brightness
+  lcd.write(0xFE);
+  lcd.write(0x99);
+  lcd.write(255);
+  delay(10);
+
+  //lcd.write(0xFE);
+  //lcd.write(0x58);
+
+  clearSerialLCD(lcd);
+
+  setSerialCursor(lcd, 0, 0);
+  lcd.print("Starting up...");

   Serial.begin(115200);
   while (CAN_OK != CAN.begin(CAN_500KBPS)) {
     lcd.print(F("Waiting for CAN bus"));
-    lcd.setCursor(0, 0);
+    setSerialCursor(lcd,0, 0);
     delay(100);
   }
-
-  lcd.clear();
+    setSerialCursor(lcd,0, 0);
+    lcd.print(F("Connected to ECU"));
+    setSerialCursor(lcd,0, 0);
+
+  //lcd.clear();
+  //lcd.write(0xFE);
+  //lcd.write(0x58);

   /*currentModeButton = digitalRead(MODE_PIN);
   previousModeButton = currentModeButton;
@@ -368,32 +414,34 @@
   quadModeReady = false;
   octoModeReady = false;
   diagModeReady = false;
-  lcd.clear();
+  //lcd.clear();
+  lcd.write(0xFE);
+  lcd.write(0x58);
 }

 void draw_dual_gauges() {
   if(!dualModeReady) {
     clear_mode();
-    lcd.setCursor(0, 0);
+    setSerialCursor(lcd,0, 0);
     lcd.print(dualModeGauges[dualIndex][0]->shortLabel);
-    lcd.setCursor(0, 2);
+    setSerialCursor(lcd,0, 2);
     lcd.print(dualModeGauges[dualIndex][1]->shortLabel);
     dualModeReady = true;
   }
   //if(dualModeGauges[0][0]->currentValue != dualModeGauges[dualIndex][0]->previousValue) {
-    lcd.setCursor(4, 0);
+    setSerialCursor(lcd,4, 0);
     if(is_current_value_shorter(*dualModeGauges[0][0])) {
       lcd.print(F("     "));
-      lcd.setCursor(4, 0);
+      setSerialCursor(lcd,4, 0);
     }
     lcd.print(dualModeGauges[dualIndex][0]->currentValue, dualModeGauges[dualIndex][0]->decimalPlaces);
     draw_bar(*dualModeGauges[dualIndex][0], 1, 0);
   //}
   //if(dualModeGauges[0][1]->currentValue != dualModeGauges[0][1]->previousValue) {
-    lcd.setCursor(4, 2);
+    setSerialCursor(lcd,4, 2);
     if(is_current_value_shorter(*dualModeGauges[dualIndex][1])) {
       lcd.print(F("     "));
-      lcd.setCursor(4, 2);
+      setSerialCursor(lcd,4, 2);
     }
     lcd.print(dualModeGauges[dualIndex][1]->currentValue, dualModeGauges[dualIndex][1]->decimalPlaces);
     draw_bar(*dualModeGauges[dualIndex][1], 3, 0);
@@ -403,45 +451,45 @@
 void draw_quad_gauges() {
   if(!quadModeReady) {
     clear_mode();
-    lcd.setCursor(0, 0);
+    setSerialCursor(lcd,0, 0);
     lcd.print(quadModeGauges[quadIndex][0]->shortLabel);
-    lcd.setCursor(0, 1);
+    setSerialCursor(lcd,0, 1);
     lcd.print(quadModeGauges[quadIndex][1]->shortLabel);
-    lcd.setCursor(0, 2);
+    setSerialCursor(lcd,0, 2);
     lcd.print(quadModeGauges[quadIndex][2]->shortLabel);
-    lcd.setCursor(0, 3);
+    setSerialCursor(lcd,0, 3);
     lcd.print(quadModeGauges[quadIndex][3]->shortLabel);
     quadModeReady = true;
   }

-  lcd.setCursor(4, 0);
+  setSerialCursor(lcd,4, 0);
   if(is_current_value_shorter(*quadModeGauges[quadIndex][0])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 0);
+    setSerialCursor(lcd,4, 0);
   }
   lcd.print(quadModeGauges[quadIndex][0]->currentValue, quadModeGauges[quadIndex][0]->decimalPlaces);
   draw_bar(*quadModeGauges[quadIndex][0], 0, 9);

-  lcd.setCursor(4, 1);
+  setSerialCursor(lcd,4, 1);
   if(is_current_value_shorter(*quadModeGauges[quadIndex][1])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 1);
+    setSerialCursor(lcd,4, 1);
   }
   lcd.print(quadModeGauges[quadIndex][1]->currentValue, quadModeGauges[quadIndex][1]->decimalPlaces);
   draw_bar(*quadModeGauges[quadIndex][1], 1, 9);

-  lcd.setCursor(4, 2);
+  setSerialCursor(lcd,4, 2);
   if(is_current_value_shorter(*quadModeGauges[quadIndex][2])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 2);
+    setSerialCursor(lcd,4, 2);
   }
   lcd.print(quadModeGauges[quadIndex][2]->currentValue, quadModeGauges[quadIndex][2]->decimalPlaces);
   draw_bar(*quadModeGauges[quadIndex][2], 2, 9);

-  lcd.setCursor(4, 3);
+  setSerialCursor(lcd,4, 3);
   if(is_current_value_shorter(*quadModeGauges[quadIndex][3])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 3);
+    setSerialCursor(lcd,4, 3);
   }
   lcd.print(quadModeGauges[quadIndex][3]->currentValue, quadModeGauges[quadIndex][3]->decimalPlaces);
   draw_bar(*quadModeGauges[quadIndex][3], 3, 9);
@@ -452,91 +500,91 @@
   if(!octoModeReady) {
     clear_mode();
     //left column of labels
-    lcd.setCursor(0, 0);
+    setSerialCursor(lcd,0, 0);
     lcd.print(octoModeGauges[octoIndex][0]->shortLabel);
-    lcd.setCursor(0, 1);
+    setSerialCursor(lcd,0, 1);
     lcd.print(octoModeGauges[octoIndex][1]->shortLabel);
-    lcd.setCursor(0, 2);
+    setSerialCursor(lcd,0, 2);
     lcd.print(octoModeGauges[octoIndex][2]->shortLabel);
-    lcd.setCursor(0, 3);
+    setSerialCursor(lcd,0, 3);
     lcd.print(octoModeGauges[octoIndex][3]->shortLabel);

     //draw dividing line
-    lcd.setCursor(9, 0);
+    setSerialCursor(lcd,9, 0);
     lcd.write(byte(5));
-    lcd.setCursor(9, 1);
+    setSerialCursor(lcd,9, 1);
     lcd.write(byte(5));
-    lcd.setCursor(9, 2);
+    setSerialCursor(lcd,9, 2);
     lcd.write(byte(5));
-    lcd.setCursor(9, 3);
+    setSerialCursor(lcd,9, 3);
     lcd.write(byte(5));

     //right column of labels
-    lcd.setCursor(11, 0);
+    setSerialCursor(lcd,11, 0);
     lcd.print(octoModeGauges[octoIndex][4]->shortLabel);
-    lcd.setCursor(11, 1);
+    setSerialCursor(lcd,11, 1);
     lcd.print(octoModeGauges[octoIndex][5]->shortLabel);
-    lcd.setCursor(11, 2);
+    setSerialCursor(lcd,11, 2);
     lcd.print(octoModeGauges[octoIndex][6]->shortLabel);
-    lcd.setCursor(11, 3);
+    setSerialCursor(lcd,11, 3);
     lcd.print(octoModeGauges[octoIndex][7]->shortLabel);

     octoModeReady = true;
   }

-  lcd.setCursor(4, 0);
+  setSerialCursor(lcd,4, 0);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][0])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 0);
+    setSerialCursor(lcd,4, 0);
   }
   lcd.print(octoModeGauges[octoIndex][0]->currentValue, octoModeGauges[octoIndex][0]->decimalPlaces);

-  lcd.setCursor(4, 1);
+  setSerialCursor(lcd,4, 1);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][1])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 1);
+    setSerialCursor(lcd,4, 1);
   }
   lcd.print(octoModeGauges[octoIndex][1]->currentValue, octoModeGauges[octoIndex][1]->decimalPlaces);

-  lcd.setCursor(4, 2);
+  setSerialCursor(lcd,4, 2);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][2])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 2);
+    setSerialCursor(lcd,4, 2);
   }
   lcd.print(octoModeGauges[octoIndex][2]->currentValue, octoModeGauges[octoIndex][2]->decimalPlaces);

-  lcd.setCursor(4, 3);
+  setSerialCursor(lcd,4, 3);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][3])) {
     lcd.print(F("     "));
-    lcd.setCursor(4, 3);
+    setSerialCursor(lcd,4, 3);
   }
   lcd.print(octoModeGauges[octoIndex][3]->currentValue, octoModeGauges[octoIndex][3]->decimalPlaces);

-  lcd.setCursor(15, 0);
+  setSerialCursor(lcd,15, 0);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][4])) {
     lcd.print(F("     "));
-    lcd.setCursor(15, 0);
+    setSerialCursor(lcd,15, 0);
   }
   lcd.print(octoModeGauges[octoIndex][4]->currentValue, octoModeGauges[octoIndex][4]->decimalPlaces);

-  lcd.setCursor(15, 1);
+  setSerialCursor(lcd,15, 1);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][5])) {
     lcd.print(F("     "));
-    lcd.setCursor(15, 1);
+    setSerialCursor(lcd,15, 1);
   }
   lcd.print(octoModeGauges[octoIndex][5]->currentValue, octoModeGauges[octoIndex][5]->decimalPlaces);

-  lcd.setCursor(15, 2);
+  setSerialCursor(lcd,15, 2);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][6])) {
     lcd.print(F("     "));
-    lcd.setCursor(15, 2);
+    setSerialCursor(lcd,15, 2);
   }
   lcd.print(octoModeGauges[octoIndex][6]->currentValue, octoModeGauges[octoIndex][6]->decimalPlaces);

-  lcd.setCursor(15, 3);
+  setSerialCursor(lcd, 15, 3);
   if(is_current_value_shorter(*octoModeGauges[octoIndex][7])) {
     lcd.print(F("     "));
-    lcd.setCursor(15, 3);
+    setSerialCursor(lcd, 15, 3);
   }
   lcd.print(octoModeGauges[octoIndex][7]->currentValue, octoModeGauges[octoIndex][7]->decimalPlaces);
 }
@@ -721,7 +769,7 @@
     //relax homeboy
   }*/
   if(true){
-    lcd.setCursor(column, row);
+    setSerialCursor(lcd, column, row);

     //delete previous bar if it is too long
     //todo optimize to only delete the needful
@@ -744,7 +792,7 @@
       else {
         lcd.write("           ");           //hard-coded value for quad mode
       }
-      lcd.setCursor(column, row);
+      setSerialCursor(lcd, column, row);
     }

     //calculate bars
@@ -766,7 +814,7 @@
       partialBars = 0;
     }

-    lcd.setCursor(column, row);
+    setSerialCursor(lcd, column, row);
     for(int i = 0; i < fullBars; i++) {
       lcd.write(byte(4));
     }
@@ -799,3 +847,15 @@
   return inError;
 }

+void setSerialCursor(SoftwareSerial lcd, int column, int row) {
+  lcd.write(0xFE);
+  lcd.write(0x47);
+  lcd.write((byte)column+1);
+  lcd.write((byte)row+1);
+}
+
+void clearSerialLCD(SoftwareSerial lcd) {
+  lcd.write(0xFE);
+  lcd.write(0x58);
+}
+


Removed hard coded arg2

Removed hard coded arg2

--- teensy3r1/blue/absdev/absdev.ino
+++ teensy3r1/blue/absdev/absdev.ino
@@ -28,7 +28,7 @@
 int linecount = 0;
 int cycle = 0;

-unsigned char cmdBuff[200];
+/* unsigned */ char cmdBuff[200];

 int cmdPtr = 0;

@@ -127,7 +127,7 @@
     if (cmdPtr > 2){
       char key = cmdBuff[0];
       char delim = cmdBuff[1];
-      strcpy(argstr, "42");
+      strcpy(argstr, cmdBuff+2);
       val = atoi(argstr);
       Serial1.print(key);
       Serial1.print("=");


Rmove debug

Rmove debug

--- examples/cobra.ino
+++ examples/cobra.ino
@@ -356,7 +356,6 @@

 void setup()
 {
-  teensy_sync();
   GD.begin();
   LOAD_ASSETS();
   GD.BitmapHandle(BACKGROUND_HANDLE);
@@ -445,8 +444,6 @@
 #endif        // }JCB

   GD.swap();
-  if (t & 1)
-    GD.dumpscreen();

   t++;
 }


Update Cyclone_PCB_Factory.ino

Update Cyclone_PCB_Factory.ino

--- Cyclone_PCB_Factory/Cyclone_PCB_Factory.ino
+++ Cyclone_PCB_Factory/Cyclone_PCB_Factory.ino
@@ -1,556 +1,557 @@
-//------------------------------------------------------------------------------
-// LIBRERIAS
-//------------------------------------------------------------------------------
-#include <Servo.h>
-
-//------------------------------------------------------------------------------
-// CONSTANTES SOFTWARE
-//------------------------------------------------------------------------------
-
-
-// BASADO EN
-/*
-  https://thingiverse-production-new.s3.amazonaws.com/assets/87/b0/2c/f5/4c/CheatSheet.pdf
-*/
-
-#define BAUD 115200
-#define MAX_BUF 100
-
-#define STEPS_PER_MM_X (float)(12500.0/87.0)
-#define STEPS_PER_MM_Y (float)(100000.0/677.0)
-//fijar estos 3 parametros de acuerdo a especificaciones maximas del motor y/o del ensamble mecanico
-#define MAX_FEEDRATE   650.0
-#define MIN_FEEDRATE   50.0
-#define DEFAULT_FEEDRATE   400.0
-#define MIN_STEP_DELAY 1000000.0 / MAX_FEEDRATE
-
-#define Y_PASO_POR_MM (float)(100000.0/677.0)
-#define Y_MM_POR_PASO (float)(677.0/100000.0)
-#define X_PASO_POR_MM (float)(12500.0/87.0)
-#define X_MM_POR_PASO (float)(87.0/12500.0)
-
-#define Z_UP 15
-#define Z_DOWN 0
-
-//Servo Motor en Z
-Servo MiServo;
-
-// velocidades globales
-
-float fr =     DEFAULT_FEEDRATE;  // version humano
-long  step_delay = 1000000 / DEFAULT_FEEDRATE; // version maquina
-
-// Ubicacion global
-float px, py;
-// Modo Absoluto o relativo
-char mode_abs = 1; // 1 absoluto(default) 0 relativo
-
-//Buffer de comunicacion y variales para recorrerlo
-char  buffer[MAX_BUF];  // Almacena una linea entera
-int   iterador;            // how much is in the buffer
-
-//Modo Verbose
-unsigned int verboseVar = 0; // 1 -> Activo 0 -> Desactivado
-
-//Milimitros (mm) o Pulgadas (in)
-unsigned int mm = 1; // 1 -> Modo en mm 0 -> Modo en in
-
-//------------------------------------------------------------------------------
-// CONSTANTES HARDWARE
-//------------------------------------------------------------------------------
-
-#define M1_STEP 2     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
-#define M1_DIR  5     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
-#define M1_ENA  8     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
-
-#define M2_STEP 3     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
-#define M2_DIR  6     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
-#define M2_ENA  8     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
-
-#define ENDSTOP_X 11
-#define ENDSTOP_Y 10
-
-#define AXIS_Z 9
-
-//------------------------------------------------------------------------------
-// METODOS HARDWARE
-//------------------------------------------------------------------------------
-
-void m1step(int dir) {
-  digitalWrite(M1_ENA, LOW);
-  digitalWrite(M1_DIR, dir);
-  digitalWrite(M1_STEP, HIGH);
-  digitalWrite(M1_STEP, LOW);
-}
-
-void m2step(int dir) {
-  digitalWrite(M2_ENA, LOW);
-  digitalWrite(M2_DIR, dir);
-  digitalWrite(M2_STEP, HIGH);
-  digitalWrite(M2_STEP, LOW);
-}
-
-void zAxisMove(float dir) {
-  if (dir > 0) {
-    MiServo.write(Z_UP);
-    delay(100);
-    if (verboseVar == 1)
-      Serial.println(F("Motor Z Movido arriba."));
-  }
-  else {
-    if (dir < 0) {
-      MiServo.write(Z_DOWN);
-      delay(100);
-      if (verboseVar == 1)
-        Serial.println(F("Motor Z Movido abajo."));
-    }
-  }
-}
-
-void disable() {
-  digitalWrite(M1_ENA, HIGH);
-  digitalWrite(M2_ENA, HIGH);
-  if (verboseVar == 1)
-    Serial.println(F("Motores Desactivados."));
-}
-
-void enable() {
-  digitalWrite(M1_ENA, LOW);
-  digitalWrite(M2_ENA, LOW);
-  if (verboseVar == 1)
-    Serial.println(F("Motores Activados."));
-}
-
-void setup_controller() {
-  pinMode(M1_ENA, OUTPUT);
-  pinMode(M2_ENA, OUTPUT);
-  pinMode(M1_STEP, OUTPUT);
-  pinMode(M2_STEP, OUTPUT);
-  pinMode(M1_DIR, OUTPUT);
-  pinMode(M2_DIR, OUTPUT);
-  pinMode(ENDSTOP_X, INPUT_PULLUP);
-  pinMode(ENDSTOP_Y, INPUT_PULLUP);
-  MiServo.attach(9);
-  MiServo.write(Z_UP);
-}
-
-
-
-
-
-//------------------------------------------------------------------------------
-// METODOS SOFTWARE
-//------------------------------------------------------------------------------
-
-void help() {
-  Serial.println(F("Este es un ejemplo de funcion de ayuda: \n"));
-  Serial.println(F("Comandos soportados:"));
-  Serial.println(F("G00 [X(steps)] [Y(steps)] [F(feedrate)]; - fast line"));
-  Serial.println(F("G01 [X(steps)] [Y(steps)] [F(feedrate)]; - fast line igual que G00 "));
-  Serial.println(F("G04 P[seconds]; - delay"));
-  Serial.println(F("G20 Cambio a pulgadas (in)."));
-  Serial.println(F("G21 Cambio a milimetros (mm)."));
-  Serial.println(F("G28; -Volver a home"));
-  Serial.println(F("G90; - Modo absoluto"));
-  Serial.println(F("G91; - Modo relativo"));
-  Serial.println(F("G92 [X(steps)] [Y(steps)]; - Cambiar setpoint"));
-  Serial.println(F("M2; -Codigo G finalizado"));
-  Serial.println(F("M17; -Habilitar motores"));
-  Serial.println(F("M18; - Deshabilitar motores"));
-  Serial.println(F("M100; - Imprimir ayuda"));
-  Serial.println(F("M111 S[Debug Level]; -Unicamente activado desactivado"));
-  Serial.println(F("M112; -Parada de emergencia"));
-  Serial.println(F("M114; - reporte de estado de la maquina"));
-  Serial.println(F("M115; Obtener informacion del software Firmeware"));
-  Serial.println(F("NOTA: TODOS LOS COMANDOS DEBEN TERMINAR CON NUEVA LINEA O -ESPACIO#-"));
-}
-
-
-
-// la funcion delayMicroseconds de arduino no funciona para valores mayores a 16k. por eso toca usar esta.
-void pause(long us) {
-  delay(us / 1000);
-  delayMicroseconds(us % 1000);
-}
-
-
-
-
-
-void feedrate(float nfr) {
-  if (fr == nfr) return;
-
-
-  if (nfr > MAX_FEEDRATE || nfr < MIN_FEEDRATE) { // depurar
-    Serial.print(F("WARNING: Feedrate debe ser mayor a  "));
-    Serial.print(MIN_FEEDRATE);
-    Serial.print(F("pero menor a  "));
-    Serial.print(MAX_FEEDRATE);
-    Serial.println(F("pasos/ssegundo. NO SE CONGIFURA NADA"));
-    return;//salir sin cambiar el valor
-  }
-  step_delay = 1000000.0 / nfr; //valor maquina
-  fr = nfr;//valor humano
-}
-
-/**
-  pos actual, util para tener pos absolutas y relativas.
-**/
-void position(float npx, float npy) {
-  px = npx;
-  py = npy;
-}
-
-
-/**
-  Usa el algoritmo de  bresenham para delinear lineas en dos motores XY
-  https://es.wikipedia.org/wiki/Algoritmo_de_Bresenham
-**/
-
-void lineaBresenhamPasos(float newx, float newy) {
-  long i;
-  long over = 0;
-
-  long dx  = newx - px;
-  long dy  = newy - py;
-  int dirx = dx > 0 ? LOW : HIGH;
-  int diry = dy > 0 ? HIGH : LOW; //diry = dy>0?LOW:HIGH; dependiendo de ensamble POR FAVOR revisar.
-  dx = abs(dx);
-  dy = abs(dy);
-
-  if (dx > dy) {
-    over = dx / 2; //OJO division entera
-    for (i = 0; i < dx; ++i) {
-      m1step(dirx);
-      over += dy;
-      if (over >= dx) {
-        over -= dx;
-        m2step(diry);
-      }
-      pause(step_delay);
-    }
-
-  } else {/*dx<=dy*/
-    over = dy / 2;
-    for (i = 0; i < dy; ++i) {
-      m2step(diry);
-      over += dx;
-      if (over >= dy) {
-        over -= dy;
-        m1step(dirx);
-      }
-      pause(step_delay);
-    }
-  }
-  px = newx;
-  py = newy;
-}
-
-
-
-/**
-  Busca el caracter /code/ en la variable  buffer global,  y  retorna el flotante que encuentre a continuacion
-  Si no se encuentra nada se retorna /val/
-**/
-float parsenumber(char code, float val) {
-  char *ptr = &buffer[0];
-  while (ptr != NULL && *ptr && ptr < buffer + iterador) {
-    if (*ptr == code) {
-      return atof(ptr + 1);
-    }
-    ptr++;
-  }
-  return val;
-}
-
-
-/**
-  Escribe en el serial el codigo y el valor decifrado, útil para hacer depuracion
-*/
-void output(const char *code, float val) {
-  Serial.print(code);
-  Serial.println(val);
-}
-
-
-/**
-  Imprime la configuracion actual.
-*/
-void where() {
-  output("X_mm ", px / STEPS_PER_MM_X);
-  output("Y_mm", py / STEPS_PER_MM_Y);
-  output("X_ST", px);
-  output("Y_ST", py);
-  output("F", fr);
-  Serial.println(mode_abs ? "MODO ABS" : "MODO REL");
-  Serial.println(mm ? "Milimetros" : "Pulgadas");
-}
-/*
-  Home: Movimiento de los ejes X y Y hacia el cero cero de la maquina
-*/
-void homes () {
-
-  zAxisMove(1);
-
-  while (digitalRead(ENDSTOP_X) == HIGH) {
-    m1step(HIGH);
-    pause(5000);
-  }
-  while (digitalRead(ENDSTOP_Y) == HIGH) {
-    m2step(LOW);
-    pause(5000);
-  }
-
-  pause(100000);
-
-  for (int i = 0; i < 300; i++) {
-    m1step(LOW);
-    pause(10000);
-    m2step(HIGH);
-    pause(10000);
-  }
-
-  while (digitalRead(ENDSTOP_X) == HIGH) {
-    m1step(HIGH);
-    pause(20000);
-  }
-  if (verboseVar == 1)
-    Serial.print(F("FIN CALIBRACION EJE X...\n"));
-  while (digitalRead(ENDSTOP_Y) == HIGH) {
-    m2step(LOW);
-    pause(20000);
-  }
-  if (verboseVar == 1)
-    Serial.print(F("FIN CALIBRACION EJE Y...\n"));
-
-  for (int i = 0; i < 300; i++) {
-    m1step(LOW);
-    pause(10000);
-    m2step(HIGH);
-    pause(10000);
-  }
-
-  disable();
-  px = 0;
-  py = 0;
-}
-
-/*
-   Firmeware version
-*/
-void firmeware() {
-  Serial.print(F("-------------VERSION firmeware-----------------\n"));
-  Serial.print(F("-> Version del software: 1.30\n"));
-  Serial.print(F("Realizado por: \n"));
-  Serial.print(F("Francisco Calderon.\n"));
-  Serial.print(F("Modificado por: \n"));
-  Serial.print(F("Alejandro Castro, Oscar Mendez y Daniel Pineda.\n"));
-  Serial.print(F("Diseno de la maquina fisica:\n"));
-  Serial.print(F(" http://reprap.org/wiki/Cyclone_PCB_Factory\n"));
-  Serial.print(F("----------------------------------------------------\n"));
-}
-
-/**
-   borra el buffer de entrada y envia el caracter de nueva linea de comandos.
-*/
-void ready() {
-  iterador = 0; // reinicia el buffer de entrada
-  Serial.print(F(">"));  // envia el caracter > para que se envie nueva linea
-}
-
-
-/**
-  Lee el buffer de entrada y reconoce los comandos de haberlos.
-  NOTA: solo soporta un comando G o M por linea.
-*/
-void processCommand() {
-  float XX, YY, ZZ;
-  int cmd = parsenumber('G', -1);
-  switch (cmd) {
-    case -1:
-      Serial.println(F("No encuentro codigo G en linea..."));
-      break;
-    case  0:
-    case  1:
-      Serial.print(F("Comando G"));
-      Serial.println(cmd);
-      feedrate(parsenumber('F', fr));
-      // no olvidar que px y py estan en pasos y los comandos llegan en mm
-      if (verboseVar == 1)
-        where();
-      XX = (parsenumber('X', (mode_abs ? px / STEPS_PER_MM_X : 0)) + (mode_abs ? 0 : px / STEPS_PER_MM_X));
-      YY = (parsenumber('Y', (mode_abs ? py / STEPS_PER_MM_Y : 0)) + (mode_abs ? 0 : py / STEPS_PER_MM_Y));
-      ZZ = (parsenumber('Z', 0));
-      if (verboseVar == 1) {
-        Serial.print(F("Moviendo a X= "));
-        Serial.print(-X_MM_POR_PASO * px + XX);
-        Serial.print(F(", Y= "));
-        Serial.print(-Y_MM_POR_PASO * py + YY);
-        Serial.print(F("Moviendo Z="));
-        if (ZZ <= 0)
-          Serial.print(F("ABAJO"));
-        else
-          Serial.print(F("ARRIBA"));
-        Serial.print(F(", F= "));
-        Serial.println(fr);
-      }
-      if (ZZ != 0)
-        zAxisMove(ZZ);
-      if (mm == 1)
-        lineaBresenhamPasos( STEPS_PER_MM_X * XX , STEPS_PER_MM_Y * YY );
-      else
-        lineaBresenhamPasos( STEPS_PER_MM_X * (XX * 25.4), STEPS_PER_MM_Y * (YY * 25.4));
-      if (mode_abs == 0)
-        position( parsenumber('X', 0),
-                  parsenumber('Y', 0) );
-      if (verboseVar == 1)
-        where();
-      break;
-    case  4:
-      Serial.print(F("Comando G"));
-      Serial.println(cmd);
-      pause(parsenumber('P', 0) * 1000);
-      Serial.println(F("Pausa realizada..."));
-      break;  // dwell
-    case 20: //a in
-      mm = 0;
-      Serial.println(F("Cambio a pulgadas."));
-      break;
-    case 21://a mm
-      mm = 1;
-      Serial.println(F("Cambio a mm."));
-      break;
-    case  28:
-      Serial.print(F("Comando G"));
-      Serial.println(cmd);
-      homes();
-      break;  // dwell
-    case 90:  //modo absoluto
-      Serial.print(F("Comando G"));
-      Serial.println(cmd);
-      Serial.println(F("modo absoluto"));
-      mode_abs = 1;
-      break;
-    case 91:  //modo relativo
-      Serial.print(F("Comando G"));
-      Serial.println(cmd);
-      Serial.println(F("modo relativo"));
-      mode_abs = 0;
-      break;
-    case 92:  // definir pos
-      Serial.print(F("Comando G"));
-      Serial.println(cmd);
-      position( parsenumber('X', 0),
-                parsenumber('Y', 0) );
-      Serial.println(F("Posicion en cero cero"));
-      break;
-    default:
-      Serial.print(F("Comando G"));
-      Serial.print(cmd);
-      Serial.println(F(" No implementado..."));
-
-      break;
-  }
-
-  cmd = parsenumber('M', -1);
-  switch (cmd) {
-    case -1:
-      Serial.println(F("Sin codigo M en linea..."));
-      break;
-    case 2:
-      Serial.println(F("Codigo G finalizado"));
-      zAxisMove(1);
-      break;
-    case 17:  // enable motors
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      enable();
-      Serial.println(F("Motores habilitados"));
-      break;
-    case 18:  // disable motors
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      disable();
-      Serial.println(F("Motores desahabilitados"));
-      break;
-    case 100:
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      help();
-      break;
-    case 111:  // debug level
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      if (parsenumber('S', -1) == 1) {
-        verboseVar = 1;
-        Serial.println(F("Modo Verbose Activado"));
-      }
-      else {
-        if ((parsenumber('S', -1) == 0)) {
-          verboseVar = 0;
-          Serial.println(F("Modo Verbose Desactivado"));
-        }
-        else
-          Serial.println(F("Opcion invalida. Ejecucion: M111 S[Debug Level]"));
-      }
-      break;
-    case 112:  // Emergency Stop
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      zAxisMove(1);
-      disable();
-      Serial.println(F("Parada de emergencia."));
-      break;
-    case 114:
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      where();
-      break;
-    case 115:
-      Serial.print(F("Comando M"));
-      Serial.println(cmd);
-      firmeware();
-      break;
-    default:
-      Serial.print(F("Comando M"));
-      Serial.print(cmd);
-      Serial.println(F(" No implementado..."));
-      break;
-  }
-}
-
-
-
-/**
-   Funcion setup arduino
-*/
-void setup() {
-  Serial.begin(BAUD);
-  setup_controller();
-  position(0, 0); // pos de inicio
-  feedrate(DEFAULT_FEEDRATE);  // inicializa con velocidad por defecto en caso de que no se provea ninguna
-  help();  // say hello
-  ready();
-}
-
-/**
-   Funcion loop de arduino
-*/
-void loop() {
-  while (Serial.available() > 0) { // Si algo esta disponible
-    char c = Serial.read(); // lea
-    Serial.print(c);  // echo
-    if (iterador < MAX_BUF - 1)
-      buffer[iterador++] = c; // guarde y aumente iterador
-    if ((c == '\n') || (c == '\r') || (c == '#') )
-    { // si se recibe una linea entera
-      buffer[iterador] = 0; // finalice el buffer con 0
-      Serial.print(F("--\r\n"));  // echo de un caracter de return y nueva linea
-      processCommand();  // procese el comando
-      ready(); // pida nuevo comando.
-    }
-  }
-}
-
-
-
+//------------------------------------------------------------------------------
+// LIBRERIAS
+//------------------------------------------------------------------------------
+#include <Servo.h>
+
+//------------------------------------------------------------------------------
+// CONSTANTES SOFTWARE
+//------------------------------------------------------------------------------
+
+
+// BASADO EN
+/*
+  https://thingiverse-production-new.s3.amazonaws.com/assets/87/b0/2c/f5/4c/CheatSheet.pdf
+*/
+
+#define BAUD 115200
+#define MAX_BUF 100
+
+#define STEPS_PER_MM_X (float)(12500.0/87.0)
+#define STEPS_PER_MM_Y (float)(100000.0/677.0)
+//fijar estos 3 parametros de acuerdo a especificaciones maximas del motor y/o del ensamble mecanico
+#define MAX_FEEDRATE   650.0
+#define MIN_FEEDRATE   50.0
+#define DEFAULT_FEEDRATE   400.0
+#define MIN_STEP_DELAY 1000000.0 / MAX_FEEDRATE
+
+#define Y_PASO_POR_MM (float)(100000.0/677.0)
+#define Y_MM_POR_PASO (float)(677.0/100000.0)
+#define X_PASO_POR_MM (float)(12500.0/87.0)
+#define X_MM_POR_PASO (float)(87.0/12500.0)
+
+#define Z_UP 15
+#define Z_DOWN 0
+
+//Servo Motor en Z
+Servo MiServo;
+
+// velocidades globales
+
+float fr =     DEFAULT_FEEDRATE;  // version humano
+long  step_delay = 1000000 / DEFAULT_FEEDRATE; // version maquina
+
+// Ubicacion global
+float px, py;
+// Modo Absoluto o relativo
+char mode_abs = 1; // 1 absoluto(default) 0 relativo
+
+//Buffer de comunicacion y variales para recorrerlo
+char  buffer[MAX_BUF];  // Almacena una linea entera
+int   iterador;            // how much is in the buffer
+
+//Modo Verbose
+unsigned int verboseVar = 0; // 1 -> Activo 0 -> Desactivado
+
+//Milimitros (mm) o Pulgadas (in)
+unsigned int mm = 1; // 1 -> Modo en mm 0 -> Modo en in
+
+//------------------------------------------------------------------------------
+// CONSTANTES HARDWARE
+//------------------------------------------------------------------------------
+
+#define M1_STEP 2     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
+#define M1_DIR  5     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
+#define M1_ENA  8     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
+
+#define M2_STEP 3     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
+#define M2_DIR  6     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
+#define M2_ENA  8     /*POR FAVOR CAMBIAR ESTO CUANDO LEA EL CODIGO. NO SEA AFANADO*/
+
+#define ENDSTOP_X 11
+#define ENDSTOP_Y 10
+
+#define AXIS_Z 9
+
+//------------------------------------------------------------------------------
+// METODOS HARDWARE
+//------------------------------------------------------------------------------
+
+void m1step(int dir) {
+  digitalWrite(M1_ENA, LOW);
+  digitalWrite(M1_DIR, dir);
+  digitalWrite(M1_STEP, HIGH);
+  digitalWrite(M1_STEP, LOW);
+}
+
+void m2step(int dir) {
+  digitalWrite(M2_ENA, LOW);
+  digitalWrite(M2_DIR, dir);
+  digitalWrite(M2_STEP, HIGH);
+  digitalWrite(M2_STEP, LOW);
+}
+
+void zAxisMove(float dir) {
+  if (dir > 0) {
+    MiServo.write(Z_UP);
+    delay(100);
+    if (verboseVar == 1)
+      Serial.println(F("Motor Z Movido arriba."));
+  }
+  else {
+    if (dir < 0) {
+      MiServo.write(Z_DOWN);
+      delay(100);
+      if (verboseVar == 1)
+        Serial.println(F("Motor Z Movido abajo."));
+    }
+  }
+}
+
+void disable() {
+  digitalWrite(M1_ENA, HIGH);
+  digitalWrite(M2_ENA, HIGH);
+  if (verboseVar == 1)
+    Serial.println(F("Motores Desactivados."));
+}
+
+void enable() {
+  digitalWrite(M1_ENA, LOW);
+  digitalWrite(M2_ENA, LOW);
+  if (verboseVar == 1)
+    Serial.println(F("Motores Activados."));
+}
+
+void setup_controller() {
+  pinMode(M1_ENA, OUTPUT);
+  pinMode(M2_ENA, OUTPUT);
+  pinMode(M1_STEP, OUTPUT);
+  pinMode(M2_STEP, OUTPUT);
+  pinMode(M1_DIR, OUTPUT);
+  pinMode(M2_DIR, OUTPUT);
+  pinMode(ENDSTOP_X, INPUT_PULLUP);
+  pinMode(ENDSTOP_Y, INPUT_PULLUP);
+  MiServo.attach(9);
+  MiServo.write(Z_UP);
+}
+
+
+
+
+
+//------------------------------------------------------------------------------
+// METODOS SOFTWARE
+//------------------------------------------------------------------------------
+
+void help() {
+  Serial.println(F("Este es un ejemplo de funcion de ayuda: \n"));
+  Serial.println(F("Comandos soportados:"));
+  Serial.println(F("G00 [X(steps)] [Y(steps)] [F(feedrate)]; - fast line"));
+  Serial.println(F("G01 [X(steps)] [Y(steps)] [F(feedrate)]; - fast line igual que G00 "));
+  Serial.println(F("G04 P[seconds]; - delay"));
+  Serial.println(F("G20 Cambio a pulgadas (in)."));
+  Serial.println(F("G21 Cambio a milimetros (mm)."));
+  Serial.println(F("G28; -Volver a home"));
+  Serial.println(F("G90; - Modo absoluto"));
+  Serial.println(F("G91; - Modo relativo"));
+  Serial.println(F("G92 [X(steps)] [Y(steps)]; - Cambiar setpoint"));
+  Serial.println(F("M2; -Codigo G finalizado"));
+  Serial.println(F("M17; -Habilitar motores"));
+  Serial.println(F("M18; - Deshabilitar motores"));
+  Serial.println(F("M100; - Imprimir ayuda"));
+  Serial.println(F("M111 S[Debug Level]; -Unicamente activado desactivado"));
+  Serial.println(F("M112; -Parada de emergencia"));
+  Serial.println(F("M114; - reporte de estado de la maquina"));
+  Serial.println(F("M115; Obtener informacion del software Firmeware"));
+  Serial.println(F("NOTA: TODOS LOS COMANDOS DEBEN TERMINAR CON NUEVA LINEA O -ESPACIO#-"));
+}
+
+
+
+// la funcion delayMicroseconds de arduino no funciona para valores mayores a 16k. por eso toca usar esta.
+void pause(long us) {
+  delay(us / 1000);
+  delayMicroseconds(us % 1000);
+}
+
+
+
+
+
+void feedrate(float nfr) {
+  if (fr == nfr) return;
+
+
+  if (nfr > MAX_FEEDRATE || nfr < MIN_FEEDRATE) { // depurar
+    Serial.print(F("WARNING: Feedrate debe ser mayor a  "));
+    Serial.print(MIN_FEEDRATE);
+    Serial.print(F("pero menor a  "));
+    Serial.print(MAX_FEEDRATE);
+    Serial.println(F("pasos/ssegundo. NO SE CONGIFURA NADA"));
+    return;//salir sin cambiar el valor
+  }
+  step_delay = 1000000.0 / nfr; //valor maquina
+  fr = nfr;//valor humano
+}
+
+/**
+  pos actual, util para tener pos absolutas y relativas.
+**/
+void position(float npx, float npy) {
+  px = npx;
+  py = npy;
+}
+
+
+/**
+  Usa el algoritmo de  bresenham para delinear lineas en dos motores XY
+  https://es.wikipedia.org/wiki/Algoritmo_de_Bresenham
+**/
+
+void lineaBresenhamPasos(float newx, float newy) {
+  long i;
+  long over = 0;
+
+  long dx  = newx - px;
+  long dy  = newy - py;
+  int dirx = dx > 0 ? LOW : HIGH;
+  int diry = dy > 0 ? HIGH : LOW; //diry = dy>0?LOW:HIGH; dependiendo de ensamble POR FAVOR revisar.
+  dx = abs(dx);
+  dy = abs(dy);
+
+  if (dx > dy) {
+    over = dx / 2; //OJO division entera
+    for (i = 0; i < dx; ++i) {
+      m1step(dirx);
+      over += dy;
+      if (over >= dx) {
+        over -= dx;
+        m2step(diry);
+      }
+      pause(step_delay);
+    }
+
+  } else {/*dx<=dy*/
+    over = dy / 2;
+    for (i = 0; i < dy; ++i) {
+      m2step(diry);
+      over += dx;
+      if (over >= dy) {
+        over -= dy;
+        m1step(dirx);
+      }
+      pause(step_delay);
+    }
+  }
+  px = newx;
+  py = newy;
+}
+
+
+
+/**
+  Busca el caracter /code/ en la variable  buffer global,  y  retorna el flotante que encuentre a continuacion
+  Si no se encuentra nada se retorna /val/
+**/
+float parsenumber(char code, float val) {
+  char *ptr = &buffer[0];
+  while (ptr != NULL && *ptr && ptr < buffer + iterador) {
+    if (*ptr == code) {
+      return atof(ptr + 1);
+    }
+    ptr++;
+  }
+  return val;
+}
+
+
+/**
+  Escribe en el serial el codigo y el valor decifrado, útil para hacer depuracion
+*/
+void output(const char *code, float val) {
+  Serial.print(code);
+  Serial.println(val);
+}
+
+
+/**
+  Imprime la configuracion actual.
+*/
+void where() {
+  output("X_mm ", px / STEPS_PER_MM_X);
+  output("Y_mm", py / STEPS_PER_MM_Y);
+  output("X_ST", px);
+  output("Y_ST", py);
+  output("F", fr);
+  Serial.println(mode_abs ? "MODO ABS" : "MODO REL");
+  Serial.println(mm ? "Milimetros" : "Pulgadas");
+}
+/*
+  Home: Movimiento de los ejes X y Y hacia el cero cero de la maquina
+*/
+void homes () {
+
+  zAxisMove(1);
+
+  while (digitalRead(ENDSTOP_X) == HIGH) {
+    m1step(HIGH);
+    pause(5000);
+  }
+  while (digitalRead(ENDSTOP_Y) == HIGH) {
+    m2step(LOW);
+    pause(5000);
+  }
+
+  pause(100000);
+
+  for (int i = 0; i < 300; i++) {
+    m1step(LOW);
+    pause(10000);
+    m2step(HIGH);
+    pause(10000);
+  }
+
+  while (digitalRead(ENDSTOP_X) == HIGH) {
+    m1step(HIGH);
+    pause(20000);
+  }
+  if (verboseVar == 1)
+    Serial.print(F("FIN CALIBRACION EJE X...\n"));
+  while (digitalRead(ENDSTOP_Y) == HIGH) {
+    m2step(LOW);
+    pause(20000);
+  }
+  if (verboseVar == 1)
+    Serial.print(F("FIN CALIBRACION EJE Y...\n"));
+
+  for (int i = 0; i < 300; i++) {
+    m1step(LOW);
+    pause(10000);
+    m2step(HIGH);
+    pause(10000);
+  }
+
+  disable();
+  px = 0;
+  py = 0;
+}
+
+/*
+   Firmeware version
+*/
+void firmeware() {
+  Serial.print(F("-------------VERSION firmeware-----------------\n"));
+  Serial.print(F("-> Version del software: 1.30\n"));
+  Serial.print(F("Realizado por: \n"));
+  Serial.print(F("Francisco Calderon.\n"));
+  Serial.print(F("Modificado por: \n"));
+  Serial.print(F("Alejandro Castro, Oscar Mendez y Daniel Pineda.\n"));
+  Serial.print(F("Diseno de la maquina fisica:\n"));
+  Serial.print(F(" http://reprap.org/wiki/Cyclone_PCB_Factory\n"));
+  Serial.print(F("----------------------------------------------------\n"));
+}
+
+/**
+   borra el buffer de entrada y envia el caracter de nueva linea de comandos.
+*/
+void ready() {
+  iterador = 0; // reinicia el buffer de entrada
+  Serial.print(F(">"));  // envia el caracter > para que se envie nueva linea
+}
+
+
+/**
+  Lee el buffer de entrada y reconoce los comandos de haberlos.
+  NOTA: solo soporta un comando G o M por linea.
+*/
+void processCommand() {
+  float XX, YY, ZZ;
+  int cmd = parsenumber('G', -1);
+  switch (cmd) {
+    case -1:
+      Serial.println(F("No encuentro codigo G en linea..."));
+      break;
+    case  0:
+    case  1:
+      Serial.print(F("Comando G"));
+      Serial.println(cmd);
+      feedrate(parsenumber('F', fr));
+      // no olvidar que px y py estan en pasos y los comandos llegan en mm
+      if (verboseVar == 1)
+        where();
+      XX = (parsenumber('X', (mode_abs ? px / STEPS_PER_MM_X : 0)) + (mode_abs ? 0 : px / STEPS_PER_MM_X));
+      YY = (parsenumber('Y', (mode_abs ? py / STEPS_PER_MM_Y : 0)) + (mode_abs ? 0 : py / STEPS_PER_MM_Y));
+      ZZ = (parsenumber('Z', 0));
+      if (verboseVar == 1) {
+        Serial.print(F("Moviendo a X= "));
+        Serial.print(-X_MM_POR_PASO * px + XX);
+        Serial.print(F(", Y= "));
+        Serial.print(-Y_MM_POR_PASO * py + YY);
+        Serial.print(F("Moviendo Z="));
+        if (ZZ <= 0)
+          Serial.print(F("ABAJO"));
+        else
+          Serial.print(F("ARRIBA"));
+        Serial.print(F(", F= "));
+        Serial.println(fr);
+      }
+      if (ZZ != 0)
+        zAxisMove(ZZ);
+      if (mm == 1)
+        lineaBresenhamPasos( STEPS_PER_MM_X * XX , STEPS_PER_MM_Y * YY );
+      else
+        lineaBresenhamPasos( STEPS_PER_MM_X * (XX * 25.4), STEPS_PER_MM_Y * (YY * 25.4));
+      if (mode_abs == 0)
+        position( parsenumber('X', 0),
+                  parsenumber('Y', 0) );
+      if (verboseVar == 1)
+        where();
+      break;
+    case  4:
+      Serial.print(F("Comando G"));
+      Serial.println(cmd);
+      pause(parsenumber('P', 0) * 1000);
+      Serial.println(F("Pausa realizada..."));
+      break;  // dwell
+    case 20: //a in
+      mm = 0;
+      Serial.println(F("Cambio a pulgadas."));
+      break;
+    case 21://a mm
+      mm = 1;
+      Serial.println(F("Cambio a mm."));
+      break;
+    case  28:
+      Serial.print(F("Comando G"));
+      Serial.println(cmd);
+      homes();
+      break;  // dwell
+    case 90:  //modo absoluto
+      Serial.print(F("Comando G"));
+      Serial.println(cmd);
+      Serial.println(F("modo absoluto"));
+      mode_abs = 1;
+      break;
+    case 91:  //modo relativo
+      Serial.print(F("Comando G"));
+      Serial.println(cmd);
+      Serial.println(F("modo relativo"));
+      mode_abs = 0;
+      break;
+    case 92:  // definir pos
+      Serial.print(F("Comando G"));
+      Serial.println(cmd);
+      position( parsenumber('X', 0),
+                parsenumber('Y', 0) );
+      Serial.println(F("Posicion en cero cero"));
+      break;
+    default:
+      Serial.print(F("Comando G"));
+      Serial.print(cmd);
+      Serial.println(F(" No implementado..."));
+
+      break;
+  }
+
+  cmd = parsenumber('M', -1);
+  switch (cmd) {
+    case -1:
+      Serial.println(F("Sin codigo M en linea..."));
+      break;
+    case 2:
+      Serial.println(F("Codigo G finalizado"));
+      zAxisMove(1);
+      disable();
+      break;
+    case 17:  // enable motors
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      enable();
+      Serial.println(F("Motores habilitados"));
+      break;
+    case 18:  // disable motors
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      disable();
+      Serial.println(F("Motores desahabilitados"));
+      break;
+    case 100:
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      help();
+      break;
+    case 111:  // debug level
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      if (parsenumber('S', -1) == 1) {
+        verboseVar = 1;
+        Serial.println(F("Modo Verbose Activado"));
+      }
+      else {
+        if ((parsenumber('S', -1) == 0)) {
+          verboseVar = 0;
+          Serial.println(F("Modo Verbose Desactivado"));
+        }
+        else
+          Serial.println(F("Opcion invalida. Ejecucion: M111 S[Debug Level]"));
+      }
+      break;
+    case 112:  // Emergency Stop
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      zAxisMove(1);
+      disable();
+      Serial.println(F("Parada de emergencia."));
+      break;
+    case 114:
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      where();
+      break;
+    case 115:
+      Serial.print(F("Comando M"));
+      Serial.println(cmd);
+      firmeware();
+      break;
+    default:
+      Serial.print(F("Comando M"));
+      Serial.print(cmd);
+      Serial.println(F(" No implementado..."));
+      break;
+  }
+}
+
+
+
+/**
+   Funcion setup arduino
+*/
+void setup() {
+  Serial.begin(BAUD);
+  setup_controller();
+  position(0, 0); // pos de inicio
+  feedrate(DEFAULT_FEEDRATE);  // inicializa con velocidad por defecto en caso de que no se provea ninguna
+  help();  // say hello
+  ready();
+}
+
+/**
+   Funcion loop de arduino
+*/
+void loop() {
+  while (Serial.available() > 0) { // Si algo esta disponible
+    char c = Serial.read(); // lea
+    Serial.print(c);  // echo
+    if (iterador < MAX_BUF - 1)
+      buffer[iterador++] = c; // guarde y aumente iterador
+    if ((c == '\n') || (c == '\r') || (c == '#') )
+    { // si se recibe una linea entera
+      buffer[iterador] = 0; // finalice el buffer con 0
+      Serial.print(F("--\r\n"));  // echo de un caracter de return y nueva linea
+      processCommand();  // procese el comando
+      ready(); // pida nuevo comando.
+    }
+  }
+}
+
+
+


Slow ramps on all 4 DAC channels

Slow ramps on all 4 DAC channels

--- Elcano_C2_MotorSPI2/Elcano_C2_MotorSPI2.ino
+++ Elcano_C2_MotorSPI2/Elcano_C2_MotorSPI2.ino
@@ -105,8 +105,11 @@
       // change the voltage on this channel from min to max:
       for (int level = 70; level < 200; level+=4)
       {
-        DAC_Write(channel, level);
-        Serial.print(SpeedCyclometer_degPs); Serial.print(", ");
+        DAC_Write(0, level);
+        DAC_Write(1, level);
+        DAC_Write(2, level);
+        DAC_Write(3, level);
+//       Serial.print(SpeedCyclometer_degPs); Serial.print(", ");
         Serial.println(level);
         delay(3000);
       }
@@ -115,8 +118,11 @@
       // change the voltage on this channel from max to min:
       for (int level = 200; level > 70; level-=4)
       {
-        DAC_Write(channel, level);
-        Serial.print(SpeedCyclometer_degPs); Serial.print(", ");
+        DAC_Write(0, level);
+        DAC_Write(1, level);
+        DAC_Write(2, level);
+        DAC_Write(3, level);
+//        Serial.print(SpeedCyclometer_degPs); Serial.print(", ");
         Serial.println(level);
         delay(3000);
       }


Moved btSetup() to after LEDs turn on.

Moved btSetup() to after LEDs turn on.

--- ballbot.ino
+++ ballbot.ino
@@ -60,11 +60,11 @@

     Serial.begin(115200);   // doesn't really matter what we put here (Teensy 3.x serial isn't "real" serial)

-    btSetup(HC06, 921600, BAUD_1382400);
-
     pinMode(INT_PIN, INPUT);
     pinMode(LED, OUTPUT);    digitalWriteFast(LED, HIGH);   // initial set LEDs on high
-    pinMode(LED2, OUTPUT);    digitalWriteFast(LED2, HIGH);
+    pinMode(LED2, OUTPUT);    digitalWriteFast(LED2, HIGH);
+
+    btSetup(HC06, 921600, BAUD_1382400);

     // use a higher frequency of >12kHz to reduce audible sound and reduce switching losses
     motorA.begin(PWM_FREQ);


Capture: made timer-interrupt-driven

Capture: made timer-interrupt-driven

--- Capture/Capture.ino
+++ Capture/Capture.ino
@@ -1,62 +1,132 @@
 int in = 3;
 int debug = 4;

+static const int prescaler = 1;
+static const double systemHz = 16000000;
+static const double bitLength = 52.0 / 1000000.0;
+static const unsigned int finetuning = 50; // fine-tuned with an oscilloscope
+static const unsigned int timerPreload = 65536 - systemHz / prescaler / (1 / bitLength) + finetuning;
+static const unsigned int timerPreload2 = 65536 - systemHz / prescaler / (1 / (bitLength / 2)) + finetuning;
+
 static const int sampleLength = 52;
+static const int maxSampleBytes = 500;
+
+volatile bool intrReading = false;
+volatile bool intrFirst;
+volatile int intrAtBit;
+volatile int intrAtByte;
+volatile int intrOnes;
+volatile int intrZeroes;
+unsigned char intrSamples[maxSampleBytes];

 // the loop routine runs over and over again forever:
 void setup() {
   pinMode(debug, OUTPUT);
   pinMode(in, INPUT);
   digitalWrite(debug, HIGH);
+  setupTimer();
   Serial.begin(115200);
   Serial.println("Start");
 }

-unsigned long time;
+void setupTimer()
+{
+  // initialize timer1
+  noInterrupts();           // disable all interrupts
+  TCCR1A = 0;
+  TCCR1B = 0;
+
+  TCNT1 = timerPreload2;            // preload timer 65536-16MHz/256/2Hz
+//  TCCR1B |= (1 << CS12);    // 256 prescaler
+  TCCR1B |= (1 << CS10);    // no prescaler
+//  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
+  interrupts();             // enable all interrupts
+}
+
+void enableTimer()
+{
+  noInterrupts();
+  TIMSK1 |= (1 << TOIE1);
+  intrReading = true;
+  intrFirst = true;
+  intrAtBit = 0;
+  intrAtByte = 0;
+  intrOnes = 0;
+  intrZeroes = 0;
+  intrSamples[0] = 0;
+  interrupts();
+}
+
+void disableTimer()
+{
+  intrReading = false;
+  TIMSK1 &= ~(1 << TOIE1);
+}
+
+ISR(TIMER1_OVF_vect)
+{
+  TCNT1 = timerPreload;            // preload timer
+#if 1
+  int value = digitalRead(in) == HIGH ? 1 : 0;
+  digitalWrite(debug, value);
+  intrSamples[intrAtByte] |= value << intrAtBit;
+  if (++intrAtBit == 8) {
+    ++intrAtByte;
+    intrSamples[intrAtByte] = 0;
+    intrAtBit = 0;
+  }
+  if (value) {
+    ++intrOnes;
+    intrZeroes = 0;
+  } else {
+    ++intrZeroes;
+    intrOnes = 0;
+  }
+  if (intrOnes > 20 || intrZeroes > 20 || intrAtByte == maxSampleBytes) {
+    disableTimer();
+  }
+#else
+  static int value = 0;
+  value ^= 1;
+  digitalWrite(out, value);
+  digitalWrite(debug, value);
+#endif
+}

 void dump() {
-  bool samples[200];
-  unsigned n = 0;
-  unsigned ones = 0;
-  unsigned zeroes = 0;
-  while (ones < 20 && zeroes < 20 && n < sizeof(samples) / sizeof(*samples)) {
-    int value = digitalRead(in);
-    digitalWrite(debug, value);
-    samples[n] = value == HIGH;
-    time += sampleLength;
-    unsigned sleepTime = time - micros();
-    delayMicroseconds(sleepTime);
-    if (value == HIGH) {
-      ++ones;
-      zeroes = 0;
-    } else {
-      ++zeroes;
-      ones = 0;
+  enableTimer();
+  while (intrReading) {
+    // wait
+  }
+  for (int c = 0; c < intrOnes; ++c) {
+    if (intrAtBit-- == 0) {
+      intrAtBit = 7;
+      --intrAtByte;
     }
-    ++n;
   }
-  Serial.print('{');
-  for (int c = 0; c < n - ones; ++c) {
-    if (c) {
-      Serial.print(",");
+  for (int atByte = 0, atBit = 0;
+       atByte != intrAtByte || atBit != intrAtBit;
+       (++atBit == 8) ? (atBit = 0, ++atByte) : 0) {
+    if (atByte && atBit == 0) {
+      Serial.print(" ");
     }
-    Serial.print(samples[c] ? '1' : '0');
+    Serial.print((intrSamples[atByte] & (1 << atBit)) ? '1' : '0');
   }
-  if (zeroes == 20) {
+  if (intrZeroes == 20) {
     Serial.print("/*..*/");
   }
-  Serial.println("};");
+  Serial.println();
 }

 void loop() {
   static bool started = false;
-  int value = digitalRead(in);
   if (!started) {
+    int value = digitalRead(in);
     if (value == HIGH) {
       started = true;
     }
   } else {
-    time = micros() + sampleLength / 2;
+    int value = digitalRead(in);
     if (value == LOW) {
       dump();
       started = false;


added a comment for later

added a comment for later

--- ZstabalizationTest1/ZstabalizationTest1.ino
+++ ZstabalizationTest1/ZstabalizationTest1.ino
@@ -57,11 +57,13 @@
       if(sensor.depth() > depthSavedState){
           // Move ROV DOWN
           // Insert MOTOR CODE here
+          // michael note: use map to max it from max to zero. you'll remember
       }
     // if ROV is below saved state
       if(sensor.depth() < depthSavedState){
           // Move ROV UP
           // Insert MOTOR CODE here
+          // michael note: use map to max it from max to zero. you'll remember
       }

     }


Use renamed classes

Use renamed classes

--- chaise2.ino
+++ chaise2.ino
@@ -5,13 +5,13 @@
 #include <Wire.h>
 #include <EEPROM.h>

-#include "ChairAffair_HeartBeatLED.h"
+#include "HeartBeatLED.h"
 #include "ChairAffair_LightBar.h"
 #include "ChairAffair_TouchManager.h"
 #include "ChairAffair_OpStateManager.h"
 #include "ChairAffair_DemoSwitchManager.h"
-#include "ChairAffair_TouchManager.h"
-#include "ChairAffair_ColorCoordinator.h"
+#include "TouchManager.h"
+#include "ColorCoordinator.h"
 #include "ChairAffair_SerialDebugger.h"
 #include "DxLEDTimers.h"

@@ -29,12 +29,12 @@
 #define DEBUG_PRINTLN_F(x,f)	NOP
 #endif

-ChairAffair_Heartbeat heartbeat(LED_BUILTIN,250,2000);
+Heartbeat heartbeat(LED_BUILTIN,250,2000);
 // ChairAffair_LightBar DemoBar(0,10, NUM_LEDS >> 2,10);
 // ChairAffair_OpStateManager OpStateManager = ChairAffair_OpStateManager();
 // ChairAffair_DemoSwitchManager DemoSwitchManager = ChairAffair_DemoSwitchManager(DEMO_SW_PIN);
 // ChairAffair_ColorCoordinator ColorCoordinator = ChairAffair_ColorCoordinator();
-ChairAffair_TouchManager TouchManager = ChairAffair_TouchManager();
+TouchManager TouchManager = TouchManager();
 ChairAffair_SerialDebugger SerialDebugger = ChairAffair_SerialDebugger();
 uint16_t loop_count = 0;


updated task

updated task

--- gestureDetection/gestureDetection.ino
+++ gestureDetection/gestureDetection.ino
@@ -18,6 +18,7 @@
  *
  *In each execution loop, we first acquire the accel readings (need to determine freq (John's job)) and ADC reading of flex sensor
  *use switch cases to see which state we should be in, if there is a state change, we go into that state
+ *Albert's task: set up different states and action in those states(now just use distinguishable LED pattern so we can debug. Use serial.print for prelimanary testing but not in final testing)
  *
  */


untested loop

untested loop

--- run/arduino/arduinoActuator/arduinoActuator.ino
+++ run/arduino/arduinoActuator/arduinoActuator.ino
@@ -7,6 +7,7 @@
 #define dirPin 2

 int currentVal = 0;
+int changedVal = 0;

 void setup() {
   // put your setup code here, to run once:
@@ -44,10 +45,12 @@
     analogWrite(pwmPin, 0);
   }
   delay(5);
+  currentVal = newVal;
 }

 void loop() {
   // put your main code here, to run repeatedly:
+  setActuator(changedVal);
 }

 // callback for received data
@@ -55,10 +58,7 @@
   while(Wire.available()) {
     int newVal = Wire.read();
     if (newVal <= 200) {
-      int change = newVal - currentVal;
-      Serial.println(change);
-      setActuatorValue(change);
-      currentVal = newVal;
+      changedVal = newVal - currentVal;
     }
   }
 }