fix little bugs in derotator

This commit is contained in:
eddyem 2018-07-03 12:21:20 +03:00
parent 841ac20c88
commit b1771c5104
3 changed files with 32 additions and 20 deletions

View File

@ -4,15 +4,17 @@ BTA_utils
clone of my BTA_utils on sourceforge
** jsonbta
* jsonbta
Allows to stream BTA data over TCP socket
** Stellarium_control
* Stellarium_control
Allows to point telescope with help of stellarium
** fits_headers
* fits_headers
Process FITS-files with WCS headers and calculate reference angle between plate angle (P2) and parallax angle
** wfs_read
* wfs_read
Read WFS/DAT files got by SHA tool (Shack-Hartmann processing utilite) and get some information from it.
* p1rotator
Raspberry-Pi based tool for BTA field derotators

View File

@ -37,14 +37,14 @@
// End-switch - GPIO25 (leg22)
#define ESW_PIN (25)
// Stepper: EN - GPIO18 (leg12), DIR - GPIO23 (leg16), STEP - GPIO24 (leg18)
// Stepper: STEP - GPIO18 (leg12), DIR - GPIO23 (leg16), EN - GPIO24 (leg18)
#define DIR_PIN (23)
#define STEP_PIN (24)
#define EN_PIN (18)
#define STEP_PIN (18)
#define EN_PIN (24)
// active/passive levels (depending on stepper driver connection schematic)
#define PIN_ACTIVE (1)
#define PIN_PASSIVE (0)
#define PIN_ACTIVE (0)
#define PIN_PASSIVE (1)
// active level on end-switch: 0 - normally opened, 1 - normally closed
#define ESW_ACTIVE (0)
@ -55,7 +55,7 @@
// maximum 200 steps per second
#define MAX_SPEED (200)
#define USTEP_DELAY (1./MAX_SPEED/USTEPS)
#define USTEP_DELAY (1./MAX_SPEED/USTEPS/2)
// Position angle calculation (val_Alp, val_Del, S_time - for real work)
#define CALC_PA() calc_PA(SrcAlpha, SrcDelta, S_time)
@ -65,7 +65,7 @@
// microsteps per one revolution
#define ONETURN_USTEPS (ONETURN_STEPS * USTEPS * GEARRAT)
#define ONETURN_USTEPS (ONETURN_STEPS * USTEPS * GEARRAT * 2)
// initial (wrong) value of microsteps counter
#define USTEPSBAD (2*ONETURN_USTEPS)
// minimal PA delta

View File

@ -98,9 +98,11 @@ void print_PA(double ang){
#ifdef __arm__
static void Write(int pin, int val){
double t0 = dtime();
if(val) val = 1;
digitalWrite(pin, val);
while(digitalRead(pin) != val);
while(digitalRead(pin) != val && dtime() - t0 > 1.);
if(digitalRead(pin) != val) WARNX("error setting pin value: need %d, got %d", val, digitalRead(pin));
}
static void Toggle(int pin){
int v = digitalRead(pin);
@ -110,15 +112,19 @@ static void Toggle(int pin){
void setup_pins(){
#ifdef __arm__
DBG("setup GPIO");
wiringPiSetupGpio();
Write(EN_PIN, PIN_PASSIVE); // disable all @ start
Write(DIR_PIN, PIN_PASSIVE);
Write(STEP_PIN, PIN_PASSIVE);
DBG("setup PINs");
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(ESW_PIN, INPUT);
Write(EN_PIN, PIN_PASSIVE); // disable all @ start
Write(DIR_PIN, PIN_PASSIVE);
Write(STEP_PIN, PIN_PASSIVE);
DBG("setup pullup");
pullUpDnControl(ESW_PIN, PUD_UP);
DBG("done");
#else // __arm__
green("Setup GPIO\n");
#endif // __arm__
@ -129,17 +135,19 @@ void setup_pins(){
*/
void stop_motor(){
// force_exit = 1;
usleep(1000);
// usleep(1000);
#ifdef __arm__
// disable motor & all other
pullUpDnControl(ESW_PIN, PUD_OFF);
pinMode(DIR_PIN, INPUT);
pinMode(EN_PIN, INPUT);
pinMode(STEP_PIN, INPUT);
DBG("return pin modes");
// return values to initial state
Write(EN_PIN, 0);
Write(DIR_PIN, 0);
Write(STEP_PIN, 0);
pinMode(DIR_PIN, INPUT);
//pinMode(EN_PIN, INPUT);
pinMode(STEP_PIN, INPUT);
DBG("pull control");
pullUpDnControl(ESW_PIN, PUD_OFF);
DBG("STOPPED");
#else
green("Stop Stepper\n");
@ -170,6 +178,7 @@ static void move_motor(int nusteps){
dir = -1;
nusteps = -nusteps;
}
DBG("moving for %d steps", nusteps);
#ifdef __arm__
Write(DIR_PIN, (dir > 0) ? DIR_POSITIVE : DIR_NEGATIVE); // prepare direction
for(; nusteps; --nusteps){
@ -187,6 +196,7 @@ int gotozero(){
#ifdef __arm__
int nusteps = ONETURN_USTEPS * 1.1;
Write(DIR_PIN, DIR_NEGATIVE);
DBG("go to zero position");
for(; nusteps; --nusteps){
Toggle(STEP_PIN);
mk_pause(USTEP_DELAY);