laptophead
Well-known member
I am building a robot with 8 motors and I am sending to a PC where I have a GUI all kind of data. 112500 baud,
8 encoders, 8 current readings and some other variables. I was counting on my 3.6 to be fast enough to do it, but then I read that serial print or write is blocking...
In order not to block my processes I send 3 strings at 3 different times.
In the background, I have a routine that is reading encoders every 5 mS. I need it in order to know what the robot is doing. I need it fast in order to balance it, shift weight from one leg to another.... etc
I am discovering that my sprintf is blocking my reads and some other periodic processes.
The scope shows a gap in my readings. The gap disappears if I suspend the Print,
The encoders are read on other Serials, (2 and 3).
What is a wiser way to handle this?
Thanks
I only included the main file, there are another 5 full of functions...
8 encoders, 8 current readings and some other variables. I was counting on my 3.6 to be fast enough to do it, but then I read that serial print or write is blocking...
In order not to block my processes I send 3 strings at 3 different times.
Code:
if (millis() - Transmission_Millis > 100)
{ Transmission_Millis = millis();
TransInc++; // transmission incrementor
if (TransInc == 1)
{ sprintf(data_out, "%s Step: %d Compl A: %d Compl B: %d Send Once:%d First: %c Show Gaps:%d ",
ModeStr, StepNo, Completed_A, Completed_B, SendOnce, First, Show_Gaps);
Serial5.println(data_out);
}
else if (TransInc == 2)
{ sprintf(data_enc, "Encs: M1:%.1f, %.1f, %.1f, %.1f, B: M11:%.1f, %.1f, %.1f, %.1f, ",
Mot_Ang_Read[1], Mot_Ang_Read[2], Mot_Ang_Read[3], Mot_Ang_Read[4], Mot_Ang_Read[11], Mot_Ang_Read[12],
Mot_Ang_Read[13], Mot_Ang_Read[14]);
Serial5.println(data_enc);
}
else if (TransInc == 3)
{ float TotalCurrent = ( Mot_Curr[1] + Mot_Curr[2] + Mot_Curr[3] + Mot_Curr[4] + Mot_Curr[11] + Mot_Curr[12] + Mot_Curr[13] + Mot_Curr[14]);
sprintf(data_currents, "M.Curr: M1:%.1fA %.1fA %.1fA %.1fA B: M11:%.1fA %.1fA %.1fA %.1fA, Volts:%.1fA %.1fA Total,",
Mot_Curr[1], Mot_Curr[2], Mot_Curr[3], Mot_Curr[4] , Mot_Curr[11], Mot_Curr[12], Mot_Curr[13], Mot_Curr[14], Volts_B, TotalCurrent );
Serial5.println(data_currents);
Serial.println(data_currents);
TransInc = 0;
}
In the background, I have a routine that is reading encoders every 5 mS. I need it in order to know what the robot is doing. I need it fast in order to balance it, shift weight from one leg to another.... etc
I am discovering that my sprintf is blocking my reads and some other periodic processes.
The scope shows a gap in my readings. The gap disappears if I suspend the Print,
The encoders are read on other Serials, (2 and 3).
What is a wiser way to handle this?
Thanks
I only included the main file, there are another 5 full of functions...