From a423bb2267eaa70ab955d04c7ebcb40d053ab4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Tue, 13 Jun 2017 23:21:44 +0200 Subject: [PATCH] check routine in C++ and python --- native/native.C | 42 ++++++++++++++++++++++++++++++++++++++++++ native/native.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 native/native.C create mode 100755 native/native.py diff --git a/native/native.C b/native/native.C new file mode 100644 index 0000000..3686051 --- /dev/null +++ b/native/native.C @@ -0,0 +1,42 @@ +#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; + +#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; + + +/* static const unsigned int microstepping_div = 16; */ +/* static const unsigned int nr_steps = 200 * microstepping_div; */ + +/* static const double stepper_gear_rad_per_step = (2*PI) / nr_steps; */ + + +// this needs to be reset +/* static struct rot_state_t { */ +/* unsigned long elapsed_time_millis; */ +/* 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); + + return r; +} + + +int main(int argc, char **argv) { + unsigned long millis_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)); + + } + return 0; +} diff --git a/native/native.py b/native/native.py new file mode 100755 index 0000000..c51a7b7 --- /dev/null +++ b/native/native.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +import sys +import numpy + +BOLT_THREAD = 1.25 +NR_TEETH_BIG=53 +NR_TEETH_SMALL=11 + +EARTH_SIDERAL_DAY = 1440 +HINGE_ROD_LEN = 200 + +def rodlen_to_angle(rod_len): + return numpy.arctan(rod_len / HINGE_ROD_LEN) + +def drivegear_angle_to_rodlen(angle): + return BOLT_THREAD*angle/(2*numpy.pi) + +def steppergear_angle_to_drivegear_angle(sangle): + return sangle * NR_TEETH_SMALL/NR_TEETH_BIG + + +def debug_from_step_angle(sangle): + step_angle = float(sangle) + + print("Step angle {}rad".format(step_angle)) + + drivegear_angle = steppergear_angle_to_drivegear_angle(step_angle) + + print("Drive gear angle {}rad".format(drivegear_angle)) + + rodlen = drivegear_angle_to_rodlen(drivegear_angle) + + print("Rod length {}mm".format(rodlen)) + + final_angle = rodlen_to_angle(rodlen) + + print("Final angle {}rad".format(final_angle)) + +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)) + verif_final = debug_from_step_angle(sangle) + +get_step_angle_from_time(int(sys.argv[1]))