Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/AP_Periph/proximity.cpp
Views: 1798
#include "AP_Periph.h"12#ifdef HAL_PERIPH_ENABLE_PROXIMITY34/*5proximity support6*/78#include <dronecan_msgs.h>910void AP_Periph_FW::can_proximity_update()11{12if (proximity.get_type(0) == AP_Proximity::Type::None) {13return;14}1516uint32_t now = AP_HAL::millis();17static uint32_t last_update_ms;18if (g.proximity_max_rate > 0 &&19now - last_update_ms < 1000/g.proximity_max_rate) {20// limit to max rate21return;22}23last_update_ms = now;24proximity.update();25AP_Proximity::Status status = proximity.get_status();26if (status <= AP_Proximity::Status::NoData) {27// don't send any data28return;29}3031ardupilot_equipment_proximity_sensor_Proximity pkt {};3233const uint8_t obstacle_count = proximity.get_obstacle_count();3435// if no objects return36if (obstacle_count == 0) {37return;38}3940// calculate maximum roll, pitch values from objects41for (uint8_t i=0; i<obstacle_count; i++) {42if (!proximity.get_obstacle_info(i, pkt.yaw, pkt.pitch, pkt.distance)) {43// not a valid obstacle44continue;45}4647pkt.sensor_id = proximity.get_address(0);4849switch (status) {50case AP_Proximity::Status::NotConnected:51pkt.reading_type = ARDUPILOT_EQUIPMENT_PROXIMITY_SENSOR_PROXIMITY_READING_TYPE_NOT_CONNECTED;52break;53case AP_Proximity::Status::Good:54pkt.reading_type = ARDUPILOT_EQUIPMENT_PROXIMITY_SENSOR_PROXIMITY_READING_TYPE_GOOD;55break;56case AP_Proximity::Status::NoData:57default:58pkt.reading_type = ARDUPILOT_EQUIPMENT_PROXIMITY_SENSOR_PROXIMITY_READING_TYPE_NO_DATA;59break;60}6162uint8_t buffer[ARDUPILOT_EQUIPMENT_PROXIMITY_SENSOR_PROXIMITY_MAX_SIZE];63uint16_t total_size = ardupilot_equipment_proximity_sensor_Proximity_encode(&pkt, buffer, !periph.canfdout());6465canard_broadcast(ARDUPILOT_EQUIPMENT_PROXIMITY_SENSOR_PROXIMITY_SIGNATURE,66ARDUPILOT_EQUIPMENT_PROXIMITY_SENSOR_PROXIMITY_ID,67CANARD_TRANSFER_PRIORITY_LOW,68&buffer[0],69total_size);7071}72}7374#endif // HAL_PERIPH_ENABLE_PROXIMITY757677