Advertisement
Guest User

linuxcnc dispenser

a guest
May 26th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <math.h>
  4. #include <assert.h>
  5.  
  6. /*
  7. Compile this with "gcc M102.c -o M102" to build an M102 executable
  8. program in the emc/programs/ directory. M102 in your G code program
  9. will execute this code, passing the P and Q variables as command
  10. line arguments.
  11. */
  12.  
  13. #define SCALEFACTOR1 2.5
  14. #define SCALEFACTOR2 2.5
  15.  
  16.  
  17.  
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21. double p = 0.0, q = 0.0;
  22.  
  23. /* process the P and Q command line args we will be given */
  24. if (argc > 1) {
  25. sscanf(argv[1], "%lf", &p);
  26. }
  27. if (argc > 2) {
  28. sscanf(argv[2], "%lf", &q);
  29. }
  30.  
  31. assert(0 <= p && p <= 1);
  32. int usec_white = (int) (p * SCALEFACTOR1 * 1000000);
  33. int usec_black = (int) ((1 - p) * SCALEFACTOR2 * 1000000);
  34. /*
  35. printf("%d w\n", usec_w);
  36. printf("%d b\n", usec_b);
  37. */
  38.  
  39. if(usec_w > 0)
  40. printf("M64 P0\n"); // enable w dispenser
  41. if(usec_black > 0)
  42. printf("M64 P1\n"); // enable b dispenser
  43.  
  44. if(usec_white < usec_b) {
  45. usleep(usec_w);
  46. printf("M65 P0\n");
  47. usleep(usec_b - usec_w);
  48. printf("M65 P1\n");
  49. } else {
  50. usleep(usec_b);
  51. printf("M65 P1\n");
  52. usleep(usec_w - usec_b);
  53. printf("M65 P0\n");
  54. }
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement