fork download
  1. DualVNH5019MotorShield motors;
  2.  
  3. char LED1 = 5;
  4. char LED2 = 3;
  5.  
  6. void setup()
  7. {
  8. Serial.begin(115200);
  9. motors.init();
  10.  
  11. pinMode(LED1, OUTPUT);
  12. pinMode(LED2, OUTPUT);
  13.  
  14. digitalWrite(LED1, HIGH);
  15. digitalWrite(LED2, LOW);
  16. }
  17.  
  18. uint8_t ReceiveBuffer[64];
  19. int AR_STATE = 0;
  20. char unlock = 17;
  21. char starter = 29;
  22. char terminator = 30;
  23.  
  24.  
  25. static const char arm_motorshield = 0;
  26. static const char get_milliamps = 1;
  27. static const char get_fault = 2;
  28. static const char set_brakes = 3;
  29. static const char set_speed = 4;
  30. static const char set_brakes_A = 5;
  31. static const char set_brakes_B = 6;
  32. static const char set_speed_A = 7;
  33. static const char set_speed_B = 8;
  34. static const char echo_data = 9;
  35. static const char set_max_speed = 10;
  36. static const char I_AM_ALIVE = 111;
  37. static const char CONNECTION_OK = 69;
  38. static const char UN_ARM = 33;
  39.  
  40. class AliveTime
  41. {
  42. unsigned long LastAliveTick;
  43. unsigned long ConnectionOk;
  44. public:
  45. AliveTime()
  46. {
  47. LastAliveTick = millis();
  48. ConnectionOk = LastAliveTick;
  49. }
  50. void IAmAlive()
  51. {
  52. LastAliveTick = millis();
  53. }
  54. unsigned long GetElapsed()
  55. {
  56. return millis() - LastAliveTick;
  57. }
  58. void ConnectionCheck()
  59. {
  60. ConnectionOk = millis();
  61. }
  62. unsigned long ConnectionOkElapsed()
  63. {
  64. return millis() - ConnectionOk;
  65. }
  66. } AliveTimer;
  67. //starter action data1 data2 data3 data4 terminator|7
  68.  
  69. char ACTION_TO_DO;
  70. int Value_One;
  71. int Value_Two;
  72.  
  73. #define MULTI_TO_INT(a,b) ((ReceiveBuffer[a] << 8) & ReceiveBuffer[b])
  74. #define INT_TO_MULTI(a,b,c) {ReceiveBuffer[a] = ((c & 0xFF00) >> 8); ReceiveBuffer[b] = (c & 0xFF);}
  75.  
  76. void SafetyChecks()
  77. {
  78. if (motors.getM1CurrentMilliamps() > 13000)
  79. {
  80. motors.setM1Speed(0);
  81. }
  82. if (motors.getM2CurrentMilliamps() > 13000)
  83. {
  84. motors.setM2Speed(0);
  85. }
  86. if (AliveTimer.GetElapsed() > 1000)
  87. {
  88. motors.setBrakes(maximumspeed, maximumspeed);
  89. }
  90. if (AliveTimer.ConnectionOkElapsed() > 1000)
  91. {
  92. AliveTimer.ConnectionCheck();
  93. ReceiveBuffer[0] = starter;
  94. ReceiveBuffer[1] = CONNECTION_OK;
  95. ReceiveBuffer[6] = terminator;
  96. //Serial.write(ReceiveBuffer, 7);
  97.  
  98. Value_One = motors.getM1CurrentMilliamps();
  99. Value_Two = motors.getM2CurrentMilliamps();
  100.  
  101. ReceiveBuffer[7] = starter;
  102. ReceiveBuffer[8] = get_milliamps;
  103. INT_TO_MULTI(9, 10, Value_One);
  104. INT_TO_MULTI(11, 12, Value_Two);
  105. ReceiveBuffer[13] = terminator;
  106.  
  107. //Serial.write(ReceiveBuffer, 7);
  108.  
  109. ReceiveBuffer[14] = starter;
  110. ReceiveBuffer[15] = get_fault;
  111. ReceiveBuffer[16] = motors.getM1Fault();
  112. ReceiveBuffer[17] = motors.getM2Fault();
  113. ReceiveBuffer[18] = 0;
  114. ReceiveBuffer[19] = 0;
  115. ReceiveBuffer[20] = terminator;
  116.  
  117. Serial.write(ReceiveBuffer, 21);
  118. }
  119. }
  120.  
  121. void Tick()
  122. {
  123. while (Serial.available() >= 7 && AR_STATE)
  124. {
  125. if (Serial.read() == starter)
  126. {
  127. Serial.readBytes((char*)&ReceiveBuffer[0], 6);
  128. if (ReceiveBuffer[5] == terminator)
  129. {
  130. ACTION_TO_DO = ReceiveBuffer[0];
  131. switch (ACTION_TO_DO)
  132. {
  133. case get_milliamps:
  134. {
  135. Value_One = motors.getM1CurrentMilliamps();
  136. Value_Two = motors.getM2CurrentMilliamps();
  137.  
  138. ReceiveBuffer[0] = starter;
  139. ReceiveBuffer[1] = ACTION_TO_DO;
  140. INT_TO_MULTI(2, 3, Value_One);
  141. INT_TO_MULTI(4, 5, Value_Two);
  142. ReceiveBuffer[6] = terminator;
  143.  
  144. Serial.write(ReceiveBuffer, 7);
  145.  
  146. break;
  147. }
  148. case get_fault:
  149. {
  150. ReceiveBuffer[0] = starter;
  151. ReceiveBuffer[1] = ACTION_TO_DO;
  152. ReceiveBuffer[2] = motors.getM1Fault();
  153. ReceiveBuffer[3] = motors.getM2Fault();
  154. ReceiveBuffer[4] = 0;
  155. ReceiveBuffer[5] = 0;
  156. ReceiveBuffer[6] = terminator;
  157.  
  158. Serial.write(ReceiveBuffer, 7);
  159. break;
  160. }
  161. case set_brakes:
  162. {
  163. Value_One = MULTI_TO_INT(1, 2);
  164. Value_Two = MULTI_TO_INT(3, 4);
  165.  
  166. motors.setBrakes(Value_One, Value_Two);
  167. break;
  168. }
  169. case set_speed:
  170. {
  171. Value_One = MULTI_TO_INT(1, 2);
  172. Value_Two = MULTI_TO_INT(3, 4);
  173.  
  174. motors.setSpeeds(Value_One, Value_Two);
  175. break;
  176. }
  177. case set_brakes_A:
  178. {
  179. Value_One = MULTI_TO_INT(1, 2);
  180.  
  181. motors.setM1Brake(Value_One);
  182. break;
  183. }
  184. case set_brakes_B:
  185. {
  186. Value_One = MULTI_TO_INT(1, 2);
  187.  
  188. motors.setM2Brake(Value_One);
  189. break;
  190. }
  191. case set_speed_A:
  192. {
  193. Value_One = MULTI_TO_INT(1, 2);
  194.  
  195. motors.setM1Speed(Value_One);
  196. break;
  197. }
  198. case set_speed_B:
  199. {
  200. Value_One = MULTI_TO_INT(1, 2);
  201.  
  202. motors.setM2Speed(Value_One);
  203. break;
  204. }
  205. case echo_data:
  206. {
  207. ReceiveBuffer[1] = ReceiveBuffer[0];
  208. ReceiveBuffer[2] = ReceiveBuffer[1];
  209. ReceiveBuffer[3] = ReceiveBuffer[2];
  210. ReceiveBuffer[4] = ReceiveBuffer[3];
  211. ReceiveBuffer[5] = ReceiveBuffer[4];
  212. ReceiveBuffer[0] = starter;
  213. ReceiveBuffer[6] = terminator;
  214. Serial.write(ReceiveBuffer, 7);
  215. break;
  216. }
  217. case I_AM_ALIVE:
  218. {
  219. AliveTimer.IAmAlive();
  220. break;
  221. }
  222. case arm_motorshield:
  223. {
  224. Serial.print("UNLOCKOK-5AE3C2\0");
  225. break;
  226. }
  227. case UN_ARM:
  228. {
  229. Value_One = MULTI_TO_INT(1, 2);
  230. Value_Two = MULTI_TO_INT(3, 4);
  231. if (Value_One == 5000 && Value_Two == 3333)
  232. {
  233. digitalWrite(LED1, HIGH);
  234. digitalWrite(LED2, LOW);
  235.  
  236. motors.setSpeeds(0, 0);
  237. AR_STATE = 0;
  238. }
  239. }
  240. case set_max_speed:
  241. {
  242. Value_One = MULTI_TO_INT(1, 2);
  243. Value_Two = abs(Value_One);
  244. if (Value_Two > 400)
  245. {
  246. Value_Two = 400;
  247. }
  248. maximumspeed = Value_Two;
  249. }
  250. default:
  251. {
  252.  
  253. }
  254. }
  255. }
  256. }
  257. SafetyChecks();
  258. }
  259. SafetyChecks();
  260. }
  261.  
  262. void loop()
  263. {
  264. if (AR_STATE)
  265. {
  266. Tick();
  267. }
  268. else
  269. {
  270. while (Serial.available() >= 7)
  271. {
  272. if (Serial.read() == starter)
  273. {
  274. char tempbuffer[6];
  275. Serial.readBytes(&tempbuffer[0], 6);
  276. if (tempbuffer[0] == arm_motorshield && (tempbuffer[1] == unlock || tempbuffer[2] == unlock || tempbuffer[3] == unlock || tempbuffer[4] == unlock) && tempbuffer[5] == terminator)
  277. {
  278. AR_STATE = 1;
  279. Serial.print("UNLOCKOK-5AE3C2\0");
  280. digitalWrite(LED1, LOW);
  281. digitalWrite(LED2, HIGH);
  282. }
  283. else
  284. {
  285. Serial.print("ARDUINO IS LOCKED\r\n");
  286. digitalWrite(LED1, LOW);
  287. delay(50);
  288. digitalWrite(LED1, HIGH);
  289. delay(50);
  290. digitalWrite(LED1, LOW);
  291. delay(50);
  292. digitalWrite(LED1, HIGH);
  293. delay(50);
  294. digitalWrite(LED1, LOW);
  295. delay(50);
  296. digitalWrite(LED1, HIGH);
  297. }
  298. }
  299. }
  300. }
  301. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘DualVNH5019MotorShield’ does not name a type
 DualVNH5019MotorShield motors;
 ^
prog.cpp: In function ‘void setup()’:
prog.cpp:8:2: error: ‘Serial’ was not declared in this scope
  Serial.begin(115200);
  ^
prog.cpp:9:2: error: ‘motors’ was not declared in this scope
  motors.init();
  ^
prog.cpp:11:16: error: ‘OUTPUT’ was not declared in this scope
  pinMode(LED1, OUTPUT);
                ^
prog.cpp:11:22: error: ‘pinMode’ was not declared in this scope
  pinMode(LED1, OUTPUT);
                      ^
prog.cpp:14:21: error: ‘HIGH’ was not declared in this scope
  digitalWrite(LED1, HIGH);
                     ^
prog.cpp:14:25: error: ‘digitalWrite’ was not declared in this scope
  digitalWrite(LED1, HIGH);
                         ^
prog.cpp:15:21: error: ‘LOW’ was not declared in this scope
  digitalWrite(LED2, LOW);
                     ^
prog.cpp: At global scope:
prog.cpp:18:1: error: ‘uint8_t’ does not name a type
 uint8_t ReceiveBuffer[64];
 ^
prog.cpp: In constructor ‘AliveTime::AliveTime()’:
prog.cpp:47:26: error: ‘millis’ was not declared in this scope
   LastAliveTick = millis();
                          ^
prog.cpp: In member function ‘void AliveTime::IAmAlive()’:
prog.cpp:52:26: error: ‘millis’ was not declared in this scope
   LastAliveTick = millis();
                          ^
prog.cpp: In member function ‘long unsigned int AliveTime::GetElapsed()’:
prog.cpp:56:17: error: ‘millis’ was not declared in this scope
   return millis() - LastAliveTick;
                 ^
prog.cpp: In member function ‘void AliveTime::ConnectionCheck()’:
prog.cpp:60:25: error: ‘millis’ was not declared in this scope
   ConnectionOk = millis();
                         ^
prog.cpp: In member function ‘long unsigned int AliveTime::ConnectionOkElapsed()’:
prog.cpp:64:17: error: ‘millis’ was not declared in this scope
   return millis() - ConnectionOk;
                 ^
prog.cpp: In function ‘void SafetyChecks()’:
prog.cpp:78:6: error: ‘motors’ was not declared in this scope
  if (motors.getM1CurrentMilliamps() > 13000)
      ^
prog.cpp:82:6: error: ‘motors’ was not declared in this scope
  if (motors.getM2CurrentMilliamps() > 13000)
      ^
prog.cpp:88:3: error: ‘motors’ was not declared in this scope
   motors.setBrakes(maximumspeed, maximumspeed);
   ^
prog.cpp:88:20: error: ‘maximumspeed’ was not declared in this scope
   motors.setBrakes(maximumspeed, maximumspeed);
                    ^
prog.cpp:93:3: error: ‘ReceiveBuffer’ was not declared in this scope
   ReceiveBuffer[0] = starter;
   ^
prog.cpp:98:15: error: ‘motors’ was not declared in this scope
   Value_One = motors.getM1CurrentMilliamps();
               ^
prog.cpp:117:3: error: ‘Serial’ was not declared in this scope
   Serial.write(ReceiveBuffer, 21);
   ^
prog.cpp: In function ‘void Tick()’:
prog.cpp:123:9: error: ‘Serial’ was not declared in this scope
  while (Serial.available() >= 7 && AR_STATE)
         ^
prog.cpp:127:29: error: ‘ReceiveBuffer’ was not declared in this scope
    Serial.readBytes((char*)&ReceiveBuffer[0], 6);
                             ^
prog.cpp:135:19: error: ‘motors’ was not declared in this scope
       Value_One = motors.getM1CurrentMilliamps();
                   ^
prog.cpp:152:26: error: ‘motors’ was not declared in this scope
       ReceiveBuffer[2] = motors.getM1Fault();
                          ^
prog.cpp:166:7: error: ‘motors’ was not declared in this scope
       motors.setBrakes(Value_One, Value_Two);
       ^
prog.cpp:174:7: error: ‘motors’ was not declared in this scope
       motors.setSpeeds(Value_One, Value_Two);
       ^
prog.cpp:181:7: error: ‘motors’ was not declared in this scope
       motors.setM1Brake(Value_One);
       ^
prog.cpp:188:7: error: ‘motors’ was not declared in this scope
       motors.setM2Brake(Value_One);
       ^
prog.cpp:195:7: error: ‘motors’ was not declared in this scope
       motors.setM1Speed(Value_One);
       ^
prog.cpp:202:7: error: ‘motors’ was not declared in this scope
       motors.setM2Speed(Value_One);
       ^
prog.cpp:233:27: error: ‘HIGH’ was not declared in this scope
        digitalWrite(LED1, HIGH);
                           ^
prog.cpp:233:31: error: ‘digitalWrite’ was not declared in this scope
        digitalWrite(LED1, HIGH);
                               ^
prog.cpp:234:27: error: ‘LOW’ was not declared in this scope
        digitalWrite(LED2, LOW);
                           ^
prog.cpp:236:8: error: ‘motors’ was not declared in this scope
        motors.setSpeeds(0, 0);
        ^
prog.cpp:243:32: error: ‘abs’ was not declared in this scope
       Value_Two = abs(Value_One);
                                ^
prog.cpp:248:7: error: ‘maximumspeed’ was not declared in this scope
       maximumspeed = Value_Two;
       ^
prog.cpp: In function ‘void loop()’:
prog.cpp:270:10: error: ‘Serial’ was not declared in this scope
   while (Serial.available() >= 7)
          ^
prog.cpp:280:25: error: ‘LOW’ was not declared in this scope
      digitalWrite(LED1, LOW);
                         ^
prog.cpp:280:28: error: ‘digitalWrite’ was not declared in this scope
      digitalWrite(LED1, LOW);
                            ^
prog.cpp:281:25: error: ‘HIGH’ was not declared in this scope
      digitalWrite(LED2, HIGH);
                         ^
prog.cpp:286:25: error: ‘LOW’ was not declared in this scope
      digitalWrite(LED1, LOW);
                         ^
prog.cpp:286:28: error: ‘digitalWrite’ was not declared in this scope
      digitalWrite(LED1, LOW);
                            ^
prog.cpp:287:14: error: ‘delay’ was not declared in this scope
      delay(50);
              ^
prog.cpp:288:25: error: ‘HIGH’ was not declared in this scope
      digitalWrite(LED1, HIGH);
                         ^
prog.cpp: In member function ‘long unsigned int AliveTime::GetElapsed()’:
prog.cpp:57:2: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
prog.cpp: In member function ‘long unsigned int AliveTime::ConnectionOkElapsed()’:
prog.cpp:65:2: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
stdout
Standard output is empty