/* Program uses a struct containing an array of doubles and an int to move
 *   in a square.
 */

#include <MyroC.h>

#define NUM_ACTIONS 8

typedef struct {
  double speed;
  double time;
} movement_t;


int
main()
{
  rConnect("/dev/rfcomm0");
  rSetForwardnessTxt("fluke-forward");

  int a; 

  /* Declares an array of NUM_ACTIONS movement structs */
  movement_t actions[NUM_ACTIONS];

  /* Loop to initialize the values in the structs */
  for (a = 0; a < NUM_ACTIONS; a++)
    {
      /* Sets a constant speed for all actions */
      actions[a].speed = 1 - (.1 * a);

      /* Sets the time for each action to increase by half a second */
      actions[a].time = (a / 2.0) + 0.5;
    }

  /* Loop to move the Scribbler according to the structs stored times
     and speed(s). */
  for (a = 0; a < NUM_ACTIONS; a++)
    {
      /* Command to move forward according to the speed and time stored
         in the struct in the array position i */
      rForward( actions[a].speed, actions[a].time);

      /* Command to make a (roughly) 90 degree turn to the left */
      rTurnLeft(1, 0.8);
    }

  rBeep (1, 600);

  rDisconnect();
  return 0;
} // main
