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

Basic AM thread in SM #30

Merged
merged 21 commits into from
Nov 27, 2023
Merged

Basic AM thread in SM #30

merged 21 commits into from
Nov 27, 2023

Conversation

lekangwang
Copy link
Contributor

@lekangwang lekangwang commented Sep 1, 2023

Description

What was completed, changed, or updated?

  • Add private AM class instance as a SM class member
  • Modify flyManually() SM member function to set throttle, yaw, pitch and roll via a setter to allow communication with AM which will operate the motors using PWM accordingly (via outputToMotor() method)
  • Added static runAM() function to run runControlLoopIteration() at set frequency
  • Initialize/destroy AM thread in SM constructor/destructor

Why was this done (if applicable)?

  • Have SM spawn AM thread to use AM and start communicating new RC inputs to AM thread

Testing

What manual tests were used to validate the code?

  • Code compiles
  • Did some hardware tests to validate that AM thread runControlLoopIteration(); receives updated values to AM controller struct

What unit tests were used to validate the code?

  • None so far

Documentation

Milestone number and name:

Link to Asana task:

Link to Confluence documentation:


Reminders

  • Add reviewers to the PR

  • Mention the PR in the appropriate discord channel

@lekangwang lekangwang self-assigned this Sep 1, 2023
@lekangwang lekangwang changed the base branch from main to basic-system-manager September 1, 2023 01:58
@lekangwang lekangwang changed the base branch from basic-system-manager to main September 6, 2023 02:03
@lekangwang lekangwang changed the base branch from main to basic-system-manager September 6, 2023 02:03
@lekangwang lekangwang marked this pull request as ready for review September 11, 2023 14:53
SystemManager/Src/SystemManager.cpp Outdated Show resolved Hide resolved
Comment on lines 55 to 62
if (this->rcInputs_.arm >= (SBUS_MAX/2)) {
am_input.roll = rcInputs_.roll;
am_input.pitch = rcInputs_.pitch;
am_input.yaw = rcInputs_.yaw;
am_input.throttle = rcInputs_.throttle;
AM::AttitudeManager::setControlInputs(am_input);
} else {
AM::AttitudeManager::setControlInputs(am_input);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should add arm and disarm methods directly into AM, so as to ensure that we can't accidentally write some value to the motors if we are in a flight mode that does not just directly map the controller inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you saying we should add arm/disarm logic to AM::setControlInputs()? I'm guessing you want to disarm based on some flightmode property.

watchdog_(&hiwdg),
am_instance_(config::flightmodes[config::DEFAULT_FLIGHTMODE].flightmodeConstructor())
{
xTaskCreate(runAM, "AM Thread", 400U, (void*)&am_instance_, osPriorityNormal, &AM_handle_);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't remember if anything else needs to be done to start a task (I don't think so though...). Were you able to test this on hardware?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

This looks promising.

I'm running the AM thread at a period of 1 second and the set AM instructions thread at a period of 2 seconds (which simply increments the AM control struct using the static getter and setter methods defined in AM).

The AM thread runControlLoopIteration() seems to be picking up the new values at the regular interval.

am_instance->runControlLoopIteration(AM::AttitudeManager::getControlInputs());
vTaskDelayUntil(&xLastWakeTime, AM_PERIOD_MS);
}
}

void SystemManager::flyManually() {
for(;;){
Copy link
Contributor

Choose a reason for hiding this comment

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

Where would this be called? I imagine it would ideally run repeatedly at the same rate as runAM so that it has up-to-date control inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called in main.cpp when we create a SM thread that calls flyManually()

Copy link

@SnackkOverflowError SnackkOverflowError left a comment

Choose a reason for hiding this comment

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

lets get this money

@HardyYu HardyYu self-requested a review November 27, 2023 05:13
@lekangwang lekangwang merged commit a57de6a into basic-system-manager Nov 27, 2023
2 checks passed
@DerekTang04 DerekTang04 deleted the am-thread-instance branch May 6, 2024 22:10
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.

7 participants