给定四个狗腿的坐标,计算8个舵机转动角度 需要考虑左右腿的安装角度
左腿
右腿
//特定位置的舵机角度
void leg_inverse_angle(double rq_x,double rq_y,double rh_x,double rh_y,
double lq_x,double lq_y,double lh_x,double lh_y,double steering_angles[8]){
//右前
leg_inverse(rq_x,rq_y,&alpha,&beta);
steering_angles[0] = rad2deg(PI-beta);
steering_angles[1] = rad2deg(alpha);
//printf("dj1:%lf ,dj2:%lf\n",steering_angles[0],steering_angles[1]);
//右后
leg_inverse(rh_x,rh_y,&alpha,&beta);
steering_angles[2] = rad2deg(PI-beta);
steering_angles[3] = rad2deg(alpha);
//printf("dj3:%lf ,dj4:%lf\n",steering_angles[2],steering_angles[3]);
//左前
leg_inverse(lq_x,lq_y,&alpha,&beta);
steering_angles[4] = rad2deg(beta);
steering_angles[5] = rad2deg(PI-alpha);
//printf("dj5:%lf ,dj6:%lf\n",steering_angles[4],steering_angles[5]);
//左后
leg_inverse(lh_x,lh_y,&alpha,&beta);
steering_angles[6] = rad2deg(beta);
steering_angles[7] = rad2deg(PI-alpha);
//printf("dj7:%lf ,dj8:%lf\n",steering_angles[6],steering_angles[7]);
}
狗腿运动到指定的位置
//狗运动到指定的位置
void dog_to_coord(double rq_x,double rq_y,double rh_x,double rh_y,
double lq_x,double lq_y,double lh_x,double lh_y){
leg_inverse_angle(rq_x, rq_y, rh_x, rh_y,lq_x, lq_y, lh_x, lh_y, steering_angles);
bsp_pwm0_angle(steering_angles[0]);
bsp_pwm1_angle(steering_angles[1]);
bsp_pwm2_angle(steering_angles[2]);
bsp_pwm3_angle(steering_angles[3]);
bsp_pwm4_angle(steering_angles[4]);
bsp_pwm5_angle(steering_angles[5]);
bsp_pwm6_angle(steering_angles[6]);
bsp_pwm7_angle(steering_angles[7]);
}