Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include "kinematics.h" /* these decls */
  2. #include "posemath.h"
  3. #include "hal.h"
  4. #include "rtapi.h"
  5. #include "rtapi_math.h"
  6.  
  7. #define d2r(d) ((d)*PM_PI/180.0)
  8. #define r2d(r) ((r)*180.0/PM_PI)
  9.  
  10. struct haldata {
  11. hal_float_t *tool_length;
  12. hal_float_t *pivot_length;
  13.  
  14. } *haldata;
  15.  
  16. static PmCartesian s2r(double r, double t, double p ) {
  17. PmCartesian c;
  18.  
  19. double dx = -0.63;
  20. double dy = -0.04;
  21.  
  22.  
  23. t = d2r(t), p = d2r(p);
  24.  
  25. double t1 = sqrt(dx*dx*cos(p)*cos(p)+dy*dy);
  26. double t2 = t + atan(dy/dx/cos(p));
  27.  
  28. c.x = t1*cos(t2) - r * sin(p)*cos(t);
  29. c.y = t1*sin(t2) - r * sin(p)*sin(t);
  30. c.z = -(dx*sin(p)+r*cos(p));
  31.  
  32.  
  33.  
  34. return c;
  35. }
  36.  
  37. int kinematicsForward(const double *joints,
  38. EmcPose * pos,
  39. const KINEMATICS_FORWARD_FLAGS * fflags,
  40. KINEMATICS_INVERSE_FLAGS * iflags)
  41. {
  42. PmCartesian r = s2r(*(haldata->pivot_length)+*(haldata->tool_length), joints[5], joints[4]);
  43.  
  44. pos->tran.x = joints[0] + r.x;
  45. pos->tran.y = joints[1] + r.y;
  46. pos->tran.z = joints[2] + r.z;
  47. pos->a = joints[3];
  48. pos->b = joints[4];
  49. pos->c = joints[5];
  50. pos->u = joints[6];
  51. pos->v = joints[7];
  52. pos->w = joints[8];
  53.  
  54. return 0;
  55. }
  56.  
  57. int kinematicsInverse(const EmcPose * pos,
  58. double *joints,
  59. const KINEMATICS_INVERSE_FLAGS * iflags,
  60. KINEMATICS_FORWARD_FLAGS * fflags)
  61. {
  62.  
  63. PmCartesian r = s2r(*(haldata->pivot_length)+*(haldata->tool_length), pos->c, pos->b);
  64.  
  65. joints[0] = pos->tran.x - r.x;
  66. joints[1] = pos->tran.y - r.y;
  67. joints[2] = pos->tran.z - r.z;
  68. joints[3] = pos->a;
  69. joints[4] = pos->b;
  70. joints[5] = pos->c;
  71. joints[6] = pos->u;
  72. joints[7] = pos->v;
  73. joints[8] = pos->w;
  74.  
  75. return 0;
  76. }
  77.  
  78. /* implemented for these kinematics as giving joints preference */
  79. int kinematicsHome(EmcPose * world,
  80. double *joint,
  81. KINEMATICS_FORWARD_FLAGS * fflags,
  82. KINEMATICS_INVERSE_FLAGS * iflags)
  83. {
  84. *fflags = 0;
  85. *iflags = 0;
  86.  
  87. return kinematicsForward(joint, world, fflags, iflags);
  88. }
  89.  
  90. KINEMATICS_TYPE kinematicsType()
  91. {
  92. return KINEMATICS_BOTH;
  93. }
  94.  
  95. #include "rtapi.h" /* RTAPI realtime OS API */
  96. #include "rtapi_app.h" /* RTAPI realtime module decls */
  97. #include "hal.h"
  98.  
  99. EXPORT_SYMBOL(kinematicsType);
  100. EXPORT_SYMBOL(kinematicsForward);
  101. EXPORT_SYMBOL(kinematicsInverse);
  102. MODULE_LICENSE("GPL");
  103.  
  104. int comp_id;
  105. int rtapi_app_main(void) {
  106. int result;
  107. comp_id = hal_init("5axecomp");
  108. if(comp_id < 0) return comp_id;
  109.  
  110. haldata = hal_malloc(sizeof(struct haldata));
  111.  
  112. result = hal_pin_float_new("5axe.tooloffset.z", HAL_IN, &(haldata->tool_length), comp_id);
  113. if(result < 0) goto error;
  114. result = hal_pin_float_new("5axe.pivot-length", HAL_IO, &(haldata->pivot_length), comp_id);
  115. if(result < 0) goto error;
  116.  
  117. *(haldata->pivot_length) = 185.455;
  118.  
  119. hal_ready(comp_id);
  120. return 0;
  121.  
  122. error:
  123. hal_exit(comp_id);
  124. return result;
  125. }
  126.  
  127. void rtapi_app_exit(void) { hal_exit(comp_id); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement