Projet Drone de surveillance du labo TRSE (INGESUP)

Dependencies:   mbed PID ADXL345 Camera_LS_Y201 ITG3200 RangeFinder mbos xbee_lib Motor Servo

Committer:
Gaetan
Date:
Sat Apr 27 11:00:25 2013 +0000
Revision:
32:74608bce78f6
Parent:
10:c8d73680b9fd
Child:
33:f85d47baaeb4
Mise ? jour de l'OS de test, nouveau fonctionnement des ?v?nements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gaetan 10:c8d73680b9fd 1 /* Copyright (c) 2012 - 2013 Gaëtan PLEYBER
Gaetan 10:c8d73680b9fd 2 *
Gaetan 10:c8d73680b9fd 3 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
Gaetan 10:c8d73680b9fd 4 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Gaetan 10:c8d73680b9fd 5 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
Gaetan 10:c8d73680b9fd 6 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Gaetan 10:c8d73680b9fd 7 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
Gaetan 10:c8d73680b9fd 8 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Gaetan 10:c8d73680b9fd 9 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Gaetan 10:c8d73680b9fd 10 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Gaetan 10:c8d73680b9fd 11 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Gaetan 10:c8d73680b9fd 12 */
Gaetan 10:c8d73680b9fd 13
Gaetan 10:c8d73680b9fd 14 /*
Gaetan 10:c8d73680b9fd 15 * Description
Gaetan 10:c8d73680b9fd 16 * Input
Gaetan 10:c8d73680b9fd 17 * Output
Gaetan 10:c8d73680b9fd 18 */
Gaetan 32:74608bce78f6 19
Gaetan 32:74608bce78f6 20 /*
Gaetan 32:74608bce78f6 21 #include "mbed.h"
Gaetan 6:0e3d95e9885e 22 #include "mbos.h"
NicolasH 0:8d93a5e4e4ab 23
NicolasH 0:8d93a5e4e4ab 24 DigitalOut myled(LED1);
NicolasH 0:8d93a5e4e4ab 25
NicolasH 0:8d93a5e4e4ab 26 int main() {
NicolasH 0:8d93a5e4e4ab 27 while(1) {
NicolasH 0:8d93a5e4e4ab 28 myled = 1;
NicolasH 0:8d93a5e4e4ab 29 wait(0.2);
NicolasH 0:8d93a5e4e4ab 30 myled = 0;
NicolasH 0:8d93a5e4e4ab 31 wait(0.2);
NicolasH 7:4757e20e6f0f 32
NicolasH 7:4757e20e6f0f 33 //modification
NicolasH 0:8d93a5e4e4ab 34 }
Gaetan 6:0e3d95e9885e 35 }*/
Gaetan 32:74608bce78f6 36
Gaetan 6:0e3d95e9885e 37 #include "mbed.h"
Gaetan 6:0e3d95e9885e 38 #include "mbos.h"
Gaetan 32:74608bce78f6 39 #include "os.h"
Gaetan 32:74608bce78f6 40
Gaetan 6:0e3d95e9885e 41
Gaetan 6:0e3d95e9885e 42 void task1(void); // task function prototypes
Gaetan 6:0e3d95e9885e 43 void task2(void);
Gaetan 6:0e3d95e9885e 44
Gaetan 6:0e3d95e9885e 45 DigitalOut led1(LED1);
Gaetan 6:0e3d95e9885e 46 DigitalOut led2(LED2);
Gaetan 32:74608bce78f6 47 DigitalOut led3(LED3);
Gaetan 32:74608bce78f6 48 mbos os(2, 2); // Instantiate mbos with 7 tasks & 7 timer
Gaetan 32:74608bce78f6 49
Gaetan 6:0e3d95e9885e 50
Gaetan 6:0e3d95e9885e 51 int main(void)
Gaetan 6:0e3d95e9885e 52 {
Gaetan 6:0e3d95e9885e 53 // Configure tasks and timers
Gaetan 32:74608bce78f6 54 os.CreateTask(TASK_COM, TASK_COM_PRIO, TASK_COM_STACK_SZ, task1);
Gaetan 32:74608bce78f6 55 os.CreateTask(TASK_DETEC, TASK_DETEC_PRIO, TASK_DETEC_STACK_SZ, task2);
Gaetan 32:74608bce78f6 56 /*os.CreateTask(TASK_MOUV, TASK_MOUV_PRIO, TASK_MOUV_STACK_SZ, task1);
Gaetan 32:74608bce78f6 57 os.CreateTask(TASK_TRAJ, TASK_TRAJ_PRIO, TASK_TRAJ_STACK_SZ, task2);
Gaetan 32:74608bce78f6 58 os.CreateTask(TASK_BATT, TASK_BATT_PRIO, TASK_BATT_STACK_SZ, task1);
Gaetan 32:74608bce78f6 59 os.CreateTask(TASK_VIDEO, TASK_VIDEO_PRIO, TASK_VIDEO_STACK_SZ, task2);
Gaetan 32:74608bce78f6 60 os.CreateTask(TASK_ARRET_URGENT, TASK_ARRET_URGENT_PRIO, TASK_ARRET_URGENT_STACK_SZ, task1);*/
Gaetan 32:74608bce78f6 61
Gaetan 32:74608bce78f6 62 os.CreateTimer(TIMER_COM_ID, TASK_COM, TIMER_EVENT);
Gaetan 32:74608bce78f6 63 os.CreateTimer(TIMER_DETEC_ID, TASK_DETEC, TIMER_EVENT);
Gaetan 32:74608bce78f6 64 /*os.CreateTimer(TIMER_MOUV_ID, TIMER_MOUV_PERIOD, TIMER_MOUV_EVENT);
Gaetan 32:74608bce78f6 65 os.CreateTimer(TIMER_BATT_ID, TIMER_BATT_PERIOD, TIMER_BATT_EVENT);
Gaetan 32:74608bce78f6 66 os.CreateTimer(TIMER_VIDEO_ID, TIMER_VIDEO_PERIOD, TIMER_VIDEO_EVENT);
Gaetan 32:74608bce78f6 67 os.CreateTimer(TIMER_ARRET_URGENT_ID, TIMER_ARRET_URGENT_PERIOD, TIMER_ARRET_URGENT_EVENT);*/
Gaetan 32:74608bce78f6 68
Gaetan 6:0e3d95e9885e 69 // Start mbos
Gaetan 6:0e3d95e9885e 70 os.Start();
Gaetan 6:0e3d95e9885e 71 // never return!
NicolasH 0:8d93a5e4e4ab 72 }
Gaetan 6:0e3d95e9885e 73
Gaetan 6:0e3d95e9885e 74 void task1(void)
Gaetan 6:0e3d95e9885e 75 {
Gaetan 32:74608bce78f6 76 os.SetTimer(TIMER_COM_ID, TIMER_COM_PERIOD, TIMER_COM_PERIOD);
Gaetan 6:0e3d95e9885e 77 while(1){
Gaetan 32:74608bce78f6 78 os.WaitEvent(TIMER_EVENT);
Gaetan 6:0e3d95e9885e 79 led1 = !led1;
Gaetan 32:74608bce78f6 80 os.SetEvent(COMMUNICATION_EVENT, TASK_DETEC);
Gaetan 6:0e3d95e9885e 81 }
Gaetan 6:0e3d95e9885e 82 }
Gaetan 6:0e3d95e9885e 83
Gaetan 6:0e3d95e9885e 84 void task2(void)
Gaetan 6:0e3d95e9885e 85 {
Gaetan 32:74608bce78f6 86 os.SetTimer(TIMER_DETEC_ID, TIMER_DETEC_PERIOD, TIMER_DETEC_PERIOD);
Gaetan 6:0e3d95e9885e 87 while(1){
Gaetan 32:74608bce78f6 88 os.WaitEvent(TIMER_EVENT | COMMUNICATION_EVENT);
Gaetan 32:74608bce78f6 89 /*switch(os.GetEvent()){
Gaetan 32:74608bce78f6 90 case TIMER_EVENT:
Gaetan 32:74608bce78f6 91 led2 = !led2;
Gaetan 32:74608bce78f6 92 break;
Gaetan 32:74608bce78f6 93 case COMMUNICATION_EVENT:
Gaetan 32:74608bce78f6 94 led3 = !led3;
Gaetan 32:74608bce78f6 95 break;
Gaetan 32:74608bce78f6 96 }*/
Gaetan 32:74608bce78f6 97 if(os.GetEvent() & TIMER_EVENT) led2 = !led2;
Gaetan 32:74608bce78f6 98 if(os.GetEvent() & COMMUNICATION_EVENT) led3 = !led3;
Gaetan 6:0e3d95e9885e 99 }
Gaetan 6:0e3d95e9885e 100 }