Subversion Repositories svnkaklik

Rev

Blame | Last modification | View Log | Download

/* 
 * Copyright (C) 2004 Darren Hutchinson (dbh@gbdt.com.au)
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Library General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA. 
 *
 * $Id: combine.c,v 1.5 2004/04/05 06:42:15 dbh Exp $
 */

#include <avr/io.h>
#include "combine.h"
#include "stepper.h"

/* Instance of rate input/output variables. Normally we would pass these via
 * pointers, but this is a small code/data/environment, so they're
 * accessed globally
 */
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};
struct rateOutput_s rateOutput = {SPEED_0_X, SPEED_0_X};

/* TEST: defeat tracking for testing */
uint8_t         noTrack = 0;

/* updateMountSpeed() takes the various speed inputs from the paddle,
 * serial port, and guiding inputs and determines the actual RA and
 * DEC rates
 *
 * Passed:
 *         nothing
 *
 * Returns:
 *         nothing
 *
 * Notes:
 *         Updates rateOutput global structure
 */
void
updateMountSpeed(void)
{
    int8_t      guideRate;

    /* Determine the DEC rate. This is the simple one! */
    if (rateInput.paddleDecRate != SPEED_0_X)
        guideRate = rateInput.paddleDecRate;
    else if (rateInput.serialDecRate != SPEED_0_X)
        guideRate = rateInput.serialDecRate;
    else if (rateInput.guideDecRate != SPEED_0_X)
        guideRate = rateInput.guideDecRate;
    else
        guideRate = SPEED_0_X;

    rateOutput.decRate = guideRate;
    setDecSpeed(rateOutput.decRate);

    /* Determine the RA rate. This is complicated by the need to perform
     * tracking as well as guiding on this axis
     */
    if (rateInput.paddleRaRate != SPEED_0_X)
        guideRate = rateInput.paddleRaRate;
    else if (rateInput.serialRaRate != SPEED_0_X)
        guideRate = rateInput.serialRaRate;
    else if (rateInput.guideRaRate != SPEED_0_X)
        guideRate = rateInput.guideRaRate;
    else
        guideRate = SPEED_0_X;

    /* Now we need to add the traking rate to the guiding rate. Fractional
     * guiding rates simply adjust the tracking rate, x1 guiding
     * doubles/stops the motion, higher tracking rate override the
     * guiding rate.
     */
    if (noTrack || (guideRate > SPEED_1_X) || (guideRate < -SPEED_1_X))
        rateOutput.raRate = guideRate;
    else if ((guideRate < SPEED_1_X) && (guideRate > -SPEED_1_X))
        rateOutput.raRate = rateInput.siderialRate + guideRate;
    else if ((guideRate == SPEED_1_X) && (rateInput.siderialRate == SPEED_1_X))
        rateOutput.raRate = SPEED_2_X;
    else if ((guideRate == -SPEED_1_X) && (rateInput.siderialRate == -SPEED_1_X))
        rateOutput.raRate = -SPEED_2_X;
    else
        rateOutput.raRate = SPEED_0_X;

    /* The RA axis needs to turn in the opposite direction of the
     * DEC axis. This is the simplest place to do it
     */
    setRaSpeed(-rateOutput.raRate);

    /* All done! */
}