33 #include "physical_constants.h"
64 float val = fmodf(err + 180.0
f, 360.0
f);
88 float val = fmodf(err +
PI, 2*
PI);
113 return (x * ((100 - g) / 100.0
f) + powf(x, 3) * (g / 100.0
f));
116 float expoM(
float x, int32_t g,
float exponent) {
117 float out = x * (100 - g) * .01
f;
120 out +=
powapprox(x, exponent) * g * 0.01f;
122 out -=
powapprox(-x, exponent) * g * 0.01f;
146 const float endVal) {
147 return beginVal + (endVal - beginVal) *
bound_min_max(fraction, 0, 1);
163 for (
int i=0;
i<n;
i++) {
164 sum += powf(v[
i], 2);
179 const float *desired,
float *out,
bool normalize)
181 out[0] = desired[0] - actual[0];
182 out[1] = desired[1] - actual[1];
183 out[2] = desired[2] - actual[2];
188 if (mag < 0.00001
f) {
190 out[0] = 1.0; out[1] = 0.0; out[2] = 0.0;
192 out[0] /=
mag; out[1] /=
mag; out[2] /=
mag;
212 if (mag > limit && mag != 0) {
228 out[0] = original[0] * cosf(angle) - original[1] * sinf(angle);
229 out[1] = original[0] * sinf(angle) + original[1] * cosf(angle);
252 }
else if (in >= w) {
256 return powf(m*in, 3)+b*in;
272 *m = cbrtf((1-b)/(3*powf(w,2)));
274 *r = powf(*m*w, 3)+b*w;
290 float linear_interpolate(
float const input,
float const * curve, uint8_t num_points,
const float input_min,
const float input_max)
293 float scale = fmaxf( (input - input_min) / (input_max - input_min), 0.0
f) * (float) (num_points - 1);
297 scale -= (float)idx1;
301 if (idx2 >= num_points) {
303 idx2 = num_points -1;
305 if (idx1 >= num_points) {
307 return curve[num_points-1];
310 return curve[idx1] * (1.0f -
scale) + curve[idx2] * scale;
313 static uint32_t
random_state[4] = { 0xdeadbeef, 0xfeedfeed, 0xcafebabe, 1234 };
333 random_state[2] = random_state[1];
334 random_state[1] = random_state[0];
346 uint32_t thresh = UINT32_MAX;
350 uint32_t remainder = UINT32_MAX % interval;
352 if (remainder != (interval - 1)) {
353 thresh -= remainder + 1;
361 }
while (rand_val > thresh);
367 return rand_val % interval;
375 if (deadband < 0.0001
f)
return;
376 if (deadband >= 0.85
f)
return;
378 if (fabsf(*value) < deadband) {
387 *value /= (1 - deadband);
float cubic_deadband(float in, float w, float b, float m, float r)
float expoM(float x, int32_t g, float exponent)
float circular_modulus_rad(float err)
static float scale(float val, float inMin, float inMax, float outMin, float outMax)
float vector3_distances(const float *actual, const float *desired, float *out, bool normalize)
static uint32_t randomize_int32()
float interpolate_value(const float fraction, const float beginVal, const float endVal)
float circular_modulus_deg(float err)
Circular modulus.
void apply_channel_deadband(float *value, float deadband)
Apply deadband to Roll/Pitch/Yaw channels.
void vector2_clip(float *vels, float limit)
uint32_t randomize_int(uint32_t interval)
float bound_min_max(float val, float min, float max)
Bound input value between min and max.
float bound_sym(float val, float range)
Bound input value within range (plus or minus)
void cubic_deadband_setup(float w, float b, float *m, float *r)
void randomize_addseed(uint32_t seed)
float linear_interpolate(float const input, float const *curve, uint8_t num_points, const float input_min, const float input_max)
float vectorn_magnitude(const float *v, int n)
static uint32_t random_state[4]
float expo3(float x, int32_t g)
Approximation an exponential scale curve.
void vector2_rotate(const float *original, float *out, float angle)