Teensy 3.6 controlling Kangaroo x2 motor controller

Status
Not open for further replies.

Xray

New member
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
 
I guess that the Teensy 3.6 is just too quick compared to the Arduino DUE and when you send your start command immediately after Serial1.begin(9600) in setup(), the Serial1 communication might not yet be ready an established. You should insert the line
Code:
while(!Serial1);
after Serial1.begin(9600) to make sure that the Teensy waits until the motor serial communication is up and ready before sending the start command.
 
I don't think that will work in this situation. I am just sending commands to the motor controller that is constantly listening. I do not even have the rx1 pin connected. I do not need to receive any info from the controller.
 
The fact that it works when you put the start command in the loop where it is invoked later proves that it's clearly a timing problem due to the Teensy being much faster than the Arduino. If you won't be confident and just give it a try (why???), you might still use a delay(x); after Serial1.begin(); starting with x = 400 and decreasing the value until the start command is ignored again.
 
I just tried the delay it works! I found the threshold to be 487 milliseconds. So I set it for 600. Thank you very much!
 
Status
Not open for further replies.
Back
Top