No Description

stepmotor.cxx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
  3. * Mihai Tudor Panu <mihai.tudor.panu@intel.com>
  4. * Copyright (c) 2014 Intel Corporation.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <unistd.h>
  26. #include <iostream>
  27. #include <signal.h>
  28. #include "stepmotor.h"
  29. using namespace std;
  30. int doWork = 1;
  31. upm::StepMotor *sensor = NULL;
  32. void
  33. sig_handler(int signo)
  34. {
  35. printf("got signal\n");
  36. if (signo == SIGINT) {
  37. printf("exiting application\n");
  38. doWork = 0;
  39. }
  40. }
  41. int
  42. main(int argc, char **argv)
  43. {
  44. //! [Interesting]
  45. sensor = new upm::StepMotor(2, 3);
  46. while (doWork) {
  47. cout << "1 Revolution forward and back at 60 rpm" << endl;
  48. sensor->setSpeed(60);
  49. sensor->stepForward(200);
  50. usleep(1000000);
  51. sensor->stepBackward(200);
  52. usleep(1000000);
  53. cout << "1 Revolution forward and back at 150 rpm" << endl;
  54. sensor->setSpeed(150);
  55. sensor->stepForward(200);
  56. usleep(1000000);
  57. sensor->stepBackward(200);
  58. usleep(1000000);
  59. cout << "1 Revolution forward and back at 300 rpm" << endl;
  60. sensor->setSpeed(300);
  61. sensor->stepForward(200);
  62. usleep (1000000);
  63. sensor->stepBackward(200);
  64. usleep (1000000);
  65. }
  66. delete sensor;
  67. //! [Interesting]
  68. return 0;
  69. }