|
|
|
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* Copyright (c) 2019-2021 PX4 Development Team. All rights reserved. |
|
|
|
|
* Copyright (c) 2022 PX4 Development Team. All rights reserved. |
|
|
|
|
* |
|
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
|
* modification, are permitted provided that the following conditions |
|
|
|
@ -31,67 +31,47 @@
@@ -31,67 +31,47 @@
|
|
|
|
|
* |
|
|
|
|
****************************************************************************/ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author CUAVcaijie <caijie@cuav.net> |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "safetybutton.hpp" |
|
|
|
|
#include <cstdint> |
|
|
|
|
#include <drivers/drv_hrt.h> |
|
|
|
|
#include <systemlib/err.h> |
|
|
|
|
#include <mathlib/mathlib.h> |
|
|
|
|
#include <parameters/param.h> |
|
|
|
|
#include "safety_button.hpp" |
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
using namespace time_literals; |
|
|
|
|
const char *const UavcanSafetyBridge::NAME = "safety"; |
|
|
|
|
const char *const UavcanSafetyButtonBridge::NAME = "safety_button"; |
|
|
|
|
|
|
|
|
|
UavcanSafetyBridge::UavcanSafetyBridge(uavcan::INode &node) : |
|
|
|
|
_node(node), |
|
|
|
|
_sub_safety(node), |
|
|
|
|
_pub_safety(node) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
UavcanSafetyButtonBridge::UavcanSafetyButtonBridge(uavcan::INode &node) : |
|
|
|
|
UavcanSensorBridgeBase("uavcan_safety_button", |
|
|
|
|
ORB_ID(safety)), // TODO: either multiple publishers or `button_event` uORB topic
|
|
|
|
|
_sub_button(node) |
|
|
|
|
{ } |
|
|
|
|
|
|
|
|
|
int UavcanSafetyBridge::init() |
|
|
|
|
int UavcanSafetyButtonBridge::init() |
|
|
|
|
{ |
|
|
|
|
int res = _pub_safety.init(uavcan::TransferPriority::MiddleLower); |
|
|
|
|
int res = _sub_button.start(ButtonCbBinder(this, &UavcanSafetyButtonBridge::button_sub_cb)); |
|
|
|
|
|
|
|
|
|
if (res < 0) { |
|
|
|
|
printf("safety pub failed %i", res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
res = _sub_safety.start(SafetyCommandCbBinder(this, &UavcanSafetyBridge::safety_sub_cb)); |
|
|
|
|
|
|
|
|
|
if (res < 0) { |
|
|
|
|
printf("safety pub failed %i", res); |
|
|
|
|
DEVICE_LOG("failed to start uavcan sub: %d", res); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned UavcanSafetyBridge::get_num_redundant_channels() const |
|
|
|
|
{ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UavcanSafetyBridge::print_status() const |
|
|
|
|
void UavcanSafetyButtonBridge::button_sub_cb(const |
|
|
|
|
uavcan::ReceivedDataStructure<ardupilot::indication::Button> &msg) |
|
|
|
|
{ |
|
|
|
|
bool is_safety = msg.button == ardupilot::indication::Button::BUTTON_SAFETY; |
|
|
|
|
bool pressed = msg.press_time >= 10; // 0.1s increments
|
|
|
|
|
|
|
|
|
|
if (is_safety && pressed) { |
|
|
|
|
safety_s safety = {}; |
|
|
|
|
safety.timestamp = hrt_absolute_time(); |
|
|
|
|
safety.safety_switch_available = true; |
|
|
|
|
safety.safety_off = true; |
|
|
|
|
publish(msg.getSrcNodeID().get(), &safety); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UavcanSafetyBridge::safety_sub_cb(const uavcan::ReceivedDataStructure<ardupilot::indication::Button> &msg) |
|
|
|
|
int UavcanSafetyButtonBridge::init_driver(uavcan_bridge::Channel *channel) |
|
|
|
|
{ |
|
|
|
|
if (msg.press_time > 10 && msg.button == 1) { |
|
|
|
|
if (_safety_disabled) { return; } |
|
|
|
|
|
|
|
|
|
_safety_disabled = true; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
_safety_disabled = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return PX4_OK; |
|
|
|
|
} |