Final Project files for mBed development.

Dependencies:   m3pi mbed

Committer:
lsaristo
Date:
Tue Dec 09 22:56:54 2014 +0000
Revision:
32:8b589710632b
Parent:
31:1e950ee04481
Child:
34:3066686d5152
Added pi.stop()s back in. Removed unneeded stuff.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lsaristo 8:12d780f7443e 1 /**
lsaristo 10:94b068b2ce1d 2 * @file main.h
lsaristo 8:12d780f7443e 3 * @brief Main header file for includes and whatnot
lsaristo 8:12d780f7443e 4 * for the other project files.
lsaristo 8:12d780f7443e 5 * @author John Wilkey
lsaristo 29:459ff10d2a07 6 * @author Alec Guertin
lsaristo 29:459ff10d2a07 7 * @author Chester Chu
lsaristo 8:12d780f7443e 8 */
lsaristo 8:12d780f7443e 9
lsaristo 10:94b068b2ce1d 10 #ifndef _MAIN_H
lsaristo 10:94b068b2ce1d 11 #define _MAIN_H
lsaristo 8:12d780f7443e 12
lsaristo 8:12d780f7443e 13 #include "mbed.h"
lsaristo 8:12d780f7443e 14 #include "m3pi.h"
lsaristo 9:3a0433c391cb 15 #include <string.h>
lsaristo 9:3a0433c391cb 16 #include <stdarg.h>
lsaristo 9:3a0433c391cb 17 #include <stdio.h>
lsaristo 21:0c80a5d89ea3 18 #include <math.h>
lsaristo 21:0c80a5d89ea3 19 #define TURN_SPEED 0.15
lsaristo 21:0c80a5d89ea3 20 #define DRIVE_SPEED 0.2
lsaristo 8:12d780f7443e 21 #define ERR_SUCCESS 0
lsaristo 8:12d780f7443e 22 #define ERR_FAILURE 1
lsaristo 9:3a0433c391cb 23 #define DRIVE_RATE 1/50
chstrchu 31:1e950ee04481 24 #define TIME_FACT 1780
lsaristo 21:0c80a5d89ea3 25 #define CAL_SPEED .1
alecguertin 22:46b9d9b2e35c 26 #define CLOSE_ENOUGH .0008
lsaristo 8:12d780f7443e 27
lsaristo 29:459ff10d2a07 28 /** @brief Move the robot from its current position to (x,y) */
alecguertin 18:eab7b0e89398 29 void move(int x, int y, int draw);
alecguertin 18:eab7b0e89398 30
lsaristo 8:12d780f7443e 31 /**
alecguertin 17:c72c092fcdf7 32 * @brief get values of next PostScript instruction.
alecguertin 17:c72c092fcdf7 33 *
alecguertin 17:c72c092fcdf7 34 * @param buf Buffer with PS instructions.
alecguertin 17:c72c092fcdf7 35 * @param x Pointer to storage for x coordinate.
alecguertin 17:c72c092fcdf7 36 * @param y Pointer to storage for y coordinate.
alecguertin 17:c72c092fcdf7 37 * @param draw Pointer to storage for draw/move boolean.
alecguertin 17:c72c092fcdf7 38 *
alecguertin 17:c72c092fcdf7 39 * @return Success or failure code.
alecguertin 17:c72c092fcdf7 40 */
alecguertin 17:c72c092fcdf7 41 int retrieve_inst(char *buf, int *x, int *y, int *draw);
alecguertin 17:c72c092fcdf7 42
alecguertin 17:c72c092fcdf7 43 /**
lsaristo 29:459ff10d2a07 44 * @brief Driver forward for a time.
lsaristo 8:12d780f7443e 45 *
lsaristo 29:459ff10d2a07 46 * @param[in] amt Amount to drive forward. In milliseconds.
lsaristo 8:12d780f7443e 47 */
lsaristo 29:459ff10d2a07 48 void forward(int amt);
lsaristo 8:12d780f7443e 49
lsaristo 8:12d780f7443e 50 /**
lsaristo 29:459ff10d2a07 51 * @brief Drive backward for a time.
lsaristo 8:12d780f7443e 52 *
lsaristo 29:459ff10d2a07 53 * @param[in] amt Amount to drive backward. In milliseconds.
lsaristo 8:12d780f7443e 54 */
lsaristo 29:459ff10d2a07 55 void backward(int amt);
lsaristo 8:12d780f7443e 56
lsaristo 8:12d780f7443e 57 /**
lsaristo 29:459ff10d2a07 58 * @brief Turn right by some angle.
lsaristo 8:12d780f7443e 59 *
lsaristo 29:459ff10d2a07 60 * @param[in] deg Desired final turn angle in degrees from start.
lsaristo 29:459ff10d2a07 61 * Note that a negative angle will turn in the opposite
lsaristo 29:459ff10d2a07 62 * direction.
lsaristo 8:12d780f7443e 63 */
lsaristo 29:459ff10d2a07 64 void right(float deg);
lsaristo 8:12d780f7443e 65
lsaristo 8:12d780f7443e 66 /**
lsaristo 29:459ff10d2a07 67 * @brief Turn left by some angle.
lsaristo 8:12d780f7443e 68 *
lsaristo 29:459ff10d2a07 69 * @param[in] deg Desired final turn angle in degrees from start.
lsaristo 29:459ff10d2a07 70 * Note that a negative angle will turn in the opposite
lsaristo 29:459ff10d2a07 71 * direction.
lsaristo 8:12d780f7443e 72 */
lsaristo 29:459ff10d2a07 73 void left (float deg);
lsaristo 8:12d780f7443e 74
lsaristo 29:459ff10d2a07 75 /** @brief Lower pen intro drawing position */
lsaristo 10:94b068b2ce1d 76 void pen_down();
lsaristo 10:94b068b2ce1d 77
lsaristo 29:459ff10d2a07 78 /** @brief Raise pen into moveto position */
lsaristo 29:459ff10d2a07 79 void pen_up();
lsaristo 10:94b068b2ce1d 80
lsaristo 10:94b068b2ce1d 81 /**
lsaristo 8:12d780f7443e 82 * @brief Controller decision logic.
lsaristo 8:12d780f7443e 83 *
lsaristo 8:12d780f7443e 84 * Decide what to do next based on the status of the drawing so far.
lsaristo 8:12d780f7443e 85 */
lsaristo 8:12d780f7443e 86 void next_action();
lsaristo 21:0c80a5d89ea3 87
lsaristo 21:0c80a5d89ea3 88 /**
lsaristo 29:459ff10d2a07 89 * @brief Wait for a number of seconds, possibly fractional.
lsaristo 29:459ff10d2a07 90 *
lsaristo 29:459ff10d2a07 91 * Timer resolution is on the order of microseconds. A negative wait
lsaristo 29:459ff10d2a07 92 * time does nothing.
lsaristo 21:0c80a5d89ea3 93 *
lsaristo 29:459ff10d2a07 94 * @param[in] amt Time to wait, in seconds.
lsaristo 21:0c80a5d89ea3 95 */
lsaristo 29:459ff10d2a07 96 void timerWait(float amt);
lsaristo 29:459ff10d2a07 97 #endif