remove preprocessor_math.h
Compiler are pretty smart today. sqrt is precalculated for constant values. E.g. you need to #include <math.h>. But no need to link the libmath. cos/sin and other stuff should also work.
This commit is contained in:
parent
3b13eb342f
commit
e23a9b3e23
9
dda.c
9
dda.c
|
|
@ -9,7 +9,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "dda_maths.h"
|
#include "dda_maths.h"
|
||||||
#include "preprocessor_math.h"
|
|
||||||
#include "dda_kinematics.h"
|
#include "dda_kinematics.h"
|
||||||
#include "dda_lookahead.h"
|
#include "dda_lookahead.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
@ -64,10 +63,10 @@ static const axes_uint32_t PROGMEM maximum_feedrate_P = {
|
||||||
/// \brief Initialization constant for the ramping algorithm. Timer cycles for
|
/// \brief Initialization constant for the ramping algorithm. Timer cycles for
|
||||||
/// first step interval.
|
/// first step interval.
|
||||||
static const axes_uint32_t PROGMEM c0_P = {
|
static const axes_uint32_t PROGMEM c0_P = {
|
||||||
(uint32_t)((double)F_CPU / SQRT((double)STEPS_PER_M_X * ACCELERATION / 2000.)),
|
(uint32_t)((double)F_CPU / sqrt((double)STEPS_PER_M_X * ACCELERATION / 2000.)),
|
||||||
(uint32_t)((double)F_CPU / SQRT((double)STEPS_PER_M_Y * ACCELERATION / 2000.)),
|
(uint32_t)((double)F_CPU / sqrt((double)STEPS_PER_M_Y * ACCELERATION / 2000.)),
|
||||||
(uint32_t)((double)F_CPU / SQRT((double)STEPS_PER_M_Z * ACCELERATION / 2000.)),
|
(uint32_t)((double)F_CPU / sqrt((double)STEPS_PER_M_Z * ACCELERATION / 2000.)),
|
||||||
(uint32_t)((double)F_CPU / SQRT((double)STEPS_PER_M_E * ACCELERATION / 2000.))
|
(uint32_t)((double)F_CPU / sqrt((double)STEPS_PER_M_E * ACCELERATION / 2000.))
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/** \file
|
|
||||||
|
|
||||||
\brief Math functions meant to be calculated in the C preprocessor.
|
|
||||||
|
|
||||||
\details Math functions presented here avoid library calls, which means they
|
|
||||||
can be solved at compile time and as such used to initialise
|
|
||||||
constants. When used for intitialising, their cost at runtime is
|
|
||||||
zero, as they resolve into a single number.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _PREPROCESSOR_MATH_H
|
|
||||||
#define _PREPROCESSOR_MATH_H
|
|
||||||
|
|
||||||
|
|
||||||
/*! Preprocessor square root.
|
|
||||||
|
|
||||||
(uint32_t)(SQRT(i) + .5)
|
|
||||||
equals
|
|
||||||
(uint32_t)(sqrt(i) + .5)
|
|
||||||
|
|
||||||
These two provide identical results for all tested numbers across the
|
|
||||||
uint32 range. Casting to other sizes is also possible.
|
|
||||||
|
|
||||||
Can principally be used for calculations at runtime, too, but its compiled
|
|
||||||
size is prohibitively large (more than 20kB per instance).
|
|
||||||
|
|
||||||
Initial version found on pl.comp.lang.c, posted by Jean-Louis PATANE.
|
|
||||||
*/
|
|
||||||
#define SQR00(x) (((x) > 65535) ? (double)65535 : (double)(x) / 2)
|
|
||||||
#define SQR01(x) ((SQR00(x) + ((x) / SQR00(x))) / 2)
|
|
||||||
#define SQR02(x) ((SQR01(x) + ((x) / SQR01(x))) / 2)
|
|
||||||
#define SQR03(x) ((SQR02(x) + ((x) / SQR02(x))) / 2)
|
|
||||||
#define SQR04(x) ((SQR03(x) + ((x) / SQR03(x))) / 2)
|
|
||||||
#define SQR05(x) ((SQR04(x) + ((x) / SQR04(x))) / 2)
|
|
||||||
#define SQR06(x) ((SQR05(x) + ((x) / SQR05(x))) / 2)
|
|
||||||
#define SQR07(x) ((SQR06(x) + ((x) / SQR06(x))) / 2)
|
|
||||||
#define SQR08(x) ((SQR07(x) + ((x) / SQR07(x))) / 2)
|
|
||||||
#define SQR09(x) ((SQR08(x) + ((x) / SQR08(x))) / 2)
|
|
||||||
#define SQR10(x) ((SQR09(x) + ((x) / SQR09(x))) / 2)
|
|
||||||
#define SQR11(x) ((SQR10(x) + ((x) / SQR10(x))) / 2)
|
|
||||||
#define SQR12(x) ((SQR11(x) + ((x) / SQR11(x))) / 2)
|
|
||||||
// We use 9 iterations, note how SQR10() and up get ignored. You can add more
|
|
||||||
// iterations here, but beware, the length of the preprocessed term
|
|
||||||
// explodes, leading to several seconds compile time above about SQR10().
|
|
||||||
#define SQRT(x) ((SQR09(x) + ((x) / SQR09(x))) / 2)
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _PREPROCESSOR_MATH_H */
|
|
||||||
Loading…
Reference in New Issue