EENX15/EENX15_LQR/lqr_fullstate.ino

23 lines
799 B
Arduino
Raw Permalink Normal View History

2021-05-13 11:38:40 +02:00
//lqr_fullstate.ino
float lqr_fullstate(float position_m, float speed_ms, float angle_r, float angle_speed_rs){
2021-04-21 15:26:24 +02:00
const float matrix_K [4] = {-0.7071, -1.7751, 34.5368, 4.8793};
float result;
result = matrix_K[0] * position_m +
matrix_K[1] * speed_ms +
matrix_K[2] * angle_r +
matrix_K[3] * angle_speed_rs;
2021-04-24 11:15:41 +02:00
Serial.print("K calculation (force): "); Serial.println(result);
return result;
}
float calc_speed(float input) {
2021-04-20 13:27:26 +02:00
float scale = 1.5;
input = abs(input)*0.30796; // scale down to rad/s (78,53/255)
Serial.print("input: "); Serial.println(input);
2021-04-21 15:27:25 +02:00
float result = 3145.84/(pow((90.75 - input),1.00715)); // break out x from response graph
2021-04-20 13:27:26 +02:00
result *= scale;
Serial.print("calcspeed: "); Serial.println(result);
return result;
}