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_FUNCTIONPOINTER_H
hayama 0:da22b0b4395a 17 #define MBED_FUNCTIONPOINTER_H
hayama 0:da22b0b4395a 18
hayama 0:da22b0b4395a 19 #include <string.h>
hayama 0:da22b0b4395a 20
hayama 0:da22b0b4395a 21 namespace mbed {
hayama 0:da22b0b4395a 22
hayama 0:da22b0b4395a 23 /** A class for storing and calling a pointer to a static or member void function
hayama 0:da22b0b4395a 24 */
hayama 0:da22b0b4395a 25 class FunctionPointer {
hayama 0:da22b0b4395a 26 public:
hayama 0:da22b0b4395a 27
hayama 0:da22b0b4395a 28 /** Create a FunctionPointer, attaching a static function
hayama 0:da22b0b4395a 29 *
hayama 0:da22b0b4395a 30 * @param function The void static function to attach (default is none)
hayama 0:da22b0b4395a 31 */
hayama 0:da22b0b4395a 32 FunctionPointer(void (*function)(void) = 0);
hayama 0:da22b0b4395a 33
hayama 0:da22b0b4395a 34 /** Create a FunctionPointer, attaching a member function
hayama 0:da22b0b4395a 35 *
hayama 0:da22b0b4395a 36 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
hayama 0:da22b0b4395a 37 * @param function The address of the void member function to attach
hayama 0:da22b0b4395a 38 */
hayama 0:da22b0b4395a 39 template<typename T>
hayama 0:da22b0b4395a 40 FunctionPointer(T *object, void (T::*member)(void)) {
hayama 0:da22b0b4395a 41 attach(object, member);
hayama 0:da22b0b4395a 42 }
hayama 0:da22b0b4395a 43
hayama 0:da22b0b4395a 44 /** Attach a static function
hayama 0:da22b0b4395a 45 *
hayama 0:da22b0b4395a 46 * @param function The void static function to attach (default is none)
hayama 0:da22b0b4395a 47 */
hayama 0:da22b0b4395a 48 void attach(void (*function)(void) = 0);
hayama 0:da22b0b4395a 49
hayama 0:da22b0b4395a 50 /** Attach a member function
hayama 0:da22b0b4395a 51 *
hayama 0:da22b0b4395a 52 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
hayama 0:da22b0b4395a 53 * @param function The address of the void member function to attach
hayama 0:da22b0b4395a 54 */
hayama 0:da22b0b4395a 55 template<typename T>
hayama 0:da22b0b4395a 56 void attach(T *object, void (T::*member)(void)) {
hayama 0:da22b0b4395a 57 _object = static_cast<void*>(object);
hayama 0:da22b0b4395a 58 memcpy(_member, (char*)&member, sizeof(member));
hayama 0:da22b0b4395a 59 _membercaller = &FunctionPointer::membercaller<T>;
hayama 0:da22b0b4395a 60 _function = 0;
hayama 0:da22b0b4395a 61 }
hayama 0:da22b0b4395a 62
hayama 0:da22b0b4395a 63 /** Call the attached static or member function
hayama 0:da22b0b4395a 64 */
hayama 0:da22b0b4395a 65 void call();
hayama 0:da22b0b4395a 66
hayama 0:da22b0b4395a 67 private:
hayama 0:da22b0b4395a 68 template<typename T>
hayama 0:da22b0b4395a 69 static void membercaller(void *object, char *member) {
hayama 0:da22b0b4395a 70 T* o = static_cast<T*>(object);
hayama 0:da22b0b4395a 71 void (T::*m)(void);
hayama 0:da22b0b4395a 72 memcpy((char*)&m, member, sizeof(m));
hayama 0:da22b0b4395a 73 (o->*m)();
hayama 0:da22b0b4395a 74 }
hayama 0:da22b0b4395a 75
hayama 0:da22b0b4395a 76 void (*_function)(void); // static function pointer - 0 if none attached
hayama 0:da22b0b4395a 77 void *_object; // object this pointer - 0 if none attached
hayama 0:da22b0b4395a 78 char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
hayama 0:da22b0b4395a 79 void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object
hayama 0:da22b0b4395a 80 };
hayama 0:da22b0b4395a 81
hayama 0:da22b0b4395a 82 } // namespace mbed
hayama 0:da22b0b4395a 83
hayama 0:da22b0b4395a 84 #endif