Advertisement
neuberfran

smartdriveCXXissue

Sep 23rd, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Author: Oussema Harbi <oussema.elharbi@gmail.com>
  5. * Copyright (c) <2016> <Oussema Harbi>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24.  
  25. #include <unistd.h>
  26. #include <iostream>
  27. #include "smartdrive.hpp"
  28. #include <signal.h>
  29.  
  30. upm::SmartDrive *drive = NULL;
  31.  
  32. void
  33. sig_handler(int signo)
  34. {
  35. printf("got signal\n");
  36. if (signo == SIGINT) {
  37. printf("exiting application\n");
  38. if (drive != NULL)
  39. delete drive;
  40. exit (0);
  41. }
  42. }
  43.  
  44. int
  45. main(int argc, char **argv)
  46. {
  47. float voltage = 0;
  48.  
  49. std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
  50. sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
  51.  
  52. //! [Interesting]
  53. // Instantiate a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
  54. drive = new upm::SmartDrive(0);
  55.  
  56. std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
  57. //Set motor M1 to run for 120 seconds, with speed of 15RPM, waith for it to finish and then Brake It
  58. drive->Run_Seconds(SmartDrive_Motor_ID_1, SmartDrive_Dir_Forward, 15, 120, true, SmartDrive_Action_Brake);
  59. std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
  60. //Rotate motor M2 2270 degrees, in reverse sense, with speed of 10RPM, return immediately from function call
  61. drive->Run_Degrees(SmartDrive_Motor_ID_2, SmartDrive_Dir_Reverse, 10, 2270, false, SmartDrive_Action_Float);
  62. //While motor is running, Display its status
  63. drive->PrintMotorStatus(SmartDrive_Motor_ID_2);
  64. sleep(2); //Sleep for 2 seconds
  65. //Stop motor M2 and then finish program
  66. drive->StopMotor(SmartDrive_Motor_ID_2, SmartDrive_Action_BrakeHold);
  67. //! [Interesting]
  68.  
  69. std::cout << "Demo complete. GoodBye" << std::endl;
  70.  
  71. delete drive;
  72. drive = NULL;
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement