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: Communication_Robot QEI iSerial mbed motion_control
Fork of dog_V3_2_testmotor by
main.cpp@7:6a99be179329, 2015-07-17 (annotated)
- Committer:
- soulx
- Date:
- Fri Jul 17 07:11:46 2015 +0000
- Revision:
- 7:6a99be179329
- Parent:
- 6:8d80c84e0c09
- Child:
- 8:8d30ce9a9463
create class motor_relay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soulx | 0:2433ddae2772 | 1 | #include "mbed.h" |
soulx | 0:2433ddae2772 | 2 | #include "pin_config.h" |
soulx | 0:2433ddae2772 | 3 | |
soulx | 6:8d80c84e0c09 | 4 | #include "communication.h" |
soulx | 6:8d80c84e0c09 | 5 | #include "protocol.h" |
soulx | 6:8d80c84e0c09 | 6 | |
soulx | 6:8d80c84e0c09 | 7 | //set frequancy unit in Hz |
soulx | 6:8d80c84e0c09 | 8 | #define F_UPDATE 10.0f |
soulx | 6:8d80c84e0c09 | 9 | #define TIMER_UPDATE 1.0f/F_UPDATE |
soulx | 6:8d80c84e0c09 | 10 | |
soulx | 6:8d80c84e0c09 | 11 | //counter not receive from station |
soulx | 6:8d80c84e0c09 | 12 | #define TIMEOUT_RESPONE_COMMAND 5 |
soulx | 6:8d80c84e0c09 | 13 | |
soulx | 0:2433ddae2772 | 14 | //define pin class |
soulx | 0:2433ddae2772 | 15 | DigitalOut dirA_LU(INA_L_U); |
soulx | 0:2433ddae2772 | 16 | DigitalOut dirB_LU(INB_L_U); |
soulx | 0:2433ddae2772 | 17 | |
soulx | 0:2433ddae2772 | 18 | DigitalOut dirA_LL(INA_L_L); |
soulx | 0:2433ddae2772 | 19 | DigitalOut dirB_LL(INB_L_L); |
soulx | 0:2433ddae2772 | 20 | |
soulx | 0:2433ddae2772 | 21 | DigitalOut dirA_RU(INA_R_U); |
soulx | 0:2433ddae2772 | 22 | DigitalOut dirB_RU(INB_R_U); |
soulx | 0:2433ddae2772 | 23 | |
soulx | 0:2433ddae2772 | 24 | DigitalOut dirA_RL(INA_R_L); |
soulx | 0:2433ddae2772 | 25 | DigitalOut dirB_RL(INB_R_L); |
soulx | 0:2433ddae2772 | 26 | |
soulx | 0:2433ddae2772 | 27 | DigitalIn sw_LU_U(LIMIT_LU_U,PullUp); |
soulx | 0:2433ddae2772 | 28 | DigitalIn sw_LU_D(LIMIT_LU_D,PullUp); |
soulx | 0:2433ddae2772 | 29 | |
soulx | 0:2433ddae2772 | 30 | DigitalIn sw_LL_U(LIMIT_LL_U,PullUp); |
soulx | 0:2433ddae2772 | 31 | DigitalIn sw_LL_D(LIMIT_LL_D,PullUp); |
soulx | 0:2433ddae2772 | 32 | |
soulx | 0:2433ddae2772 | 33 | DigitalIn sw_RU_U(LIMIT_RU_U,PullUp); |
soulx | 0:2433ddae2772 | 34 | DigitalIn sw_RU_D(LIMIT_RU_D,PullUp); |
soulx | 0:2433ddae2772 | 35 | |
soulx | 0:2433ddae2772 | 36 | DigitalIn sw_RL_U(LIMIT_RL_U,PullUp); |
soulx | 0:2433ddae2772 | 37 | DigitalIn sw_RL_D(LIMIT_RL_D,PullUp); |
soulx | 0:2433ddae2772 | 38 | |
soulx | 0:2433ddae2772 | 39 | AnalogIn position_LU(VR_LU); |
soulx | 0:2433ddae2772 | 40 | AnalogIn position_LL(VR_LL); |
soulx | 0:2433ddae2772 | 41 | AnalogIn position_RU(VR_RU); |
soulx | 0:2433ddae2772 | 42 | AnalogIn position_RL(VR_RL); |
soulx | 0:2433ddae2772 | 43 | |
soulx | 0:2433ddae2772 | 44 | DigitalOut myled(LED1); |
soulx | 0:2433ddae2772 | 45 | DigitalIn mybutton(USER_BUTTON); |
soulx | 0:2433ddae2772 | 46 | |
soulx | 6:8d80c84e0c09 | 47 | //communication config |
soulx | 6:8d80c84e0c09 | 48 | //serial for debug |
soulx | 0:2433ddae2772 | 49 | Serial pc(USBTX, USBRX); |
soulx | 6:8d80c84e0c09 | 50 | //serial for xbee |
soulx | 6:8d80c84e0c09 | 51 | COMMUNICATION pan_a(TX_XBEE, RX_XBEE,115200,1000,1000); // tx, rx |
soulx | 0:2433ddae2772 | 52 | |
soulx | 0:2433ddae2772 | 53 | //Function Prototype |
soulx | 0:2433ddae2772 | 54 | void motor_set(uint8_t id, uint8_t direct); |
soulx | 0:2433ddae2772 | 55 | void motor_stop(uint8_t id); |
soulx | 0:2433ddae2772 | 56 | |
soulx | 0:2433ddae2772 | 57 | uint8_t limit_motor(uint8_t id, uint8_t dirction); |
soulx | 0:2433ddae2772 | 58 | uint8_t position_control(uint8_t id, uint16_t current, uint16_t target); |
soulx | 0:2433ddae2772 | 59 | |
soulx | 0:2433ddae2772 | 60 | void calibration(uint8_t id); |
soulx | 0:2433ddae2772 | 61 | |
soulx | 6:8d80c84e0c09 | 62 | void getCommand(); |
soulx | 6:8d80c84e0c09 | 63 | |
soulx | 0:2433ddae2772 | 64 | |
soulx | 0:2433ddae2772 | 65 | //Globle Variable |
soulx | 0:2433ddae2772 | 66 | uint16_t max_pos_LU= 10000; |
soulx | 0:2433ddae2772 | 67 | uint16_t min_pos_LU= 6000; |
soulx | 0:2433ddae2772 | 68 | uint16_t max_pos_LL= 50000; |
soulx | 0:2433ddae2772 | 69 | uint16_t min_pos_LL= 37000; |
soulx | 0:2433ddae2772 | 70 | |
soulx | 0:2433ddae2772 | 71 | uint16_t max_pos_RU= 17800; |
soulx | 0:2433ddae2772 | 72 | uint16_t min_pos_RU= 9000; |
soulx | 0:2433ddae2772 | 73 | uint16_t max_pos_RL= 51000; |
soulx | 0:2433ddae2772 | 74 | uint16_t min_pos_RL= 11000; |
soulx | 0:2433ddae2772 | 75 | |
soulx | 1:768d359e9d96 | 76 | uint16_t offset_pos =1000; |
Pitiwut | 3:bb5fbe510fa5 | 77 | uint16_t test_variable =1000; |
soulx | 1:768d359e9d96 | 78 | |
soulx | 0:2433ddae2772 | 79 | int16_t MARGIN = 500; |
soulx | 0:2433ddae2772 | 80 | |
soulx | 6:8d80c84e0c09 | 81 | //set foreground |
soulx | 6:8d80c84e0c09 | 82 | Ticker Update_command; |
soulx | 6:8d80c84e0c09 | 83 | |
soulx | 6:8d80c84e0c09 | 84 | |
soulx | 0:2433ddae2772 | 85 | //Main function |
soulx | 0:2433ddae2772 | 86 | int main() |
soulx | 0:2433ddae2772 | 87 | { |
soulx | 0:2433ddae2772 | 88 | uint16_t vr_lu,vr_ru; |
soulx | 0:2433ddae2772 | 89 | uint16_t vr_ll,vr_rl; |
soulx | 0:2433ddae2772 | 90 | pc.printf("wait\n"); |
soulx | 0:2433ddae2772 | 91 | motor_stop(0); |
soulx | 0:2433ddae2772 | 92 | // wait(10); |
soulx | 0:2433ddae2772 | 93 | /* |
soulx | 0:2433ddae2772 | 94 | while(1) { |
soulx | 0:2433ddae2772 | 95 | motor_set(1,1); |
soulx | 0:2433ddae2772 | 96 | motor_set(2,1); |
soulx | 0:2433ddae2772 | 97 | motor_set(3,1); |
soulx | 0:2433ddae2772 | 98 | motor_set(4,1); |
soulx | 0:2433ddae2772 | 99 | wait(1); |
soulx | 0:2433ddae2772 | 100 | motor_set(1,2); |
soulx | 0:2433ddae2772 | 101 | motor_set(2,2); |
soulx | 0:2433ddae2772 | 102 | motor_set(3,2); |
soulx | 0:2433ddae2772 | 103 | motor_set(4,2); |
soulx | 0:2433ddae2772 | 104 | wait(1); |
soulx | 0:2433ddae2772 | 105 | } |
soulx | 0:2433ddae2772 | 106 | */ |
soulx | 0:2433ddae2772 | 107 | |
soulx | 0:2433ddae2772 | 108 | /* |
soulx | 0:2433ddae2772 | 109 | while(1) { |
soulx | 0:2433ddae2772 | 110 | //Read position |
soulx | 0:2433ddae2772 | 111 | vr_ll = position_LL.read_u16(); |
soulx | 0:2433ddae2772 | 112 | vr_lu = position_LU.read_u16(); |
soulx | 0:2433ddae2772 | 113 | vr_rl = position_RL.read_u16(); |
soulx | 0:2433ddae2772 | 114 | vr_ru = position_RU.read_u16(); |
soulx | 0:2433ddae2772 | 115 | pc.printf("vr_LL = %d\t",vr_ll); |
soulx | 0:2433ddae2772 | 116 | pc.printf("vr_LU = %d\t",vr_lu); |
soulx | 0:2433ddae2772 | 117 | pc.printf("vr_RL = %d\t",vr_rl); |
soulx | 0:2433ddae2772 | 118 | pc.printf("vr_RU = %d\n",vr_ru); |
soulx | 0:2433ddae2772 | 119 | } |
soulx | 0:2433ddae2772 | 120 | */ |
soulx | 0:2433ddae2772 | 121 | |
soulx | 0:2433ddae2772 | 122 | /* |
soulx | 5:f07cbb5a86c3 | 123 | while(1) { |
soulx | 5:f07cbb5a86c3 | 124 | if(sw_LU_U) { |
soulx | 5:f07cbb5a86c3 | 125 | pc.printf("sw_LU_U = 1"); |
soulx | 5:f07cbb5a86c3 | 126 | } else { |
soulx | 5:f07cbb5a86c3 | 127 | pc.printf("sw_LU_U = 0"); |
soulx | 5:f07cbb5a86c3 | 128 | } |
soulx | 5:f07cbb5a86c3 | 129 | |
soulx | 5:f07cbb5a86c3 | 130 | if(sw_LU_D) { |
soulx | 5:f07cbb5a86c3 | 131 | pc.printf(" sw_LU_D = 1"); |
soulx | 5:f07cbb5a86c3 | 132 | } else { |
soulx | 5:f07cbb5a86c3 | 133 | pc.printf(" sw_LU_D = 0"); |
soulx | 5:f07cbb5a86c3 | 134 | } |
soulx | 5:f07cbb5a86c3 | 135 | pc.printf("\n"); |
soulx | 5:f07cbb5a86c3 | 136 | /////////////////////////////////// |
soulx | 5:f07cbb5a86c3 | 137 | if(sw_LL_U) { |
soulx | 5:f07cbb5a86c3 | 138 | pc.printf("sw_LL_U = 1"); |
soulx | 5:f07cbb5a86c3 | 139 | } else { |
soulx | 5:f07cbb5a86c3 | 140 | pc.printf("sw_LL_U = 0"); |
soulx | 5:f07cbb5a86c3 | 141 | } |
soulx | 5:f07cbb5a86c3 | 142 | |
soulx | 5:f07cbb5a86c3 | 143 | if(sw_LL_D) { |
soulx | 5:f07cbb5a86c3 | 144 | pc.printf(" sw_LL_D = 1"); |
soulx | 5:f07cbb5a86c3 | 145 | } else { |
soulx | 5:f07cbb5a86c3 | 146 | pc.printf(" sw_LL_D = 0"); |
soulx | 5:f07cbb5a86c3 | 147 | } |
soulx | 5:f07cbb5a86c3 | 148 | pc.printf("\n"); |
soulx | 5:f07cbb5a86c3 | 149 | ////////////////////////////////////// |
soulx | 5:f07cbb5a86c3 | 150 | /////////////////////////////////// |
soulx | 5:f07cbb5a86c3 | 151 | |
soulx | 5:f07cbb5a86c3 | 152 | ///////////////////// |
soulx | 5:f07cbb5a86c3 | 153 | if(sw_RU_U) { |
soulx | 5:f07cbb5a86c3 | 154 | pc.printf("sw_RU_U = 1"); |
soulx | 5:f07cbb5a86c3 | 155 | } else { |
soulx | 5:f07cbb5a86c3 | 156 | pc.printf("sw_RU_U = 0"); |
soulx | 5:f07cbb5a86c3 | 157 | } |
soulx | 5:f07cbb5a86c3 | 158 | |
soulx | 5:f07cbb5a86c3 | 159 | if(sw_RU_D) { |
soulx | 5:f07cbb5a86c3 | 160 | pc.printf(" sw_RU_D = 1"); |
soulx | 5:f07cbb5a86c3 | 161 | } else { |
soulx | 5:f07cbb5a86c3 | 162 | pc.printf(" sw_RU_D = 0"); |
soulx | 5:f07cbb5a86c3 | 163 | } |
soulx | 5:f07cbb5a86c3 | 164 | pc.printf("\n"); |
soulx | 5:f07cbb5a86c3 | 165 | /////////////////////////////////// |
soulx | 5:f07cbb5a86c3 | 166 | if(sw_RL_U) { |
soulx | 5:f07cbb5a86c3 | 167 | pc.printf("sw_RL_U = 1"); |
soulx | 5:f07cbb5a86c3 | 168 | } else { |
soulx | 5:f07cbb5a86c3 | 169 | pc.printf("sw_RL_U = 0"); |
soulx | 5:f07cbb5a86c3 | 170 | } |
soulx | 5:f07cbb5a86c3 | 171 | |
soulx | 5:f07cbb5a86c3 | 172 | if(sw_RL_D) { |
soulx | 5:f07cbb5a86c3 | 173 | pc.printf(" sw_RL_D = 1"); |
soulx | 5:f07cbb5a86c3 | 174 | } else { |
soulx | 5:f07cbb5a86c3 | 175 | pc.printf(" sw_RL_D = 0"); |
soulx | 5:f07cbb5a86c3 | 176 | } |
soulx | 5:f07cbb5a86c3 | 177 | ////////////////////////////////////// |
soulx | 5:f07cbb5a86c3 | 178 | pc.printf("\n"); |
soulx | 5:f07cbb5a86c3 | 179 | pc.printf("\n"); |
soulx | 5:f07cbb5a86c3 | 180 | wait(1); |
soulx | 5:f07cbb5a86c3 | 181 | } |
soulx | 5:f07cbb5a86c3 | 182 | */ |
soulx | 5:f07cbb5a86c3 | 183 | |
soulx | 5:f07cbb5a86c3 | 184 | /* |
soulx | 0:2433ddae2772 | 185 | while(1) { |
soulx | 0:2433ddae2772 | 186 | myled =1; |
soulx | 0:2433ddae2772 | 187 | wait_ms(200); |
soulx | 0:2433ddae2772 | 188 | |
soulx | 0:2433ddae2772 | 189 | if(mybutton == 0) { |
soulx | 0:2433ddae2772 | 190 | myled =0; |
soulx | 0:2433ddae2772 | 191 | wait_ms(200); |
soulx | 0:2433ddae2772 | 192 | } |
soulx | 0:2433ddae2772 | 193 | |
soulx | 0:2433ddae2772 | 194 | if(sw_LU_U == 0) { |
soulx | 0:2433ddae2772 | 195 | myled =0; |
soulx | 0:2433ddae2772 | 196 | wait_ms(200); |
soulx | 0:2433ddae2772 | 197 | } |
soulx | 0:2433ddae2772 | 198 | |
soulx | 0:2433ddae2772 | 199 | if(sw_LU_D == 0) { |
soulx | 0:2433ddae2772 | 200 | myled =0; |
soulx | 0:2433ddae2772 | 201 | wait_ms(200); |
soulx | 0:2433ddae2772 | 202 | } |
soulx | 0:2433ddae2772 | 203 | |
soulx | 0:2433ddae2772 | 204 | if(sw_LL_U == 0) { |
soulx | 0:2433ddae2772 | 205 | myled =0; |
soulx | 0:2433ddae2772 | 206 | wait_ms(200); |
soulx | 0:2433ddae2772 | 207 | } |
soulx | 0:2433ddae2772 | 208 | |
soulx | 0:2433ddae2772 | 209 | if(sw_LL_D == 0) { |
soulx | 0:2433ddae2772 | 210 | myled =0; |
soulx | 0:2433ddae2772 | 211 | wait_ms(200); |
soulx | 0:2433ddae2772 | 212 | } |
soulx | 0:2433ddae2772 | 213 | |
soulx | 0:2433ddae2772 | 214 | if(sw_RU_U == 0) { |
soulx | 0:2433ddae2772 | 215 | myled =0; |
soulx | 0:2433ddae2772 | 216 | wait_ms(200); |
soulx | 0:2433ddae2772 | 217 | } |
soulx | 0:2433ddae2772 | 218 | |
soulx | 0:2433ddae2772 | 219 | if(sw_RU_D == 0) { |
soulx | 0:2433ddae2772 | 220 | myled =0; |
soulx | 0:2433ddae2772 | 221 | wait_ms(200); |
soulx | 0:2433ddae2772 | 222 | } |
soulx | 0:2433ddae2772 | 223 | |
soulx | 0:2433ddae2772 | 224 | if(sw_RL_U == 0) { |
soulx | 0:2433ddae2772 | 225 | myled =0; |
soulx | 0:2433ddae2772 | 226 | wait_ms(200); |
soulx | 0:2433ddae2772 | 227 | } |
soulx | 0:2433ddae2772 | 228 | |
soulx | 0:2433ddae2772 | 229 | if(sw_RL_D == 0) { |
soulx | 0:2433ddae2772 | 230 | myled =0; |
soulx | 0:2433ddae2772 | 231 | wait_ms(200); |
soulx | 0:2433ddae2772 | 232 | } |
soulx | 0:2433ddae2772 | 233 | |
soulx | 0:2433ddae2772 | 234 | } |
soulx | 0:2433ddae2772 | 235 | */ |
soulx | 0:2433ddae2772 | 236 | |
soulx | 7:6a99be179329 | 237 | while(1) { |
soulx | 7:6a99be179329 | 238 | //calibration |
soulx | 7:6a99be179329 | 239 | pc.printf("Welcome to DOGWHEELSCHAIR\n"); |
soulx | 7:6a99be179329 | 240 | pc.printf("Calibration [START]\n"); |
soulx | 7:6a99be179329 | 241 | calibration(1); |
soulx | 7:6a99be179329 | 242 | calibration(2); |
soulx | 7:6a99be179329 | 243 | calibration(3); |
soulx | 7:6a99be179329 | 244 | calibration(4); |
soulx | 7:6a99be179329 | 245 | pc.printf("Calibration [FINISH]\n"); |
soulx | 7:6a99be179329 | 246 | pc.printf("RUN mode [START]\n"); |
soulx | 7:6a99be179329 | 247 | } |
soulx | 0:2433ddae2772 | 248 | |
soulx | 6:8d80c84e0c09 | 249 | Update_command.attach(&getCommand,TIMER_UPDATE); |
soulx | 0:2433ddae2772 | 250 | |
soulx | 0:2433ddae2772 | 251 | uint8_t count=0; |
soulx | 0:2433ddae2772 | 252 | |
soulx | 0:2433ddae2772 | 253 | while(1) { |
soulx | 0:2433ddae2772 | 254 | uint8_t state=0; |
soulx | 0:2433ddae2772 | 255 | pc.printf("Count %d",count); |
soulx | 0:2433ddae2772 | 256 | do { |
soulx | 0:2433ddae2772 | 257 | state=0; |
soulx | 0:2433ddae2772 | 258 | |
soulx | 1:768d359e9d96 | 259 | if(position_control(1,position_LU.read_u16(),max_pos_LU-offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 260 | state++; |
soulx | 0:2433ddae2772 | 261 | } |
soulx | 0:2433ddae2772 | 262 | |
soulx | 1:768d359e9d96 | 263 | if(position_control(2,position_LL.read_u16(),max_pos_LL-offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 264 | state++; |
soulx | 0:2433ddae2772 | 265 | } |
soulx | 0:2433ddae2772 | 266 | |
soulx | 1:768d359e9d96 | 267 | if(position_control(3,position_RU.read_u16(),max_pos_RU-offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 268 | state++; |
soulx | 0:2433ddae2772 | 269 | } |
soulx | 0:2433ddae2772 | 270 | |
soulx | 1:768d359e9d96 | 271 | if(position_control(4,position_RL.read_u16(),max_pos_RL-offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 272 | state++; |
soulx | 0:2433ddae2772 | 273 | } |
soulx | 0:2433ddae2772 | 274 | |
soulx | 0:2433ddae2772 | 275 | pc.printf("state = %d",state); |
soulx | 0:2433ddae2772 | 276 | } while(state <= 4 ); |
soulx | 0:2433ddae2772 | 277 | |
soulx | 0:2433ddae2772 | 278 | do { |
soulx | 0:2433ddae2772 | 279 | state=0; |
soulx | 0:2433ddae2772 | 280 | |
soulx | 1:768d359e9d96 | 281 | if(position_control(1,position_LU.read_u16(),min_pos_LU+offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 282 | state++; |
soulx | 0:2433ddae2772 | 283 | } |
soulx | 0:2433ddae2772 | 284 | |
soulx | 1:768d359e9d96 | 285 | if(position_control(2,position_LL.read_u16(),min_pos_LL+offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 286 | state++; |
soulx | 0:2433ddae2772 | 287 | } |
soulx | 0:2433ddae2772 | 288 | |
soulx | 1:768d359e9d96 | 289 | if(position_control(3,position_RU.read_u16(),min_pos_RU+offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 290 | state++; |
soulx | 0:2433ddae2772 | 291 | } |
soulx | 0:2433ddae2772 | 292 | |
soulx | 1:768d359e9d96 | 293 | if(position_control(4,position_RL.read_u16(),min_pos_RL+offset_pos) == 1) { |
soulx | 0:2433ddae2772 | 294 | state++; |
soulx | 0:2433ddae2772 | 295 | } |
soulx | 0:2433ddae2772 | 296 | |
soulx | 0:2433ddae2772 | 297 | pc.printf("state = %d",state); |
soulx | 0:2433ddae2772 | 298 | } while(state <= 4 ); |
soulx | 0:2433ddae2772 | 299 | count++; |
soulx | 0:2433ddae2772 | 300 | } |
soulx | 0:2433ddae2772 | 301 | } |
soulx | 0:2433ddae2772 | 302 | |
soulx | 0:2433ddae2772 | 303 | |
soulx | 0:2433ddae2772 | 304 | |
soulx | 0:2433ddae2772 | 305 | void motor_set(uint8_t id, uint8_t direct) |
soulx | 0:2433ddae2772 | 306 | { |
soulx | 0:2433ddae2772 | 307 | //direct: Should be between 0 and 3, with the following result |
soulx | 0:2433ddae2772 | 308 | //0: Brake to VCC |
soulx | 0:2433ddae2772 | 309 | //1: Clockwise |
soulx | 0:2433ddae2772 | 310 | //2: CounterClockwise |
soulx | 0:2433ddae2772 | 311 | //3: Brake to GND |
soulx | 0:2433ddae2772 | 312 | |
soulx | 0:2433ddae2772 | 313 | if(direct <=4) { |
soulx | 0:2433ddae2772 | 314 | switch(id) { |
soulx | 0:2433ddae2772 | 315 | case 1: |
soulx | 0:2433ddae2772 | 316 | // Set inA[motor] |
soulx | 0:2433ddae2772 | 317 | if (direct <=1) |
soulx | 0:2433ddae2772 | 318 | dirA_LU=0; |
soulx | 0:2433ddae2772 | 319 | else |
soulx | 0:2433ddae2772 | 320 | dirA_LU=1; |
soulx | 0:2433ddae2772 | 321 | |
soulx | 0:2433ddae2772 | 322 | // Set inB[motor] |
soulx | 0:2433ddae2772 | 323 | if ((direct==0)||(direct==2)) |
soulx | 0:2433ddae2772 | 324 | dirB_LU=0; |
soulx | 0:2433ddae2772 | 325 | else |
soulx | 0:2433ddae2772 | 326 | dirB_LU=1; |
soulx | 0:2433ddae2772 | 327 | break; |
soulx | 0:2433ddae2772 | 328 | |
soulx | 0:2433ddae2772 | 329 | case 2: |
soulx | 0:2433ddae2772 | 330 | // Set inA[motor] |
soulx | 0:2433ddae2772 | 331 | if (direct <=1) |
soulx | 0:2433ddae2772 | 332 | dirA_LL=0; |
soulx | 0:2433ddae2772 | 333 | else |
soulx | 0:2433ddae2772 | 334 | dirA_LL=1; |
soulx | 0:2433ddae2772 | 335 | |
soulx | 0:2433ddae2772 | 336 | // Set inB[motor] |
soulx | 0:2433ddae2772 | 337 | if ((direct==0)||(direct==2)) |
soulx | 0:2433ddae2772 | 338 | dirB_LL=0; |
soulx | 0:2433ddae2772 | 339 | else |
soulx | 0:2433ddae2772 | 340 | dirB_LL=1; |
soulx | 0:2433ddae2772 | 341 | break; |
soulx | 0:2433ddae2772 | 342 | |
soulx | 0:2433ddae2772 | 343 | case 3: |
soulx | 0:2433ddae2772 | 344 | // Set inA[motor] |
soulx | 0:2433ddae2772 | 345 | if (direct <=1) |
soulx | 0:2433ddae2772 | 346 | dirA_RU=0; |
soulx | 0:2433ddae2772 | 347 | else |
soulx | 0:2433ddae2772 | 348 | dirA_RU=1; |
soulx | 0:2433ddae2772 | 349 | |
soulx | 0:2433ddae2772 | 350 | // Set inB[motor] |
soulx | 0:2433ddae2772 | 351 | if ((direct==0)||(direct==2)) |
soulx | 0:2433ddae2772 | 352 | dirB_RU=0; |
soulx | 0:2433ddae2772 | 353 | else |
soulx | 0:2433ddae2772 | 354 | dirB_RU=1; |
soulx | 0:2433ddae2772 | 355 | break; |
soulx | 0:2433ddae2772 | 356 | |
soulx | 0:2433ddae2772 | 357 | case 4: |
soulx | 0:2433ddae2772 | 358 | // Set inA[motor] |
soulx | 0:2433ddae2772 | 359 | if (direct <=1) |
soulx | 0:2433ddae2772 | 360 | dirA_RL=0; |
soulx | 0:2433ddae2772 | 361 | else |
soulx | 0:2433ddae2772 | 362 | dirA_RL=1; |
soulx | 0:2433ddae2772 | 363 | // Set inB[motor] |
soulx | 0:2433ddae2772 | 364 | if ((direct==0)||(direct==2)) |
soulx | 0:2433ddae2772 | 365 | dirB_RL=0; |
soulx | 0:2433ddae2772 | 366 | else |
soulx | 0:2433ddae2772 | 367 | dirB_RL=1; |
soulx | 0:2433ddae2772 | 368 | break; |
soulx | 0:2433ddae2772 | 369 | } |
soulx | 0:2433ddae2772 | 370 | } |
soulx | 0:2433ddae2772 | 371 | } |
soulx | 0:2433ddae2772 | 372 | |
soulx | 0:2433ddae2772 | 373 | void motor_stop(uint8_t id) |
soulx | 0:2433ddae2772 | 374 | { |
soulx | 0:2433ddae2772 | 375 | switch(id) { |
soulx | 0:2433ddae2772 | 376 | case 1: |
soulx | 0:2433ddae2772 | 377 | dirA_LU=1; |
soulx | 0:2433ddae2772 | 378 | dirB_LU=1; |
soulx | 0:2433ddae2772 | 379 | break; |
soulx | 0:2433ddae2772 | 380 | |
soulx | 0:2433ddae2772 | 381 | case 2: |
soulx | 0:2433ddae2772 | 382 | dirA_LL=1; |
soulx | 0:2433ddae2772 | 383 | dirB_LL=1; |
soulx | 0:2433ddae2772 | 384 | break; |
soulx | 0:2433ddae2772 | 385 | |
soulx | 0:2433ddae2772 | 386 | case 3: |
soulx | 0:2433ddae2772 | 387 | dirA_RU=1; |
soulx | 0:2433ddae2772 | 388 | dirB_RU=1; |
soulx | 0:2433ddae2772 | 389 | break; |
soulx | 0:2433ddae2772 | 390 | |
soulx | 0:2433ddae2772 | 391 | case 4: |
soulx | 0:2433ddae2772 | 392 | dirA_RL=1; |
soulx | 0:2433ddae2772 | 393 | dirB_RL=1; |
soulx | 0:2433ddae2772 | 394 | break; |
soulx | 0:2433ddae2772 | 395 | |
soulx | 0:2433ddae2772 | 396 | case 0: |
soulx | 0:2433ddae2772 | 397 | dirA_LU=1; |
soulx | 0:2433ddae2772 | 398 | dirB_LU=1; |
soulx | 0:2433ddae2772 | 399 | |
soulx | 0:2433ddae2772 | 400 | dirA_LL=1; |
soulx | 0:2433ddae2772 | 401 | dirB_LL=1; |
soulx | 0:2433ddae2772 | 402 | |
soulx | 0:2433ddae2772 | 403 | dirA_RU=1; |
soulx | 0:2433ddae2772 | 404 | dirB_RU=1; |
soulx | 0:2433ddae2772 | 405 | |
soulx | 0:2433ddae2772 | 406 | dirA_RL=1; |
soulx | 0:2433ddae2772 | 407 | dirB_RL=1; |
soulx | 0:2433ddae2772 | 408 | break; |
soulx | 0:2433ddae2772 | 409 | } |
soulx | 0:2433ddae2772 | 410 | } |
soulx | 0:2433ddae2772 | 411 | |
soulx | 0:2433ddae2772 | 412 | |
soulx | 0:2433ddae2772 | 413 | |
soulx | 0:2433ddae2772 | 414 | uint8_t limit_motor(uint8_t id, uint8_t dirction) |
soulx | 0:2433ddae2772 | 415 | { |
soulx | 0:2433ddae2772 | 416 | switch(id) { |
soulx | 0:2433ddae2772 | 417 | case 1://Left Upper |
soulx | 5:f07cbb5a86c3 | 418 | if(~sw_LU_U && ~sw_LU_D) { |
soulx | 0:2433ddae2772 | 419 | motor_set(id,dirction); |
soulx | 0:2433ddae2772 | 420 | } else { |
soulx | 0:2433ddae2772 | 421 | motor_stop(id); |
soulx | 0:2433ddae2772 | 422 | return 0; |
soulx | 0:2433ddae2772 | 423 | } |
soulx | 0:2433ddae2772 | 424 | break; |
soulx | 0:2433ddae2772 | 425 | |
soulx | 0:2433ddae2772 | 426 | case 2://Left Lowwer |
soulx | 5:f07cbb5a86c3 | 427 | if(~sw_LL_U && ~sw_LL_D) { |
soulx | 0:2433ddae2772 | 428 | motor_set(id,dirction); |
soulx | 0:2433ddae2772 | 429 | } else { |
soulx | 0:2433ddae2772 | 430 | motor_stop(id); |
soulx | 0:2433ddae2772 | 431 | return 0; |
soulx | 0:2433ddae2772 | 432 | } |
soulx | 0:2433ddae2772 | 433 | break; |
soulx | 0:2433ddae2772 | 434 | |
soulx | 0:2433ddae2772 | 435 | case 3://Right Upper |
soulx | 5:f07cbb5a86c3 | 436 | if(~sw_RU_U && ~sw_RU_D) { |
soulx | 0:2433ddae2772 | 437 | motor_set(id,dirction); |
soulx | 0:2433ddae2772 | 438 | } else { |
soulx | 0:2433ddae2772 | 439 | motor_stop(id); |
soulx | 0:2433ddae2772 | 440 | return 0; |
soulx | 0:2433ddae2772 | 441 | } |
soulx | 0:2433ddae2772 | 442 | break; |
soulx | 0:2433ddae2772 | 443 | |
soulx | 0:2433ddae2772 | 444 | case 4://Right Lowwer |
soulx | 5:f07cbb5a86c3 | 445 | if(~sw_RL_U && ~sw_RL_D) { |
soulx | 0:2433ddae2772 | 446 | motor_set(id,dirction); |
soulx | 0:2433ddae2772 | 447 | } else { |
soulx | 0:2433ddae2772 | 448 | motor_stop(id); |
soulx | 0:2433ddae2772 | 449 | return 0; |
soulx | 0:2433ddae2772 | 450 | } |
soulx | 0:2433ddae2772 | 451 | break; |
soulx | 0:2433ddae2772 | 452 | } |
soulx | 0:2433ddae2772 | 453 | return 1;//normally |
soulx | 0:2433ddae2772 | 454 | } |
soulx | 0:2433ddae2772 | 455 | |
soulx | 0:2433ddae2772 | 456 | |
soulx | 0:2433ddae2772 | 457 | uint8_t position_control(uint8_t id, uint16_t current, uint16_t target) |
soulx | 0:2433ddae2772 | 458 | { |
soulx | 0:2433ddae2772 | 459 | //uint8_t state=0; |
soulx | 0:2433ddae2772 | 460 | int16_t error = target-current; |
soulx | 0:2433ddae2772 | 461 | |
soulx | 0:2433ddae2772 | 462 | pc.printf("error[%d]=%d\n",id,error); |
soulx | 0:2433ddae2772 | 463 | if(error > MARGIN) { |
soulx | 0:2433ddae2772 | 464 | if(limit_motor(id,1)==0 ) { //limit sens |
soulx | 0:2433ddae2772 | 465 | |
soulx | 0:2433ddae2772 | 466 | pc.printf("motor[%d]=limit error\n",id); |
soulx | 0:2433ddae2772 | 467 | |
soulx | 0:2433ddae2772 | 468 | return 2; |
soulx | 0:2433ddae2772 | 469 | } |
soulx | 0:2433ddae2772 | 470 | |
soulx | 0:2433ddae2772 | 471 | |
soulx | 0:2433ddae2772 | 472 | } else if(error < -MARGIN) { |
soulx | 0:2433ddae2772 | 473 | if(limit_motor(id,2)==0 ) { //limit sens |
soulx | 0:2433ddae2772 | 474 | |
soulx | 0:2433ddae2772 | 475 | pc.printf("motor[%d]=limit error\n",id); |
soulx | 0:2433ddae2772 | 476 | |
soulx | 0:2433ddae2772 | 477 | return 2; |
soulx | 0:2433ddae2772 | 478 | } |
soulx | 0:2433ddae2772 | 479 | |
soulx | 0:2433ddae2772 | 480 | } else { //in zone |
soulx | 0:2433ddae2772 | 481 | motor_stop(2); |
soulx | 0:2433ddae2772 | 482 | |
soulx | 0:2433ddae2772 | 483 | pc.printf("motor[%d]=complete\n",id); |
soulx | 0:2433ddae2772 | 484 | |
soulx | 0:2433ddae2772 | 485 | return 1; //in zone complete |
soulx | 0:2433ddae2772 | 486 | } |
soulx | 0:2433ddae2772 | 487 | |
soulx | 0:2433ddae2772 | 488 | pc.printf("motor[%d]=in process\n",id); |
soulx | 0:2433ddae2772 | 489 | return 0; //in process |
soulx | 0:2433ddae2772 | 490 | } |
soulx | 0:2433ddae2772 | 491 | |
soulx | 0:2433ddae2772 | 492 | void calibration(uint8_t id) |
soulx | 0:2433ddae2772 | 493 | { |
soulx | 0:2433ddae2772 | 494 | switch(id) { |
soulx | 0:2433ddae2772 | 495 | case 1: |
soulx | 0:2433ddae2772 | 496 | pc.printf("motor[1] run up\n"); |
soulx | 5:f07cbb5a86c3 | 497 | do { |
soulx | 0:2433ddae2772 | 498 | motor_set(id,1); |
soulx | 5:f07cbb5a86c3 | 499 | } while(sw_LU_U ==0); |
soulx | 0:2433ddae2772 | 500 | pc.printf("motor[1] stop up\n"); |
soulx | 0:2433ddae2772 | 501 | //wait_ms(500); |
soulx | 0:2433ddae2772 | 502 | do { |
soulx | 0:2433ddae2772 | 503 | motor_set(id,2); |
soulx | 5:f07cbb5a86c3 | 504 | } while(sw_LU_U); |
soulx | 0:2433ddae2772 | 505 | motor_stop(id); |
soulx | 0:2433ddae2772 | 506 | wait_ms(500); |
soulx | 0:2433ddae2772 | 507 | pc.printf("motor[1] read position\n"); |
soulx | 0:2433ddae2772 | 508 | max_pos_LU = position_LU.read_u16(); |
soulx | 0:2433ddae2772 | 509 | pc.printf("max_pos_LU= %d\n",max_pos_LU); |
soulx | 0:2433ddae2772 | 510 | |
soulx | 0:2433ddae2772 | 511 | pc.printf("motor[1] run down\n"); |
soulx | 5:f07cbb5a86c3 | 512 | do { |
soulx | 0:2433ddae2772 | 513 | motor_set(id,2); |
soulx | 5:f07cbb5a86c3 | 514 | } while(sw_LU_D==0) ; |
soulx | 0:2433ddae2772 | 515 | pc.printf("motor[1] stop down\n"); |
soulx | 0:2433ddae2772 | 516 | do { |
soulx | 0:2433ddae2772 | 517 | motor_set(id,1); |
soulx | 5:f07cbb5a86c3 | 518 | } while(sw_LU_D); |
soulx | 0:2433ddae2772 | 519 | motor_stop(id); |
soulx | 0:2433ddae2772 | 520 | wait_ms(500); |
soulx | 0:2433ddae2772 | 521 | pc.printf("motor[1] read position\n"); |
soulx | 0:2433ddae2772 | 522 | min_pos_LU = position_LU.read_u16(); |
soulx | 0:2433ddae2772 | 523 | pc.printf("min_pos_LU= %d\n",min_pos_LU); |
soulx | 0:2433ddae2772 | 524 | break; |
soulx | 0:2433ddae2772 | 525 | |
soulx | 0:2433ddae2772 | 526 | case 2: |
soulx | 0:2433ddae2772 | 527 | |
soulx | 0:2433ddae2772 | 528 | pc.printf("motor[2] run up\n"); |
soulx | 7:6a99be179329 | 529 | do { |
soulx | 0:2433ddae2772 | 530 | motor_set(id,1); |
soulx | 7:6a99be179329 | 531 | } while(sw_LL_U==0) ; |
soulx | 0:2433ddae2772 | 532 | motor_stop(id); |
soulx | 0:2433ddae2772 | 533 | wait_ms(500); |
soulx | 0:2433ddae2772 | 534 | pc.printf("motor[2] stop up\n"); |
soulx | 0:2433ddae2772 | 535 | do { |
soulx | 0:2433ddae2772 | 536 | motor_set(id,2); |
soulx | 5:f07cbb5a86c3 | 537 | } while(sw_LL_U ); |
soulx | 0:2433ddae2772 | 538 | motor_stop(id); |
soulx | 0:2433ddae2772 | 539 | wait_ms(500); |
soulx | 0:2433ddae2772 | 540 | max_pos_LL = position_LL.read_u16(); |
soulx | 0:2433ddae2772 | 541 | pc.printf("max_pos_LL= %d\n",max_pos_LL); |
soulx | 0:2433ddae2772 | 542 | pc.printf("motor[2] run down\n"); |
soulx | 7:6a99be179329 | 543 | do { |
soulx | 0:2433ddae2772 | 544 | motor_set(id,2); |
soulx | 7:6a99be179329 | 545 | } while(sw_LL_D==0) ; |
soulx | 0:2433ddae2772 | 546 | motor_stop(id); |
soulx | 0:2433ddae2772 | 547 | wait_ms(500); |
soulx | 0:2433ddae2772 | 548 | pc.printf("motor[2] stop down\n"); |
soulx | 0:2433ddae2772 | 549 | do { |
soulx | 0:2433ddae2772 | 550 | motor_set(id,1); |
soulx | 5:f07cbb5a86c3 | 551 | } while(sw_LL_D); |
soulx | 0:2433ddae2772 | 552 | motor_stop(id); |
soulx | 0:2433ddae2772 | 553 | wait_ms(500); |
soulx | 0:2433ddae2772 | 554 | min_pos_LL = position_LL.read_u16(); |
soulx | 0:2433ddae2772 | 555 | pc.printf("min_pos_LL= %d\n",min_pos_LL); |
soulx | 0:2433ddae2772 | 556 | break; |
soulx | 0:2433ddae2772 | 557 | |
soulx | 0:2433ddae2772 | 558 | case 3: |
soulx | 5:f07cbb5a86c3 | 559 | // uint8_t count=1000; |
soulx | 0:2433ddae2772 | 560 | pc.printf("motor[3] run up\n"); |
soulx | 5:f07cbb5a86c3 | 561 | do { |
soulx | 0:2433ddae2772 | 562 | motor_set(id,1); |
soulx | 7:6a99be179329 | 563 | } while(sw_RU_U==0); |
soulx | 0:2433ddae2772 | 564 | motor_stop(id); |
soulx | 0:2433ddae2772 | 565 | wait_ms(500); |
soulx | 0:2433ddae2772 | 566 | pc.printf("motor[3] stop up\n"); |
soulx | 1:768d359e9d96 | 567 | |
soulx | 0:2433ddae2772 | 568 | do { |
soulx | 0:2433ddae2772 | 569 | motor_set(id,2); |
soulx | 5:f07cbb5a86c3 | 570 | } while(sw_RU_U); |
soulx | 0:2433ddae2772 | 571 | motor_stop(id); |
soulx | 0:2433ddae2772 | 572 | wait_ms(500); |
soulx | 0:2433ddae2772 | 573 | max_pos_RU = position_RU.read_u16(); |
soulx | 0:2433ddae2772 | 574 | pc.printf("max_pos_RU= %d\n",max_pos_RU); |
soulx | 0:2433ddae2772 | 575 | |
soulx | 0:2433ddae2772 | 576 | pc.printf("motor[3] run down\n"); |
soulx | 1:768d359e9d96 | 577 | |
soulx | 7:6a99be179329 | 578 | do { |
soulx | 0:2433ddae2772 | 579 | motor_set(id,2); |
soulx | 7:6a99be179329 | 580 | } while(sw_RU_D==0); |
soulx | 0:2433ddae2772 | 581 | motor_stop(id); |
soulx | 0:2433ddae2772 | 582 | wait_ms(500); |
soulx | 0:2433ddae2772 | 583 | pc.printf("motor[3] stop down\n"); |
soulx | 7:6a99be179329 | 584 | |
soulx | 0:2433ddae2772 | 585 | do { |
soulx | 0:2433ddae2772 | 586 | motor_set(id,1); |
soulx | 5:f07cbb5a86c3 | 587 | } while(sw_RU_D); |
soulx | 0:2433ddae2772 | 588 | motor_stop(id); |
soulx | 0:2433ddae2772 | 589 | wait_ms(500); |
soulx | 0:2433ddae2772 | 590 | min_pos_RU = position_RU.read_u16(); |
soulx | 0:2433ddae2772 | 591 | pc.printf("min_pos_RU= %d\n",min_pos_RU); |
soulx | 0:2433ddae2772 | 592 | break; |
soulx | 0:2433ddae2772 | 593 | |
soulx | 0:2433ddae2772 | 594 | case 4: |
soulx | 0:2433ddae2772 | 595 | |
soulx | 0:2433ddae2772 | 596 | pc.printf("motor[4] run up\n"); |
soulx | 5:f07cbb5a86c3 | 597 | do { |
soulx | 0:2433ddae2772 | 598 | motor_set(id,1); |
soulx | 7:6a99be179329 | 599 | } while(sw_RL_U==0); |
soulx | 0:2433ddae2772 | 600 | motor_stop(id); |
soulx | 0:2433ddae2772 | 601 | wait_ms(500); |
soulx | 0:2433ddae2772 | 602 | pc.printf("motor[4] stop up\n"); |
soulx | 0:2433ddae2772 | 603 | do { |
soulx | 0:2433ddae2772 | 604 | motor_set(id,2); |
soulx | 5:f07cbb5a86c3 | 605 | } while(sw_RL_U); |
soulx | 0:2433ddae2772 | 606 | motor_stop(id); |
soulx | 0:2433ddae2772 | 607 | wait_ms(500); |
soulx | 0:2433ddae2772 | 608 | max_pos_RL = position_RL.read_u16(); |
soulx | 0:2433ddae2772 | 609 | pc.printf("max_pos_RL= %d\n",max_pos_RL); |
soulx | 0:2433ddae2772 | 610 | pc.printf("motor[4] run down\n"); |
soulx | 7:6a99be179329 | 611 | do { |
soulx | 0:2433ddae2772 | 612 | motor_set(id,2); |
soulx | 7:6a99be179329 | 613 | } while(sw_RL_D==0); |
soulx | 0:2433ddae2772 | 614 | motor_stop(id); |
soulx | 0:2433ddae2772 | 615 | wait_ms(500); |
soulx | 0:2433ddae2772 | 616 | pc.printf("motor[4] stop down\n"); |
soulx | 0:2433ddae2772 | 617 | do { |
soulx | 0:2433ddae2772 | 618 | motor_set(id,1); |
soulx | 5:f07cbb5a86c3 | 619 | } while(sw_RL_D); |
soulx | 0:2433ddae2772 | 620 | motor_stop(id); |
soulx | 0:2433ddae2772 | 621 | wait_ms(500); |
soulx | 0:2433ddae2772 | 622 | min_pos_RL = position_RL.read_u16(); |
soulx | 0:2433ddae2772 | 623 | pc.printf("min_pos_RL= %d\n",min_pos_RL); |
soulx | 0:2433ddae2772 | 624 | break; |
soulx | 0:2433ddae2772 | 625 | } |
soulx | 0:2433ddae2772 | 626 | |
soulx | 1:768d359e9d96 | 627 | } |
soulx | 5:f07cbb5a86c3 | 628 | /* |
soulx | 1:768d359e9d96 | 629 | uint16_t convert(uint16_t data) |
soulx | 1:768d359e9d96 | 630 | { |
soulx | 1:768d359e9d96 | 631 | uint16_t ans=0; |
soulx | 1:768d359e9d96 | 632 | |
soulx | 1:768d359e9d96 | 633 | //ans = |
soulx | 1:768d359e9d96 | 634 | |
soulx | 1:768d359e9d96 | 635 | return |
soulx | 1:768d359e9d96 | 636 | } |
soulx | 1:768d359e9d96 | 637 | |
soulx | 1:768d359e9d96 | 638 | uint16_t scale(uint16_t data) |
soulx | 1:768d359e9d96 | 639 | { |
soulx | 5:f07cbb5a86c3 | 640 | |
soulx | 5:f07cbb5a86c3 | 641 | } |
soulx | 6:8d80c84e0c09 | 642 | */ |
soulx | 6:8d80c84e0c09 | 643 | |
soulx | 6:8d80c84e0c09 | 644 | void getCommand() |
soulx | 6:8d80c84e0c09 | 645 | { |
soulx | 6:8d80c84e0c09 | 646 | static uint8_t count =0; |
soulx | 6:8d80c84e0c09 | 647 | |
soulx | 6:8d80c84e0c09 | 648 | ANDANTE_PROTOCOL_PACKET packet; |
soulx | 6:8d80c84e0c09 | 649 | |
soulx | 6:8d80c84e0c09 | 650 | uint8_t status = pan_a.receiveCommunicatePacket(&packet); |
soulx | 6:8d80c84e0c09 | 651 | myled=0; |
soulx | 7:6a99be179329 | 652 | |
soulx | 6:8d80c84e0c09 | 653 | |
soulx | 6:8d80c84e0c09 | 654 | |
soulx | 6:8d80c84e0c09 | 655 | if(status == ANDANTE_ERRBIT_NONE) { |
soulx | 6:8d80c84e0c09 | 656 | if(count >2 && count <10) { |
soulx | 6:8d80c84e0c09 | 657 | count--; |
soulx | 6:8d80c84e0c09 | 658 | } else { |
soulx | 6:8d80c84e0c09 | 659 | count=0; |
soulx | 7:6a99be179329 | 660 | |
soulx | 6:8d80c84e0c09 | 661 | } |
soulx | 6:8d80c84e0c09 | 662 | pan_a.sendCommunicatePacket(&packet); |
soulx | 6:8d80c84e0c09 | 663 | //update command |
soulx | 6:8d80c84e0c09 | 664 | //setControl(&packet); |
soulx | 6:8d80c84e0c09 | 665 | |
soulx | 6:8d80c84e0c09 | 666 | } else if(status == ANDANTE_ERRBIT_READ_TIMEOUT) { |
soulx | 6:8d80c84e0c09 | 667 | count++; |
soulx | 6:8d80c84e0c09 | 668 | } |
soulx | 6:8d80c84e0c09 | 669 | |
soulx | 6:8d80c84e0c09 | 670 | if(count >= TIMEOUT_RESPONE_COMMAND) { |
soulx | 6:8d80c84e0c09 | 671 | //stop robot |
soulx | 6:8d80c84e0c09 | 672 | count++; |
soulx | 6:8d80c84e0c09 | 673 | myled=1; |
soulx | 7:6a99be179329 | 674 | // setSpeedControl(0.0); |
soulx | 6:8d80c84e0c09 | 675 | } |
soulx | 6:8d80c84e0c09 | 676 | } |