My math is weak, hope to get some help from someone .
I am building a robot and I am looking for smooth motion.
I developed an micro steps generating function based on:
Encoder reading- the origin of motion,
First Waypoint to go (degrees)
Microsteps to the first Waypoint - int
Second Waypoint
Microsteps to the Second waypoint.
I am getting a good micro steps but the motion is rude and jerky because is linear.
All smoothing libraries are referring to an analog input so I can't feed my micro steps array...
See attached pic, the red is the micro steps generated, the green would be the motion I would like, (Drawn by hand)
Thanks a lot, I know this is not easy....
int Inc;
float EncoderRead = 45;
float GoTo_Gauss [20] [1001]; // motor no, steps no
int Calc_Once = 0;
void setup() {
Serial.begin(921600); //115200);
Serial5.begin(115200);
}
void loop() {
while (Serial.available () > 0 ) // receiving stuff from keyboard - Serial monitor
{
unsigned long SerStamp = millis();
Serial.println (SerStamp);
String Kbd_Str = Serial.readStringUntil('\n');
char FirstKbd = Kbd_Str.charAt(0);
if (FirstKbd == 'd')
{
Linear_Calc_2_W_Pnt (100, 127.76, 250, 30.699, 13 );
}
}
}
void Linear_Calc_2_W_Pnt (int MS0, float Tar0, int MS1, float Tar1, int motor_id ) // No of steps, Encoder Position, target, motor id
{ //Serial.print (millis());
Inc = MS0 + MS1;
float Enc = EncoderRead;
float Adj_Tar = Tar0 - Enc; //Distance from current postion to the first target
//Serial.println (Adj_Tar);
float I_0 = Adj_Tar / MS0; // this is the increment of each step first segme
float I_1 = (Tar0 - Tar1) / MS1; // this is the increment of each step secont segment
for (int i = 1; i <= Inc; ++i) {
if (i <= MS0)
{
GoTo_Gauss[motor_id][i] = (I_0 * i) + Enc;
}
else if (i > MS0)
{
GoTo_Gauss[motor_id][i] = Tar0 - (I_1 * (i - MS0)) ;
}
//Serial.println (GoTo_Gauss[motor_id][i], 4);
Serial5.printf ( "P%.3f %d \n", GoTo_Gauss[motor_id][i] , i); // array goes to Processing for plotting
Serial.printf ( "P%.3f %d \n", GoTo_Gauss[motor_id][i] , i);
}
}
I am running this on a teensy 4.1