Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
CAN_asser.cpp@7:753e901d441b, 2019-05-20 (annotated)
- Committer:
- Wael_H
- Date:
- Mon May 20 14:58:09 2019 +0000
- Revision:
- 7:753e901d441b
- Parent:
- 5:34048faec367
- Child:
- 8:94ecfe411d02
Premier automate de Wael et Theo :)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wael_H | 7:753e901d441b | 1 | #include "mbed.h" |
Wael_H | 7:753e901d441b | 2 | #include "CAN_asser.h" |
Wael_H | 5:34048faec367 | 3 | |
Wael_H | 7:753e901d441b | 4 | CANMessage msg_can[256]; |
Wael_H | 5:34048faec367 | 5 | CAN can(PB_8, PB_9,1000000); |
Wael_H | 5:34048faec367 | 6 | unsigned char pt_lecture_can = 0, pt_ecriture_can = 0; |
Wael_H | 5:34048faec367 | 7 | int nb_msg_can = 0; |
Wael_H | 5:34048faec367 | 8 | short pos[3]; |
Wael_H | 7:753e901d441b | 9 | int flagFinDpl = 0; |
Wael_H | 7:753e901d441b | 10 | Serial dbug(USBTX, USBRX, 115200); |
Wael_H | 7:753e901d441b | 11 | |
Wael_H | 7:753e901d441b | 12 | void can_init(void) |
Wael_H | 7:753e901d441b | 13 | { |
Wael_H | 7:753e901d441b | 14 | can.attach(&isr_can, CAN::RxIrq); |
Wael_H | 7:753e901d441b | 15 | } |
Wael_H | 7:753e901d441b | 16 | |
Wael_H | 5:34048faec367 | 17 | void isr_can() |
Wael_H | 5:34048faec367 | 18 | { |
Wael_H | 5:34048faec367 | 19 | can.read(msg_can[pt_ecriture_can]); |
Wael_H | 5:34048faec367 | 20 | nb_msg_can++; |
Wael_H | 5:34048faec367 | 21 | pt_ecriture_can++; |
Wael_H | 5:34048faec367 | 22 | if(nb_msg_can > 6) |
Wael_H | 5:34048faec367 | 23 | { |
Wael_H | 7:753e901d441b | 24 | //dbug.printf("!!!!!! CAN BUFFER OVERFLOW !!!!!!!!\n"); |
Wael_H | 5:34048faec367 | 25 | pt_lecture_can++; |
Wael_H | 5:34048faec367 | 26 | nb_msg_can--; |
Wael_H | 5:34048faec367 | 27 | } |
Wael_H | 7:753e901d441b | 28 | } |
Wael_H | 7:753e901d441b | 29 | |
Wael_H | 5:34048faec367 | 30 | void trait_can() |
Wael_H | 5:34048faec367 | 31 | { |
Wael_H | 5:34048faec367 | 32 | while(nb_msg_can>0) |
Wael_H | 5:34048faec367 | 33 | { |
Wael_H | 7:753e901d441b | 34 | if(msg_can[pt_lecture_can].id == ODOMETRIE_POSITION) |
Wael_H | 7:753e901d441b | 35 | get_pos(msg_can[pt_lecture_can], pos); |
Wael_H | 7:753e901d441b | 36 | |
Wael_H | 5:34048faec367 | 37 | else if(msg_can[pt_lecture_can].id == 0x111) |
Wael_H | 5:34048faec367 | 38 | { |
Wael_H | 7:753e901d441b | 39 | flagFinDpl = 1; |
Wael_H | 7:753e901d441b | 40 | dbug.printf("CAN fin dpl\n"); |
Wael_H | 5:34048faec367 | 41 | } |
Wael_H | 7:753e901d441b | 42 | |
Wael_H | 5:34048faec367 | 43 | else if(msg_can[pt_lecture_can].id == 0x101) |
Wael_H | 5:34048faec367 | 44 | dbug.printf("CAN revived\n"); |
Wael_H | 7:753e901d441b | 45 | |
Wael_H | 5:34048faec367 | 46 | nb_msg_can--; |
Wael_H | 5:34048faec367 | 47 | pt_lecture_can++; |
Wael_H | 5:34048faec367 | 48 | } |
Wael_H | 7:753e901d441b | 49 | } |
Wael_H | 7:753e901d441b | 50 | |
Wael_H | 5:34048faec367 | 51 | void get_pos(CANMessage msg_pos, short* position) |
Wael_H | 5:34048faec367 | 52 | { |
Wael_H | 5:34048faec367 | 53 | memcpy((void *)((void *)&position[0]), &(msg_pos.data[0]), 2); |
Wael_H | 5:34048faec367 | 54 | memcpy((void *)((void *)&position[1]), &(msg_pos.data[2]), 2); |
Wael_H | 5:34048faec367 | 55 | memcpy((void *)((void *)&position[2]), &(msg_pos.data[4]), 2); |
Wael_H | 5:34048faec367 | 56 | } |
Wael_H | 5:34048faec367 | 57 | |
Wael_H | 5:34048faec367 | 58 | void SendCoefK (unsigned short id, double K) |
Wael_H | 5:34048faec367 | 59 | { |
Wael_H | 5:34048faec367 | 60 | |
Wael_H | 5:34048faec367 | 61 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 62 | |
Wael_H | 5:34048faec367 | 63 | msgTx.id=id; |
Wael_H | 5:34048faec367 | 64 | |
Wael_H | 5:34048faec367 | 65 | msgTx.len=2; |
Wael_H | 5:34048faec367 | 66 | |
Wael_H | 5:34048faec367 | 67 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 68 | |
Wael_H | 5:34048faec367 | 69 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 70 | |
Wael_H | 5:34048faec367 | 71 | // from sur 2 octets |
Wael_H | 5:34048faec367 | 72 | for(int i=0;i<8;i++) |
Wael_H | 5:34048faec367 | 73 | { |
Wael_H | 5:34048faec367 | 74 | memcpy(&(msgTx.data[i]), (void *)((void *)&K + i), 1); |
Wael_H | 5:34048faec367 | 75 | } |
Wael_H | 5:34048faec367 | 76 | |
Wael_H | 5:34048faec367 | 77 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 78 | } |
Wael_H | 5:34048faec367 | 79 | /*********************************************************************************************************/ |
Wael_H | 5:34048faec367 | 80 | |
Wael_H | 5:34048faec367 | 81 | /* FUNCTION NAME: SendRawId */ |
Wael_H | 5:34048faec367 | 82 | /* DESCRIPTION : Envoie un message sans donnée, c'est-à-dire contenant uniquement un ID, sur le bus CAN */ |
Wael_H | 5:34048faec367 | 83 | /*********************************************************************************************************/ |
Wael_H | 5:34048faec367 | 84 | void SendRawId (unsigned short id) |
Wael_H | 5:34048faec367 | 85 | { |
Wael_H | 5:34048faec367 | 86 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 87 | |
Wael_H | 5:34048faec367 | 88 | msgTx.id=id; |
Wael_H | 5:34048faec367 | 89 | |
Wael_H | 5:34048faec367 | 90 | msgTx.len=0; |
Wael_H | 5:34048faec367 | 91 | |
Wael_H | 5:34048faec367 | 92 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 93 | |
Wael_H | 5:34048faec367 | 94 | wait_us(200); |
Wael_H | 5:34048faec367 | 95 | } |
Wael_H | 5:34048faec367 | 96 | |
Wael_H | 5:34048faec367 | 97 | /*********************************************************************************************/ |
Wael_H | 5:34048faec367 | 98 | |
Wael_H | 5:34048faec367 | 99 | /* FUNCTION NAME: SendAck */ |
Wael_H | 5:34048faec367 | 100 | |
Wael_H | 5:34048faec367 | 101 | /* DESCRIPTION : Envoyer un acknowledge */ |
Wael_H | 5:34048faec367 | 102 | /*********************************************************************************************/ |
Wael_H | 5:34048faec367 | 103 | void SendAck(unsigned short id, unsigned short from) |
Wael_H | 5:34048faec367 | 104 | { |
Wael_H | 5:34048faec367 | 105 | |
Wael_H | 5:34048faec367 | 106 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 107 | |
Wael_H | 5:34048faec367 | 108 | msgTx.id=id; |
Wael_H | 5:34048faec367 | 109 | |
Wael_H | 5:34048faec367 | 110 | msgTx.len=2; |
Wael_H | 5:34048faec367 | 111 | |
Wael_H | 5:34048faec367 | 112 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 113 | |
Wael_H | 5:34048faec367 | 114 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 115 | |
Wael_H | 5:34048faec367 | 116 | // from sur 2 octets |
Wael_H | 5:34048faec367 | 117 | |
Wael_H | 5:34048faec367 | 118 | msgTx.data[0]=(unsigned char)from; |
Wael_H | 5:34048faec367 | 119 | |
Wael_H | 5:34048faec367 | 120 | msgTx.data[1]=(unsigned char)(from>>8); |
Wael_H | 5:34048faec367 | 121 | |
Wael_H | 5:34048faec367 | 122 | |
Wael_H | 5:34048faec367 | 123 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 124 | } |
Wael_H | 5:34048faec367 | 125 | |
Wael_H | 5:34048faec367 | 126 | /*********************************************************************************************/ |
Wael_H | 5:34048faec367 | 127 | |
Wael_H | 5:34048faec367 | 128 | /* FUNCTION NAME: GoToPosition */ |
Wael_H | 5:34048faec367 | 129 | /* DESCRIPTION : Transmission CAN correspondant à un asservissement en position (x,y,theta) */ |
Wael_H | 5:34048faec367 | 130 | /*********************************************************************************************/ |
Wael_H | 5:34048faec367 | 131 | void GoToPosition (unsigned short x,unsigned short y,signed short theta,signed char sens) |
Wael_H | 5:34048faec367 | 132 | { |
Wael_H | 5:34048faec367 | 133 | |
Wael_H | 5:34048faec367 | 134 | //id_to_expect=ACK_CONSIGNE; |
Wael_H | 5:34048faec367 | 135 | |
Wael_H | 5:34048faec367 | 136 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 137 | |
Wael_H | 5:34048faec367 | 138 | msgTx.id=ASSERVISSEMENT_XYT; // tx nouvelle position en (x,y,theta) |
Wael_H | 5:34048faec367 | 139 | |
Wael_H | 5:34048faec367 | 140 | msgTx.len=7; |
Wael_H | 5:34048faec367 | 141 | |
Wael_H | 5:34048faec367 | 142 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 143 | |
Wael_H | 5:34048faec367 | 144 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 145 | |
Wael_H | 5:34048faec367 | 146 | // x sur 2 octets |
Wael_H | 5:34048faec367 | 147 | |
Wael_H | 5:34048faec367 | 148 | msgTx.data[0]=(unsigned char)x; |
Wael_H | 5:34048faec367 | 149 | |
Wael_H | 5:34048faec367 | 150 | msgTx.data[1]=(unsigned char)(x>>8); |
Wael_H | 5:34048faec367 | 151 | |
Wael_H | 5:34048faec367 | 152 | // y sur 2 octets |
Wael_H | 5:34048faec367 | 153 | |
Wael_H | 5:34048faec367 | 154 | msgTx.data[2]=(unsigned char)y; |
Wael_H | 5:34048faec367 | 155 | |
Wael_H | 5:34048faec367 | 156 | msgTx.data[3]=(unsigned char)(y>>8); |
Wael_H | 5:34048faec367 | 157 | |
Wael_H | 5:34048faec367 | 158 | // theta signé sur 2 octets |
Wael_H | 5:34048faec367 | 159 | |
Wael_H | 5:34048faec367 | 160 | msgTx.data[4]=(unsigned char)theta; |
Wael_H | 5:34048faec367 | 161 | |
Wael_H | 5:34048faec367 | 162 | msgTx.data[5]=(unsigned char)(theta>>8); |
Wael_H | 5:34048faec367 | 163 | |
Wael_H | 5:34048faec367 | 164 | msgTx.data[6]=sens; |
Wael_H | 5:34048faec367 | 165 | |
Wael_H | 5:34048faec367 | 166 | |
Wael_H | 5:34048faec367 | 167 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 168 | } |
Wael_H | 5:34048faec367 | 169 | |
Wael_H | 5:34048faec367 | 170 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 171 | |
Wael_H | 5:34048faec367 | 172 | /* FUNCTION NAME: Rotate */ |
Wael_H | 5:34048faec367 | 173 | |
Wael_H | 5:34048faec367 | 174 | /* DESCRIPTION : Transmission CAN correspondant à une rotation */ |
Wael_H | 5:34048faec367 | 175 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 176 | void Rotate (signed short angle) |
Wael_H | 5:34048faec367 | 177 | { |
Wael_H | 5:34048faec367 | 178 | |
Wael_H | 5:34048faec367 | 179 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 180 | |
Wael_H | 5:34048faec367 | 181 | msgTx.id=ASSERVISSEMENT_ROTATION; // Tx rotation autour du centre du robot |
Wael_H | 5:34048faec367 | 182 | |
Wael_H | 5:34048faec367 | 183 | msgTx.len=2; |
Wael_H | 5:34048faec367 | 184 | |
Wael_H | 5:34048faec367 | 185 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 186 | |
Wael_H | 5:34048faec367 | 187 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 188 | |
Wael_H | 5:34048faec367 | 189 | // Angle signé sur 2 octets |
Wael_H | 5:34048faec367 | 190 | |
Wael_H | 5:34048faec367 | 191 | msgTx.data[0]=(unsigned char)angle; |
Wael_H | 5:34048faec367 | 192 | |
Wael_H | 5:34048faec367 | 193 | msgTx.data[1]=(unsigned char)(angle>>8); |
Wael_H | 5:34048faec367 | 194 | |
Wael_H | 5:34048faec367 | 195 | |
Wael_H | 5:34048faec367 | 196 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 197 | } |
Wael_H | 5:34048faec367 | 198 | |
Wael_H | 5:34048faec367 | 199 | |
Wael_H | 5:34048faec367 | 200 | /*********************************************************************************************/ |
Wael_H | 5:34048faec367 | 201 | |
Wael_H | 5:34048faec367 | 202 | /* FUNCTION NAME: GoStraight */ |
Wael_H | 5:34048faec367 | 203 | /* DESCRIPTION : Transmission CAN correspondant à une ligne droite, avec ou sans recalage */ |
Wael_H | 5:34048faec367 | 204 | |
Wael_H | 5:34048faec367 | 205 | /* recalage : 0 => pas de recalage */ |
Wael_H | 5:34048faec367 | 206 | |
Wael_H | 5:34048faec367 | 207 | /* 1 => recalage en X */ |
Wael_H | 5:34048faec367 | 208 | |
Wael_H | 5:34048faec367 | 209 | /* 2 => Recalage en Y */ |
Wael_H | 5:34048faec367 | 210 | |
Wael_H | 5:34048faec367 | 211 | /* newValue : Uniquement en cas de recalage, indique la nouvelle valeur de l'odo */ |
Wael_H | 5:34048faec367 | 212 | |
Wael_H | 5:34048faec367 | 213 | /* isEnchainement : Indique si il faut executer l'instruction en enchainement */ |
Wael_H | 5:34048faec367 | 214 | |
Wael_H | 5:34048faec367 | 215 | /* 0 => non */ |
Wael_H | 5:34048faec367 | 216 | |
Wael_H | 5:34048faec367 | 217 | /* 1 => oui */ |
Wael_H | 5:34048faec367 | 218 | |
Wael_H | 5:34048faec367 | 219 | /* 2 => dernière instruction de l'enchainement */ |
Wael_H | 5:34048faec367 | 220 | /*********************************************************************************************/ |
Wael_H | 5:34048faec367 | 221 | void GoStraight (signed short distance,unsigned char recalage, unsigned short newValue, unsigned char isEnchainement) |
Wael_H | 5:34048faec367 | 222 | { |
Wael_H | 5:34048faec367 | 223 | |
Wael_H | 5:34048faec367 | 224 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 225 | |
Wael_H | 5:34048faec367 | 226 | msgTx.id=ASSERVISSEMENT_RECALAGE; |
Wael_H | 5:34048faec367 | 227 | |
Wael_H | 5:34048faec367 | 228 | msgTx.len=6; |
Wael_H | 5:34048faec367 | 229 | |
Wael_H | 5:34048faec367 | 230 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 231 | |
Wael_H | 5:34048faec367 | 232 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 233 | |
Wael_H | 5:34048faec367 | 234 | // x sur 2 octets |
Wael_H | 5:34048faec367 | 235 | |
Wael_H | 5:34048faec367 | 236 | msgTx.data[0]=(unsigned char)distance; |
Wael_H | 5:34048faec367 | 237 | |
Wael_H | 5:34048faec367 | 238 | msgTx.data[1]=(unsigned char)(distance>>8); |
Wael_H | 5:34048faec367 | 239 | |
Wael_H | 5:34048faec367 | 240 | //Recalage sur 1 octet |
Wael_H | 5:34048faec367 | 241 | |
Wael_H | 5:34048faec367 | 242 | msgTx.data[2]=recalage; |
Wael_H | 5:34048faec367 | 243 | |
Wael_H | 5:34048faec367 | 244 | //Valeur du recalage sur 2 octets |
Wael_H | 5:34048faec367 | 245 | |
Wael_H | 5:34048faec367 | 246 | msgTx.data[3]=(unsigned char)newValue; |
Wael_H | 5:34048faec367 | 247 | |
Wael_H | 5:34048faec367 | 248 | msgTx.data[4]=(unsigned char)(newValue>>8); |
Wael_H | 5:34048faec367 | 249 | |
Wael_H | 5:34048faec367 | 250 | //Enchainement sur 1 octet |
Wael_H | 5:34048faec367 | 251 | |
Wael_H | 5:34048faec367 | 252 | msgTx.data[5]=isEnchainement; |
Wael_H | 5:34048faec367 | 253 | |
Wael_H | 5:34048faec367 | 254 | |
Wael_H | 5:34048faec367 | 255 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 256 | |
Wael_H | 5:34048faec367 | 257 | //wait_ms(500); |
Wael_H | 5:34048faec367 | 258 | } |
Wael_H | 5:34048faec367 | 259 | |
Wael_H | 5:34048faec367 | 260 | /********************************************************************************************/ |
Wael_H | 5:34048faec367 | 261 | |
Wael_H | 5:34048faec367 | 262 | /* FUNCTION NAME: BendRadius */ |
Wael_H | 5:34048faec367 | 263 | |
Wael_H | 5:34048faec367 | 264 | /* DESCRIPTION : Transmission CAN correspondant à un rayon de courbure */ |
Wael_H | 5:34048faec367 | 265 | /********************************************************************************************/ |
Wael_H | 5:34048faec367 | 266 | void BendRadius (unsigned short rayon,signed short angle,signed char sens, unsigned char enchainement) |
Wael_H | 5:34048faec367 | 267 | { |
Wael_H | 5:34048faec367 | 268 | |
Wael_H | 5:34048faec367 | 269 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 270 | |
Wael_H | 5:34048faec367 | 271 | msgTx.id=ASSERVISSEMENT_COURBURE; // tx asservissement rayon de courbure |
Wael_H | 5:34048faec367 | 272 | |
Wael_H | 5:34048faec367 | 273 | msgTx.len=6; |
Wael_H | 5:34048faec367 | 274 | |
Wael_H | 5:34048faec367 | 275 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 276 | |
Wael_H | 5:34048faec367 | 277 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 278 | |
Wael_H | 5:34048faec367 | 279 | // Rayon sur 2 octets |
Wael_H | 5:34048faec367 | 280 | |
Wael_H | 5:34048faec367 | 281 | msgTx.data[0]=(unsigned char)rayon; |
Wael_H | 5:34048faec367 | 282 | |
Wael_H | 5:34048faec367 | 283 | msgTx.data[1]=(unsigned char)(rayon>>8); |
Wael_H | 5:34048faec367 | 284 | |
Wael_H | 5:34048faec367 | 285 | // Angle signé sur 2 octets |
Wael_H | 5:34048faec367 | 286 | |
Wael_H | 5:34048faec367 | 287 | msgTx.data[2]=(unsigned char)angle; |
Wael_H | 5:34048faec367 | 288 | |
Wael_H | 5:34048faec367 | 289 | msgTx.data[3]=(unsigned char)(angle>>8); |
Wael_H | 5:34048faec367 | 290 | |
Wael_H | 5:34048faec367 | 291 | // Sens signé sur 1 octet |
Wael_H | 5:34048faec367 | 292 | |
Wael_H | 5:34048faec367 | 293 | msgTx.data[4]=sens; |
Wael_H | 5:34048faec367 | 294 | |
Wael_H | 5:34048faec367 | 295 | // Enchainement sur 1 octet |
Wael_H | 5:34048faec367 | 296 | |
Wael_H | 5:34048faec367 | 297 | msgTx.data[5]=enchainement; |
Wael_H | 5:34048faec367 | 298 | |
Wael_H | 5:34048faec367 | 299 | |
Wael_H | 5:34048faec367 | 300 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 301 | } |
Wael_H | 5:34048faec367 | 302 | |
Wael_H | 5:34048faec367 | 303 | void SetOdometrie (unsigned short canId, unsigned short x,unsigned short y,signed short theta) |
Wael_H | 5:34048faec367 | 304 | { |
Wael_H | 5:34048faec367 | 305 | |
Wael_H | 5:34048faec367 | 306 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 307 | |
Wael_H | 5:34048faec367 | 308 | msgTx.id=canId; |
Wael_H | 5:34048faec367 | 309 | |
Wael_H | 5:34048faec367 | 310 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 311 | |
Wael_H | 5:34048faec367 | 312 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 313 | |
Wael_H | 5:34048faec367 | 314 | msgTx.len=6; |
Wael_H | 5:34048faec367 | 315 | |
Wael_H | 5:34048faec367 | 316 | |
Wael_H | 5:34048faec367 | 317 | // x sur 2 octets |
Wael_H | 5:34048faec367 | 318 | |
Wael_H | 5:34048faec367 | 319 | msgTx.data[0]=(unsigned char)x; |
Wael_H | 5:34048faec367 | 320 | |
Wael_H | 5:34048faec367 | 321 | msgTx.data[1]=(unsigned char)(x>>8); |
Wael_H | 5:34048faec367 | 322 | |
Wael_H | 5:34048faec367 | 323 | // y sur 2 octets |
Wael_H | 5:34048faec367 | 324 | |
Wael_H | 5:34048faec367 | 325 | msgTx.data[2]=(unsigned char)y; |
Wael_H | 5:34048faec367 | 326 | |
Wael_H | 5:34048faec367 | 327 | msgTx.data[3]=(unsigned char)(y>>8); |
Wael_H | 5:34048faec367 | 328 | |
Wael_H | 5:34048faec367 | 329 | // theta signé sur 2 octets |
Wael_H | 5:34048faec367 | 330 | |
Wael_H | 5:34048faec367 | 331 | msgTx.data[4]=(unsigned char)theta; |
Wael_H | 5:34048faec367 | 332 | |
Wael_H | 5:34048faec367 | 333 | msgTx.data[5]=(unsigned char)(theta>>8); |
Wael_H | 5:34048faec367 | 334 | |
Wael_H | 5:34048faec367 | 335 | |
Wael_H | 5:34048faec367 | 336 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 337 | } |
Wael_H | 5:34048faec367 | 338 | |
Wael_H | 5:34048faec367 | 339 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 340 | |
Wael_H | 5:34048faec367 | 341 | /* FUNCTION NAME: setAsservissementEtat */ |
Wael_H | 5:34048faec367 | 342 | |
Wael_H | 5:34048faec367 | 343 | /* DESCRIPTION : Activer ou désactiver l'asservissement */ |
Wael_H | 5:34048faec367 | 344 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 345 | void setAsservissementEtat(unsigned char enable) |
Wael_H | 5:34048faec367 | 346 | { |
Wael_H | 5:34048faec367 | 347 | |
Wael_H | 5:34048faec367 | 348 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 349 | |
Wael_H | 5:34048faec367 | 350 | msgTx.id=ASSERVISSEMENT_ENABLE; // Tx rotation autour du centre du robot |
Wael_H | 5:34048faec367 | 351 | |
Wael_H | 5:34048faec367 | 352 | msgTx.len=1; |
Wael_H | 5:34048faec367 | 353 | |
Wael_H | 5:34048faec367 | 354 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 355 | |
Wael_H | 5:34048faec367 | 356 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 357 | |
Wael_H | 5:34048faec367 | 358 | // Angle signé sur 2 octets |
Wael_H | 5:34048faec367 | 359 | |
Wael_H | 5:34048faec367 | 360 | msgTx.data[0]=(unsigned char)((enable==0)?0:1); |
Wael_H | 5:34048faec367 | 361 | |
Wael_H | 5:34048faec367 | 362 | |
Wael_H | 5:34048faec367 | 363 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 364 | } |
Wael_H | 5:34048faec367 | 365 | |
Wael_H | 5:34048faec367 | 366 | |
Wael_H | 5:34048faec367 | 367 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 368 | |
Wael_H | 5:34048faec367 | 369 | /* FUNCTION NAME: SendSpeed */ |
Wael_H | 5:34048faec367 | 370 | |
Wael_H | 5:34048faec367 | 371 | /* DESCRIPTION : Envoie un asservissement paramètre retournant à une vitesse */ |
Wael_H | 5:34048faec367 | 372 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 373 | void SendSpeed (unsigned short vitesse, unsigned short acceleration) |
Wael_H | 5:34048faec367 | 374 | { |
Wael_H | 5:34048faec367 | 375 | |
Wael_H | 5:34048faec367 | 376 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 377 | |
Wael_H | 5:34048faec367 | 378 | msgTx.id=ASSERVISSEMENT_CONFIG; |
Wael_H | 5:34048faec367 | 379 | |
Wael_H | 5:34048faec367 | 380 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 381 | |
Wael_H | 5:34048faec367 | 382 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 383 | |
Wael_H | 5:34048faec367 | 384 | msgTx.len=4; |
Wael_H | 5:34048faec367 | 385 | |
Wael_H | 5:34048faec367 | 386 | msgTx.data[0]=(unsigned char)(vitesse&0x00FF); |
Wael_H | 5:34048faec367 | 387 | |
Wael_H | 5:34048faec367 | 388 | msgTx.data[1]=(unsigned char)((vitesse&0xFF00)>>8); |
Wael_H | 5:34048faec367 | 389 | |
Wael_H | 5:34048faec367 | 390 | msgTx.data[2]=(unsigned char)(acceleration&0x00FF); |
Wael_H | 5:34048faec367 | 391 | |
Wael_H | 5:34048faec367 | 392 | |
Wael_H | 5:34048faec367 | 393 | msgTx.data[3]=(unsigned char)((acceleration&0xFF00)>>8); |
Wael_H | 5:34048faec367 | 394 | |
Wael_H | 5:34048faec367 | 395 | |
Wael_H | 5:34048faec367 | 396 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 397 | |
Wael_H | 5:34048faec367 | 398 | |
Wael_H | 5:34048faec367 | 399 | } |
Wael_H | 5:34048faec367 | 400 | |
Wael_H | 5:34048faec367 | 401 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 402 | |
Wael_H | 5:34048faec367 | 403 | /* FUNCTION NAME: SendSpeedDecel */ |
Wael_H | 5:34048faec367 | 404 | |
Wael_H | 5:34048faec367 | 405 | /* DESCRIPTION : Envoie un asservissement paramètre retournant à une vitesse */ |
Wael_H | 5:34048faec367 | 406 | /****************************************************************************************/ |
Wael_H | 5:34048faec367 | 407 | |
Wael_H | 5:34048faec367 | 408 | void SendSpeedDecel (unsigned short vitesse, unsigned short deceleration) |
Wael_H | 5:34048faec367 | 409 | { |
Wael_H | 5:34048faec367 | 410 | |
Wael_H | 5:34048faec367 | 411 | CANMessage msgTx=CANMessage(); |
Wael_H | 5:34048faec367 | 412 | |
Wael_H | 5:34048faec367 | 413 | msgTx.id=ASSERVISSEMENT_CONFIG_DECEL; |
Wael_H | 5:34048faec367 | 414 | |
Wael_H | 5:34048faec367 | 415 | msgTx.format=CANStandard; |
Wael_H | 5:34048faec367 | 416 | |
Wael_H | 5:34048faec367 | 417 | msgTx.type=CANData; |
Wael_H | 5:34048faec367 | 418 | |
Wael_H | 5:34048faec367 | 419 | msgTx.len=4; |
Wael_H | 5:34048faec367 | 420 | |
Wael_H | 5:34048faec367 | 421 | msgTx.data[0]=(unsigned char)(vitesse&0x00FF); |
Wael_H | 5:34048faec367 | 422 | |
Wael_H | 5:34048faec367 | 423 | msgTx.data[1]=(unsigned char)((vitesse&0xFF00)>>8); |
Wael_H | 5:34048faec367 | 424 | |
Wael_H | 5:34048faec367 | 425 | msgTx.data[2]=(unsigned char)(deceleration&0x00FF); |
Wael_H | 5:34048faec367 | 426 | |
Wael_H | 5:34048faec367 | 427 | msgTx.data[3]=(unsigned char)((deceleration&0xFF00)>>8); |
Wael_H | 5:34048faec367 | 428 | |
Wael_H | 5:34048faec367 | 429 | can.write(msgTx); |
Wael_H | 5:34048faec367 | 430 | |
Wael_H | 5:34048faec367 | 431 | |
Wael_H | 5:34048faec367 | 432 | } |