Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make brushed motors resistant to changing missions #474

Merged
merged 11 commits into from
May 12, 2023

Conversation

CameronTressler
Copy link
Contributor

Summary

Closes #(Your issue number here)

What features did you add, bugs did you fix, etc?

Did you add documentation to the wiki?

Yes/No (If not explain why not)

How was this code tested?

Summarize how you tested this code. Your objective here is to prove to the reviewers that this code actually works without them having to run it themselves. It is often helpful to include screenshots, tables, graphs, and/or a short write-up of testing procedures. Results can be either from sim, the robot, or both depending on what you think is sufficient for the feature you added.

Did you test this in sim?

Yes/No

Did you test this on the rover?

Yes/No

Did you add unit tests?

Yes/No (If not explain why not)

src/esw/brushed_motors/Controller.cpp Outdated Show resolved Hide resolved
src/esw/brushed_motors/Controller.cpp Outdated Show resolved Hide resolved
src/esw/brushed_motors/Controller.cpp Outdated Show resolved Hide resolved
src/esw/brushed_motors/Controller.h Outdated Show resolved Hide resolved
@tabiosg
Copy link
Contributor

tabiosg commented May 3, 2023

Oh this is 🔥

@tabiosg tabiosg added the esw label May 3, 2023
@tabiosg tabiosg linked an issue May 3, 2023 that may be closed by this pull request

// if key is absent, no motor with that key has been made live
auto it = liveMap.find(key);
if (it != liveMap.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wait I think you'll want to put the unique lock outside of the if statement, I think it loses scope right after it leaves the if statement. So I think you can find a way to move it outside the if statement (the if statement is only necessary for emplacing the key,state into the liveMap

if (it == liveMap.end()) {
LiveState state;
state.jointName = name;
liveMap.emplace(key, state);
Copy link
Contributor

Choose a reason for hiding this comment

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

you should use a lock guard whenever emplacing (basically just need to put a lock and unlock around the emplace, but a lock_guard can do that.(something like std::lock_guardstd::mutex lock(state.liveMutex); )

// EFFECTS: I2C bus, if not already live,
// configures the physical controller.
// Then makes live.

std::unordered_map<uint8_t, LiveState> Controller::liveMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if you ran into this issue when emplacing but if you run into issues when emplacing, it's probably because C++ does not know how to handle default stuff when it is a uint8_t (it requires a hash). An easy and acceptable fix is to just make the unordered map take an integer fr the key

Copy link
Contributor Author

@CameronTressler CameronTressler left a comment

Choose a reason for hiding this comment

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

Yeah I think this looks really good overall, I've made some pretty nitpicky comments. Can you also remove some of the old commented out code when you get a chance?

src/esw/brushed_motors/Controller.cpp Outdated Show resolved Hide resolved
src/esw/brushed_motors/Controller.cpp Outdated Show resolved Hide resolved
src/esw/brushed_motors/Controller.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@tabiosg tabiosg left a comment

Choose a reason for hiding this comment

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

lgtm! Other than that, may you fix the merge conflicts?

@CameronTressler
Copy link
Contributor Author

Looks great, need to test before merging though

@CameronTressler CameronTressler marked this pull request as ready for review May 10, 2023 22:35
@CameronTressler CameronTressler merged commit 0930165 into master May 12, 2023
2 checks passed
@CameronTressler CameronTressler deleted the isabel/makeLive branch May 12, 2023 03:09
tabiosg pushed a commit that referenced this pull request May 12, 2023
--------
Co-authored-by: wisabel <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
tabiosg pushed a commit that referenced this pull request May 12, 2023
--------
Co-authored-by: wisabel0 <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
tabiosg pushed a commit that referenced this pull request May 12, 2023
--------
Co-authored-by: wisabel0 <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
tabiosg added a commit that referenced this pull request May 12, 2023
Co-authored-by: wisabel0 <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
tabiosg added a commit that referenced this pull request May 12, 2023
Co-authored-by: wisabel0 <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
tabiosg added a commit that referenced this pull request May 12, 2023
Co-authored-by: wisabel0 <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
tabiosg added a commit that referenced this pull request May 12, 2023
Co-authored-by: wisabel0 <wisabel@umich.edu>
Co-authored-by: tabiosg <gutstabios@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change makeLive to properly swap between controllers for brushed motors
3 participants