/*   @(#) $Header: navigate.h,v  abrown Exp $
 * Author:
 *	"Allen Brown" http://brown.armoredpenguin.com/~abrown/contact.html
 * Description:
 *   Header for navigation software.
 *
 * Copyright (C) 2006,2007,2008 Allen Brown
 *
 * License:
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU 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 General Public License for more details.
 *   
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *     Free Software Foundation, Inc.,
 *     51 Franklin Street, Fifth Floor,
 *     Boston, MA  02110-1301, USA.
 */
#ifndef NAVIGATE_H
  #define NAVIGATE_H

  #include "varsizes.h"

/* ----------------------------------------------------------------
 * Declares a pair of quadrature objects as related for navigation
 * purposes.
 * quad_left and quad_right: the pointers returned from the two
 *   calls to quadrature_new().
 * encoder_spacing: distance between the two encoder wheels.
 *   The units should be the same as you use for calibrating the
 *   encoders.  The axis of each wheel should be in line with the
 *   other.  This common axis should pass through the center of
 *   gravity of the robot so that any pivoting the robot does is
 *   about the midpoint between these wheels.
 */
  void* navigate_new(int16 encoder_spacing);

/* ----------------------------------------------------------------
 * Set the initial navigation location.
 * Coordinates are in the number space.
 */
  void navigate_init(void* nav_data_set, int32 left, int32 right, int32 x, int32 y, int16 heading);

/* ----------------------------------------------------------------
 * Updates the x,y position of the robot.
 * This must be called fairly frequently or xy navigation accuracy
 * will suffer.  Each call to navigate_poll() must provide the then
 * current total distance traveled by each of the two wheels.
 * navigate_poll() will compare that to the last numbers provided
 * to determine the new location and heading.
 */
  void navigate_poll(void* nav_data_set,
		     int32 left_dist_new, int32 right_dist_new,
		     int16 gyroheading);

/* ----------------------------------------------------------------
 * Returns the heading in units of NavUnitPerDegree from a starting heading
 * of 0. Numbers do *not* wrap at 360*NavUnitPerDegree or negative.
 */
  int16 navigate_heading(void* nav_data_set);

/* ----------------------------------------------------------------
 * Returns the current x and y coords of the robot.
 */
  void navigate_xy(void* nav_data_set, int32 *x, int32 *y);
#endif

#define NavUnitPerInch ((int32)100)	// Fractional inch units.
#define NavUnitPerFoot ((int32)12)*NavUnitPerInch
#define NavUnitPerMeter ((int32)3937)

