Bayley Wang
/
foc-ed_in_the_bot_compact
robot
DQMapper/DQMapper.cpp
- Committer:
- bwang
- Date:
- 2017-01-06
- Revision:
- 42:030e0ec4eac5
- Child:
- 44:3fd6a43b91f0
File content as of revision 42:030e0ec4eac5:
#include "DQMapper.h" #include "config_motor.h" #include "config_table.h" #include "dtab_n_w25.h" #include "dtab_p_w25.h" #include "qtab_n_w25.h" #include "qtab_p_w25.h" void LutMapper::map(float torque_percent, float w, float *d, float *q) { w *= POLE_PAIRS; if (w < 0.f) { w = -w; torque_percent = -torque_percent; } if (torque_percent > 0) { int row = (int) (w / W_STEP); int col = (int) (torque_percent * COLUMNS); if (row >= ROWS) row = ROWS - 1; if (col >= COLUMNS) col = COLUMNS - 1; *d = (float) dtab_p_w25[row][col] / 128.f; *q = (float) qtab_p_w25[row][col] / 128.f; } else { int row = (int) (w / W_STEP); int col = (int) (-torque_percent * COLUMNS); if (row >= ROWS) row = ROWS - 1; if (col >= COLUMNS) col = COLUMNS - 1; *d = (float) dtab_n_w25[row][col] / 128.f; *q = (float) qtab_n_w25[row][col] / 128.f; } }