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/libraries/AP_ESC_Telem/AP_ESC_Telem_SITL.cpp
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#include "AP_ESC_Telem_SITL.h"16#include "AP_ESC_Telem.h"17#include <AP_HAL/AP_HAL.h>18#include <SITL/SITL.h>1920#if CONFIG_HAL_BOARD == HAL_BOARD_SITL2122#include <AP_Math/AP_Math.h>2324extern const AP_HAL::HAL& hal;2526AP_ESC_Telem_SITL::AP_ESC_Telem_SITL()27{28}2930void AP_ESC_Telem_SITL::update()31{32SITL::SIM* sitl = AP::sitl();3334if (!sitl) {35return;36}3738#if HAL_WITH_ESC_TELEM3940if (AP_HAL::millis64() < 6000) {41// this prevents us sending blank data at startup, which triggers42// ESC telem messages for all channels43return;44}45uint32_t mask = sitl->state.motor_mask;4647/*48mask out motors we should not be providing telemetry for. On49AP_Periph SIM_CAN_SRV_MSK are the outputs we will provide50telemetry for, on the main firmware it is the ones we don't51provide telemetry for52*/53#if defined(HAL_BUILD_AP_PERIPH)54mask &= uint32_t(sitl->can_servo_mask);55#else56mask &= ~uint32_t(sitl->can_servo_mask);57#endif58uint8_t bit;5960while ((bit = __builtin_ffs(mask)) != 0) {61uint8_t motor = bit-1;62mask &= ~(1U<<motor);6364const float min_rpm = hal.util->get_soft_armed()? sitl->esc_rpm_armed : 0;65update_rpm(motor, MAX(min_rpm, sitl->state.rpm[motor]));6667// some fake values so that is_telemetry_active() returns true68TelemetryData t {69.temperature_cdeg = 3200,70.voltage = 16.8f,71.current = 0.8f,72.consumption_mah = 1.0f,73.motor_temp_cdeg = 3500,74#if AP_EXTENDED_ESC_TELEM_ENABLED75.input_duty = 1,76.output_duty = 2,77.flags = 3,78.power_percentage = 4,79#endif80};8182update_telem_data(motor, t,83AP_ESC_Telem_Backend::TelemetryType::CURRENT84| AP_ESC_Telem_Backend::TelemetryType::VOLTAGE85| AP_ESC_Telem_Backend::TelemetryType::CONSUMPTION86| AP_ESC_Telem_Backend::TelemetryType::TEMPERATURE87| AP_ESC_Telem_Backend::TelemetryType::MOTOR_TEMPERATURE88#if AP_EXTENDED_ESC_TELEM_ENABLED89| AP_ESC_Telem_Backend::TelemetryType::POWER_PERCENTAGE90| AP_ESC_Telem_Backend::TelemetryType::INPUT_DUTY91| AP_ESC_Telem_Backend::TelemetryType::OUTPUT_DUTY92| AP_ESC_Telem_Backend::TelemetryType::FLAGS93#endif94);95}96#endif97}9899#endif100101102