I have a robot leg in two sections, femur and tibia, with two gearservos. I have a sequence of angles I want the sections to move through. The angles change in amounts from 1 degree to something like 12 degrees. I want a constant time between each movement although the two servos usually are moving a different number of degrees. My SSC-32U is working and things move to the correct angles I want but the motion is jerky.
I am using a Teensy 3.5 microcontroller and sending commands to the SSC-32U by serial 115200 bps.
What is the way to get this to smooth out. Below is some pseudocode.
float heron_femur[10] = {18.7, 24.47, 30.83, 39.73, 48.63, 56.93, 65.22, 74.4, 83.59, 88.94};
float heron_tibia[10] = {49.75, 37.41, 25.07, 16.49, 7.91, 3.95, 2.0, 2.03, 3.06, 4.64};
int heron_femur_usec[10];
int heron_tibia_usec[10];
void setup()
{
// Heron angles to uSec
for (int i = 0; i < 10; i++)
{
if (heron_femur[i] <= 90.0)
{
heron_femur_usec[i] = 1500 - int((90.0 - heron_femur[i]) * 3.0 + 0.5); // 3 uSec per degree to turn servo
}
else
{
heron_femur_usec[i] = 1500 + int((heron_femur[i] - 90.0) * 3.0 + 0.5);
}
// Tibia angles to uSec
heron_tibia[i] = 180.0 - heron_tibia[i];
if (heron_tibia[i] <= 90.0)
{
// signs are reversed from femur because tibia motor is mounted 180 deg from femur
heron_tibia_usec[i] = 1500 + int((90.0 - heron_tibia[i]) * 3.0 + 0.5);
}
else
{
heron_tibia_usec[i] = 1500 - int((heron_tibia[i] - 90.0) * 3.0 + 0.5);
}
// Deal with angle of femur
if (heron_femur_usec[i] <= 1500)
{
heron_tibia_usec[i] -= 1500 - heron_femur_usec[i];
}
else
{
heron_tibia_usec[i] += heron_femur_usec[i] - 1500;
}
}
void loop()
{
for (int i = 0; i < 10; i++)
{
String s = “#0P” + String(heron_femur_usec[i]) + “#1P” + String(heron_tibia_usec[i]);
Serial3.println(s);
delay(40);
}
}