-
Notifications
You must be signed in to change notification settings - Fork 1
Added handling methods through mavlink #244
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
Draft
Michal-Mankowski
wants to merge
1
commit into
master
Choose a base branch
from
mima_mavlink_methods
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#include <vector> | ||
#include "apps/fc/radio_service/radio_app.h" | ||
#include "core/common/condition.h" | ||
#include "apps/fc/main_service/rocket_state.h" | ||
|
||
namespace srp { | ||
namespace apps { | ||
|
@@ -28,6 +29,7 @@ constexpr auto KGPS_UART_baudrate = B115200; | |
constexpr auto kSystemId = 1; | ||
constexpr auto kComponentId = 200; | ||
constexpr auto kTime = 1000; | ||
constexpr auto kBufferSize = 12; | ||
} // namespace | ||
|
||
void RadioApp::TransmittingLoop(const std::stop_token& token) { | ||
|
@@ -72,15 +74,101 @@ void RadioApp::TransmittingLoop(const std::stop_token& token) { | |
} | ||
} | ||
|
||
void RadioApp::ListeningLoop(const std::stop_token& token) { | ||
mavlink_message_t msg; | ||
mavlink_status_t status; | ||
|
||
while (!token.stop_requested()) { | ||
auto bytes_read_opt = uart_->Read(kBufferSize); | ||
if (!bytes_read_opt.has_value()) { | ||
continue; | ||
} | ||
auto bytes_read = bytes_read_opt.value(); | ||
for (uint8_t byte : bytes_read) { | ||
if (mavlink_parse_char(MAVLINK_COMM_0, byte, &msg, &status)) { | ||
Comment on lines
+82
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skoro i tak to potem dzielisz na uint8, to moze odczytywać po 1 bajcie z uart? |
||
uint8_t status = 0; | ||
switch (msg.msgid) { | ||
case 144: { | ||
uint8_t abort = RocketState_t::ABORD; | ||
auto result = this->main_service_handler->setMode(abort); | ||
status = result.HasValue() ? result.Value() : false; | ||
break; | ||
} | ||
case 145: { | ||
// uint8_t hold = ; | ||
// auto result = this->main_service_handler->setMode(hold); | ||
// status = result.HasValue() ? result.Value() : false; | ||
break; | ||
} | ||
case 146: { | ||
uint8_t cmd_change = mavlink_msg_simba_cmd_change_get_cmd_change(&msg); | ||
auto result = this->main_service_handler->setMode(cmd_change); | ||
status = result.HasValue() ? result.Value() : false; | ||
} | ||
case 147: { | ||
uint8_t actuator_id = mavlink_msg_simba_actuator_cmd_get_actuator_id(&msg); | ||
uint8_t value = mavlink_msg_simba_actuator_cmd_get_value(&msg); | ||
status = ActuatorCMD(actuator_id, value); | ||
break; | ||
} | ||
} | ||
SendAck(msg.msgid, msg.seq, status); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void RadioApp::SendAck(uint8_t msgId, uint8_t msgSeq, uint8_t status) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. zmien argumenty na enumy z simba mavlink, jak bedziesz mial nowa wersje |
||
mavlink_message_t msg; | ||
uint8_t buffer[MAVLINK_MAX_PACKET_LEN]; | ||
// change to actual ack pack func | ||
mavlink_msg_simba_gps_pack(kSystemId, kComponentId, &msg, msgId, msgSeq, status); | ||
uint16_t len = mavlink_msg_to_send_buffer(buffer, &msg); | ||
mavl_logger.LogDebug() << std::vector<uint8_t>(buffer, buffer + len); | ||
uart_->Write(std::vector<uint8_t>(buffer, buffer + len)); | ||
} | ||
|
||
bool RadioApp::ActuatorCMD(uint8_t actuator_id, uint8_t value) { | ||
switch (actuator_id) { | ||
case 1: { | ||
auto result = this->servo_service_handler->SetMainServoValue(value); | ||
return result.HasValue() ? result.Value() : false; | ||
break; | ||
} | ||
case 2: { | ||
auto result = this->servo_service_handler->SetVentServoValue(value); | ||
return result.HasValue() ? result.Value() : false; | ||
break; | ||
} | ||
case 3: { | ||
if (value == 1) { | ||
auto result = this->recovery_service_handler->OpenReefedParachute(); | ||
return result.HasValue() ? result.Value() : false; | ||
} | ||
break; | ||
} | ||
case 4: { | ||
if (value == 1) { | ||
auto result = this->recovery_service_handler->UnreefeParachute(); | ||
return result.HasValue() ? result.Value() : false; | ||
} | ||
break; | ||
} | ||
} | ||
return false; | ||
} | ||
int RadioApp::Run(const std::stop_token& token) { | ||
std::jthread transmitting_thread([this](const std::stop_token& t) { | ||
this->TransmittingLoop(t); | ||
}); | ||
core::condition::wait(token); | ||
service_ipc->StopOffer(); | ||
service_udp->StopOffer(); | ||
uart_->Close(); | ||
return core::ErrorCode::kOk; | ||
std::jthread listening_thread([this](const std::stop_token& t) { | ||
this->ListeningLoop(t); | ||
}); | ||
core::condition::wait(token); | ||
service_ipc->StopOffer(); | ||
service_udp->StopOffer(); | ||
uart_->Close(); | ||
return core::ErrorCode::kOk; | ||
} | ||
|
||
void RadioApp::InitUart(std::unique_ptr<core::uart::IUartDriver> uart) { | ||
|
@@ -222,9 +310,10 @@ primer_service_proxy{ara::core::InstanceSpecifier{kPrimer_service_path_name}}, | |
primer_service_handler{nullptr}, | ||
servo_service_proxy{ara::core::InstanceSpecifier{kServo_service_path_name}}, | ||
servo_service_handler{nullptr}, | ||
main_service_handler{nullptr}, | ||
recovery_service_handler{nullptr}, | ||
mavl_logger{ara::log::LoggingMenager::GetInstance()->CreateLogger("MAVL", "", ara::log::LogLevel::kDebug)} | ||
{ | ||
} | ||
|
||
} // namespace apps | ||
} // namespace srp |
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
czemu akurat 12?
skoro masz dostępne
MAVLINK_MAX_PACKET_LEN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spojrzałem ile bitów trzeba wysłać przed i po wiadomości no i jakiej długości jest największa wiadomość. Wyszło mi 12 z tych szybkich obliczeń.