Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified interpolator mode #458

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions tests/arduino_math/arduino_math.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ typedef union
#define ROUND roundf(a / b)
#define ROUNDA roundf(a)
#define CAST (int32_t)a
#define INV 1 / a
#define INV 1 / (a*0.001f)
#define INV2 ({flt_t res; res.f=a*0.001f; res.i = (0x7eef1aa0 - res.i);res.f;})
#define DBL 2 * a
#define SQRT sqrtf(a)
#define COS cos(a)
#define SIN sin(a)
#define TAN tan(a)
#define HALF (0.5f*a)
#define TANH ({float k=a*0.001;k-=0.5f;((k / (0.5f + abs(k))) + 0.5f);})
#define SCURVE ({float k=a*0.001;float x=(1.0f/(1.0f+pow(k/(1.0f-k),-2)));x;})
#define BEZIER ({uint32_t k=128*a*0.001;float k2=k*k; float c1=k2-2.5*k; float c2=(c1*3+5); (c2*2*k2*k);})
#define HALF_FAST ({int32_t result = (*(int32_t*)&a); if((result&0x7f800000)!=0) result-=0x00800000; else result = 0; (*(float*)&result); })
#define MUL_124 ((a<<7)-(a<<2))
#define DIV_124 ((a>>7)+(a>>12))
Expand All @@ -63,14 +66,14 @@ uint16_t clocks = TCNT1;TCCR1B=0;\
Serial.println(#TYPE);\
PRINT_OP(OP);\
Serial.print("a = ");\
Serial.println((uint32_t)a);\
Serial.println(a);\
Serial.print("b = ");\
Serial.println((uint32_t)b);\
Serial.println(b);\
if(a<res) \
Serial.print("res > ");\
else \
Serial.print("res < ");\
Serial.println((uint32_t) res);\
Serial.println(res);\
Serial.print("Elapsed (clocks): ");\
Serial.println(clocks-offset);\
}
Expand All @@ -87,7 +90,7 @@ void setup() {
offset = TCNT1;
TCCR1B=0;

Serial.println("8-bit");
/*Serial.println("8-bit");
DO_OP(uint8_t, uint16_t, 0,0xFF,ADD);
DO_OP(uint8_t, uint16_t, 0,0xFF,SUB);
DO_OP(uint8_t, uint16_t, 0,0xFF,MUL);
Expand All @@ -109,13 +112,13 @@ void setup() {
DO_OP(uint64_t, uint64_t, 0,0xFFFF,ADD);
DO_OP(uint64_t, uint64_t, 0,0xFFFF,SUB);
DO_OP(uint64_t, uint64_t, 0,0xFFFF,MUL);
DO_OP(uint64_t, uint64_t, 0,0xFFFF,DIV);
DO_OP(uint64_t, uint64_t, 0,0xFFFF,DIV);*/
Serial.println("float");
DO_OP(float, float, 0,10000,ADD);
DO_OP(float, float, 0,10000,SUB);
DO_OP(float, float, 0,10000,MUL);
DO_OP(float, float, 0,10000,DIV);
DO_OP(float, float, 0,10000,FLT_BY4);
DO_OP(float, float, 0,1000,TANH);
DO_OP(float, float, 0,1000,SCURVE);
DO_OP(float, float, 0,1000,BEZIER);
DO_OP(float, float, 0,1000,INV);
DO_OP(float, float, 0,1000,INV2);
/*Serial.println("testes");
DO_OP(float, 0,10000,ROUND);
DO_OP(float, 0,10000,ROUNDA);
Expand Down
16 changes: 6 additions & 10 deletions uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,19 +427,15 @@ extern "C"
* Performs motions with variable acceleration (trapezoidal speed profile
* with rounded speed transition between accel/deaccel and constant speed)
* instead of constant acceleration (trapezoidal speed profile)
*
* 0 - disabled
* 1 - mild profile (smaller mid slope and higher initial and exit slopes)
* 2 - medium profile (medium mid slope and medium initial and exit slopes)
* 3 - agressive (higher mid slope and smaller initial and exit slopes - uses bezier 5th order)
*
* */

// #define ENABLE_S_CURVE_ACCELERATION

/**
* Enables legacy step interpolation generator (prior to version 1.4)
* This runs a variable time window Riemman sum integrator (better performance).
* S-Curve acceleration will disable this option
* This produces option outputs code smaller size
* */

#define USE_LEGACY_STEP_INTERPOLATOR
#define S_CURVE_ACCELERATION_LEVEL 0

/**
* Forces pin pooling for all limits and control pins (with or without
Expand Down
6 changes: 2 additions & 4 deletions uCNC/src/cnc_hal_config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1996,10 +1996,8 @@ typedef uint16_t step_t;
#error "DSS_CUTOFF_FREQ should not be set above 1/8th of the max step rate"
#endif

#ifdef ENABLE_S_CURVE_ACCELERATION
#ifdef USE_LEGACY_STEP_INTERPOLATOR
#undef USE_LEGACY_STEP_INTERPOLATOR
#endif
#if ((S_CURVE_ACCELERATION_LEVEL < 0) || (S_CURVE_ACCELERATION_LEVEL > 3))
#error "invalid s-curve velocity profile setting"
#endif

#if (defined(KINEMATICS_MOTION_BY_SEGMENTS))
Expand Down
Loading
Loading