Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // Test code
  2. // PICO drives 1 meter forward, 1 meter backward, 1 meter left, 1 meter right, 180 degree turn left, 180 degree turn right.
  3. // PICO should end in its initial position.
  4.  
  5. #include <emc/io.h>
  6. #include <emc/rate.h>
  7. #include <cmath>
  8. #include <iostream>
  9.  
  10. emc::IO io; // Create IO object, which will initialize the io layer
  11. emc::OdometryData odom;
  12. emc::LaserData scan;
  13. emc::Rate r(10);
  14.  
  15. float xvec, yvec;
  16.  
  17. bool forcevector()
  18. {
  19. float rpico 0.1;
  20. float Fpush -100;
  21.  
  22. float da = 4/scan.ranges.size();
  23. float a = -2;
  24.  
  25. float cosvec;
  26. float sinvec;
  27. float totvec;
  28.  
  29. for(int i = 0; i < scan.ranges.size(); i++)
  30. {
  31. cosvec += cos(a)/pow(fabs(scan.ranges[i]-rpico),3);
  32. sinvec += sin(a)/pow(fabs(scan.ranges[i]-rpico),3);
  33. totvec += 1 /pow(fabs(scan.ranges[i]-rpico),3);
  34. a += da;
  35. }
  36.  
  37. xvec = (Fpush*cosvec)/totvec;
  38. yvec = (Fpush*sinvec)/totvec;
  39.  
  40. return true;
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46. float picomass = 20;
  47. float time = 0.1;
  48.  
  49. float ax;
  50. float ay;
  51. float vx;
  52. float vy;
  53.  
  54. while(io.ok())
  55. {
  56. forcevector();
  57. ax = xvec*picomass;
  58. ay = yvec*picomass;
  59.  
  60. vx = ax*time;
  61. vy = ay*time;
  62.  
  63. io.sendBaseReference(vx,vy,0);
  64. r.sleep();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement