Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #include <iostream>
  2. #include "ServoJoint.h"
  3.  
  4. int main() {
  5. //2D array containing the 7 calibrated positions for each of the 10 servo motors
  6. size_t servoCalibrations[10][7]={{143, 190, 245, 305, 365, 410, 467},
  7. {143, 205, 260, 320, 377, 423, 475},
  8. {115, 168, 230, 280, 340, 392, 440},
  9. {130, 182, 235, 290, 340, 397, 455},
  10. {135, 190, 235, 290, 345, 400, 455},
  11. {140, 190, 250, 305, 355, 415, 465},
  12. {130, 185, 240, 300, 355, 415, 465},
  13. {140, 200, 245, 300, 355, 410, 460},
  14. {140, 200, 245, 300, 355, 410, 460},
  15. {140, 200, 245, 300, 355, 410, 460}};
  16.  
  17. //Array of pointers to 10 size_t arrays of size 7
  18. //This is because C++ doesn't allow accessing an entire row/column of a 2D array
  19. //or I don't know how to
  20. size_t * calibrationArrays[10];
  21. for(size_t i=0; i<10; i++){
  22. size_t * tmp= new size_t[7];
  23. for(size_t j=0; j<7; j++){
  24. tmp[j]= servoCalibrations[i][j];
  25. }
  26. calibrationArrays[i]= tmp;
  27. }
  28.  
  29. //Array of pointers to 10 ServoJoint objects
  30. ServoJoint * servos[10];
  31.  
  32. //Dynamically allocate 10 ServoJoint objects
  33. for(size_t i=0; i<10; i++){
  34. servos[i]= new ServoJoint(i, 7, calibrationArrays[i]);
  35. }
  36.  
  37. for(size_t i=0; i<10; i++){
  38. std::cout << "Servo motor " << i << " has the following PWM values: ";
  39. for(size_t j=0; j<7; j++){
  40. std::cout << servos[i]->getPWM(-90+j*30) << " ";
  41. }
  42. std::cout<< std::endl;
  43. };
  44.  
  45. return 0;
  46. }
  47.  
  48. #ifndef QUADRUPEDROBOT_SERVOJOINT_H
  49. #define QUADRUPEDROBOT_SERVOJOINT_H
  50.  
  51. #include <cstdint>
  52. #include <map>
  53. //#include "PWMDriver.h"
  54.  
  55. class ServoJoint{
  56.  
  57. private:
  58.  
  59. //servo motor channel number on the PWM/Servo driver; [0, 15]
  60. size_t mChannel;
  61.  
  62. //number of calibrated positions
  63. size_t mSize;
  64.  
  65. //pointer to a map of the servo motor's angular position with its corresponding pulse width value
  66. std::map<int, size_t>* mPWM;
  67.  
  68. public:
  69.  
  70. //size indicates the number of calibrated positions in [-90 deg, 90deg];
  71. //calibrated positions must be at equal intervals. i.e. -90, -45, -30, ... is not valid
  72. ServoJoint(size_t givenChannel, size_t size, size_t givenPWM[]);
  73.  
  74. };
  75.  
  76. #endif //QUADRUPEDROBOT_SERVOJOINT_H
  77.  
  78. undefined reference to `ServoJoint::ServoJoint(unsigned long long, unsigned long long, unsigned long long*)'
  79. undefined reference to `ServoJoint::getPWM(double)'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement