Roving robot using the RS-EDP.
Dependencies: mbed RSEDP_AM_MC1_lib SDFileSystem
main.cpp@0:8d15dc761944, 2010-08-16 (annotated)
- Committer:
- aberk
- Date:
- Mon Aug 16 09:46:28 2010 +0000
- Revision:
- 0:8d15dc761944
- Child:
- 1:ffef6386027b
Version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aberk | 0:8d15dc761944 | 1 | /** |
aberk | 0:8d15dc761944 | 2 | * @author Aaron Berk |
aberk | 0:8d15dc761944 | 3 | * |
aberk | 0:8d15dc761944 | 4 | * @section LICENSE |
aberk | 0:8d15dc761944 | 5 | * |
aberk | 0:8d15dc761944 | 6 | * Copyright (c) 2010 ARM Limited |
aberk | 0:8d15dc761944 | 7 | * |
aberk | 0:8d15dc761944 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
aberk | 0:8d15dc761944 | 9 | * of this software and associated documentation files (the "Software"), to deal |
aberk | 0:8d15dc761944 | 10 | * in the Software without restriction, including without limitation the rights |
aberk | 0:8d15dc761944 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
aberk | 0:8d15dc761944 | 12 | * copies of the Software, and to permit persons to whom the Software is |
aberk | 0:8d15dc761944 | 13 | * furnished to do so, subject to the following conditions: |
aberk | 0:8d15dc761944 | 14 | * |
aberk | 0:8d15dc761944 | 15 | * The above copyright notice and this permission notice shall be included in |
aberk | 0:8d15dc761944 | 16 | * all copies or substantial portions of the Software. |
aberk | 0:8d15dc761944 | 17 | * |
aberk | 0:8d15dc761944 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
aberk | 0:8d15dc761944 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
aberk | 0:8d15dc761944 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
aberk | 0:8d15dc761944 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
aberk | 0:8d15dc761944 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
aberk | 0:8d15dc761944 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
aberk | 0:8d15dc761944 | 24 | * THE SOFTWARE. |
aberk | 0:8d15dc761944 | 25 | * |
aberk | 0:8d15dc761944 | 26 | * @section DESCRIPTION |
aberk | 0:8d15dc761944 | 27 | * |
aberk | 0:8d15dc761944 | 28 | * Rover example. |
aberk | 0:8d15dc761944 | 29 | * |
aberk | 0:8d15dc761944 | 30 | * Reads and executes a set of commands from a simple command script. |
aberk | 0:8d15dc761944 | 31 | */ |
aberk | 0:8d15dc761944 | 32 | |
aberk | 0:8d15dc761944 | 33 | /** |
aberk | 0:8d15dc761944 | 34 | * Includes |
aberk | 0:8d15dc761944 | 35 | */ |
aberk | 0:8d15dc761944 | 36 | #include "Rover.h" |
aberk | 0:8d15dc761944 | 37 | |
aberk | 0:8d15dc761944 | 38 | //Debugging. |
aberk | 0:8d15dc761944 | 39 | Serial pc(USBTX, USBRX); |
aberk | 0:8d15dc761944 | 40 | |
aberk | 0:8d15dc761944 | 41 | //Globals. |
aberk | 0:8d15dc761944 | 42 | LocalFileSystem local("local"); |
aberk | 0:8d15dc761944 | 43 | SDFileSystem sd(p11, p12, p13, p14, "sd"); |
aberk | 0:8d15dc761944 | 44 | |
aberk | 0:8d15dc761944 | 45 | int main() { |
aberk | 0:8d15dc761944 | 46 | |
aberk | 0:8d15dc761944 | 47 | //left motor pwm, left motor brake, left motor direction, |
aberk | 0:8d15dc761944 | 48 | //right motor pwm, right motor brake, right motor direction, |
aberk | 0:8d15dc761944 | 49 | //left qei A, left qei B, left qei index, left pulses per rev, |
aberk | 0:8d15dc761944 | 50 | //right qei A, right qei B, right qei index, right pulses per rev. |
aberk | 0:8d15dc761944 | 51 | Rover myRover(p23, p19, p28, p26, p22, p24, |
aberk | 0:8d15dc761944 | 52 | p29, p30, NC, 624, |
aberk | 0:8d15dc761944 | 53 | p18, p21, NC, 624); |
aberk | 0:8d15dc761944 | 54 | |
aberk | 0:8d15dc761944 | 55 | //----------------------- |
aberk | 0:8d15dc761944 | 56 | // Simple command parser |
aberk | 0:8d15dc761944 | 57 | //----------------------- |
aberk | 0:8d15dc761944 | 58 | char cmd0[16]; //{"move", "turn"} |
aberk | 0:8d15dc761944 | 59 | char cmd1[16]; //{{"forward", "backward"}, {"left", "right"}} |
aberk | 0:8d15dc761944 | 60 | int cmd2 = 0; //{distance, angle} |
aberk | 0:8d15dc761944 | 61 | |
aberk | 0:8d15dc761944 | 62 | pc.printf("Starting...\n"); |
aberk | 0:8d15dc761944 | 63 | |
aberk | 0:8d15dc761944 | 64 | wait(3); |
aberk | 0:8d15dc761944 | 65 | |
aberk | 0:8d15dc761944 | 66 | FILE *fp = fopen("/local/commands.txt", "r"); |
aberk | 0:8d15dc761944 | 67 | |
aberk | 0:8d15dc761944 | 68 | if (fp == NULL) { |
aberk | 0:8d15dc761944 | 69 | pc.printf("Opening file failed...\n"); |
aberk | 0:8d15dc761944 | 70 | } else { |
aberk | 0:8d15dc761944 | 71 | pc.printf("Opening file succeeded!\n"); |
aberk | 0:8d15dc761944 | 72 | } |
aberk | 0:8d15dc761944 | 73 | |
aberk | 0:8d15dc761944 | 74 | while (fscanf(fp, "%s%s%d", cmd0, cmd1, &cmd2) >= 0) { |
aberk | 0:8d15dc761944 | 75 | |
aberk | 0:8d15dc761944 | 76 | wait(1); |
aberk | 0:8d15dc761944 | 77 | |
aberk | 0:8d15dc761944 | 78 | pc.printf("%s %s %d\n", cmd0, cmd1, cmd2); |
aberk | 0:8d15dc761944 | 79 | |
aberk | 0:8d15dc761944 | 80 | //move command. |
aberk | 0:8d15dc761944 | 81 | if (strcmp(cmd0, "move") == 0) { |
aberk | 0:8d15dc761944 | 82 | if (strcmp(cmd1, "forward") == 0) { |
aberk | 0:8d15dc761944 | 83 | myRover.move(cmd2); |
aberk | 0:8d15dc761944 | 84 | while (myRover.getState() != Rover::STATE_STATIONARY) { |
aberk | 0:8d15dc761944 | 85 | } |
aberk | 0:8d15dc761944 | 86 | } else if (strcmp(cmd1, "backward") == 0) { |
aberk | 0:8d15dc761944 | 87 | myRover.move(-cmd2); |
aberk | 0:8d15dc761944 | 88 | while (myRover.getState() != Rover::STATE_STATIONARY) { |
aberk | 0:8d15dc761944 | 89 | } |
aberk | 0:8d15dc761944 | 90 | } |
aberk | 0:8d15dc761944 | 91 | } |
aberk | 0:8d15dc761944 | 92 | //turn command. |
aberk | 0:8d15dc761944 | 93 | else if (strcmp(cmd0, "turn") == 0) { |
aberk | 0:8d15dc761944 | 94 | if (strcmp(cmd1, "left") == 0) { |
aberk | 0:8d15dc761944 | 95 | myRover.turn(-cmd2); |
aberk | 0:8d15dc761944 | 96 | while (myRover.getState() != Rover::STATE_STATIONARY) { |
aberk | 0:8d15dc761944 | 97 | } |
aberk | 0:8d15dc761944 | 98 | } else if (strcmp(cmd1, "right") == 0) { |
aberk | 0:8d15dc761944 | 99 | myRover.turn(cmd2); |
aberk | 0:8d15dc761944 | 100 | while (myRover.getState() != Rover::STATE_STATIONARY) { |
aberk | 0:8d15dc761944 | 101 | } |
aberk | 0:8d15dc761944 | 102 | } |
aberk | 0:8d15dc761944 | 103 | } |
aberk | 0:8d15dc761944 | 104 | |
aberk | 0:8d15dc761944 | 105 | } |
aberk | 0:8d15dc761944 | 106 | |
aberk | 0:8d15dc761944 | 107 | wait(1); |
aberk | 0:8d15dc761944 | 108 | |
aberk | 0:8d15dc761944 | 109 | myRover.stopLogging(); |
aberk | 0:8d15dc761944 | 110 | fclose(fp); |
aberk | 0:8d15dc761944 | 111 | |
aberk | 0:8d15dc761944 | 112 | } |