PX4 Firmware
PX4 Autopilot Software http://px4.io
drv_tap_esc.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2016 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #pragma once
35 
36 #include <board_config.h>
37 
38 #include <stdint.h>
39 
40 #define TAP_ESC_DEVICE_PATH "/dev/tap_esc"
41 
42 /* At the moment the only known use is with a current sensor */
43 #define ESC_HAVE_CURRENT_SENSOR
44 
45 #define TAP_ESC_MAX_PACKET_LEN 20
46 #define TAP_ESC_MAX_MOTOR_NUM 8
47 
48 #define PACKET_HEAD 0xfe
49 
50 /* ESC_POS maps the values stored in the channelMapTable to reorder the ESC's
51  * id so that that match the mux setting, so that the ressonder's data
52  * will be read.
53  * The index on channelMapTable[p] p is the physical ESC
54  * The value it is set to is the logical value from ESC_POS[p]
55  * Phy Log
56  * 0 0
57  * 1 1
58  * 2 4
59  * 3 3
60  * 4 2
61  * 5 5
62  * ....
63  *
64  */
65 
66 // Circular from back right in CCW direction
67 #define ESC_POS {0, 1, 4, 3, 2, 5, 7, 8}
68 // 0 is CW, 1 is CCW
69 #define ESC_DIR {0, 1, 0, 1, 0, 1, 0, 1}
70 
71 #define RPMMAX 1900
72 #define RPMMIN 1200
73 #define RPMSTOPPED (RPMMIN - 10)
74 
75 
76 #define MAX_BOOT_TIME_MS (550) // Minimum time to wait after Power on before sending commands
77 
78 #pragma pack(push,1)
79 
80 /****** Run ***********/
81 
82 #define RUN_CHANNEL_VALUE_MASK (uint16_t)0x07ff
83 #define RUN_RED_LED_ON_MASK (uint16_t)0x0800
84 #define RUN_GREEN_LED_ON_MASK (uint16_t)0x1000
85 #define RUN_BLUE_LED_ON_MASK (uint16_t)0x2000
86 #define RUN_LED_ON_MASK (uint16_t)0x3800
87 #define RUN_FEEDBACK_ENABLE_MASK (uint16_t)0x4000
88 #define RUN_REVERSE_MASK (uint16_t)0x8000
89 
90 typedef struct {
91 
92  uint16_t rpm_flags[TAP_ESC_MAX_MOTOR_NUM];
93 } RunReq;
94 
95 typedef struct {
96  uint8_t channelID;
97  uint8_t ESCStatus;
98  int16_t speed; // -32767 - 32768
99 #if defined(ESC_HAVE_VOLTAGE_SENSOR)
100  uint16_t voltage; // 0.00 - 100.00 V
101 #endif
102 #if defined(ESC_HAVE_CURRENT_SENSOR)
103  uint16_t current; // 0.0 - 200.0 A
104 #endif
105 #if defined(ESC_HAVE_TEMPERATURE_SENSOR)
106  uint8_t temperature; // 0 - 256 degree celsius
107 #endif
109 /****** Run ***********/
110 
111 /****** ConFigInfoBasic ***********/
112 typedef struct {
114  uint8_t channelMapTable[TAP_ESC_MAX_MOTOR_NUM];
115  uint8_t monitorMsgType;
116  uint8_t controlMode;
117  uint16_t minChannelValue;
118  uint16_t maxChannelValue;
120 
121 typedef struct {
122  uint8_t channelID;
125 
126 #define ESC_MASK_MAP_CHANNEL 0x0f
127 #define ESC_MASK_MAP_RUNNING_DIRECTION 0xf0
128 /****** ConFigInfoBasicResponse ***********/
129 
130 /****** InfoRequest ***********/
131 typedef enum {
138 } InfoTypes;
139 
140 typedef struct {
141  uint8_t channelID;
143 } InfoRequest;
144 
145 /****** InfoRequest ***********/
146 
147 typedef struct {
148  uint8_t head;
149  uint8_t len;
150  uint8_t msg_id;
151  union {
157  uint8_t bytes[100];
158  } d;
159  uint8_t crc_data;
160 
161 } EscPacket;
162 
163 #define UART_BUFFER_SIZE 128
164 typedef struct {
165  uint8_t head;
166  uint8_t tail;
167  uint8_t dat_cnt;
168  uint8_t esc_feedback_buf[UART_BUFFER_SIZE];
169 } ESC_UART_BUF;
170 
171 #pragma pack(pop)
172 /******************************************************************************************
173  * ESCBUS_MSG_ID_RUN_INFO packet
174  *
175  * Monitor message of ESCs while motor is running
176  *
177  * channelID: assigned channel number
178  *
179  * ESCStatus: status of ESC
180  * Num Health status
181  * 0 HEALTHY
182  * 1 WARNING_LOW_VOLTAGE
183  * 2 WARNING_OVER_CURRENT
184  * 3 WARNING_OVER_HEAT
185  * 4 ERROR_MOTOR_LOW_SPEED_LOSE_STEP
186  * 5 ERROR_MOTOR_STALL
187  * 6 ERROR_HARDWARE
188  * 7 ERROR_LOSE_PROPELLER
189  * 8 ERROR_OVER_CURRENT
190  *
191  * speed: -32767 - 32767 rpm
192  *
193  * temperature: 0 - 256 celsius degree (if available)
194  * voltage: 0.00 - 100.00 V (if available)
195  * current: 0.0 - 200.0 A (if available)
196  */
197 
198 typedef enum {
210 
211 
212 typedef enum {
213 // messages or command to ESC
219 // messages from ESC
221  ESCBUS_MSG_ID_CONFIG_INFO_BASIC, // simple configuration info for request from flight controller
222  ESCBUS_MSG_ID_CONFIG_INFO_FULL,// full configuration info for request from host such as computer
223  ESCBUS_MSG_ID_RUN_INFO,// feedback message in RUN mode
224  ESCBUS_MSG_ID_STUDY_INFO, // studied parameters in STUDY mode
225  ESCBUS_MSG_ID_COMM_INFO, // communication method info
226  ESCBUS_MSG_ID_DEVICE_INFO,// ESC device info
227  ESCBUS_MSG_ID_ASSIGNED_ID, // never touch ESCBUS_MSG_ID_MAX_NUM
228  //boot loader used
229  PROTO_OK = 0x10, // INSYNC/OK - 'ok' response
230  PROTO_FAILED = 0x11, // INSYNC/FAILED - 'fail' response
231 
232  ESCBUS_MSG_ID_BOOT_SYNC = 0x21, // boot loader used
233  PROTO_GET_DEVICE = 0x22, // get device ID bytes
234  PROTO_CHIP_ERASE = 0x23, // erase program area and reset program address
235  PROTO_PROG_MULTI = 0x27, // write bytes at program address and increment
236  PROTO_GET_CRC = 0x29, // compute & return a CRC
237  PROTO_BOOT = 0x30, // boot the application
240 }
242 
243 typedef enum {
246  ID,
249 
ESCBUS_ENUM_ESC_STATUS
Definition: drv_tap_esc.h:198
RunInfoRepsonse rspRunInfo
Definition: drv_tap_esc.h:156
InfoRequest reqInfo
Definition: drv_tap_esc.h:152
uint8_t ESCStatus
Definition: drv_tap_esc.h:97
InfoTypes
Definition: drv_tap_esc.h:131
uint8_t requestInfoType
Definition: drv_tap_esc.h:142
ESCBUS_ENUM_MESSAGE_ID
Definition: drv_tap_esc.h:212
uint8_t tail
Definition: drv_tap_esc.h:166
#define UART_BUFFER_SIZE
Definition: drv_tap_esc.h:163
RunReq reqRun
Definition: drv_tap_esc.h:154
ConfigInfoBasicResponse rspConfigInfoBasic
Definition: drv_tap_esc.h:155
uint8_t msg_id
Definition: drv_tap_esc.h:150
ConfigInfoBasicRequest resp
Definition: drv_tap_esc.h:123
uint8_t head
Definition: drv_tap_esc.h:148
uint8_t len
Definition: drv_tap_esc.h:149
uint8_t crc_data
Definition: drv_tap_esc.h:159
uint16_t current
Definition: drv_tap_esc.h:103
ConfigInfoBasicRequest reqConfigInfoBasic
Definition: drv_tap_esc.h:153
uint8_t head
Definition: drv_tap_esc.h:165
uint8_t channelID
Definition: drv_tap_esc.h:96
PARSR_ESC_STATE
Definition: drv_tap_esc.h:243
#define TAP_ESC_MAX_MOTOR_NUM
Definition: drv_tap_esc.h:46
uint8_t channelID
Definition: drv_tap_esc.h:141
uint8_t dat_cnt
Definition: drv_tap_esc.h:167