neuberfran

smartdriveCXXworked

Sep 23rd, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. /*
  2. * Author: Oussema Harbi <[email protected]>
  3. * Below are the terms of usage of this file
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24.  
  25. #include <unistd.h>
  26. #include <iostream>
  27. #include "smartdrive.h"
  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. // Instantiate a a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
  53. drive = new upm::SmartDrive(1);
  54.  
  55. drive->command(0x52);
  56. drive->StopMotor(Motor_ID_BOTH, Action_Brake);
  57. sleep(5);
  58. std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
  59. std::cout << "Pos M1 : " << drive->ReadTachometerPosition(Motor_ID_1)<< std::endl;
  60. std::cout << "Pos M2 : " << drive->ReadTachometerPosition(Motor_ID_2)<< std::endl;
  61. //Set motor M1 to run for 300seconds, with speed of 15RPM, waith for it to finish and then Brake It
  62. drive->Run_Seconds(Motor_ID_BOTH, Dir_Reverse, 90, 70, true, Action_Brake );
  63. std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
  64. std::cout << "Pos M1 : " << drive->ReadTachometerPosition(Motor_ID_1) << std::endl;
  65.  
  66. //you pass ID of motor to run to functions
  67. //If you want to run only motor 1, you use Motor_ID_1
  68. //IF you want to run only motor 2, you use Motor_ID_2
  69. //If you want to run 2 motors, you use Motor_ID_BOTH
  70. // ok ?
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment