-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_RCProtocol: add support for RC input from SITL FDM data
- Loading branch information
1 parent
94050fb
commit ad29cba
Showing
7 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "AP_RCProtocol_config.h" | ||
|
||
#if AP_RCPROTOCOL_FDM_ENABLED | ||
|
||
#include "AP_RCProtocol_FDM.h" | ||
|
||
#include <AP_HAL/AP_HAL.h> | ||
#include <SITL/SITL.h> | ||
|
||
extern const AP_HAL::HAL& hal; | ||
|
||
void AP_RCProtocol_FDM::update() | ||
{ | ||
const auto sitl = AP::sitl(); | ||
if (sitl == nullptr) { | ||
return; | ||
} | ||
|
||
const auto &fdm = sitl->state; | ||
|
||
// see if there's fresh input. Until timestamps are worked out, | ||
// just check for non-zero values: | ||
if (fdm.rcin_chan_count == 0) { | ||
return; | ||
} | ||
|
||
// simulate RC input at 50Hz | ||
if (AP_HAL::millis() - last_input_ms < 20) { | ||
return; | ||
} | ||
|
||
last_input_ms = AP_HAL::millis(); | ||
|
||
// scale from FDM 0-1 floats to PWM values | ||
// these are the values that will be fed into the autopilot. | ||
uint16_t pwm_input[16]; | ||
const uint8_t count = MIN(ARRAY_SIZE(pwm_input), fdm.rcin_chan_count); | ||
for (uint8_t i=0; i<count; i++) { | ||
pwm_input[i] = 1000 + fdm.rcin[i] * 1000; | ||
} | ||
add_input( | ||
count, | ||
pwm_input, | ||
false, // failsafe | ||
0, // check me | ||
0 // link quality | ||
); | ||
} | ||
|
||
#endif // AP_RCPROTOCOL_FDM_ENABLED |
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "AP_RCProtocol_config.h" | ||
|
||
#if AP_RCPROTOCOL_FDM_ENABLED | ||
|
||
#include "AP_RCProtocol_Backend.h" | ||
|
||
class AP_RCProtocol_FDM : public AP_RCProtocol_Backend { | ||
public: | ||
|
||
using AP_RCProtocol_Backend::AP_RCProtocol_Backend; | ||
|
||
void update() override; | ||
|
||
bool active() const { return last_input_ms > 0; } | ||
|
||
private: | ||
|
||
uint32_t last_input_ms; | ||
}; | ||
|
||
|
||
#endif // AP_RCPROTOCOL_FDM_ENABLED |
This file contains 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 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 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