Advertisement
Guest User

Untitled

a guest
Nov 4th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include "posemath.h"
  2. #include "rtapi_math.h"
  3. #include "kinematics.h" /* decls for kinematicsForward, etc. */
  4.  
  5. #include "rtapi.h" /* RTAPI realtime OS API */
  6. #include "rtapi_app.h" /* RTAPI realtime module decls */
  7. #include "hal.h"
  8.  
  9. struct mk5data_data {
  10. hal_float_t *d1, *d2;
  11. } *haldata = 0;
  12.  
  13. /* key dimensions
  14.  
  15. */
  16.  
  17. #define D1 (*(haldata->d1))
  18. #define D2 (*(haldata->d2))
  19.  
  20.  
  21.  
  22. /* joint[0] and joint[1] are in degrees and joint[2] is in length units */
  23.  
  24. /* forward kinematics */
  25.  
  26. int kinematicsForward(const double * joint,
  27. EmcPose * world,
  28. const KINEMATICS_FORWARD_FLAGS * fflags,
  29. KINEMATICS_INVERSE_FLAGS * iflags)
  30. {
  31. double a0, a1;
  32. double x, y, a, f;
  33.  
  34. /* convert joint angles to radians for sin() and cos() */
  35.  
  36. a0 = joint[0] * ( PM_PI / 180 );
  37. a1 = joint[1] * ( PM_PI / 180 );
  38. a = 1.57;
  39. f = 0.40;
  40. /* convert angles into world coords */
  41.  
  42.  
  43. x = 250 - ((D1*sin(a-a0))+(D2*cos(180-((a-a0)+f+a1))));
  44. y = 600 - ((D1*cos(a-a0))+(D2*sin(180-((a-a0)+f+a1))));
  45.  
  46.  
  47. *iflags = 0;
  48. if (joint[1] < 90)
  49. *iflags = 1;
  50.  
  51. world->tran.x = x;
  52. world->tran.y = y;
  53.  
  54.  
  55.  
  56. return (0);
  57. }
  58.  
  59.  
  60. /* inverse kinematics */
  61.  
  62. int kinematicsInverse(const EmcPose * world,
  63. double * joint,
  64. const KINEMATICS_INVERSE_FLAGS * iflags,
  65. KINEMATICS_FORWARD_FLAGS * fflags)
  66. {
  67. double q0, q1;
  68. double xt, yt;
  69. double x, y, h, h1, s, xta;
  70.  
  71. x = world->tran.x;
  72. y = world->tran.y;
  73.  
  74.  
  75.  
  76.  
  77. xt = 250 - x;
  78. yt = 600 - y;
  79.  
  80. h = sqrt(x*x + y*y);
  81. h1 = (((D1*D1)+(D2*D2))-(h*h))/2*(D1+D2);
  82. s = (((D1*D1)+(h*h))-(D2*D2))/2*(D1+h);
  83. xta = x/y;
  84.  
  85. q0 = s + xta;
  86. q1 = h1 - 0.3078163;
  87.  
  88. q0 = q0 * (180 / PM_PI);
  89. q1 = q1 * (180 / PM_PI);
  90.  
  91. joint[0] = q0;
  92. joint[1] = q1;
  93.  
  94.  
  95.  
  96. *fflags = 0;
  97.  
  98. return (0);
  99. }
  100.  
  101.  
  102. /* Kinematics Both */
  103.  
  104.  
  105. #define DEFAULT_D1 753.77
  106. #define DEFAULT_D2 580.32
  107.  
  108.  
  109. /* implemented for these kinematics as giving joints preference */
  110. int kinematicsHome(EmcPose * world,
  111. double *joint,
  112. KINEMATICS_FORWARD_FLAGS * fflags,
  113. KINEMATICS_INVERSE_FLAGS * iflags)
  114. {
  115. *fflags = 0;
  116. *iflags = 0;
  117.  
  118. return kinematicsForward(joint, world, fflags, iflags);
  119. }
  120.  
  121. KINEMATICS_TYPE kinematicsType()
  122. {
  123. return KINEMATICS_BOTH;
  124. }
  125.  
  126.  
  127. EXPORT_SYMBOL(kinematicsType);
  128. EXPORT_SYMBOL(kinematicsForward);
  129. EXPORT_SYMBOL(kinematicsInverse);
  130.  
  131.  
  132. int comp_id;
  133. int rtapi_app_main(void) {
  134. comp_id = hal_init("mk5kins1");
  135. if(comp_id > 0) {
  136. hal_ready(comp_id);
  137. return 0;
  138. }
  139. return comp_id;
  140. }
  141.  
  142. void rtapi_app_exit(void) { hal_exit(comp_id); }
  143.  
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement