Full refactor#53
Open
siddharth-narayan wants to merge 12 commits into
Open
Conversation
It introduces a new TrapezoidProfile, Magnetometer, and Encoder. It contains the following squashed commits: testing it goes in a circle lol Add new profile/controller Use new trapezoid profile implementation Tune PID? encoders are dead now tweak integral value add magnetometer library build magnet class for robot erm this should work haha fix magnet object now it works raise debug level Move magnet into control, log heading Update src/robot/magnet.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> move readDegrees from header to cpp reset the default offsets to the correct sign Remove .DS_Store Fix feedforward overpowering PID Low pass filter over magnetometer readings Ensure no state changes (it really didn't before anyway, might revert later) Add minimum motor power config value Increase BMM350 Data Rate Fix feedforward overpowering PID More tuning? Ensure no state changes (it really didn't before anyway, might revert later) Add minimum motor power config value Tune PID some more comment out heading reading... looks like its blocking the main thread slightly and causing PID oscillations Temp fix for now to hopefully prevent blocking the thread? unsure nvm only works if data ready interrupt pin is enabled add todo, commented out interrupt code lol. fixed magnetometer issues (and a lot of other pid stability issues) all we needed to do was measure the actual loop time instead of the expected loop time Add interrupt to magnetometer anyway Wait for magnet ready before finishing bot setup Add heading controller Properly wait for magnet to initialize configurable error tolerance, fix multiplier on heading controller output continuous pid control for heading normalize current reading, ignore low pass filter for now fix calibration, disable interrupt pin again for more consistent analysis back to high accuracy... add calibration script fix calibration cpp update pid consts Update drive test to track elapsed time, calculate accel theoretically correct whoops sign error new tuning correctly multiply soft iron matrix Added minimum speed into trapezoid profile, and feed in current position and velocity instead of expected Straight line it will usually travel straight now Precision updates Made everything into doubles. Found a better approximation for the robot Is close but still unstable Tuned a modified PID Changed PID to work on the forward and angular velocity of the robot as opposed to the speed of the individual motors. Feedback is based on the x, y, and rotation of the robot. Gets within about 5cm per forward move. Todo: realign robot to 0 degrees after forward move is completed Update control.cpp Added stop when at the destination. Adjusted power to fit between -1 and 1 for the motors. As a bonus, the robot drives even straighter. Tested backwards and longer distances with good results. Needs a bit more tuning, but is very close. Update control.cpp Lowered threshold to stop the robot and moved logging to strings that can be enabled Update control.cpp made trapezoidal profile work correctly and fixed some of the debugging info Need to edit the profile to work based on distance instead of time Re-wrote trapezoid profile Made trapezoid profile position based instead of time based. Makes the robot move slightly smoother. Rotation Added rotation support using existing turn function. So far, looks to be reasonably accurate. PID refactor Very rough readability changes. Makes the new pid work with tile movement
This commit is the *starting point* for refactoring. It does not compile. Changes made: - Added Robot, Motor and Light classes - Refactored quite a bit of control.cpp to make it much clearer - Moved control related code into the `control` folder - Started using enums for centering status instead of unkown sentinel values - Changed up the frame system for printing every `n` frames - Moved tests into their own file and separated them from the rest of the code - Moved Encoder code to the Motor class - Added serial_printf to more easily debug - Started centering refactor in center_tick - Started work on pid_tick - And more A lot of functionality was removed. Tests were commented out to get code to compile at some points during development
- Changes were made for compilation success - Added geometry calculations for easier logic encapsulation - Refactor actual calculation code: centering, turning, and PID - Created MotionController class -- uses both PID and TrapezoidalProfile as used in previous controlLoop code. - Removed commented old code, was likely not usable - Remove old trapezoidalProfile code - Most of the PID stuff *should* be good to go - MotionController uses an updated PID strategy involving merging two distance/angle PID controllers - Finish PID aligning phase, fill in more centering steps, fill in old drive functions with new goal strategy
- Replace all instances of serialLog and serialLogLn with serial_printf - Remove #ifndef #define pattern, replace with #pragma once - Alphabitize #include statements and separate library headers, paired headers, and other headers - Add new tests - Added FPS counter to check speed - Deleted old code, including splines, trapezoidalProfile
01fb194 to
889b5af
Compare
698a185 to
1f6f4a8
Compare
- Robot has DriveType status enum - Misc print improvements - Readded server communication - Improved motor power accuracy (analogWriteResoultion) - Robot can drive backwards to destination instead of always turning around - Added connection to server back in
e33ad5c to
932eea4
Compare
Motors take a speed and increase/decrease their power until they reach that target
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #51
Refactor everything
Some highlights: