定义常量
#define PI 3.1415926535
#define deg2rad(deg) ((deg)*PI/180)
#define rad2deg(rad) ((rad)*180/PI)
#define AF 12.5
#define AB 21.5
#define EF 21.5
#define CE 21.5
#define BC 34.19
#define CD 34.95
#define bcd_angle deg2rad(120)
#define half_AF (AF/2.0)
反解实现
double AD2 = 0;
double AD = 0;
double angle_DAF = 0;
double BD2 = 0;
double BD = 0;
double angle_BAD = 0;
double angle_DBA = 0;
double angle_DBC = 0;
double angle_ABC = 0;
double AC2 = 0;
double AC = 0;
double angle_BAC = 0;
double angle_CAF = 0;
double CF2 = 0;
double CF = 0;
double angle_AFC = 0;
double angle_CFE = 0;
//步态相关
double sigma = 0;
double zep = 0;
double xep_b = 0;
double xep_z = 0;
double alpha = 0;
double beta = 0;
//8个舵机的转动角度
double steering_angles[8] = {0};
void leg_inverse(double fx,double fy,double *alpha,double *beta){
//AD长度
AD2 = pow((half_AF+fx),2.0)+pow(fy,2.0);
AD = sqrt(AD2);
//DAF夹角
angle_DAF = asin(fy/AD);
//BD长度
BD2 = pow(BC,2.0)+pow(CD,2.0)-2*BC*CD*cos(bcd_angle);
BD = sqrt(BD2);
//BAD夹角
angle_BAD = acos((pow(AB,2.0)+AD2-BD2)/(2*AB*AD));
//alpha角度
*alpha = PI-angle_BAD-angle_DAF;
angle_DBA = acos((pow(AB,2.0)+BD2-AD2)/(2*AB*BD));
angle_DBC = acos((pow(BC,2.0)+BD2-pow(CD,2.0))/(2*BC*BD));
angle_ABC = angle_DBA-angle_DBC;
//AC长度
AC2 = pow(AB,2.0)+pow(BC,2.0)-2*AB*BC*cos(angle_ABC);
AC = sqrt(AC2);
angle_BAC = acos((pow(AB,2.0)+AC2-pow(BC,2.0))/(2*AB*AC));
angle_CAF = PI-(*alpha)-angle_BAC;
CF2 = pow(AF,2.0)+AC2-2*AF*AC*cos(angle_CAF);
CF = sqrt(CF2);
angle_AFC = acos((pow(AF,2.0)+CF2-AC2)/(2*AF*CF));
angle_CFE = acos((CF2+pow(EF,2.0)-pow(CE,2.0))/(2*CF*EF));
*beta = PI-angle_AFC-angle_CFE;
// printf("======================\n");
// printf("al:%lf ,beta:%lf\n",*alpha,*beta);
}