/* BAckground Sensor Actuator Loop (BASAL) for Phoenix mobile robot */
/* Maintains a number of sensory variables and interprets commands. */
/* Copyright 1998, Johuco Ltd., All Rights Reserved */
/* Written by Jon Connell, 1/98, Version 1.3 beta   */

/* ====================================================================== */

#ifndef _BASAL_

/* standard math functions */

#define abs(v) ((v >= 0) ? v : -(v))

#define max(a,b) ((a > b) ? a : b)

#define min(a,b) ((a < b) ? a : b)


/* clip value to remain in range specified */

#define clamp_val(v,lo,hi) ((v < lo) ? lo : ((v > hi) ? hi : v))


/* useful macro pseudo-function for manipulating timeout counters */

#define update_mono(m,v,t) {if (t) m = v; else if (m) m--;} 


/* transfer activation to another state and continue transition loop */

#define shift_state(n) {state = n; break;}


/* valid state found, terminate clause and exit transition loop */

#define mark_stable() {stable++; break;}


/* zero some variable if a new state is entered */

#define enter_reset(v) {if (state != start) v = 0;}


/* ---------------------------------------------------------------------- */

/* low-level control variables (write only) */

int drive_speed;
int turn_speed;
int beeper_cmd;
int led_cmd;
int ping_slot;


/* low-level sensor variables (read only) */

int wleft_val;
int wright_val;
int nleft_val;
int nright_val;
int passive_vals;
int passive_time;
int velocity;

int top_level;
int front_level;
int battery_level;
int shakiness_level;
int knob_level;
int button_val;
int roll_val;

int user6_level;
int user5_level;
int user4_level;


/* ---------------------------------------------------------------------- */

/* public function prototypes */

void init_basal (void);
int next_basal (void);


/* ---------------------------------------------------------------------- */

/* This should really be a library. But since the freeware ICC11  */
/* compiler does not support this, the .c file is included here.  */

#define _BASAL_
#include <basal.c>

#endif


/* ==================================================================== */

