From e776fb5d5c5fe07d2a21ee0440a6974a9c296f65 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 26 May 2017 14:27:39 +0200 Subject: [PATCH] Init --- .gitignore | 1 + Makefile | 26 +++ libraries/SimpleTimer/SimpleTimer.cpp | 241 ++++++++++++++++++++++++++ libraries/SimpleTimer/SimpleTimer.h | 124 +++++++++++++ notes | 17 ++ secondaire.ino | 82 +++++++++ 6 files changed, 491 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 libraries/SimpleTimer/SimpleTimer.cpp create mode 100644 libraries/SimpleTimer/SimpleTimer.h create mode 100644 notes create mode 100644 secondaire.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d92cbb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +demoAmau diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5afd8ca --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +# Configuration de la carte +BOARD_TAG = mega +#BOARD_TAG = uno +BOARD_SUB = atmega2560 +MONITOR_BAUDRATE = 115200 + +# On peut écraser cette valeur en utilisant +# make MONITOR_PORT=/dev/ttyACM1 upload +# (par exemple) +MONITOR_PORT = /dev/ttyACM* + +# Flags du compilateur +CFLAGS_STD = -std=gnu11 +CXXFLAGS_STD = -std=gnu++11 + +CXXFLAGS = -pedantic -Wall -Wextra +CXXFLAGS += -fdiagnostics-color + +# Fichires de sortie +TARGET=main +OBJDIR=build + +USER_LIB_PATH := libraries +ARDUINO_QUIET=true +include Arduino-Makefile/Arduino.mk + diff --git a/libraries/SimpleTimer/SimpleTimer.cpp b/libraries/SimpleTimer/SimpleTimer.cpp new file mode 100644 index 0000000..6d478c2 --- /dev/null +++ b/libraries/SimpleTimer/SimpleTimer.cpp @@ -0,0 +1,241 @@ + /* + * SimpleTimer.cpp + * + * SimpleTimer - A timer library for Arduino. + * Author: mromani@ottotecnica.com + * Copyright (c) 2010 OTTOTECNICA Italy + * + * This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser + * General Public License as published by the Free Software + * Foundation; either version 2.1 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser + * General Public License along with this library; if not, + * write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#include "SimpleTimer.h" + + +// Select time function: +//static inline unsigned long elapsed() { return micros(); } +static inline unsigned long elapsed() { return millis(); } + + +SimpleTimer::SimpleTimer() { + unsigned long current_millis = elapsed(); + + for (int i = 0; i < MAX_TIMERS; i++) { + enabled[i] = false; + callbacks[i] = 0; // if the callback pointer is zero, the slot is free, i.e. doesn't "contain" any timer + prev_millis[i] = current_millis; + numRuns[i] = 0; + } + + numTimers = 0; +} + + +void SimpleTimer::run() { + int i; + unsigned long current_millis; + + // get current time + current_millis = elapsed(); + + for (i = 0; i < MAX_TIMERS; i++) { + + toBeCalled[i] = DEFCALL_DONTRUN; + + // no callback == no timer, i.e. jump over empty slots + if (callbacks[i]) { + + // is it time to process this timer ? + // see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592 + + if (current_millis - prev_millis[i] >= delays[i]) { + + // update time + //prev_millis[i] = current_millis; + prev_millis[i] += delays[i]; + + // check if the timer callback has to be executed + if (enabled[i]) { + + // "run forever" timers must always be executed + if (maxNumRuns[i] == RUN_FOREVER) { + toBeCalled[i] = DEFCALL_RUNONLY; + } + // other timers get executed the specified number of times + else if (numRuns[i] < maxNumRuns[i]) { + toBeCalled[i] = DEFCALL_RUNONLY; + numRuns[i]++; + + // after the last run, delete the timer + if (numRuns[i] >= maxNumRuns[i]) { + toBeCalled[i] = DEFCALL_RUNANDDEL; + } + } + } + } + } + } + + for (i = 0; i < MAX_TIMERS; i++) { + switch(toBeCalled[i]) { + case DEFCALL_DONTRUN: + break; + + case DEFCALL_RUNONLY: + (*callbacks[i])(); + break; + + case DEFCALL_RUNANDDEL: + (*callbacks[i])(); + deleteTimer(i); + break; + } + } +} + + +// find the first available slot +// return -1 if none found +int SimpleTimer::findFirstFreeSlot() { + int i; + + // all slots are used + if (numTimers >= MAX_TIMERS) { + return -1; + } + + // return the first slot with no callback (i.e. free) + for (i = 0; i < MAX_TIMERS; i++) { + if (callbacks[i] == 0) { + return i; + } + } + + // no free slots found + return -1; +} + + +int SimpleTimer::setTimer(long d, timer_callback f, int n) { + int freeTimer; + + freeTimer = findFirstFreeSlot(); + if (freeTimer < 0) { + return -1; + } + + if (f == NULL) { + return -1; + } + + delays[freeTimer] = d; + callbacks[freeTimer] = f; + maxNumRuns[freeTimer] = n; + enabled[freeTimer] = true; + prev_millis[freeTimer] = elapsed(); + + numTimers++; + + return freeTimer; +} + + +int SimpleTimer::setInterval(long d, timer_callback f) { + return setTimer(d, f, RUN_FOREVER); +} + + +int SimpleTimer::setTimeout(long d, timer_callback f) { + return setTimer(d, f, RUN_ONCE); +} + + +void SimpleTimer::deleteTimer(int timerId) { + if (timerId >= MAX_TIMERS) { + return; + } + + // nothing to delete if no timers are in use + if (numTimers == 0) { + return; + } + + // don't decrease the number of timers if the + // specified slot is already empty + if (callbacks[timerId] != NULL) { + callbacks[timerId] = 0; + enabled[timerId] = false; + toBeCalled[timerId] = DEFCALL_DONTRUN; + delays[timerId] = 0; + numRuns[timerId] = 0; + + // update number of timers + numTimers--; + } +} + + +// function contributed by code@rowansimms.com +void SimpleTimer::restartTimer(int numTimer) { + if (numTimer >= MAX_TIMERS) { + return; + } + + prev_millis[numTimer] = elapsed(); +} + + +boolean SimpleTimer::isEnabled(int numTimer) { + if (numTimer >= MAX_TIMERS) { + return false; + } + + return enabled[numTimer]; +} + + +void SimpleTimer::enable(int numTimer) { + if (numTimer >= MAX_TIMERS) { + return; + } + + enabled[numTimer] = true; +} + + +void SimpleTimer::disable(int numTimer) { + if (numTimer >= MAX_TIMERS) { + return; + } + + enabled[numTimer] = false; +} + + +void SimpleTimer::toggle(int numTimer) { + if (numTimer >= MAX_TIMERS) { + return; + } + + enabled[numTimer] = !enabled[numTimer]; +} + + +int SimpleTimer::getNumTimers() { + return numTimers; +} \ No newline at end of file diff --git a/libraries/SimpleTimer/SimpleTimer.h b/libraries/SimpleTimer/SimpleTimer.h new file mode 100644 index 0000000..be78479 --- /dev/null +++ b/libraries/SimpleTimer/SimpleTimer.h @@ -0,0 +1,124 @@ + /* + * SimpleTimer.h + * + * SimpleTimer - A timer library for Arduino. + * Author: mromani@ottotecnica.com + * Copyright (c) 2010 OTTOTECNICA Italy + * + * This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser + * General Public License as published by the Free Software + * Foundation; either version 2.1 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser + * General Public License along with this library; if not, + * write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#ifndef SIMPLETIMER_H +#define SIMPLETIMER_H + +#if defined(ARDUINO) && ARDUINO >= 100 +#include +#else +#include +#endif + +typedef void (*timer_callback)(void); + +class SimpleTimer { + +public: + // maximum number of timers + const static int MAX_TIMERS = 10; + + // setTimer() constants + const static int RUN_FOREVER = 0; + const static int RUN_ONCE = 1; + + // constructor + SimpleTimer(); + + // this function must be called inside loop() + void run(); + + // call function f every d milliseconds + int setInterval(long d, timer_callback f); + + // call function f once after d milliseconds + int setTimeout(long d, timer_callback f); + + // call function f every d milliseconds for n times + int setTimer(long d, timer_callback f, int n); + + // destroy the specified timer + void deleteTimer(int numTimer); + + // restart the specified timer + void restartTimer(int numTimer); + + // returns true if the specified timer is enabled + boolean isEnabled(int numTimer); + + // enables the specified timer + void enable(int numTimer); + + // disables the specified timer + void disable(int numTimer); + + // enables the specified timer if it's currently disabled, + // and vice-versa + void toggle(int numTimer); + + // returns the number of used timers + int getNumTimers(); + + // returns the number of available timers + int getNumAvailableTimers() { return MAX_TIMERS - numTimers; }; + +private: + // deferred call constants + const static int DEFCALL_DONTRUN = 0; // don't call the callback function + const static int DEFCALL_RUNONLY = 1; // call the callback function but don't delete the timer + const static int DEFCALL_RUNANDDEL = 2; // call the callback function and delete the timer + + // find the first available slot + int findFirstFreeSlot(); + + // value returned by the millis() function + // in the previous run() call + unsigned long prev_millis[MAX_TIMERS]; + + // pointers to the callback functions + timer_callback callbacks[MAX_TIMERS]; + + // delay values + long delays[MAX_TIMERS]; + + // number of runs to be executed for each timer + int maxNumRuns[MAX_TIMERS]; + + // number of executed runs for each timer + int numRuns[MAX_TIMERS]; + + // which timers are enabled + boolean enabled[MAX_TIMERS]; + + // deferred function call (sort of) - N.B.: this array is only used in run() + int toBeCalled[MAX_TIMERS]; + + // actual number of timers in use + int numTimers; +}; + +#endif \ No newline at end of file diff --git a/notes b/notes new file mode 100644 index 0000000..b66c79f --- /dev/null +++ b/notes @@ -0,0 +1,17 @@ +Avance, passe la plate-forme, tiourne 90**° droite, attrappe plusieurs balles (1 par bras 5 dans soute) +servo pont-levis +capteur à ultrasons où vue sur base vois si balle +2 mcc avance +que angles droits +avance jusque balle +capt ultrason avant et arrière + + +demoAmau +elements/ + servo → servo + mcc → ultramotor + +general/ + robotsecondaire un truc comme ça + diff --git a/secondaire.ino b/secondaire.ino new file mode 100644 index 0000000..9fad99a --- /dev/null +++ b/secondaire.ino @@ -0,0 +1,82 @@ +#include + +// CONVENTIONS +// distances = mm + +// CAPTEURS +void attendreTirette() { + +} + +bool capteurAvant() { + +} + +bool capteurArriere() { + +} + +bool capteurBoule() { + +} + +// ACTIONNEURS + +void ouvrirPontLevis() { + +} + +void fermerPontLevis() { + +} + +void leverBras() { + +} + +void baisserBras() { + // Ça veut pas dire qu'il faut baisser les bras ! \o/ + +} + + +// DIRECTION + +void stop() { + +} + +void avance(float dist) { + // Ou recule + +} + +void tournerDroite() { + +} + +void tournerGauche() { + +} + +// GÉNÉRALES + +void fin() { + Serial.println("Fin du timer"); + stop(); + // TODO Autres capteurs +} + +void setup() { + Serial.begin(9600); + Serial.println("Setup"); + + // Initialisation des broches + + Serial.println("Initialisation des broches terminé"); + +} + +void loop() { + +}