LCOV - code coverage report
Current view: top level - AP_Torqeedo - AP_Torqeedo_Backend.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 2 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             :  
      16             : /*
      17             :    This driver supports communicating with Torqeedo motors that implement the "TQ Bus" protocol
      18             :    which includes the Ultralight, Cruise 2.0 R, Cruise 4.0 R, Travel 503, Travel 1003 and Cruise 10kW
      19             : 
      20             :    The autopilot should be connected either to the battery's tiller connector or directly to the motor
      21             :    as described on the ArduPilot wiki. https://ardupilot.club/rover/docs/common-torqeedo.html
      22             :    TQ Bus is a serial protocol over RS-485 meaning that a serial to RS-485 converter is required.
      23             : 
      24             :        Tiller connection: Autopilot <-> Battery (master) <-> Motor
      25             :        Motor connection:  Autopilot (master) <-> Motor
      26             : 
      27             :     Communication between the components is always initiated by the master with replies sent within 25ms
      28             : 
      29             :     Example "Remote (0x01)" reply message to allow tiller to control motor speed
      30             :     Byte        Field Definition    Example Value   Comments
      31             :     ---------------------------------------------------------------------------------
      32             :     byte 0      Header              0xAC
      33             :     byte 1      TargetAddress       0x00            see MsgAddress enum
      34             :     byte 2      Message ID          0x00            only master populates this. replies have this set to zero
      35             :     byte 3      Flags               0x05            bit0=pin present, bit2=motor speed valid
      36             :     byte 4      Status              0x00            0x20 if byte3=4, 0x0 is byte3=5
      37             :     byte 5      Motor Speed MSB     ----            Motor Speed MSB (-1000 to +1000)
      38             :     byte 6      Motor Speed LSB     ----            Motor Speed LSB (-1000 to +1000)
      39             :     byte 7      CRC-Maxim           ----            CRC-Maxim value
      40             :     byte 8      Footer              0xAD
      41             : 
      42             :    More details of the TQ Bus protocol are available from Torqeedo after signing an NDA.
      43             :  */
      44             : 
      45             : #pragma once
      46             : 
      47             : #include "AP_Torqeedo_config.h"
      48             : 
      49             : #if HAL_TORQEEDO_ENABLED
      50             : 
      51             : #include "AP_Torqeedo.h"
      52             : #include <AP_ESC_Telem/AP_ESC_Telem_Backend.h>
      53             : 
      54             : class AP_Torqeedo_Backend : public AP_ESC_Telem_Backend {
      55             : public:
      56             :     AP_Torqeedo_Backend(AP_Torqeedo_Params &params, uint8_t instance);
      57             : 
      58             :     // do not allow copies
      59             :     CLASS_NO_COPY(AP_Torqeedo_Backend);
      60             : 
      61             :     // initialise driver
      62             :     virtual void init() = 0;
      63             : 
      64             :     // returns true if communicating with the motor
      65             :     virtual bool healthy() = 0;
      66             : 
      67             :     // clear motor errors
      68             :     virtual void clear_motor_error() = 0;
      69             : 
      70             :     // get latest battery status info.  returns true on success and populates arguments
      71             :     virtual bool get_batt_info(float &voltage, float &current_amps, float &temp_C, uint8_t &pct_remaining) const WARN_IF_UNUSED = 0;
      72             :     virtual bool get_batt_capacity_Ah(uint16_t &amp_hours) const = 0;
      73             : 
      74             :    protected:
      75             : 
      76             :     // parameter helper functions
      77           0 :     AP_Torqeedo::ConnectionType get_type() const { return (AP_Torqeedo::ConnectionType)_params.type.get(); }
      78           0 :     bool option_enabled(AP_Torqeedo::options opt) const { return ((uint16_t)_params.options.get() & (uint16_t)opt) != 0; }
      79             : 
      80             :     AP_Torqeedo_Params &_params;    // parameters for this backend
      81             :     uint8_t _instance;              // this instance's number
      82             : };
      83             : 
      84             : #endif // HAL_TORQEEDO_ENABLED

Generated by: LCOV version 1.14