I have a program that worked on my arduino Due, but when I switched over to the Teensy 3.6 it would not work. I have narrowed it down to the placement of my start command. I am using simplifield serial mode. So to command the kangaroo (dimension engineering ) I print characters to the serial port. To start the controller I send ("1,start"). This is done in the setup part of the program on the due, but on the teensy it doesn't work. If I move it to the main loop of the program it works. But, it does a restart of the kangaroo each pass of the loop. This won't work if my motor controller is doing a restart each loop.
int llim = 900; // Motor tension low limit, 0 - 5000 mV
int hlim = 4100; // Motor tension high limit, 0 - 5000 mV
int pos = A0; // Axis position value
int pot1 = A1; // Potentiometer 1 position
int lmten = A3; // Low motor tension value
int maxspeed = 2000; // In mV/s, maximum speed of tension change
int pot1cntrl = 0; //
int dly = 20; // delay time
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // initiate usb serial
Serial1.begin(9600); // initiate motor control serial
Serial1.println("1,start"); // Turn on Low motor
}
void loop() {
Serial1.println("1,start"); // Turn on Low motor
startloop:
delay (dly);
analogReadResolution(8);
Serial.print("POSITION = ");
Serial.println(analogRead(pos));
Serial.print(" LM TENSION = ");
Serial.println(analogRead(lmten));
Serial.print(" POTENTIOMETER 1 = ");
Serial.println(analogRead(pot1));
pot1cntrl = map(analogRead(pot1), 0, 255, -maxspeed, maxspeed); // convert the pot input to speed
Serial.print(" POT 1 CONTROL = ");
Serial.println(pot1cntrl);
delay (dly);
if ((analogRead(pot1)) > 127)
{
Serial.println(" Increasing LM Tension ");
Serial1.print("1,p");
Serial1.print(hlim);
Serial1.print("s");
Serial1.println(pot1cntrl);
}
else
{
Serial.println(" Decreasing LM Tension ");
Serial1.print("1,p");
Serial1.print(llim);
Serial1.print("s");
Serial1.println(-1 * (pot1cntrl));
}
delay (dly);
Serial.println(" ");
delay (dly);
goto startloop;
}
I found a work around with a goto statement, but there must be something I'm missing.
Thank you
int llim = 900; // Motor tension low limit, 0 - 5000 mV
int hlim = 4100; // Motor tension high limit, 0 - 5000 mV
int pos = A0; // Axis position value
int pot1 = A1; // Potentiometer 1 position
int lmten = A3; // Low motor tension value
int maxspeed = 2000; // In mV/s, maximum speed of tension change
int pot1cntrl = 0; //
int dly = 20; // delay time
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // initiate usb serial
Serial1.begin(9600); // initiate motor control serial
Serial1.println("1,start"); // Turn on Low motor
}
void loop() {
Serial1.println("1,start"); // Turn on Low motor
startloop:
delay (dly);
analogReadResolution(8);
Serial.print("POSITION = ");
Serial.println(analogRead(pos));
Serial.print(" LM TENSION = ");
Serial.println(analogRead(lmten));
Serial.print(" POTENTIOMETER 1 = ");
Serial.println(analogRead(pot1));
pot1cntrl = map(analogRead(pot1), 0, 255, -maxspeed, maxspeed); // convert the pot input to speed
Serial.print(" POT 1 CONTROL = ");
Serial.println(pot1cntrl);
delay (dly);
if ((analogRead(pot1)) > 127)
{
Serial.println(" Increasing LM Tension ");
Serial1.print("1,p");
Serial1.print(hlim);
Serial1.print("s");
Serial1.println(pot1cntrl);
}
else
{
Serial.println(" Decreasing LM Tension ");
Serial1.print("1,p");
Serial1.print(llim);
Serial1.print("s");
Serial1.println(-1 * (pot1cntrl));
}
delay (dly);
Serial.println(" ");
delay (dly);
goto startloop;
}
I found a work around with a goto statement, but there must be something I'm missing.
Thank you