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

QURT: update motor order and add safety state #27550

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Tools/Frame_params/ModalAI/AutonomyDevKit.parm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ FLTMODE1 5
FLTMODE4 2
FLTMODE_CH 6

# motor ordering
SERVO1_FUNCTION 34
SERVO2_FUNCTION 35
SERVO3_FUNCTION 33
SERVO4_FUNCTION 36
tridge marked this conversation as resolved.
Show resolved Hide resolved

# enable PID logging
LOG_BITMASK 65535

Expand Down
19 changes: 17 additions & 2 deletions libraries/AP_HAL_QURT/RCOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "RCOutput.h"
#include <AP_Math/AP_Math.h>
#include <AP_BoardConfig/AP_BoardConfig.h>

extern const AP_HAL::HAL& hal;

Expand Down Expand Up @@ -114,10 +115,24 @@ void RCOutput::send_receive(void)
return;
}

AP_BoardConfig *boardconfig = AP_BoardConfig::get_singleton();
uint32_t safety_mask = 0;

if (boardconfig != nullptr) {
// mask of channels to allow with safety on
safety_mask = boardconfig->get_safety_mask();
}

int16_t data[5] {};

for (uint8_t i=0; i<4; i++) {
data[esc_map[i]] = pwm_to_esc(period[i]);
uint16_t v = period[i];
if (safety_on && (safety_mask & (1U<<i)) == 0) {
// when safety is on we send 0, which allows us to still
// get feedback telemetry data, including battery voltage
v = 0;
}
data[i] = pwm_to_esc(v);
}

need_write = false;
Expand All @@ -140,7 +155,7 @@ void RCOutput::send_receive(void)
*/
void RCOutput::handle_esc_feedback(const struct esc_response_v2 &pkt)
{
const uint8_t idx = esc_map_rev[pkt.id_state>>4];
const uint8_t idx = pkt.id_state>>4;
if (idx >= ARRAY_SIZE(period)) {
return;
}
Expand Down
18 changes: 14 additions & 4 deletions libraries/AP_HAL_QURT/RCOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class QURT::RCOutput : public AP_HAL::RCOutput, AP_ESC_Telem_Backend
{
public:
friend class QURT::Util;

void init() override;
void set_freq(uint32_t chmask, uint16_t freq_hz) override;
uint16_t get_freq(uint8_t ch) override;
Expand All @@ -27,6 +29,15 @@ class QURT::RCOutput : public AP_HAL::RCOutput, AP_ESC_Telem_Backend
return esc_current;
}

/*
force the safety switch on, disabling output from the ESCs/servos
*/
bool force_safety_on(void) override { safety_on = true; return true; }

/*
force the safety switch off, enabling output from the ESCs/servos
*/
void force_safety_off(void) override { safety_on = false; }

private:
const uint32_t baudrate = 2000000;
Expand Down Expand Up @@ -56,10 +67,6 @@ class QURT::RCOutput : public AP_HAL::RCOutput, AP_ESC_Telem_Backend
void handle_esc_feedback(const struct esc_response_v2 &pkt);
void handle_power_status(const struct esc_power_status &pkt);

// order is RL, FL, FR, RR, map to X frame
const uint8_t esc_map[4] {2, 0, 1, 3};
const uint8_t esc_map_rev[4] {1, 2, 0, 3};

int fd = -1;
uint16_t enable_mask;
static const uint8_t channel_count = 4;
Expand All @@ -72,4 +79,7 @@ class QURT::RCOutput : public AP_HAL::RCOutput, AP_ESC_Telem_Backend

float esc_voltage;
float esc_current;

// start with safety on, gets disabled by AP_BoardConfig
bool safety_on = true;
};
13 changes: 13 additions & 0 deletions libraries/AP_HAL_QURT/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extern const AP_HAL::HAL& hal;

#include "Util.h"
#include "RCOutput.h"

using namespace QURT;

Expand All @@ -20,6 +21,18 @@ uint32_t Util::available_memory(void)
return fc_heap_size() - fc_heap_usage();
}

/*
return state of safety switch, if applicable
*/
Util::safety_state Util::safety_switch_state(void)
{
const auto *rcout = (QURT::RCOutput *)hal.rcout;
if (rcout != nullptr && rcout->safety_on) {
return SAFETY_DISARMED;
}
return SAFETY_ARMED;
}

#if ENABLE_HEAP
void *Util::allocate_heap_memory(size_t size)
{
Expand Down
5 changes: 5 additions & 0 deletions libraries/AP_HAL_QURT/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class QURT::Util : public AP_HAL::Util

uint32_t available_memory(void) override;

/*
return state of safety switch, if applicable
*/
enum safety_state safety_switch_state(void) override;

#if ENABLE_HEAP
// heap functions, note that a heap once alloc'd cannot be dealloc'd
virtual void *allocate_heap_memory(size_t size) override;
Expand Down
Loading