Guest User

Untitled

a guest
Jun 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.05 KB | None | 0 0
  1. #include <CmdParser.hpp>
  2.  
  3. const float motorAngle = 1.8;
  4. const float stepSize = 1;
  5.  
  6. float Csteps = 5000;
  7. float Msteps = 5000;
  8. float Ysteps = 5000;
  9. float Ksteps = 5000;
  10. unsigned long rpm = 100;
  11.  
  12. bool confirm = false;
  13.  
  14. #define enPin 8
  15. #define cDirPin 5
  16. #define cStepPin 2
  17. #define mDirPin 6
  18. #define mStepPin 3
  19. #define yDirPin 7
  20. #define yStepPin 4
  21. #define kDirPin 13
  22. #define kStepPin 12
  23.  
  24. void setup() {
  25. pinMode(enPin, OUTPUT);
  26. pinMode(cDirPin, OUTPUT);
  27. pinMode(cStepPin, OUTPUT);
  28. pinMode(mDirPin, OUTPUT);
  29. pinMode(mStepPin, OUTPUT);
  30. pinMode(yDirPin, OUTPUT);
  31. pinMode(yStepPin, OUTPUT);
  32. pinMode(kDirPin, OUTPUT);
  33. pinMode(kStepPin, OUTPUT);
  34.  
  35. digitalWrite(enPin, HIGH);
  36. Serial.begin(38400);
  37. Serial.println("Send \"START <Pump>\" to calibrate......");
  38. }
  39.  
  40. void loop() {
  41. cmdRead();
  42. }
  43.  
  44. void cmdRead() {
  45. CmdParser cmdParser;
  46. CmdBuffer<64> myBuffer;
  47. if (myBuffer.readFromSerial(&Serial)) {
  48. if (cmdParser.parseCmd(&myBuffer) != CMDPARSER_ERROR) {
  49. if (cmdParser.getParamCount() == 2) {
  50. if(cmdParser.equalCmdParam(0, "START")){
  51. if(cmdParser.equalCmdParam(1, "C")){
  52. loadPump('C');
  53. confirmation();
  54. Serial.println(" ");
  55. Serial.print("Calibrating Cyan Pump with ");Serial.print(Csteps);Serial.println(" Steps");
  56. cStepperRotate(Csteps, rpm);
  57. confirm = false;
  58. Serial.println(" ");
  59. Serial.println("1) Measure the volume of liquid pumped....");
  60. Serial.println("2) Use the formula to find the <Steps per Unit(ml)>");
  61. Serial.print(" ");Serial.println(Csteps);
  62. Serial.println(" <Steps per Unit(ml)> = ---------------");
  63. Serial.println(" Measured Volume");
  64. Serial.println("3) Modify the <Cspu> value with <Steps per Unit> in Main Program");
  65. Serial.println(" ");
  66. Serial.println("Send \"START <Pump>\" to calibrate......");
  67. }
  68. else if(cmdParser.equalCmdParam(1, "M")){
  69. loadPump('M');
  70. confirmation();
  71. Serial.println(" ");
  72. Serial.print("Calibrating Magenta Pump with ");Serial.print(Msteps);Serial.println(" Steps");
  73. mStepperRotate(Msteps, rpm);
  74. confirm = false;
  75. Serial.println(" ");
  76. Serial.println("1) Measure the volume of liquid pumped....");
  77. Serial.println("2) Use the formula to find the <Steps per Unit(ml)>");
  78. Serial.print(" ");Serial.println(Msteps);
  79. Serial.println(" <Steps per Unit(ml)> = ---------------");
  80. Serial.println(" Measured Volume");
  81. Serial.println("3) Modify the <Mspu> value with <Steps per Unit> in Main Program");
  82. Serial.println(" ");
  83. Serial.println("Send \"START <Pump>\" to calibrate......");
  84. }
  85. else if(cmdParser.equalCmdParam(1, "Y")){
  86. loadPump('Y');
  87. confirmation();
  88. Serial.println(" ");
  89. Serial.print("Calibrating Yellow Pump with ");Serial.print(Ysteps);Serial.println(" Steps");
  90. yStepperRotate(Ysteps, rpm);
  91. confirm = false;
  92. Serial.println(" ");
  93. Serial.println("1) Measure the volume of liquid pumped....");
  94. Serial.println("2) Use the formula to find the <Steps per Unit(ml)>");
  95. Serial.println(" Ysteps");
  96. Serial.println(" <Steps per Unit(ml)> = ---------------");
  97. Serial.println(" Measured Volume");
  98. Serial.println("3) Modify the <Yspu> value with <Steps per Unit> in Main Program");
  99. Serial.println(" ");
  100. Serial.println("Send \"START <Pump>\" to calibrate......");
  101. }
  102. else if(cmdParser.equalCmdParam(1, "K")){
  103. loadPump('K');
  104. confirmation();
  105. Serial.println(" ");
  106. Serial.print("Calibrating Key Pump with ");Serial.print(Ksteps);Serial.println(" Steps");
  107. kStepperRotate(Ksteps, rpm);
  108. confirm = false;
  109. Serial.println(" ");
  110. Serial.println("1) Measure the volume of liquid pumped....");
  111. Serial.println("2) Use the formula to find the <Steps per Unit(ml)>");
  112. Serial.print(" ");Serial.println(Ksteps);
  113. Serial.println(" <Steps per Unit(ml)> = ---------------");
  114. Serial.println(" Measured Volume");
  115. Serial.println("3) Modify the <Kspu> value with <Steps per Unit> in Main Program");
  116. Serial.println(" ");
  117. Serial.println("Send \"START <Pump>\" to calibrate......");
  118. }
  119. else {
  120. Serial.println(" ");
  121. Serial.println("Invalid <Pump>");
  122. }
  123. }
  124. }
  125. else {
  126. Serial.println(" ");
  127. Serial.println("Invalid Command");
  128. }
  129. }
  130. }
  131. }
  132.  
  133. void cStepperRotate(float steps, float rpm) {
  134. float stepsPerRotation = (360.00 / motorAngle) / stepSize;
  135. unsigned long stepPeriodmicroSec = ((60.0000 / (rpm * stepsPerRotation)) * 1E6 / 2.0000) - 5;
  136.  
  137. digitalWrite(cDirPin, HIGH);
  138. float totalSteps = steps;
  139. for (unsigned long i = 0; i < totalSteps; i++) {
  140. digitalWrite(cStepPin, HIGH);
  141. delayMicroseconds(stepPeriodmicroSec);
  142. digitalWrite(cStepPin, LOW);
  143. delayMicroseconds(stepPeriodmicroSec);
  144. }
  145. }
  146.  
  147. void mStepperRotate(float steps, float rpm) {
  148. float stepsPerRotation = (360.00 / motorAngle) / stepSize;
  149. unsigned long stepPeriodmicroSec = ((60.0000 / (rpm * stepsPerRotation)) * 1E6 / 2.0000) - 5;
  150.  
  151. digitalWrite(mDirPin, HIGH);
  152. float totalSteps = steps;
  153. for (unsigned long i = 0; i < totalSteps; i++) {
  154. digitalWrite(mStepPin, HIGH);
  155. delayMicroseconds(stepPeriodmicroSec);
  156. digitalWrite(mStepPin, LOW);
  157. delayMicroseconds(stepPeriodmicroSec);
  158. }
  159. }
  160.  
  161. void yStepperRotate(float steps, float rpm) {
  162. float stepsPerRotation = (360.00 / motorAngle) / stepSize;
  163. unsigned long stepPeriodmicroSec = ((60.0000 / (rpm * stepsPerRotation)) * 1E6 / 2.0000) - 5;
  164.  
  165. digitalWrite(yDirPin, HIGH);
  166. float totalSteps = steps;
  167. for (unsigned long i = 0; i < totalSteps; i++) {
  168. digitalWrite(yStepPin, HIGH);
  169. delayMicroseconds(stepPeriodmicroSec);
  170. digitalWrite(yStepPin, LOW);
  171. delayMicroseconds(stepPeriodmicroSec);
  172. }
  173. }
  174.  
  175. void kStepperRotate(float steps, float rpm) {
  176. float stepsPerRotation = (360.00 / motorAngle) / stepSize;
  177. unsigned long stepPeriodmicroSec = ((60.0000 / (rpm * stepsPerRotation)) * 1E6 / 2.0000) - 5;
  178.  
  179. digitalWrite(kDirPin, HIGH);
  180. float totalSteps = steps;
  181. for (unsigned long i = 0; i < totalSteps; i++) {
  182. digitalWrite(kStepPin, HIGH);
  183. delayMicroseconds(stepPeriodmicroSec);
  184. digitalWrite(kStepPin, LOW);
  185. delayMicroseconds(stepPeriodmicroSec);
  186. }
  187. }
  188.  
  189. void loadPump(char motor) {
  190. digitalWrite(enPin, LOW);
  191. if (motor == 'C') {
  192. Serial.println(" ");
  193. Serial.print("Loading Fluid into Cyan Pump");
  194. cStepperRotate(2000, rpm);
  195. Serial.println(" .....Done");
  196. }
  197. else if (motor == 'M') {
  198. Serial.println(" ");
  199. Serial.print("Loading Fluid into Magenta Pump");
  200. mStepperRotate(2000, rpm);
  201. Serial.println(" .....Done");
  202. }
  203. else if (motor == 'Y') {
  204. Serial.println(" ");
  205. Serial.print("Loading Fluid into Yellow Pump");
  206. yStepperRotate(2000, rpm);
  207. Serial.println(" .....Done");
  208. }
  209. else if (motor == 'K') {
  210. Serial.println(" ");
  211. Serial.print("Loading Fluid into Key Pump");
  212. kStepperRotate(2000, rpm);
  213. Serial.println(" .....Done");
  214. }
  215. }
  216.  
  217. void confirmation() {
  218. Serial.println(" ");
  219. Serial.println("Now empty the Flask to start calibrating.");
  220. Serial.println("Ready to start calibration...! (Send <Yes> to Start)");
  221. while(!confirm) {
  222. CmdParser cmdParser;
  223. CmdBuffer<64> myBuffer;
  224. if (myBuffer.readFromSerial(&Serial)) {
  225. if (cmdParser.parseCmd(&myBuffer) != CMDPARSER_ERROR) {
  226. if (cmdParser.getParamCount() == 1) {
  227. if(cmdParser.equalCmdParam(0, "Yes")) {
  228. confirm = true;
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
Add Comment
Please, Sign In to add comment