Line data Source code
1 : /* 2 : * This file is free software: you can redistribute it and/or modify it 3 : * under the terms of the GNU General Public License as published by the 4 : * Free Software Foundation, either version 3 of the License, or 5 : * (at your option) any later version. 6 : * 7 : * This file is distributed in the hope that it will be useful, but 8 : * WITHOUT ANY WARRANTY; without even the implied warranty of 9 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 : * See the GNU General Public License for more details. 11 : * 12 : * You should have received a copy of the GNU General Public License along 13 : * with this program. If not, see <http://www.gnu.org/licenses/>. 14 : * 15 : * Author: Oliver Walters / Currawong Engineering Pty Ltd 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "AP_PiccoloCAN_config.h" 21 : 22 : #if AP_PICCOLOCAN_ENABLED 23 : 24 : #include <AP_Math/AP_Math.h> 25 : #include <AP_CANManager/AP_CANManager.h> 26 : #include <AP_ESC_Telem/AP_ESC_Telem_Backend.h> 27 : 28 : #include "AP_PiccoloCAN_config.h" 29 : #include "AP_PiccoloCAN_Device.h" 30 : #include "piccolo_protocol/ESCPackets.h" 31 : 32 : #define PICCOLO_CAN_MAX_NUM_ESC 16 33 : #define PICCOLO_CAN_MAX_GROUP_ESC (PICCOLO_CAN_MAX_NUM_ESC / 4) 34 : 35 : 36 : /* 37 : * Class representing an individual PiccoloCAN ESC 38 : */ 39 : class AP_PiccoloCAN_ESC : public AP_PiccoloCAN_Device, public AP_ESC_Telem_Backend 40 : { 41 : public: 42 : 43 : virtual bool handle_can_frame(AP_HAL::CANFrame &frame) override; 44 : 45 0 : bool is_sw_inhibited(void) const { return status.statusA.status.swInhibit; } 46 0 : bool is_hw_inhibited(void) const { return status.statusA.status.hwInhibit; } 47 : 48 0 : virtual bool is_enabled(void) const override { return !is_sw_inhibited() && !is_hw_inhibited(); } 49 : 50 0 : float voltage() { return (float) status.statusB.voltage * 0.01f; } // Convert to V 51 0 : float current() { return (float) status.statusB.current * 0.01f; } // Convert to A 52 0 : uint16_t rpm() { return status.statusA.rpm; } 53 0 : float temperature() { return MAX(status.statusB.escTemperature, status.statusC.fetTemperature); } 54 0 : float motorTemperature() { return status.statusB.motorTemperature; } 55 : 56 : int16_t command; //! Raw command to send to each ESC 57 : bool newCommand; //! Is the command "new"? 58 : bool newTelemetry; //! Is there new telemetry data available? 59 : 60 : // Status / telemetry data 61 : struct Status_t { 62 : ESC_StatusA_t statusA; 63 : ESC_StatusB_t statusB; 64 : ESC_StatusC_t statusC; 65 : 66 : ESC_WarningBits_t warnings; 67 : ESC_ErrorBits_t errors; 68 : } status; 69 : 70 : // Settings information 71 : struct Settings_t { 72 : ESC_Firmware_t firmware; 73 : ESC_Address_t address; 74 : ESC_EEPROMSettings_t eeprom; 75 : } settings; 76 : }; 77 : 78 : #endif // AP_PICCOLOCAN_ENABLED