
Time is good
Fork of Robot2016_2-0 by
Functions/func.cpp@78:c28bdbf29b6e, 2016-05-05 (annotated)
- Committer:
- IceTeam
- Date:
- Thu May 05 13:17:00 2016 +0000
- Revision:
- 78:c28bdbf29b6e
- Parent:
- 77:f19cc7f81f2a
Des trucs qui compilent
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IceTeam | 78:c28bdbf29b6e | 1 | #include <cmath> |
IceTeam | 78:c28bdbf29b6e | 2 | |
sype | 41:b5a2fbc20beb | 3 | #include "func.h" |
sype | 41:b5a2fbc20beb | 4 | |
IceTeam | 78:c28bdbf29b6e | 5 | int max(int a, int b) |
IceTeam | 78:c28bdbf29b6e | 6 | { |
IceTeam | 78:c28bdbf29b6e | 7 | return (a>b)?a:b; |
IceTeam | 78:c28bdbf29b6e | 8 | } |
IceTeam | 78:c28bdbf29b6e | 9 | |
IceTeam | 78:c28bdbf29b6e | 10 | int max(int a, int b, int c) |
IceTeam | 78:c28bdbf29b6e | 11 | { |
IceTeam | 78:c28bdbf29b6e | 12 | return max(a,max(b,c)); |
IceTeam | 78:c28bdbf29b6e | 13 | } |
IceTeam | 78:c28bdbf29b6e | 14 | |
IceTeam | 78:c28bdbf29b6e | 15 | int min(int a, int b) |
IceTeam | 78:c28bdbf29b6e | 16 | { |
IceTeam | 78:c28bdbf29b6e | 17 | return (a<b)?a:b; |
IceTeam | 78:c28bdbf29b6e | 18 | } |
IceTeam | 78:c28bdbf29b6e | 19 | |
sype | 51:1056dd73a748 | 20 | void init_interrupt(void) |
sype | 51:1056dd73a748 | 21 | { |
sype | 51:1056dd73a748 | 22 | ticker.attach_us(&update_main, dt); // 100 Hz |
sype | 51:1056dd73a748 | 23 | } |
sype | 51:1056dd73a748 | 24 | |
sype | 41:b5a2fbc20beb | 25 | void pressed(void) |
sype | 41:b5a2fbc20beb | 26 | { |
sype | 46:5658af4e5149 | 27 | if(SIMON_i==0) { |
sype | 46:5658af4e5149 | 28 | roboclaw.ForwardM1(0); |
sype | 46:5658af4e5149 | 29 | roboclaw.ForwardM2(0); |
sype | 46:5658af4e5149 | 30 | SIMON_i++; |
sype | 41:b5a2fbc20beb | 31 | } |
sype | 41:b5a2fbc20beb | 32 | } |
sype | 41:b5a2fbc20beb | 33 | |
sype | 41:b5a2fbc20beb | 34 | void unpressed(void) |
sype | 41:b5a2fbc20beb | 35 | { |
sype | 46:5658af4e5149 | 36 | if(SIMON_i==1) { |
sype | 46:5658af4e5149 | 37 | SIMON_i--; |
sype | 41:b5a2fbc20beb | 38 | } |
sype | 41:b5a2fbc20beb | 39 | } |
sype | 41:b5a2fbc20beb | 40 | |
sype | 41:b5a2fbc20beb | 41 | void checkAround(void) |
sype | 41:b5a2fbc20beb | 42 | { |
IceTeam | 78:c28bdbf29b6e | 43 | SDroite += (capt1.read() > seuils[0]?1:-1); |
IceTeam | 78:c28bdbf29b6e | 44 | SDroite = min(SDroite, 5); |
IceTeam | 78:c28bdbf29b6e | 45 | SDroite = max(SDroite, -5); |
IceTeam | 78:c28bdbf29b6e | 46 | |
IceTeam | 78:c28bdbf29b6e | 47 | SDevant += (capt2.read() > seuils[1]?1:-1); |
IceTeam | 78:c28bdbf29b6e | 48 | SDevant = min(SDevant, 5); |
IceTeam | 78:c28bdbf29b6e | 49 | SDevant = max(SDevant, -5); |
IceTeam | 78:c28bdbf29b6e | 50 | |
IceTeam | 78:c28bdbf29b6e | 51 | SGauche += (capt3.read() > seuils[2]?1:-1); |
IceTeam | 78:c28bdbf29b6e | 52 | SGauche = min(SGauche, 5); |
IceTeam | 78:c28bdbf29b6e | 53 | SGauche = max(SGauche, -5); |
IceTeam | 78:c28bdbf29b6e | 54 | |
IceTeam | 78:c28bdbf29b6e | 55 | drapeau[0] = SGauche>0; |
IceTeam | 78:c28bdbf29b6e | 56 | drapeau[1] = SDevant>0; |
IceTeam | 78:c28bdbf29b6e | 57 | drapeau[2] = SDroite>0; |
IceTeam | 78:c28bdbf29b6e | 58 | |
IceTeam | 78:c28bdbf29b6e | 59 | logger.printf("Sharps : %d %d %d\r\n", SGauche, SDevant, SDroite); |
sype | 41:b5a2fbc20beb | 60 | } |
sype | 41:b5a2fbc20beb | 61 | |
sype | 48:03da1aead032 | 62 | /*void init_ax12(void) |
sype | 41:b5a2fbc20beb | 63 | { |
sype | 41:b5a2fbc20beb | 64 | left_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 65 | wait_ms(10); |
sype | 41:b5a2fbc20beb | 66 | right_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 67 | wait_ms(50); |
sype | 41:b5a2fbc20beb | 68 | left_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 69 | wait_ms(10); |
sype | 41:b5a2fbc20beb | 70 | right_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 71 | wait_ms(50); |
sype | 41:b5a2fbc20beb | 72 | right_hand.setGoal(0); |
sype | 41:b5a2fbc20beb | 73 | left_hand.setGoal(0); |
sype | 41:b5a2fbc20beb | 74 | wait(2); |
sype | 41:b5a2fbc20beb | 75 | right_hand.setGoal(180); |
sype | 41:b5a2fbc20beb | 76 | left_hand.setGoal(180); |
sype | 41:b5a2fbc20beb | 77 | wait(2); |
sype | 48:03da1aead032 | 78 | }*/ |
sype | 44:b1fd7489369f | 79 | |
sype | 46:5658af4e5149 | 80 | void changeCamp(void) |
sype | 46:5658af4e5149 | 81 | { |
sype | 48:03da1aead032 | 82 | if(SCouleur==VERT) { |
sype | 48:03da1aead032 | 83 | SCouleur = VIOLET; |
sype | 48:03da1aead032 | 84 | LEDR = 1; |
sype | 48:03da1aead032 | 85 | LEDV = 0; |
sype | 51:1056dd73a748 | 86 | } else { |
sype | 48:03da1aead032 | 87 | SCouleur = VERT; |
sype | 48:03da1aead032 | 88 | LEDV = 1; |
sype | 51:1056dd73a748 | 89 | LEDR = 0; |
sype | 48:03da1aead032 | 90 | } |
sype | 46:5658af4e5149 | 91 | } |
sype | 46:5658af4e5149 | 92 | |
sype | 51:1056dd73a748 | 93 | void depart(void) |
sype | 45:b53ae54062c6 | 94 | { |
sype | 51:1056dd73a748 | 95 | while(button==1) { |
sype | 51:1056dd73a748 | 96 | if(CAMP==0) { |
sype | 51:1056dd73a748 | 97 | changeCamp(); |
sype | 51:1056dd73a748 | 98 | } |
sype | 51:1056dd73a748 | 99 | wait_ms(100); |
sype | 51:1056dd73a748 | 100 | } |
sype | 51:1056dd73a748 | 101 | |
sype | 51:1056dd73a748 | 102 | if(SCouleur == VERT)logger.printf("Couleur VERT !\n\r"); |
sype | 51:1056dd73a748 | 103 | else logger.printf("Couleur ROUGE !\n\r"); |
sype | 51:1056dd73a748 | 104 | |
sype | 51:1056dd73a748 | 105 | while(START==0) { |
sype | 51:1056dd73a748 | 106 | drapeau = SSchema; |
sype | 51:1056dd73a748 | 107 | if(CAMP==0) { |
sype | 51:1056dd73a748 | 108 | SSchema++; |
sype | 51:1056dd73a748 | 109 | if(SSchema == 6) SSchema = 1; |
sype | 51:1056dd73a748 | 110 | drapeau = SSchema; |
sype | 51:1056dd73a748 | 111 | } |
sype | 51:1056dd73a748 | 112 | wait_ms(100); |
sype | 51:1056dd73a748 | 113 | } |
sype | 51:1056dd73a748 | 114 | logger.printf("Schema numero : %d !\n\r", SSchema); |
sype | 51:1056dd73a748 | 115 | } |