mbed robotracer for education.

Robotracer (line follower robot ) using stepper motor.

/media/uploads/hayama/cimg8463.jpg

/media/uploads/hayama/mbedrobotracer-manual-english.pdf

/media/uploads/hayama/mbedrobotracer-manual-japanese.pdf

/media/uploads/hayama/eagle-design-robotracer.zip

movie -> https://www.youtube.com/watch?v=INwun8gSds4

(for competition->) https://www.youtube.com/watch?v=l_gP2pUt4w0

Committer:
hayama
Date:
Wed Jun 19 10:00:41 2013 +0000
Revision:
0:da22b0b4395a
mbed robotracer for education ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hayama 0:da22b0b4395a 1 /* mbed Microcontroller Library
hayama 0:da22b0b4395a 2 * Copyright (c) 2006-2013 ARM Limited
hayama 0:da22b0b4395a 3 *
hayama 0:da22b0b4395a 4 * Licensed under the Apache License, Version 2.0 (the "License");
hayama 0:da22b0b4395a 5 * you may not use this file except in compliance with the License.
hayama 0:da22b0b4395a 6 * You may obtain a copy of the License at
hayama 0:da22b0b4395a 7 *
hayama 0:da22b0b4395a 8 * http://www.apache.org/licenses/LICENSE-2.0
hayama 0:da22b0b4395a 9 *
hayama 0:da22b0b4395a 10 * Unless required by applicable law or agreed to in writing, software
hayama 0:da22b0b4395a 11 * distributed under the License is distributed on an "AS IS" BASIS,
hayama 0:da22b0b4395a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
hayama 0:da22b0b4395a 13 * See the License for the specific language governing permissions and
hayama 0:da22b0b4395a 14 * limitations under the License.
hayama 0:da22b0b4395a 15 */
hayama 0:da22b0b4395a 16 #ifndef MBED_FILEHANDLE_H
hayama 0:da22b0b4395a 17 #define MBED_FILEHANDLE_H
hayama 0:da22b0b4395a 18
hayama 0:da22b0b4395a 19 typedef int FILEHANDLE;
hayama 0:da22b0b4395a 20
hayama 0:da22b0b4395a 21 #include <stdio.h>
hayama 0:da22b0b4395a 22
hayama 0:da22b0b4395a 23 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
hayama 0:da22b0b4395a 24 typedef int ssize_t;
hayama 0:da22b0b4395a 25 typedef long off_t;
hayama 0:da22b0b4395a 26
hayama 0:da22b0b4395a 27 #else
hayama 0:da22b0b4395a 28 # include <sys/types.h>
hayama 0:da22b0b4395a 29 #endif
hayama 0:da22b0b4395a 30
hayama 0:da22b0b4395a 31 namespace mbed {
hayama 0:da22b0b4395a 32
hayama 0:da22b0b4395a 33 /** An OO equivalent of the internal FILEHANDLE variable
hayama 0:da22b0b4395a 34 * and associated _sys_* functions.
hayama 0:da22b0b4395a 35 *
hayama 0:da22b0b4395a 36 * FileHandle is an abstract class, needing at least sys_write and
hayama 0:da22b0b4395a 37 * sys_read to be implmented for a simple interactive device.
hayama 0:da22b0b4395a 38 *
hayama 0:da22b0b4395a 39 * No one ever directly tals to/instanciates a FileHandle - it gets
hayama 0:da22b0b4395a 40 * created by FileSystem, and wrapped up by stdio.
hayama 0:da22b0b4395a 41 */
hayama 0:da22b0b4395a 42 class FileHandle {
hayama 0:da22b0b4395a 43
hayama 0:da22b0b4395a 44 public:
hayama 0:da22b0b4395a 45 /** Write the contents of a buffer to the file
hayama 0:da22b0b4395a 46 *
hayama 0:da22b0b4395a 47 * @param buffer the buffer to write from
hayama 0:da22b0b4395a 48 * @param length the number of characters to write
hayama 0:da22b0b4395a 49 *
hayama 0:da22b0b4395a 50 * @returns
hayama 0:da22b0b4395a 51 * The number of characters written (possibly 0) on success, -1 on error.
hayama 0:da22b0b4395a 52 */
hayama 0:da22b0b4395a 53 virtual ssize_t write(const void* buffer, size_t length) = 0;
hayama 0:da22b0b4395a 54
hayama 0:da22b0b4395a 55 /** Close the file
hayama 0:da22b0b4395a 56 *
hayama 0:da22b0b4395a 57 * @returns
hayama 0:da22b0b4395a 58 * Zero on success, -1 on error.
hayama 0:da22b0b4395a 59 */
hayama 0:da22b0b4395a 60 virtual int close() = 0;
hayama 0:da22b0b4395a 61
hayama 0:da22b0b4395a 62 /** Function read
hayama 0:da22b0b4395a 63 * Reads the contents of the file into a buffer
hayama 0:da22b0b4395a 64 *
hayama 0:da22b0b4395a 65 * @param buffer the buffer to read in to
hayama 0:da22b0b4395a 66 * @param length the number of characters to read
hayama 0:da22b0b4395a 67 *
hayama 0:da22b0b4395a 68 * @returns
hayama 0:da22b0b4395a 69 * The number of characters read (zero at end of file) on success, -1 on error.
hayama 0:da22b0b4395a 70 */
hayama 0:da22b0b4395a 71 virtual ssize_t read(void* buffer, size_t length) = 0;
hayama 0:da22b0b4395a 72
hayama 0:da22b0b4395a 73 /** Check if the handle is for a interactive terminal device.
hayama 0:da22b0b4395a 74 * If so, line buffered behaviour is used by default
hayama 0:da22b0b4395a 75 *
hayama 0:da22b0b4395a 76 * @returns
hayama 0:da22b0b4395a 77 * 1 if it is a terminal,
hayama 0:da22b0b4395a 78 * 0 otherwise
hayama 0:da22b0b4395a 79 */
hayama 0:da22b0b4395a 80 virtual int isatty() = 0;
hayama 0:da22b0b4395a 81
hayama 0:da22b0b4395a 82 /** Move the file position to a given offset from a given location.
hayama 0:da22b0b4395a 83 *
hayama 0:da22b0b4395a 84 * @param offset The offset from whence to move to
hayama 0:da22b0b4395a 85 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
hayama 0:da22b0b4395a 86 * current file position, or SEEK_END for the end of the file.
hayama 0:da22b0b4395a 87 *
hayama 0:da22b0b4395a 88 * @returns
hayama 0:da22b0b4395a 89 * new file position on success,
hayama 0:da22b0b4395a 90 * -1 on failure or unsupported
hayama 0:da22b0b4395a 91 */
hayama 0:da22b0b4395a 92 virtual off_t lseek(off_t offset, int whence) = 0;
hayama 0:da22b0b4395a 93
hayama 0:da22b0b4395a 94 /** Flush any buffers associated with the FileHandle, ensuring it
hayama 0:da22b0b4395a 95 * is up to date on disk
hayama 0:da22b0b4395a 96 *
hayama 0:da22b0b4395a 97 * @returns
hayama 0:da22b0b4395a 98 * 0 on success or un-needed,
hayama 0:da22b0b4395a 99 * -1 on error
hayama 0:da22b0b4395a 100 */
hayama 0:da22b0b4395a 101 virtual int fsync() = 0;
hayama 0:da22b0b4395a 102
hayama 0:da22b0b4395a 103 virtual off_t flen() {
hayama 0:da22b0b4395a 104 /* remember our current position */
hayama 0:da22b0b4395a 105 off_t pos = lseek(0, SEEK_CUR);
hayama 0:da22b0b4395a 106 if(pos == -1) return -1;
hayama 0:da22b0b4395a 107 /* seek to the end to get the file length */
hayama 0:da22b0b4395a 108 off_t res = lseek(0, SEEK_END);
hayama 0:da22b0b4395a 109 /* return to our old position */
hayama 0:da22b0b4395a 110 lseek(pos, SEEK_SET);
hayama 0:da22b0b4395a 111 return res;
hayama 0:da22b0b4395a 112 }
hayama 0:da22b0b4395a 113
hayama 0:da22b0b4395a 114 virtual ~FileHandle();
hayama 0:da22b0b4395a 115 };
hayama 0:da22b0b4395a 116
hayama 0:da22b0b4395a 117 } // namespace mbed
hayama 0:da22b0b4395a 118
hayama 0:da22b0b4395a 119 #endif