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

Armdevel: Create PID Library #231

Merged
merged 16 commits into from
Jan 12, 2021
Merged

Armdevel: Create PID Library #231

merged 16 commits into from
Jan 12, 2021

Conversation

younesr1
Copy link
Contributor

This lib was tested with test-pid. I apologise to anyone following the git workflow of this feature it has been rough. This feature is finally ready for review

Copy link
Member

@wmmc88 wmmc88 left a comment

Choose a reason for hiding this comment

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

should write a test for threadsafety.

also what are the accumulated errors and average error compared to the matlab?

apps/test-pid/CMakeLists.txt Outdated Show resolved Hide resolved
apps/test-pid/include/control.h Outdated Show resolved Hide resolved
apps/test-pid/include/feedback.h Outdated Show resolved Hide resolved
lib/pid/include/PID.h Outdated Show resolved Hide resolved
lib/pid/include/PID.h Outdated Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
lib/pid/include/PID.h Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
apps/test-pid/CMakeLists.txt Outdated Show resolved Hide resolved
@younesr1
Copy link
Contributor Author

younesr1 commented Jan 2, 2021

should write a test for threadsafety.

also what are the accumulated errors and average error compared to the matlab?

I'll rerun the app sometime this weekend and let you know

@wmmc88
Copy link
Member

wmmc88 commented Jan 2, 2021

should write a test for threadsafety.
also what are the accumulated errors and average error compared to the matlab?

I'll rerun the app sometime this weekend and let you know

maybe have the expected value saved in the test and have an assert that checks against it. almost like a unit test haha.

@wmmc88 wmmc88 mentioned this pull request Jan 3, 2021
@younesr1
Copy link
Contributor Author

younesr1 commented Jan 3, 2021

I didnt add a test for threadability. the work needed to create any sort of meaningful test is too much to be worth it. i think we're safe skipping threadability test since it we lock a mutex with lock guard at the top of every function basically

@younesr1 younesr1 requested a review from wmmc88 January 3, 2021 22:11
Copy link
Member

@wmmc88 wmmc88 left a comment

Choose a reason for hiding this comment

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

couple comments from the old review weren't addressed and got auto dismissed because of changes

apps/test-pid/src/main.cpp Outdated Show resolved Hide resolved
apps/test-pid/src/main.cpp Outdated Show resolved Hide resolved

realOutput_ = 0.0;
void PID::Pid::updateProportionalGain(uint32_t p) {
std::lock_guard<Mutex> lock(m_mutex);
Copy link
Member

Choose a reason for hiding this comment

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

bump

float paths = computePPath(error);
paths += computeIPath(error, dt);
paths += m_antiKickback ? computeDPathOnPV(error, dt) : computeDPathOnError(processVariable, dt);
paths = std::clamp(paths, static_cast<float>(m_lowerBound), static_cast<float>(m_upperBound));
Copy link
Member

Choose a reason for hiding this comment

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

bump

lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
lib/pid/src/PID.cpp Outdated Show resolved Hide resolved
void PID::setDeadZoneError(float error) {
deadZoneError_ = error;
void PID::PID::reset() {
std::lock_guard<Mutex> lock(m_mutex);
Copy link
Member

Choose a reason for hiding this comment

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

bump on the scoped lock comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wdym bump?

Copy link
Member

Choose a reason for hiding this comment

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

Look at my previous comment about lockguard vs scoped lock

Copy link
Contributor Author

@younesr1 younesr1 Jan 4, 2021

Choose a reason for hiding this comment

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

I dont see any comment abt scoped lock (edit: nvm i found it)

@cindyli-13
Copy link
Member

Do we need feed-forward support or ability to accept tuning params on the fly? Or will those be future issues

lib/pid/include/PID.h Outdated Show resolved Hide resolved
@younesr1
Copy link
Contributor Author

younesr1 commented Jan 4, 2021

Do we need feed-forward support or ability to accept tuning params on the fly? Or will those be future issues

this is just a pid lib feed fwd is part of the control loop which is at a higher level. this includes on the fly tuning. see comment at the top of the header

@wmmc88
Copy link
Member

wmmc88 commented Jan 4, 2021

Do we need feed-forward support or ability to accept tuning params on the fly? Or will those be future issues

this is just a pid lib feed fwd is part of the control loop which is at a higher level. this includes on the fly tuning. see comment at the top of the header

something i just thought about re: feedforward is that by adding the feedforward outside of PID, we may run into issues with:

  1. going over the saturation limit
  2. pid error being wrong because its using a setpoint that isnt the true setpoint (that includes the feedforward term)

@younesr1
Copy link
Contributor Author

younesr1 commented Jan 5, 2021

This PR is currently on hold. The average error is very large atm, there must be a bug in the code

@younesr1
Copy link
Contributor Author

This PR is no longer on hold

Copy link
Member

@wmmc88 wmmc88 left a comment

Choose a reason for hiding this comment

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

lgtm. pls update the other branch and tag it or smth

@younesr1 younesr1 merged commit 1425a5a into armdevel Jan 12, 2021
@younesr1 younesr1 deleted the younes/pidforarmdevel branch January 12, 2021 02:41
younesr1 added a commit that referenced this pull request Feb 17, 2021
* Move Encoder class and create new sensor class

* Move files to better folders

* Modify Moisture sensor to use new Sensor Base

* Edit cmake file for sensor folder

* Update Moisture Sensor files and test app

* Modify make files to build moved files

* Changes to 'READ()' after PR

* modify sensor read functions

* Add actuator base class and derived classes (#171)

* Add actuator base class and derived classes

* Actuators lib: tweak actuator classes, delete old actuator libraries

* Actuators lib: add copy constructor

* Actuators lib: apply feedback comments

* Actuators lib: apply feedback comments again

* Actuators lib: Wrap classes in namespaces

* Actuators lib: fix compile errors

* Actuators lib: fix comments, rename variables, and other small tweaks

* Actuators lib: fix comments and variable names again

* Actuators lib: add std::abs guards

* Armdevel: Create PID Library (#231)

* created pid lib and fixed easily fixable errors

* Update apps/test-pid/CMakeLists.txt

Co-authored-by: Melvin Wang <[email protected]>

* implemented melvin comments

* Update apps/test-pid/CMakeLists.txt

Co-authored-by: Melvin Wang <[email protected]>

* implemented melvin comments

* formatting

* added mention of matlab code

* use scoped lock. use better anti windup.

* use new values

* avg error is now 37

* fix formatting

* debug commit (not final commit)

* ready for review

Co-authored-by: yreda1999 <[email protected]>
Co-authored-by: Melvin Wang <[email protected]>

* Younes: simplified interface, added namespaces, add config structs

* Further updates after PR

* Fixed and updated Moisture sensor and app

* update relative encoder files

* Update absolute encoder files

* fix error with pwm in

* initial commit

* arm main compiles!

* gimbtonomy also compiles

* ready for reviews

* fix silly mistake

* change protected fields of final classes to private

* forgot one file

* added comments with instructions for felix and orson

* implemented feedback and fixed failing test apps

* changed pointers to refs where appropriate

* fixed melvin anc cindy comments

* remove current sensors from arm config headers since we wont have em ready for SAR

* fix formatting

* fix formatting angain

* fixed test can app

* Fw/younes actuator (#280)

* Update science pins

* Update pin names, update science apps

* Updated for clang format

* Revert "Updated for clang format"

This reverts commit f3831a1.

* Proper clang formatting

* PR comments

* Updating PR for changes on base

* update servo range of motion

* Missed a file for clang

* Fixed code which was mistakenly changed

Co-authored-by: Felix Wong <[email protected]>

* fix formatting

* fixed check not running

* fixed comments

* updated version of bridge

Co-authored-by: Felix Wong <[email protected]>
Co-authored-by: Cindy Li <[email protected]>
Co-authored-by: yreda1999 <[email protected]>
Co-authored-by: Melvin Wang <[email protected]>
Co-authored-by: younes <[email protected]>
Co-authored-by: FK3wong <[email protected]>
Co-authored-by: Felix Wong <[email protected]>
kiransuren pushed a commit that referenced this pull request Apr 4, 2021
* Move Encoder class and create new sensor class

* Move files to better folders

* Modify Moisture sensor to use new Sensor Base

* Edit cmake file for sensor folder

* Update Moisture Sensor files and test app

* Modify make files to build moved files

* Changes to 'READ()' after PR

* modify sensor read functions

* Add actuator base class and derived classes (#171)

* Add actuator base class and derived classes

* Actuators lib: tweak actuator classes, delete old actuator libraries

* Actuators lib: add copy constructor

* Actuators lib: apply feedback comments

* Actuators lib: apply feedback comments again

* Actuators lib: Wrap classes in namespaces

* Actuators lib: fix compile errors

* Actuators lib: fix comments, rename variables, and other small tweaks

* Actuators lib: fix comments and variable names again

* Actuators lib: add std::abs guards

* Armdevel: Create PID Library (#231)

* created pid lib and fixed easily fixable errors

* Update apps/test-pid/CMakeLists.txt

Co-authored-by: Melvin Wang <[email protected]>

* implemented melvin comments

* Update apps/test-pid/CMakeLists.txt

Co-authored-by: Melvin Wang <[email protected]>

* implemented melvin comments

* formatting

* added mention of matlab code

* use scoped lock. use better anti windup.

* use new values

* avg error is now 37

* fix formatting

* debug commit (not final commit)

* ready for review

Co-authored-by: yreda1999 <[email protected]>
Co-authored-by: Melvin Wang <[email protected]>

* Younes: simplified interface, added namespaces, add config structs

* Further updates after PR

* Fixed and updated Moisture sensor and app

* update relative encoder files

* Update absolute encoder files

* fix error with pwm in

* initial commit

* arm main compiles!

* gimbtonomy also compiles

* ready for reviews

* fix silly mistake

* change protected fields of final classes to private

* forgot one file

* added comments with instructions for felix and orson

* implemented feedback and fixed failing test apps

* changed pointers to refs where appropriate

* fixed melvin anc cindy comments

* remove current sensors from arm config headers since we wont have em ready for SAR

* fix formatting

* fix formatting angain

* fixed test can app

* Fw/younes actuator (#280)

* Update science pins

* Update pin names, update science apps

* Updated for clang format

* Revert "Updated for clang format"

This reverts commit f3831a1.

* Proper clang formatting

* PR comments

* Updating PR for changes on base

* update servo range of motion

* Missed a file for clang

* Fixed code which was mistakenly changed

Co-authored-by: Felix Wong <[email protected]>

* fix formatting

* fixed check not running

* fixed comments

* updated version of bridge

Co-authored-by: Felix Wong <[email protected]>
Co-authored-by: Cindy Li <[email protected]>
Co-authored-by: yreda1999 <[email protected]>
Co-authored-by: Melvin Wang <[email protected]>
Co-authored-by: younes <[email protected]>
Co-authored-by: FK3wong <[email protected]>
Co-authored-by: Felix Wong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants