После длгих ковыряний выдавил это.
Надо скорректировать X И Z при повороте B.
Упёрся в то, что не могу скомпилить файл))
comp --install не предлагать.. он у меня не ставится (sudo apt-get install linuxcnc-dev) ((( из за того, что я версию 2.7.0 впихнул.
Прошу попинать в нужное место ткнуть носом, если что) Последнюю часть кода с pivot_length решил оставить, авось торкнет какая мысля хорошая.
Код: Выделить всё
#include "kinematics.h" /* these decls */
#include "posemath.h"
#include "hal.h"
#include "rtapi.h"
#include "rtapi_math.h"
#define d2r(d) ((d)*PM_PI/180.0)
#define r2d(r) ((r)*180.0/PM_PI)
#ifndef hypot
#define hypot(a,b) (sqrt((a)*(a)+(b)*(b)))
#endif
struct haldata {
hal_float_t *pivot_length;
} *haldata;
// should not even be called
int kinematicsForward(const double *joints,
EmcPose * pos,
const KINEMATICS_FORWARD_FLAGS * fflags,
KINEMATICS_INVERSE_FLAGS * iflags)
{
// B correction
double xzr = hypot(joints[0], joints[2]);
double xztheta = atan2(joints[2], joints[0]) + d2r(joints[4]);
pos->tran.x = xzr * cos(xytheta) ;
pos->tran.y = joints[2];
pos->tran.z = xzr * sin(xytheta) ;;
pos->a = joints[3];
pos->b = joints[4];
pos->c = joints[5];
pos->u = joints[6];
pos->v = joints[7];
pos->w = joints[8];
return 0;
}
int kinematicsInverse(const EmcPose * pos,
double *joints,
const KINEMATICS_INVERSE_FLAGS * iflags,
KINEMATICS_FORWARD_FLAGS * fflags)
{
// B correction
double xzr = hypot(pos->tran.x, pos->tran.z);
double xztheta = atan2(pos->tran.z, pos->tran.x) - d2r(pos->b);
// V correction is always in joint 1 only
joints[0] = xzr * cos(xytheta) ;
joints[1] = pos->tran.y ;
joints[2] = xzr * sin(xytheta) ;
joints[3] = pos->a;
joints[4] = pos->b;
joints[5] = pos->c;
joints[6] = pos->u;
joints[7] = pos->v;
joints[8] = pos->w;
return 0;
}
KINEMATICS_TYPE kinematicsType()
{
return KINEMATICS_BOTH;
}
#include "rtapi.h" /* RTAPI realtime OS API */
#include "rtapi_app.h" /* RTAPI realtime module decls */
EXPORT_SYMBOL(kinematicsType);
EXPORT_SYMBOL(kinematicsInverse);
EXPORT_SYMBOL(kinematicsForward);
MODULE_LICENSE("GPL");
int comp_id;
int rtapi_app_main(void) {
int result;
comp_id = hal_init("dankins2");
if(comp_id < 0) return comp_id;
haldata = hal_malloc(sizeof(struct haldata));
result = hal_pin_float_new("dankins2.pivot-length", HAL_IO, &(haldata->pivot_length), comp_id);
if(result < 0) goto error;
*(haldata->pivot_length) = 0.666;
hal_ready(comp_id);
return 0;
error:
hal_exit(comp_id);
return result;
}
void rtapi_app_exit(void) { hal_exit(comp_id); }