During summer I worked on refactoring the DJIMotor class as part of a larger project to refactor the entire codebase. Reason for this was to make the code more efficient, readable, faster, and safer. There were a lot of small changes such as renaming variables and functions to new static and time conventions, deleting lot of unused variables, changing a lot from public to private, etc. The biggest changes were as listed below:
Extremely important:
Fixed a major issue that was calling setOutput() and thus calculating a PID TWICE per loop instead of once. This happened everytime we called a motor.setFunction() and everytime we called s_sendValues()
Rest:
Added motor names to the DJIMotor class. Constructor has default parameter "NO_NAME"
Optimized s_sendValues() to only send bit array if there is at least one motor in such row
Created a smart calculateDeltaTicks() to return the position error that takes into account the periodicity of an angle
Refactored s_getFeedback() to make it more readable
Added an isConnected() motor function
Added power limits for 15 and 16 bit variables
Changed #define "constants" to constexprs
Created all neccesary motor constants: ticks, ratios, max power
Removed all non-static global variables
All function boolean debug variables are now default false parameters instead of global
Use structs instead of array for default PID motor setting
During summer I worked on refactoring the DJIMotor class as part of a larger project to refactor the entire codebase. Reason for this was to make the code more efficient, readable, faster, and safer. There were a lot of small changes such as renaming variables and functions to new static and time conventions, deleting lot of unused variables, changing a lot from public to private, etc. The biggest changes were as listed below:
Extremely important:
Rest:
#define
"constants" toconstexpr
sdebug
variables are now defaultfalse
parameters instead of globalstruct
s instead of array for default PID motor settingYet to fix: