From 8fc86f89519b60e2ef32a5bd5a46c080b38eb272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Thu, 6 Jul 2017 07:06:42 +0200 Subject: [PATCH] minor change in 'native' checker use correct gears sizes. --- native/native.C | 30 ++++++++++++++++++++---------- native/native.py | 6 +++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/native/native.C b/native/native.C index 3686051..b30acc8 100644 --- a/native/native.C +++ b/native/native.C @@ -1,14 +1,18 @@ #include #include -static const double nr_teeth_small = 11.0; -static const double nr_teeth_big = 53.0; -static const double axis_hinge_dist_mm = 200; +#include "../arduino/teeth_config.h" + +static const float nr_teeth_small = CONFIG_TEETH_SMALL; // 13.0 +static const float nr_teeth_big = CONFIG_TEETH_BIG; // 51.0 +static const float axis_hinge_dist_mm = 200; #define PI M_PI -static const double earth_rot_speed_rad_sec = 2*PI / (1440*60*1000); -static const double bolt_thread_mm = 1.25; +// Use immediate value. Using symbolic values leads to incorrect value. +static const float earth_rot_speed_rad_msec = 7.272205e-8; //2*PI / (1440*60); + +static const float bolt_thread_mm = 1.25; /* static const unsigned int microstepping_div = 16; */ @@ -23,19 +27,25 @@ static const double bolt_thread_mm = 1.25; /* double stepper_gear_rot_rad = 0; */ /* } rot_state; */ - static double get_expected_stepper_rot(unsigned long elapsed_time_millis) { - const double r = tan(fmod(earth_rot_speed_rad_sec * (elapsed_time_millis), PI)) * axis_hinge_dist_mm * 2 * PI * nr_teeth_big / (bolt_thread_mm * nr_teeth_small); + const float r = tan(earth_rot_speed_rad_msec * elapsed_time_millis) + * axis_hinge_dist_mm + * 2 * PI + * nr_teeth_big + / (bolt_thread_mm * nr_teeth_small); + + // const float r = tan(earth_rot_speed_rad_sec * (elapsed_time_millis)) * axis_hinge_dist_mm * 2 * PI * nr_teeth_big / (bolt_thread_mm * nr_teeth_small); return r; } int main(int argc, char **argv) { - unsigned long millis_step = 0; + unsigned long sec_step = 0; - for (millis_step=0; millis_step < 1000; millis_step++) { - printf("%d (%d sec) : %f\n", millis_step*1000, millis_step, get_expected_stepper_rot(millis_step * 1000)); + for (sec_step=0; sec_step < 1000; sec_step++) { + const float exp = get_expected_stepper_rot(sec_step * 1000); + printf("%d (%d sec) : %f (%f rounds)\n", sec_step*1000, sec_step, exp, exp/(2*PI)); } return 0; diff --git a/native/native.py b/native/native.py index c51a7b7..d351cba 100755 --- a/native/native.py +++ b/native/native.py @@ -4,8 +4,8 @@ import sys import numpy BOLT_THREAD = 1.25 -NR_TEETH_BIG=53 -NR_TEETH_SMALL=11 +NR_TEETH_BIG=51 +NR_TEETH_SMALL=13 EARTH_SIDERAL_DAY = 1440 HINGE_ROD_LEN = 200 @@ -40,7 +40,7 @@ def debug_from_step_angle(sangle): def get_step_angle_from_time(time_in_sec): final_angle = time_in_sec * 2 * numpy.pi / (1440*60) sangle = numpy.tan(final_angle) * HINGE_ROD_LEN * 2 * numpy.pi * NR_TEETH_BIG / (BOLT_THREAD * NR_TEETH_SMALL) - print("For {} sec, final angle is {} rad => step angle is {}".format(time_in_sec, final_angle, sangle)) + print("For {} sec, final angle is {} rad ({} deg) => step angle is {}".format(time_in_sec, final_angle, final_angle * 360 /(2*numpy.pi), sangle)) verif_final = debug_from_step_angle(sangle) get_step_angle_from_time(int(sys.argv[1]))