EE149
/
FinalProject
Final Project files for mBed development.
main.h@39:cc8691700d2a, 2014-12-13 (annotated)
- Committer:
- alecguertin
- Date:
- Sat Dec 13 07:35:57 2014 +0000
- Revision:
- 39:cc8691700d2a
- Parent:
- 37:1d51cf101b03
- Child:
- 40:0199bad6c979
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lsaristo | 8:12d780f7443e | 1 | /** |
lsaristo | 10:94b068b2ce1d | 2 | * @file main.h |
lsaristo | 35:a1c14c6d9282 | 3 | * @brief Main header file for includes and defs |
lsaristo | 8:12d780f7443e | 4 | * @author John Wilkey |
lsaristo | 29:459ff10d2a07 | 5 | * @author Alec Guertin |
lsaristo | 29:459ff10d2a07 | 6 | * @author Chester Chu |
lsaristo | 8:12d780f7443e | 7 | */ |
lsaristo | 8:12d780f7443e | 8 | |
lsaristo | 10:94b068b2ce1d | 9 | #ifndef _MAIN_H |
lsaristo | 10:94b068b2ce1d | 10 | #define _MAIN_H |
lsaristo | 8:12d780f7443e | 11 | |
lsaristo | 8:12d780f7443e | 12 | #include "mbed.h" |
lsaristo | 8:12d780f7443e | 13 | #include "m3pi.h" |
lsaristo | 9:3a0433c391cb | 14 | #include <string.h> |
lsaristo | 9:3a0433c391cb | 15 | #include <stdarg.h> |
lsaristo | 9:3a0433c391cb | 16 | #include <stdio.h> |
lsaristo | 21:0c80a5d89ea3 | 17 | #include <math.h> |
lsaristo | 35:a1c14c6d9282 | 18 | |
lsaristo | 35:a1c14c6d9282 | 19 | // Constants used in main.c |
lsaristo | 35:a1c14c6d9282 | 20 | #define TURN_SPEED 0.15 /**< Motor power for turning */ |
lsaristo | 35:a1c14c6d9282 | 21 | #define DRIVE_SPEED 0.25 /**< Motor power for drawing/moving */ |
lsaristo | 35:a1c14c6d9282 | 22 | #define TIME_FACT 1780 /**< Multiplier for forward() and backward() */ |
lsaristo | 35:a1c14c6d9282 | 23 | #define CAL_SPEED .25 /**< Drive speed during calibration */ |
lsaristo | 35:a1c14c6d9282 | 24 | #define CLOSE_ENOUGH .0008 /**< Threshold for calibration line centering */ |
alecguertin | 37:1d51cf101b03 | 25 | #define WIGGLE_MAX 30 /**< Max 'wiggles' during calibration */ |
alecguertin | 39:cc8691700d2a | 26 | #define CORNER_THRESHOLD 0.3 /**< Threshold for checking if line position denotes a corner */ |
alecguertin | 39:cc8691700d2a | 27 | #define INST_BUF_SIZE 250 /**< Size of input buffer for instructions */ |
alecguertin | 39:cc8691700d2a | 28 | #define CORRECTION_SPEED 0.2*DRIVE_SPEED /**< Amount to change speed of one wheel when following line */ |
alecguertin | 39:cc8691700d2a | 29 | #define CORRECTION_THRESHOLD 0.05 /**< Maximum tolerable deviation from line when following line */ |
alecguertin | 39:cc8691700d2a | 30 | #define RAD_TO_DEG 57.29 /**< Factor to convert radians to degrees */ |
alecguertin | 39:cc8691700d2a | 31 | #define FULL_TURN 360 /**< Degrees for a full turn */ |
alecguertin | 39:cc8691700d2a | 32 | #define HALF_TURN 180 /**< Degrees for a half turn */ |
alecguertin | 39:cc8691700d2a | 33 | #define QUARTER_TURN 90 /**< Degrees for a quarter (right angle) turn */ |
alecguertin | 39:cc8691700d2a | 34 | #define CAL_FACTOR 1.1 /**< Scaling factor for time to drive */ |
alecguertin | 39:cc8691700d2a | 35 | #define DEGREE_CORRECTION 0 /**< Amount (in degrees) added to the angle for each turn */ |
alecguertin | 39:cc8691700d2a | 36 | #define SEC_TO_MSEC 1000 /**< Scaling factor to convert seconds to milliseconds */ |
alecguertin | 39:cc8691700d2a | 37 | #define SEC_TO_USEC 1000000 /**< Scaling factor to convert seconds to microseconds */ |
alecguertin | 39:cc8691700d2a | 38 | #define MSEC_TO_USEC 1000 /**< Scaling factor to convert milliseconds to microseconds */ |
lsaristo | 8:12d780f7443e | 39 | |
lsaristo | 29:459ff10d2a07 | 40 | /** @brief Move the robot from its current position to (x,y) */ |
alecguertin | 18:eab7b0e89398 | 41 | void move(int x, int y, int draw); |
alecguertin | 18:eab7b0e89398 | 42 | |
lsaristo | 8:12d780f7443e | 43 | /** |
alecguertin | 17:c72c092fcdf7 | 44 | * @brief get values of next PostScript instruction. |
alecguertin | 17:c72c092fcdf7 | 45 | * |
alecguertin | 17:c72c092fcdf7 | 46 | * @param buf Buffer with PS instructions. |
alecguertin | 17:c72c092fcdf7 | 47 | * @param x Pointer to storage for x coordinate. |
alecguertin | 17:c72c092fcdf7 | 48 | * @param y Pointer to storage for y coordinate. |
alecguertin | 17:c72c092fcdf7 | 49 | * @param draw Pointer to storage for draw/move boolean. |
alecguertin | 17:c72c092fcdf7 | 50 | * |
alecguertin | 17:c72c092fcdf7 | 51 | * @return Success or failure code. |
alecguertin | 17:c72c092fcdf7 | 52 | */ |
alecguertin | 17:c72c092fcdf7 | 53 | int retrieve_inst(char *buf, int *x, int *y, int *draw); |
alecguertin | 17:c72c092fcdf7 | 54 | |
alecguertin | 17:c72c092fcdf7 | 55 | /** |
lsaristo | 29:459ff10d2a07 | 56 | * @brief Driver forward for a time. |
lsaristo | 8:12d780f7443e | 57 | * |
lsaristo | 29:459ff10d2a07 | 58 | * @param[in] amt Amount to drive forward. In milliseconds. |
lsaristo | 8:12d780f7443e | 59 | */ |
lsaristo | 29:459ff10d2a07 | 60 | void forward(int amt); |
lsaristo | 8:12d780f7443e | 61 | |
lsaristo | 8:12d780f7443e | 62 | /** |
lsaristo | 29:459ff10d2a07 | 63 | * @brief Drive backward for a time. |
lsaristo | 8:12d780f7443e | 64 | * |
lsaristo | 29:459ff10d2a07 | 65 | * @param[in] amt Amount to drive backward. In milliseconds. |
lsaristo | 8:12d780f7443e | 66 | */ |
lsaristo | 29:459ff10d2a07 | 67 | void backward(int amt); |
lsaristo | 8:12d780f7443e | 68 | |
lsaristo | 8:12d780f7443e | 69 | /** |
lsaristo | 29:459ff10d2a07 | 70 | * @brief Turn right by some angle. |
lsaristo | 8:12d780f7443e | 71 | * |
lsaristo | 29:459ff10d2a07 | 72 | * @param[in] deg Desired final turn angle in degrees from start. |
lsaristo | 29:459ff10d2a07 | 73 | * Note that a negative angle will turn in the opposite |
lsaristo | 29:459ff10d2a07 | 74 | * direction. |
lsaristo | 8:12d780f7443e | 75 | */ |
lsaristo | 29:459ff10d2a07 | 76 | void right(float deg); |
lsaristo | 8:12d780f7443e | 77 | |
lsaristo | 8:12d780f7443e | 78 | /** |
lsaristo | 29:459ff10d2a07 | 79 | * @brief Turn left by some angle. |
lsaristo | 8:12d780f7443e | 80 | * |
lsaristo | 29:459ff10d2a07 | 81 | * @param[in] deg Desired final turn angle in degrees from start. |
lsaristo | 29:459ff10d2a07 | 82 | * Note that a negative angle will turn in the opposite |
lsaristo | 29:459ff10d2a07 | 83 | * direction. |
lsaristo | 8:12d780f7443e | 84 | */ |
lsaristo | 29:459ff10d2a07 | 85 | void left (float deg); |
lsaristo | 8:12d780f7443e | 86 | |
lsaristo | 21:0c80a5d89ea3 | 87 | /** |
lsaristo | 29:459ff10d2a07 | 88 | * @brief Wait for a number of seconds, possibly fractional. |
lsaristo | 29:459ff10d2a07 | 89 | * |
lsaristo | 29:459ff10d2a07 | 90 | * Timer resolution is on the order of microseconds. A negative wait |
lsaristo | 29:459ff10d2a07 | 91 | * time does nothing. |
lsaristo | 21:0c80a5d89ea3 | 92 | * |
lsaristo | 29:459ff10d2a07 | 93 | * @param[in] amt Time to wait, in seconds. |
lsaristo | 21:0c80a5d89ea3 | 94 | */ |
lsaristo | 29:459ff10d2a07 | 95 | void timerWait(float amt); |
alecguertin | 39:cc8691700d2a | 96 | |
alecguertin | 39:cc8691700d2a | 97 | int find_corner(int left); |
alecguertin | 39:cc8691700d2a | 98 | |
alecguertin | 39:cc8691700d2a | 99 | void find_line(); |
alecguertin | 39:cc8691700d2a | 100 | |
alecguertin | 39:cc8691700d2a | 101 | float distance(int x1, int y1, int x2, int y2); |
alecguertin | 39:cc8691700d2a | 102 | |
alecguertin | 39:cc8691700d2a | 103 | void robot_printf(int line, const char *format, ...); |
alecguertin | 39:cc8691700d2a | 104 | |
alecguertin | 39:cc8691700d2a | 105 | float compute_turn_angle(int last_x, int last_y, int x, int y, float angle); |
lsaristo | 29:459ff10d2a07 | 106 | #endif |