24 fbk_units = PidFeedbackUnitsEnum::RAW_MACHINE_UNITS;
25 out_units = PidOutputUnitsEnum::RAW_MACHINE_UNITS;
164 ControlBoardHelper::ControlBoardHelper(
int n,
const int *aMap,
const double *angToEncs,
const double *zs,
const double *newtons,
const double *amps,
const double *volts,
const double *dutycycles,
const double *kbemf,
const double *ktau)
170 memcpy(mPriv->
axisMap, aMap,
sizeof(
int)*n);
172 if (zs!=
nullptr) memcpy(mPriv->
position_zeros, zs,
sizeof(
double)*n);
173 if (angToEncs!=
nullptr) memcpy(mPriv->
angleToEncoders, angToEncs,
sizeof(
double)*n);
174 if (newtons!=
nullptr) memcpy(mPriv->
newtonsToSensors, newtons,
sizeof(
double)*n);
175 if (amps!=
nullptr) memcpy(mPriv->
ampereToSensors, amps,
sizeof(
double)*n);
176 if (volts!=
nullptr) memcpy(mPriv->
voltToSensors, volts,
sizeof(
double)*n);
177 if (dutycycles !=
nullptr) memcpy(mPriv->
dutycycleToPWMs, dutycycles,
sizeof(
double)*n);
178 if (kbemf !=
nullptr) memcpy(mPriv->
bemfToRaws, kbemf,
sizeof(
double)*n);
179 if (ktau !=
nullptr) memcpy(mPriv->
ktauToRaws, ktau,
sizeof(
double)*n);
182 memset (mPriv->
invAxisMap, 0,
sizeof(
int) * n);
184 for (i = 0; i < n; i++)
187 for (j = 0; j < n; j++)
200 if (mPriv) {
delete mPriv; mPriv =
nullptr; }
216 if( (
id >= mPriv->
nj) || (
id< 0))
226 if(n_axes > mPriv->
nj)
229 yError(
"checkAxesIds: num of axes is too big");
232 for(
int idx = 0; idx<n_axes; idx++)
234 if( (axesList[idx]<0) || (axesList[idx]>= mPriv->
nj) )
237 yError(
"checkAxesIds: joint id out of bound");
246 {
return mPriv->
axisMap[axis]; }
254 for (
int k=0;k<mPriv->
nj;k++)
255 user[
toUser(k)]=hwData[k];
259 void ControlBoardHelper::ControlBoardHelper::toUser(
const int *hwData,
int *user)
261 for (
int k=0;k<mPriv->nj;k++)
262 user[toUser(k)]=hwData[k];
268 for (
int k=0;k<mPriv->
nj;k++)
269 hwData[
toHw(k)]=usr[k];
275 for (
int k=0;k<mPriv->
nj;k++)
276 hwData[
toHw(k)]=usr[k];
319 for(
int j=0;j<mPriv->
nj;j++)
321 impN2S(newtons[j], j, tmp, index);
342 for(
int j=0;j<mPriv->
nj;j++)
344 trqN2S(newtons[j], j, tmp, index);
354 for(
int j=0;j<mPriv->
nj;j++)
356 trqS2N(sens[j], j, tmp, index);
377 for(
int j=0;j<mPriv->
nj;j++)
379 impS2N(sens[j], j, tmp, index);
474 for(
int j=0;j<mPriv->
nj;j++)
476 posA2E(ang[j], j, tmp, index);
486 for(
int j=0;j<mPriv->
nj;j++)
488 posE2A(enc[j], j, tmp, index);
497 for(
int j=0;j<mPriv->
nj;j++)
499 velA2E(ang[j], j, tmp, index);
508 for(
int j=0;j<mPriv->
nj;j++)
519 for(
int j=0;j<mPriv->
nj;j++)
521 velE2A(enc[j], j, tmp, index);
530 for(
int j=0;j<mPriv->
nj;j++)
541 for(
int j=0;j<mPriv->
nj;j++)
543 accA2E(ang[j], j, tmp, index);
552 for(
int j=0;j<mPriv->
nj;j++)
563 for(
int j=0;j<mPriv->
nj;j++)
565 accE2A(enc[j], j, tmp, index);
574 for(
int j=0;j<mPriv->
nj;j++)
598 for(
int j=0;j<mPriv->
nj;j++)
610 for(
int j=0;j<mPriv->
nj;j++)
647 for(
int j=0;j<mPriv->
nj;j++)
659 for(
int j=0;j<mPriv->
nj;j++)
695 for (
int j = 0; j<mPriv->
nj; j++)
706 for (
int j = 0; j<mPriv->
nj; j++)
709 dutycycle[index] = tmp;
741 bemf_user = bemf_raw / mPriv->
bemfToRaws[j_user];
747 ktau_user = ktau_raw / mPriv->
ktauToRaws[j_user];
763 {
return mPriv->
nj; }
769 double output_conversion_factor;
770 switch (mPriv->
pid_units[pidtype][j].out_units)
772 case PidOutputUnitsEnum::DUTYCYCLE_PWM_PERCENT: output_conversion_factor = mPriv->
dutycycleToPWMs[j];
break;
774 case PidOutputUnitsEnum::POSITION_METRIC: output_conversion_factor = mPriv->
angleToEncoders[j];
break;
775 case PidOutputUnitsEnum::VELOCITY_METRIC: output_conversion_factor = mPriv->
angleToEncoders[j];
break;
776 case PidOutputUnitsEnum::TORQUE_METRIC: output_conversion_factor = mPriv->
newtonsToSensors[j];
break;
777 case PidOutputUnitsEnum::RAW_MACHINE_UNITS:
778 default: output_conversion_factor = mPriv->
helper_ones[j];
break;
780 return output_conversion_factor;
785 double feedback_conversion_factor = 0.0;
786 switch (mPriv->
pid_units[pidtype][j].fbk_units)
797 case PidFeedbackUnitsEnum::RAW_MACHINE_UNITS:
798 default: feedback_conversion_factor = mPriv->
helper_ones[j];
break;
800 return (1.0 / feedback_conversion_factor);
805 k_usr = cb_helper->
toUser(j_raw);
810 out_usr.
kp = out_usr.
kp / feedback_conversion_units_user2raw;
811 out_usr.
ki = out_usr.
ki / feedback_conversion_units_user2raw;
812 out_usr.
kd = out_usr.
kd / feedback_conversion_units_user2raw;
816 out_usr.
kp = out_usr.
kp / output_conversion_units_user2raw;
817 out_usr.
ki = out_usr.
ki / output_conversion_units_user2raw;
818 out_usr.
kd = out_usr.
kd / output_conversion_units_user2raw;
820 out_usr.
max_int = out_usr.
max_int / output_conversion_units_user2raw;
823 out_usr.
offset = out_usr.
offset / output_conversion_units_user2raw;
837 k_raw = cb_helper->
toHw(j_usr);
842 out_raw.
kp = out_raw.
kp * feedback_conversion_units_user2raw;
843 out_raw.
ki = out_raw.
ki * feedback_conversion_units_user2raw;
844 out_raw.
kd = out_raw.
kd * feedback_conversion_units_user2raw;
848 out_raw.
kp = out_raw.
kp * output_conversion_units_user2raw;
849 out_raw.
ki = out_raw.
ki * output_conversion_units_user2raw;
850 out_raw.
kd = out_raw.
kd * output_conversion_units_user2raw;
852 out_raw.
max_int = out_raw.
max_int * output_conversion_units_user2raw;
855 out_raw.
offset = out_raw.
offset * output_conversion_units_user2raw;
866 cb_helper->
posA2E(userval, j, machineval, k);
869 cb_helper->
velA2E(userval, j, machineval, k);
872 cb_helper->
trqN2S(userval, j, machineval, k);
875 cb_helper->
ampereA2S(userval, j, machineval, k);
878 yError() <<
"convert_units_to_machine: invalid pidtype";
891 cb_helper->
posA2E(userval, machineval);
894 cb_helper->
velA2E(userval, machineval);
897 cb_helper->
trqN2S(userval, machineval);
900 cb_helper->
ampereA2S(userval, machineval);
903 yError() <<
"convert_units_to_machine: invalid pidtype";
916 *userval = cb_helper->
posE2A(machineval, k);
919 *userval = cb_helper->
velE2A(machineval, k);
922 *userval = cb_helper->
trqS2N(machineval, k);
925 *userval = cb_helper->
ampereS2A(machineval, k);
928 yError() <<
"convert_units_to_machine: invalid pidtype";
941 cb_helper->
posE2A(machineval, userval);
944 cb_helper->
velE2A(machineval, userval);
947 cb_helper->
trqS2N(machineval, userval);
950 cb_helper->
ampereS2A(machineval, userval);
953 yError() <<
"convert_units_to_machine: invalid pidtype";
961 int nj = cb_helper->
axes();
962 for (
int i = 0; i < nj; i++)
964 mPriv->
pid_units[pidtype][i].fbk_units = fbk_conv_units;
965 mPriv->
pid_units[pidtype][i].out_units = out_conv_units;