![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
version 2.6.5 mode normal en cours(problème de décalage) voir incrément et coefficient codeur
Dependencies: mbed
Fork of Robot_a_cables_v2_6 by
main.cpp@6:ffffa9dfadfc, 2018-05-07 (annotated)
- Committer:
- protongamer
- Date:
- Mon May 07 12:12:34 2018 +0000
- Revision:
- 6:ffffa9dfadfc
- Parent:
- 5:d5a021bbe81b
- Child:
- 7:e87feff62bfd
v2.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LouisReynier | 0:1ab5fdb4fa56 | 1 | #include "mbed.h" |
protongamer | 6:ffffa9dfadfc | 2 | #include "parameters.h" |
protongamer | 3:86e21a36eecb | 3 | /* |
protongamer | 3:86e21a36eecb | 4 | Projet BTS SN - Robot à câbles - Lycée Georges Cabanis |
protongamer | 3:86e21a36eecb | 5 | Enzo Niro - Erwin Sazio |
protongamer | 3:86e21a36eecb | 6 | Transmission par Bus CAN(protocol CANOpen) |
protongamer | 3:86e21a36eecb | 7 | |
protongamer | 3:86e21a36eecb | 8 | */ |
LouisReynier | 0:1ab5fdb4fa56 | 9 | |
protongamer | 1:4d70e593345f | 10 | |
protongamer | 3:86e21a36eecb | 11 | |
protongamer | 3:86e21a36eecb | 12 | DigitalOut MOTOR1_OP(LED1); |
protongamer | 3:86e21a36eecb | 13 | DigitalOut MOTOR2_OP(LED2); |
protongamer | 3:86e21a36eecb | 14 | DigitalOut DEB_MOD_DEG(LED3); |
protongamer | 3:86e21a36eecb | 15 | DigitalOut DEB_MOD_NOR(LED4); |
protongamer | 3:86e21a36eecb | 16 | DigitalOut MOD_DEG(p26); |
protongamer | 3:86e21a36eecb | 17 | DigitalOut MOD_NOR(p25); |
protongamer | 3:86e21a36eecb | 18 | DigitalIn SWH(p5); |
protongamer | 3:86e21a36eecb | 19 | DigitalIn SWV(p6); |
protongamer | 3:86e21a36eecb | 20 | DigitalIn BPO(p7); |
Ringslev | 5:d5a021bbe81b | 21 | AnalogIn joystick_ctr(p15); // Pin 2 (fil vert) Center Tap Reference |
Ringslev | 5:d5a021bbe81b | 22 | AnalogIn joystick_x(p16); // Pin 4 (fil jaune) |
Ringslev | 5:d5a021bbe81b | 23 | AnalogIn joystick_y(p17); // Pin 5 (fil bleu) |
protongamer | 3:86e21a36eecb | 24 | |
Ringslev | 5:d5a021bbe81b | 25 | CAN can2(p30, p29, 1000000); // on definit pin et debit |
Ringslev | 5:d5a021bbe81b | 26 | CANMessage msg; |
Ringslev | 5:d5a021bbe81b | 27 | Serial pc(USBTX, USBRX); |
protongamer | 4:3fd7c53d31c1 | 28 | |
Ringslev | 5:d5a021bbe81b | 29 | uint8_t mode = 0; |
Ringslev | 5:d5a021bbe81b | 30 | int x,y,ctr_x,ctr_y; // Variables de joystick |
Ringslev | 5:d5a021bbe81b | 31 | uint8_t ping = 0; //variable pour etat de processus |
Ringslev | 5:d5a021bbe81b | 32 | uint8_t done = 0; |
Ringslev | 5:d5a021bbe81b | 33 | char command[8]; //word to send command |
Ringslev | 5:d5a021bbe81b | 34 | uint64_t timer_process_read; //counter to make mbed read actual position |
protongamer | 6:ffffa9dfadfc | 35 | float dy = 1262, dx = 492.5;//coordinates values when origin is done |
protongamer | 6:ffffa9dfadfc | 36 | //these positions are in counters |
protongamer | 6:ffffa9dfadfc | 37 | int32_t p1, p2; //motors positions |
protongamer | 6:ffffa9dfadfc | 38 | int32_t p_actual, p_pom; //p_actual position read by can, p_pom position done when origin is made |
protongamer | 6:ffffa9dfadfc | 39 | |
protongamer | 6:ffffa9dfadfc | 40 | //longueur câbles |
protongamer | 6:ffffa9dfadfc | 41 | //lx = longueur entre les point des moteurs |
protongamer | 6:ffffa9dfadfc | 42 | //l1 = longueur moteur gauche à l'effecteur |
protongamer | 6:ffffa9dfadfc | 43 | //l2 = longueur moteur droite à l'effecteur |
protongamer | 6:ffffa9dfadfc | 44 | int64_t lx, l1, l2; |
protongamer | 6:ffffa9dfadfc | 45 | |
protongamer | 6:ffffa9dfadfc | 46 | |
protongamer | 6:ffffa9dfadfc | 47 | |
protongamer | 6:ffffa9dfadfc | 48 | |
protongamer | 1:4d70e593345f | 49 | |
Ringslev | 5:d5a021bbe81b | 50 | void display_mode() |
Ringslev | 5:d5a021bbe81b | 51 | { |
Ringslev | 5:d5a021bbe81b | 52 | if(mode == 0) // MODE DEGRADE |
Ringslev | 5:d5a021bbe81b | 53 | { |
Ringslev | 5:d5a021bbe81b | 54 | MOD_DEG = 1; |
Ringslev | 5:d5a021bbe81b | 55 | MOD_NOR = 0; |
Ringslev | 5:d5a021bbe81b | 56 | } |
Ringslev | 5:d5a021bbe81b | 57 | else if(mode == 1) // MODE NORMAL |
Ringslev | 5:d5a021bbe81b | 58 | { |
Ringslev | 5:d5a021bbe81b | 59 | MOD_DEG = 0; |
Ringslev | 5:d5a021bbe81b | 60 | MOD_NOR = 1; |
Ringslev | 5:d5a021bbe81b | 61 | } |
Ringslev | 5:d5a021bbe81b | 62 | } |
protongamer | 1:4d70e593345f | 63 | |
protongamer | 1:4d70e593345f | 64 | void send(int id, char octet_emis[], char RouD, char longueur ) |
protongamer | 1:4d70e593345f | 65 | { |
protongamer | 1:4d70e593345f | 66 | int emis_ok = 0 ; |
LouisReynier | 0:1ab5fdb4fa56 | 67 | |
protongamer | 4:3fd7c53d31c1 | 68 | MOTOR1_OP = 1; |
protongamer | 4:3fd7c53d31c1 | 69 | MOTOR1_OP = 0; |
protongamer | 4:3fd7c53d31c1 | 70 | |
protongamer | 1:4d70e593345f | 71 | if (RouD == 'D') |
protongamer | 1:4d70e593345f | 72 | { emis_ok = can2.write(CANMessage(id, octet_emis, longueur, CANData, CANStandard )) ; |
protongamer | 3:86e21a36eecb | 73 | //pc.printf("id: %x, %c L = %d, \nData : %x:%x:%x:%x ... \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] ); |
protongamer | 1:4d70e593345f | 74 | }// c'ets la valeur retournée par la fonction write |
protongamer | 1:4d70e593345f | 75 | else |
protongamer | 1:4d70e593345f | 76 | { emis_ok = can2.write(CANMessage(id, octet_emis, longueur, CANRemote, CANStandard )); |
protongamer | 3:86e21a36eecb | 77 | //pc.printf("id: %x, %c L = %d, \nData : %x:%x:%x:%x ... \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] ); |
protongamer | 1:4d70e593345f | 78 | } |
protongamer | 1:4d70e593345f | 79 | //lcd.locate(0,10); |
protongamer | 1:4d70e593345f | 80 | //lcd.printf("id: %x, %c L = %d, \nData : %x:%x:%x:%x ... \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] ); |
protongamer | 3:86e21a36eecb | 81 | /*if(emis_ok) { |
protongamer | 1:4d70e593345f | 82 | // ici octet emis n'a pas de sens car trame remote ! |
protongamer | 3:86e21a36eecb | 83 | //pc.printf("send \r \n"); |
protongamer | 3:86e21a36eecb | 84 | } */ |
LouisReynier | 0:1ab5fdb4fa56 | 85 | } |
protongamer | 1:4d70e593345f | 86 | |
Ringslev | 5:d5a021bbe81b | 87 | void initialisation() |
Ringslev | 5:d5a021bbe81b | 88 | { |
Ringslev | 5:d5a021bbe81b | 89 | pc.printf("starting...\r\n"); |
Ringslev | 5:d5a021bbe81b | 90 | MOD_DEG = 1; |
Ringslev | 5:d5a021bbe81b | 91 | MOD_NOR = 0; |
Ringslev | 5:d5a021bbe81b | 92 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 93 | MOD_DEG = 0; |
Ringslev | 5:d5a021bbe81b | 94 | MOD_NOR = 1; |
Ringslev | 5:d5a021bbe81b | 95 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 96 | MOD_DEG = 1; |
Ringslev | 5:d5a021bbe81b | 97 | MOD_NOR = 0; |
Ringslev | 5:d5a021bbe81b | 98 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 99 | MOD_DEG = 0; |
Ringslev | 5:d5a021bbe81b | 100 | MOD_NOR = 1; |
Ringslev | 5:d5a021bbe81b | 101 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 102 | MOD_DEG = 1; |
Ringslev | 5:d5a021bbe81b | 103 | MOD_NOR = 0; |
Ringslev | 5:d5a021bbe81b | 104 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 105 | MOD_DEG = 0; |
Ringslev | 5:d5a021bbe81b | 106 | MOD_NOR = 0; |
Ringslev | 5:d5a021bbe81b | 107 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 108 | |
protongamer | 6:ffffa9dfadfc | 109 | command[0] = DRIVER_R1; |
Ringslev | 5:d5a021bbe81b | 110 | command[1] = DRIVER_R2; |
Ringslev | 5:d5a021bbe81b | 111 | |
Ringslev | 5:d5a021bbe81b | 112 | while(ping == 0) // INIT MOTEUR DROIT |
Ringslev | 5:d5a021bbe81b | 113 | { |
Ringslev | 5:d5a021bbe81b | 114 | pc.printf("ping droite ...\r\n"); |
Ringslev | 5:d5a021bbe81b | 115 | send(INITOP, command, 'D', 2); //send word to put pluto driver in operational mode |
Ringslev | 5:d5a021bbe81b | 116 | MOD_NOR = 1; |
Ringslev | 5:d5a021bbe81b | 117 | if(can2.read(msg)) |
Ringslev | 5:d5a021bbe81b | 118 | { |
Ringslev | 5:d5a021bbe81b | 119 | for(int i = 0; i < msg.len; i++) |
Ringslev | 5:d5a021bbe81b | 120 | { |
Ringslev | 5:d5a021bbe81b | 121 | pc.printf("0x%x ",msg.data[i]); |
Ringslev | 5:d5a021bbe81b | 122 | ping = 1; |
Ringslev | 5:d5a021bbe81b | 123 | }//end of for |
Ringslev | 5:d5a021bbe81b | 124 | pc.printf("\r \n"); |
Ringslev | 5:d5a021bbe81b | 125 | }//can.read(msg) |
Ringslev | 5:d5a021bbe81b | 126 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 127 | MOD_NOR = 0; |
Ringslev | 5:d5a021bbe81b | 128 | wait(0.9); |
Ringslev | 5:d5a021bbe81b | 129 | } |
Ringslev | 5:d5a021bbe81b | 130 | |
Ringslev | 5:d5a021bbe81b | 131 | ping =0; |
Ringslev | 5:d5a021bbe81b | 132 | command[0] = DRIVER_L1; |
Ringslev | 5:d5a021bbe81b | 133 | command[1] = DRIVER_L2; |
Ringslev | 5:d5a021bbe81b | 134 | |
Ringslev | 5:d5a021bbe81b | 135 | while(ping == 0) // INIT MOTEUR GAUCHE |
Ringslev | 5:d5a021bbe81b | 136 | { |
Ringslev | 5:d5a021bbe81b | 137 | pc.printf("ping gauche ...\r\n"); |
Ringslev | 5:d5a021bbe81b | 138 | send(INITOP, command, 'D', 2); //send word to put pluto driver in operational mode |
protongamer | 3:86e21a36eecb | 139 | MOD_DEG = 1; |
protongamer | 3:86e21a36eecb | 140 | if(can2.read(msg)) { |
protongamer | 4:3fd7c53d31c1 | 141 | for(int i = 0; i < msg.len; i++){ |
protongamer | 4:3fd7c53d31c1 | 142 | pc.printf("0x%x ",msg.data[i]); |
protongamer | 4:3fd7c53d31c1 | 143 | ping = 1; |
protongamer | 4:3fd7c53d31c1 | 144 | }//end of for |
protongamer | 4:3fd7c53d31c1 | 145 | pc.printf("\r \n"); |
protongamer | 4:3fd7c53d31c1 | 146 | }//can.read(msg) |
protongamer | 3:86e21a36eecb | 147 | wait(0.1); |
Ringslev | 5:d5a021bbe81b | 148 | MOD_DEG = 0; |
protongamer | 3:86e21a36eecb | 149 | wait(0.9); |
Ringslev | 5:d5a021bbe81b | 150 | } |
Ringslev | 5:d5a021bbe81b | 151 | } // fin initialisation |
Ringslev | 5:d5a021bbe81b | 152 | |
protongamer | 6:ffffa9dfadfc | 153 | |
protongamer | 6:ffffa9dfadfc | 154 | |
protongamer | 6:ffffa9dfadfc | 155 | void read_position(){ |
protongamer | 6:ffffa9dfadfc | 156 | |
protongamer | 6:ffffa9dfadfc | 157 | |
protongamer | 6:ffffa9dfadfc | 158 | |
protongamer | 6:ffffa9dfadfc | 159 | |
protongamer | 6:ffffa9dfadfc | 160 | |
protongamer | 6:ffffa9dfadfc | 161 | /* send(TPDO1_R, command, 'R', 0); //Ask position |
protongamer | 6:ffffa9dfadfc | 162 | timer_process_read = 0; |
protongamer | 6:ffffa9dfadfc | 163 | p2 = msg.data[3]; |
protongamer | 6:ffffa9dfadfc | 164 | p2 = p2 << 8; |
protongamer | 6:ffffa9dfadfc | 165 | p2 = p2 | msg.data[2]; |
protongamer | 6:ffffa9dfadfc | 166 | p2 = p2 << 8; |
protongamer | 6:ffffa9dfadfc | 167 | p2 = p2 | msg.data[1]; |
protongamer | 6:ffffa9dfadfc | 168 | p2 = p2 << 8; |
protongamer | 6:ffffa9dfadfc | 169 | p2 = p2 | msg.data[0];*/ |
protongamer | 6:ffffa9dfadfc | 170 | |
protongamer | 6:ffffa9dfadfc | 171 | |
protongamer | 6:ffffa9dfadfc | 172 | |
protongamer | 6:ffffa9dfadfc | 173 | lx = 985; |
protongamer | 6:ffffa9dfadfc | 174 | |
protongamer | 6:ffffa9dfadfc | 175 | //l2 = LENGTH_L2_PO + (p2*1000)/2500; |
protongamer | 6:ffffa9dfadfc | 176 | |
protongamer | 6:ffffa9dfadfc | 177 | }//fin de fonction |
protongamer | 6:ffffa9dfadfc | 178 | |
protongamer | 6:ffffa9dfadfc | 179 | |
protongamer | 6:ffffa9dfadfc | 180 | |
Ringslev | 5:d5a021bbe81b | 181 | void control_Moteur() |
Ringslev | 5:d5a021bbe81b | 182 | { |
Ringslev | 5:d5a021bbe81b | 183 | ///////////// CONTROLE MOTEUR ////////////////////////////////////////////////////////////////////////////// |
Ringslev | 5:d5a021bbe81b | 184 | // LECTURE Joystick + stockage valeurs dans x, y |
Ringslev | 5:d5a021bbe81b | 185 | ctr_x = int(-((joystick_ctr.read()*100)-50)); |
Ringslev | 5:d5a021bbe81b | 186 | ctr_y = int((joystick_ctr.read()*100)-50); |
Ringslev | 5:d5a021bbe81b | 187 | if(SWH){x = int(-((joystick_x.read()*100)-50))+ctr_x;}else{x=0;} // Detection x avec correction ctr de -42 à +42 |
Ringslev | 5:d5a021bbe81b | 188 | if(SWV){y = int((joystick_y.read()*100)-50)+ctr_y;}else{y=0;} // Detection y avec correction ctr |
Ringslev | 5:d5a021bbe81b | 189 | |
Ringslev | 5:d5a021bbe81b | 190 | if(mode ==0) |
Ringslev | 5:d5a021bbe81b | 191 | { |
Ringslev | 5:d5a021bbe81b | 192 | ///////////// MODE DEGRADE ///////////////////////////////////// |
Ringslev | 5:d5a021bbe81b | 193 | float VX = (float(x)/42)*425000; // Calcule brut vélocité x, y |
Ringslev | 5:d5a021bbe81b | 194 | float VY = (float(y)/42)*425000; |
Ringslev | 5:d5a021bbe81b | 195 | long int VM_L = VX - VY; // Calcule des vélocités exactes de chaques moteurs |
Ringslev | 5:d5a021bbe81b | 196 | long int VM_R = -VX - VY; |
Ringslev | 5:d5a021bbe81b | 197 | |
Ringslev | 5:d5a021bbe81b | 198 | command[0]= (VM_L & 0x000000FF); // Masque + décalage pour translation big vers little endian |
Ringslev | 5:d5a021bbe81b | 199 | command[1]= (VM_L & 0x0000FF00)>>8; |
Ringslev | 5:d5a021bbe81b | 200 | command[2]= (VM_L & 0x00FF0000)>>16; |
Ringslev | 5:d5a021bbe81b | 201 | command[3]= (VM_L & 0xFF000000)>>24; |
Ringslev | 5:d5a021bbe81b | 202 | send(RPDO1_L, command, 'D', 4); // Controle moteur gauche |
Ringslev | 5:d5a021bbe81b | 203 | |
Ringslev | 5:d5a021bbe81b | 204 | command[0]= (VM_R & 0x000000FF); |
Ringslev | 5:d5a021bbe81b | 205 | command[1]= (VM_R & 0x0000FF00)>>8; |
Ringslev | 5:d5a021bbe81b | 206 | command[2]= (VM_R & 0x00FF0000)>>16; |
Ringslev | 5:d5a021bbe81b | 207 | command[3]= (VM_R & 0xFF000000)>>24; |
Ringslev | 5:d5a021bbe81b | 208 | send(RPDO1_R, command, 'D', 4); // Controle moteur droit |
Ringslev | 5:d5a021bbe81b | 209 | //////////////////////////////////////////////////////////////// |
Ringslev | 5:d5a021bbe81b | 210 | } |
Ringslev | 5:d5a021bbe81b | 211 | else if(mode ==1) |
Ringslev | 5:d5a021bbe81b | 212 | { |
Ringslev | 5:d5a021bbe81b | 213 | // MODE NORMAL |
Ringslev | 5:d5a021bbe81b | 214 | } |
Ringslev | 5:d5a021bbe81b | 215 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Ringslev | 5:d5a021bbe81b | 216 | } |
Ringslev | 5:d5a021bbe81b | 217 | |
Ringslev | 5:d5a021bbe81b | 218 | int main() { |
Ringslev | 5:d5a021bbe81b | 219 | |
Ringslev | 5:d5a021bbe81b | 220 | //define Pullup switch |
Ringslev | 5:d5a021bbe81b | 221 | SWH.mode(PullUp); |
Ringslev | 5:d5a021bbe81b | 222 | SWV.mode(PullUp); |
Ringslev | 5:d5a021bbe81b | 223 | BPO.mode(PullUp); |
Ringslev | 5:d5a021bbe81b | 224 | |
Ringslev | 5:d5a021bbe81b | 225 | initialisation(); // Mise en mode opérationnel des moteurs |
Ringslev | 5:d5a021bbe81b | 226 | |
protongamer | 6:ffffa9dfadfc | 227 | |
protongamer | 6:ffffa9dfadfc | 228 | |
Ringslev | 5:d5a021bbe81b | 229 | |
Ringslev | 5:d5a021bbe81b | 230 | while(1) |
Ringslev | 5:d5a021bbe81b | 231 | { |
Ringslev | 5:d5a021bbe81b | 232 | //timer_process_ping++; |
Ringslev | 5:d5a021bbe81b | 233 | timer_process_read++; |
protongamer | 6:ffffa9dfadfc | 234 | l1 = (LENGTH_L1_PO*1000) - (p1*1000)/2500; //Longueur 1 |
protongamer | 6:ffffa9dfadfc | 235 | |
protongamer | 6:ffffa9dfadfc | 236 | if(BPO == 0){ |
protongamer | 6:ffffa9dfadfc | 237 | send(TPDO1_R, command, 'R', 0); //Ask position |
protongamer | 6:ffffa9dfadfc | 238 | |
protongamer | 6:ffffa9dfadfc | 239 | p_pom = msg.data[3]; |
protongamer | 6:ffffa9dfadfc | 240 | p_pom = p_pom << 8; |
protongamer | 6:ffffa9dfadfc | 241 | p_pom = p_pom | msg.data[2]; |
protongamer | 6:ffffa9dfadfc | 242 | p_pom = p_pom << 8; |
protongamer | 6:ffffa9dfadfc | 243 | p_pom = p_pom | msg.data[1]; |
protongamer | 6:ffffa9dfadfc | 244 | p_pom = p_pom << 8; |
protongamer | 6:ffffa9dfadfc | 245 | p_pom = p_pom | msg.data[0]; |
protongamer | 6:ffffa9dfadfc | 246 | wait(1.0); |
protongamer | 6:ffffa9dfadfc | 247 | } |
protongamer | 1:4d70e593345f | 248 | |
protongamer | 6:ffffa9dfadfc | 249 | //dy = 525000 + (d_new*1000)/2500; |
protongamer | 6:ffffa9dfadfc | 250 | |
protongamer | 4:3fd7c53d31c1 | 251 | |
Ringslev | 5:d5a021bbe81b | 252 | //wait_ms(1); |
protongamer | 4:3fd7c53d31c1 | 253 | |
Ringslev | 5:d5a021bbe81b | 254 | /* if(timer_process_ping >= 5000){ |
protongamer | 4:3fd7c53d31c1 | 255 | send(TPDO2_R, command, 'R', 0); //Ask mod of motor |
protongamer | 4:3fd7c53d31c1 | 256 | timer_process_ping = 0; |
protongamer | 4:3fd7c53d31c1 | 257 | if(can2.read(msg)) { |
protongamer | 4:3fd7c53d31c1 | 258 | for(int i = 0; i < msg.len; i++){ |
protongamer | 4:3fd7c53d31c1 | 259 | pc.printf("0x%x ",msg.data[i]); |
protongamer | 4:3fd7c53d31c1 | 260 | }//end of for |
protongamer | 4:3fd7c53d31c1 | 261 | pc.printf("\r \n"); |
protongamer | 4:3fd7c53d31c1 | 262 | }//can.read(msg) |
protongamer | 4:3fd7c53d31c1 | 263 | |
protongamer | 4:3fd7c53d31c1 | 264 | if(msg.data[0] != 0x27 || msg.data[1] != 0x56){//if device is not in operational mode |
protongamer | 4:3fd7c53d31c1 | 265 | ping = 0; |
protongamer | 4:3fd7c53d31c1 | 266 | while(ping == 0){ |
protongamer | 4:3fd7c53d31c1 | 267 | pc.printf("ping...\r\n"); |
protongamer | 4:3fd7c53d31c1 | 268 | send(INITOP, command, 'D', 2); //send word to put pluto driver in operational mode |
protongamer | 4:3fd7c53d31c1 | 269 | MOD_NOR = 1; |
protongamer | 4:3fd7c53d31c1 | 270 | if(can2.read(msg)) { |
protongamer | 4:3fd7c53d31c1 | 271 | for(int i = 0; i < msg.len; i++){ |
protongamer | 4:3fd7c53d31c1 | 272 | pc.printf("0x%x ",msg.data[i]); |
protongamer | 4:3fd7c53d31c1 | 273 | ping = 1; |
protongamer | 4:3fd7c53d31c1 | 274 | }//end of for |
protongamer | 4:3fd7c53d31c1 | 275 | pc.printf("\r \n"); |
protongamer | 4:3fd7c53d31c1 | 276 | }//can.read(msg) |
protongamer | 4:3fd7c53d31c1 | 277 | wait(0.1); |
protongamer | 4:3fd7c53d31c1 | 278 | MOD_NOR = 0; |
protongamer | 4:3fd7c53d31c1 | 279 | wait(0.9); |
protongamer | 4:3fd7c53d31c1 | 280 | |
protongamer | 4:3fd7c53d31c1 | 281 | } |
protongamer | 4:3fd7c53d31c1 | 282 | |
protongamer | 4:3fd7c53d31c1 | 283 | } |
protongamer | 4:3fd7c53d31c1 | 284 | |
protongamer | 4:3fd7c53d31c1 | 285 | }*/ |
protongamer | 6:ffffa9dfadfc | 286 | pc.printf("%d", l1); |
protongamer | 6:ffffa9dfadfc | 287 | pc.printf("\t %d", p_pom); |
protongamer | 6:ffffa9dfadfc | 288 | pc.printf("\t %d", p_actual); |
protongamer | 6:ffffa9dfadfc | 289 | pc.printf("\t %d \r\n", p1); |
protongamer | 4:3fd7c53d31c1 | 290 | if(timer_process_read >= 10){ |
protongamer | 6:ffffa9dfadfc | 291 | send(TPDO1_R, command, 'R', 0); //Ask position |
protongamer | 4:3fd7c53d31c1 | 292 | timer_process_read = 0; |
protongamer | 6:ffffa9dfadfc | 293 | p_actual = msg.data[3]; |
protongamer | 6:ffffa9dfadfc | 294 | p_actual = p_actual << 8; |
protongamer | 6:ffffa9dfadfc | 295 | p_actual = p_actual | msg.data[2]; |
protongamer | 6:ffffa9dfadfc | 296 | p_actual = p_actual << 8; |
protongamer | 6:ffffa9dfadfc | 297 | p_actual = p_actual | msg.data[1]; |
protongamer | 6:ffffa9dfadfc | 298 | p_actual = p_actual << 8; |
protongamer | 6:ffffa9dfadfc | 299 | p_actual = p_actual | msg.data[0]; |
protongamer | 6:ffffa9dfadfc | 300 | |
protongamer | 4:3fd7c53d31c1 | 301 | } |
protongamer | 6:ffffa9dfadfc | 302 | |
protongamer | 6:ffffa9dfadfc | 303 | p1 = p_pom - p_actual; |
protongamer | 4:3fd7c53d31c1 | 304 | |
protongamer | 4:3fd7c53d31c1 | 305 | |
protongamer | 3:86e21a36eecb | 306 | if(can2.read(msg)) { |
protongamer | 3:86e21a36eecb | 307 | for(int i = 0; i < msg.len; i++){ |
protongamer | 6:ffffa9dfadfc | 308 | //pc.printf("0x%x ",msg.data[i]); |
protongamer | 3:86e21a36eecb | 309 | }//end of for |
protongamer | 6:ffffa9dfadfc | 310 | //pc.printf("\r \n"); |
protongamer | 4:3fd7c53d31c1 | 311 | }//can.read(msg) |
protongamer | 3:86e21a36eecb | 312 | |
protongamer | 6:ffffa9dfadfc | 313 | //read_position(); |
Ringslev | 5:d5a021bbe81b | 314 | control_Moteur(); // Controle du meteur mode degradé et normal |
Ringslev | 5:d5a021bbe81b | 315 | display_mode(); // Controle des led affichant le mode |
protongamer | 1:4d70e593345f | 316 | |
protongamer | 1:4d70e593345f | 317 | }// fin while(1) |
protongamer | 1:4d70e593345f | 318 | |
protongamer | 1:4d70e593345f | 319 | } // fin main |
protongamer | 4:3fd7c53d31c1 | 320 | |
protongamer | 4:3fd7c53d31c1 | 321 | |
protongamer | 4:3fd7c53d31c1 | 322 | |
protongamer | 1:4d70e593345f | 323 | |
protongamer | 3:86e21a36eecb | 324 |