Skip to content
This repository has been archived by the owner on Mar 7, 2022. It is now read-only.

Drivetrain::faceDirection method implemented #13

Merged
merged 9 commits into from
Oct 24, 2021
Merged

Conversation

MrRedness
Copy link
Member

No description provided.

@MrRedness MrRedness linked an issue Oct 18, 2021 that may be closed by this pull request
Copy link
Member

@CrashTestCoder CrashTestCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a function that will make the robot snap to the nearest (front or back)

@MrRedness
Copy link
Member Author

Oh so it will check if the robot is closer to the front or back and then move to the closer one?

@CrashTestCoder
Copy link
Member

Yes

@MrRedness
Copy link
Member Author

@CrashTestCoder Does this work (I haven't linked it to a button or anything but I implemented it into the Drivetrain cpp & hpp).
(You can check commit or I'll copy paste here):

void Drivetrain::face_closest(units::meters_per_second_t dx, units::meters_per_second_t dy) { auto const currentRotation = units::degree_t { get_angle() }; units::angle::degree_t errorTheta; (ngr::fabs(currentRotation - 0) <= 90) ? errorTheta = currentRotation : errorTheta = currentRotation - 180; auto const rotateP = 1.5; auto pRotation = errorTheta * rotateP / 1_s; if(pRotation > 90_deg / 1_s) pRotation = 90_deg / 1_s; drive({ dx, dy, pRotation }); }

@MrRedness
Copy link
Member Author

Yeah go ahead and look in the code since github completely messed up the formatting.

@CrashTestCoder
Copy link
Member

Please clean up line 81, you can make errorTheta const If you move your ternary operator to line 80 (part of cleaning). You also don't need to make currentRotation degree_t as all that's accomplishing is making your code more complex in this circumstance and doesn't really add type safety because all you're doing is immediately converting back to a double

@MrRedness
Copy link
Member Author

Uh btw the code in master branch doesn't compile...

@CrashTestCoder
Copy link
Member

Why didn't you make face_closest call face_direction instead of copy pasting the code from there?

@MrRedness
Copy link
Member Author

@CrashTestCoder Can we merge this now, or are we going to merge it along with velocity?

@CrashTestCoder CrashTestCoder merged commit d7fd19a into master Oct 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants