Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
508 kaklik 1
/* 
2
 * Copyright (C) 2004 Darren Hutchinson (dbh@gbdt.com.au)
3
 * 
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU Library General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or (at your
7
 * option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
12
 * License for more details.
13
 * 
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this software; see the file COPYING.  If not, write to
16
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17
 * MA 02111-1307, USA. 
18
 *
19
 * $Id: combine.c,v 1.5 2004/04/05 06:42:15 dbh Exp $
20
 */
21
 
22
#include <avr/io.h>
23
#include "combine.h"
24
#include "stepper.h"
25
 
26
/* Instance of rate input/output variables. Normally we would pass these via
27
 * pointers, but this is a small code/data/environment, so they're
28
 * accessed globally
29
 */
30
struct rateInput_s    rateInput = {SPEED_0_X, SPEED_0_X, SPEED_0_X, SPEED_0_X, SPEED_0_X, SPEED_0_X, SPEED_0_X};
31
struct rateOutput_s rateOutput = {SPEED_0_X, SPEED_0_X};
32
 
33
/* TEST: defeat tracking for testing */
34
uint8_t         noTrack = 0;
35
 
36
/* updateMountSpeed() takes the various speed inputs from the paddle,
37
 * serial port, and guiding inputs and determines the actual RA and
38
 * DEC rates
39
 *
40
 * Passed:
41
 *         nothing
42
 *
43
 * Returns:
44
 *         nothing
45
 *
46
 * Notes:
47
 *         Updates rateOutput global structure
48
 */
49
void
50
updateMountSpeed(void)
51
{
52
    int8_t      guideRate;
53
 
54
    /* Determine the DEC rate. This is the simple one! */
55
    if (rateInput.paddleDecRate != SPEED_0_X)
56
        guideRate = rateInput.paddleDecRate;
57
    else if (rateInput.serialDecRate != SPEED_0_X)
58
        guideRate = rateInput.serialDecRate;
59
    else if (rateInput.guideDecRate != SPEED_0_X)
60
        guideRate = rateInput.guideDecRate;
61
    else
62
        guideRate = SPEED_0_X;
63
 
64
    rateOutput.decRate = guideRate;
65
    setDecSpeed(rateOutput.decRate);
66
 
67
    /* Determine the RA rate. This is complicated by the need to perform
68
     * tracking as well as guiding on this axis
69
     */
70
    if (rateInput.paddleRaRate != SPEED_0_X)
71
        guideRate = rateInput.paddleRaRate;
72
    else if (rateInput.serialRaRate != SPEED_0_X)
73
        guideRate = rateInput.serialRaRate;
74
    else if (rateInput.guideRaRate != SPEED_0_X)
75
        guideRate = rateInput.guideRaRate;
76
    else
77
        guideRate = SPEED_0_X;
78
 
79
    /* Now we need to add the traking rate to the guiding rate. Fractional
80
     * guiding rates simply adjust the tracking rate, x1 guiding
81
     * doubles/stops the motion, higher tracking rate override the
82
     * guiding rate.
83
     */
84
    if (noTrack || (guideRate > SPEED_1_X) || (guideRate < -SPEED_1_X))
85
        rateOutput.raRate = guideRate;
86
    else if ((guideRate < SPEED_1_X) && (guideRate > -SPEED_1_X))
87
        rateOutput.raRate = rateInput.siderialRate + guideRate;
88
    else if ((guideRate == SPEED_1_X) && (rateInput.siderialRate == SPEED_1_X))
89
        rateOutput.raRate = SPEED_2_X;
90
    else if ((guideRate == -SPEED_1_X) && (rateInput.siderialRate == -SPEED_1_X))
91
        rateOutput.raRate = -SPEED_2_X;
92
    else
93
        rateOutput.raRate = SPEED_0_X;
94
 
95
    /* The RA axis needs to turn in the opposite direction of the
96
     * DEC axis. This is the simplest place to do it
97
     */
98
    setRaSpeed(-rateOutput.raRate);
99
 
100
    /* All done! */
101
}