Skip to content

Commit 6529826

Browse files
committed
75/300 R2 support, terminal sync cmd, IMU support, option to disable permanent UART, collected timer functions in one place
1 parent 0db2f20 commit 6529826

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2341
-94
lines changed

CHANGELOG

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
=== FW 3.52 ===
2+
* Added support for second revision of HW75/300 with separate UART for NRF51.
3+
* Added COMM_TERMINAL_CMD_SYNC, which does not drop commands when busy.
4+
* Added option to disable permanent UART.
5+
* Moved TIM5 to own file, and use it from other places.
6+
* Removed need for TIM2 in mcpwm.
7+
* Added utilization percentage to threads terminal command.
8+
* Added IMU interface.
9+
* Added support for the MPU9150 and MPU9250.
10+
* Added COMM_GET_IMU_DATA.
11+
112
=== FW 3.51 ===
213
* Fixed AS5047 error rate bug at position 0.
314
* Increased threshold for AS5047 fault to 5 %.

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ include hwconf/hwconf.mk
108108
include applications/applications.mk
109109
include nrf/nrf.mk
110110
include libcanard/canard.mk
111+
include imu/imu.mk
111112

112113
# Define linker script file here
113114
LDSCRIPT= ld_eeprom_emu.ld
@@ -150,10 +151,13 @@ CSRC = $(STARTUPSRC) \
150151
mcpwm_foc.c \
151152
gpdrive.c \
152153
confgenerator.c \
154+
timer.c \
155+
i2c_bb.c \
153156
$(HWSRC) \
154157
$(APPSRC) \
155158
$(NRFSRC) \
156-
$(CANARDSRC)
159+
$(CANARDSRC) \
160+
$(IMUSRC)
157161

158162
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
159163
# setting.
@@ -191,7 +195,8 @@ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
191195
$(HWINC) \
192196
$(APPINC) \
193197
$(NRFINC) \
194-
$(CANARDINC)
198+
$(CANARDINC) \
199+
$(IMUINC)
195200

196201
#
197202
# Project, sources and paths

appconf/appconf_default.h

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#ifndef APPCONF_PAIRING_DONE
4949
#define APPCONF_PAIRING_DONE false
5050
#endif
51+
#ifndef APPCONF_PERMANENT_UART_ENABLED
52+
#define APPCONF_PERMANENT_UART_ENABLED true
53+
#endif
5154

5255
// The default app is UART in case the UART port is used for
5356
// firmware updates.

applications/app.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void app_set_configuration(app_configuration *conf) {
114114

115115
app_ppm_configure(&appconf.app_ppm_conf);
116116
app_adc_configure(&appconf.app_adc_conf);
117-
app_uartcomm_configure(appconf.app_uart_baudrate);
117+
app_uartcomm_configure(appconf.app_uart_baudrate, appconf.permanent_uart_enabled);
118118
app_nunchuk_configure(&appconf.app_chuk_conf);
119119

120120
#ifdef APP_CUSTOM_TO_USE

applications/app.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ float app_adc_get_voltage2(void);
4545
void app_uartcomm_start(void);
4646
void app_uartcomm_start_permanent(void);
4747
void app_uartcomm_stop(void);
48-
void app_uartcomm_configure(uint32_t baudrate);
48+
void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled);
4949
void app_uartcomm_send_packet(unsigned char *data, unsigned int len);
5050

5151
void app_nunchuk_start(void);

applications/app_uartcomm.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,29 @@ void app_uartcomm_send_packet(unsigned char *data, unsigned int len) {
148148
chMtxUnlock(&send_mutex);
149149
}
150150

151-
void app_uartcomm_configure(uint32_t baudrate) {
151+
void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled) {
152152
uart_cfg.speed = baudrate;
153153

154154
if (thread_is_running) {
155155
sdStart(&HW_UART_DEV, &uart_cfg);
156156
uart_is_running = true;
157157
}
158+
159+
#ifdef HW_UART_P_DEV
160+
if (permanent_enabled) {
161+
palSetPadMode(HW_UART_P_TX_PORT, HW_UART_P_TX_PIN, PAL_MODE_ALTERNATE(HW_UART_P_GPIO_AF) |
162+
PAL_STM32_OSPEED_HIGHEST |
163+
PAL_STM32_PUDR_PULLUP);
164+
palSetPadMode(HW_UART_P_RX_PORT, HW_UART_P_RX_PIN, PAL_MODE_ALTERNATE(HW_UART_P_GPIO_AF) |
165+
PAL_STM32_OSPEED_HIGHEST |
166+
PAL_STM32_PUDR_PULLUP);
167+
} else {
168+
palSetPadMode(HW_UART_P_TX_PORT, HW_UART_P_TX_PIN, PAL_MODE_INPUT);
169+
palSetPadMode(HW_UART_P_RX_PORT, HW_UART_P_RX_PIN, PAL_MODE_INPUT);
170+
}
171+
#else
172+
(void)permanent_enabled;
173+
#endif
158174
}
159175

160176
static THD_FUNCTION(packet_process_thread, arg) {
1.23 KB
Binary file not shown.
1.23 KB
Binary file not shown.
Binary file not shown.
1.25 KB
Binary file not shown.
1.25 KB
Binary file not shown.

build_all/46_o_47/VESC_0005ohm.bin

1.27 KB
Binary file not shown.

build_all/46_o_47/VESC_33k.bin

1.23 KB
Binary file not shown.

build_all/46_o_47/VESC_default.bin

1.27 KB
Binary file not shown.

build_all/46_o_47/VESC_servoout.bin

1.28 KB
Binary file not shown.

build_all/46_o_47/VESC_ws2811.bin

1.25 KB
Binary file not shown.

build_all/46_o_47/VESC_ws2811_33k.bin

1.22 KB
Binary file not shown.

build_all/48/VESC_0005ohm.bin

1.25 KB
Binary file not shown.

build_all/48/VESC_default.bin

1.25 KB
Binary file not shown.

build_all/48/VESC_servoout.bin

1.27 KB
Binary file not shown.

build_all/48/VESC_ws2811.bin

1.23 KB
Binary file not shown.

build_all/60/VESC_default.bin

5.24 KB
Binary file not shown.
5.24 KB
Binary file not shown.

build_all/60/VESC_servoout.bin

5.26 KB
Binary file not shown.

build_all/60/VESC_ws2811.bin

5.23 KB
Binary file not shown.

build_all/75_300/VESC_default.bin

1.31 KB
Binary file not shown.
1.31 KB
Binary file not shown.

build_all/75_300/VESC_servoout.bin

1.34 KB
Binary file not shown.

build_all/75_300/VESC_ws2811.bin

1.33 KB
Binary file not shown.

build_all/DAS_RS/VESC_default.bin

1.36 KB
Binary file not shown.

build_all/PALTA/VESC_default.bin

1.28 KB
Binary file not shown.

build_all/rebuild_all

+38
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,44 @@ cd $FWPATH
217217
make clean
218218
cd $DIR
219219

220+
#################### HW 75_300_R2 ########################
221+
222+
COPYDIR=75_300_R2
223+
rm -f $COPYDIR/*
224+
225+
# default
226+
cd $FWPATH
227+
touch conf_general.h
228+
make -j8 build_args='-DHW_SOURCE=\"hw_75_300.c\" -DHW_HEADER=\"hw_75_300.h\" -DHW75_300_REV_2'
229+
cd $DIR
230+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin
231+
232+
# default with HW limits disables
233+
cd $FWPATH
234+
touch conf_general.h
235+
make -j8 build_args='-DDISABLE_HW_LIMITS -DHW_SOURCE=\"hw_75_300.c\" -DHW_HEADER=\"hw_75_300.h\" -DHW75_300_REV_2'
236+
cd $DIR
237+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default_no_hw_limits.bin
238+
239+
# ws2811
240+
cd $FWPATH
241+
touch conf_general.h
242+
make -j8 build_args='-DWS2811_ENABLE=1 -DHW_SOURCE=\"hw_75_300.c\" -DHW_HEADER=\"hw_75_300.h\" -DHW75_300_REV_2'
243+
cd $DIR
244+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811.bin
245+
246+
# servoout
247+
cd $FWPATH
248+
touch conf_general.h
249+
make -j8 build_args='-DSERVO_OUT_ENABLE=1 -DHW_SOURCE=\"hw_75_300.c\" -DHW_HEADER=\"hw_75_300.h\" -DHW75_300_REV_2'
250+
cd $DIR
251+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin
252+
253+
# Clean
254+
cd $FWPATH
255+
make clean
256+
cd $DIR
257+
220258
#################### HW PALTA ########################
221259

222260
COPYDIR=PALTA

commands.c

+85
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "nrf_driver.h"
4141
#include "gpdrive.h"
4242
#include "confgenerator.h"
43+
#include "imu.h"
4344

4445
#include <math.h>
4546
#include <string.h>
@@ -63,10 +64,12 @@ static void(* volatile appdata_func)(unsigned char *data, unsigned int len) = 0;
6364
static disp_pos_mode display_position_mode;
6465
static mutex_t print_mutex;
6566
static mutex_t send_buffer_mutex;
67+
static mutex_t terminal_mutex;
6668

6769
void commands_init(void) {
6870
chMtxObjectInit(&print_mutex);
6971
chMtxObjectInit(&send_buffer_mutex);
72+
chMtxObjectInit(&terminal_mutex);
7073
chThdCreateStatic(blocking_thread_wa, sizeof(blocking_thread_wa), NORMALPRIO, blocking_thread, NULL);
7174
}
7275

@@ -838,6 +841,86 @@ void commands_process_packet(unsigned char *data, unsigned int len,
838841
}
839842
} break;
840843

844+
case COMM_TERMINAL_CMD_SYNC:
845+
data[len] = '\0';
846+
chMtxLock(&terminal_mutex);
847+
terminal_process_string((char*)data);
848+
chMtxUnlock(&terminal_mutex);
849+
break;
850+
851+
case COMM_GET_IMU_DATA: {
852+
int32_t ind = 0;
853+
uint8_t send_buffer[70];
854+
send_buffer[ind++] = packet_id;
855+
856+
int32_t ind2 = 0;
857+
uint32_t mask = buffer_get_uint16(data, &ind2);
858+
859+
float rpy[3], acc[3], gyro[3], mag[3], q[4];
860+
imu_get_rpy(rpy);
861+
imu_get_accel(acc);
862+
imu_get_gyro(gyro);
863+
imu_get_mag(mag);
864+
imu_get_quaternions(q);
865+
866+
buffer_append_uint16(send_buffer, mask, &ind);
867+
868+
if (mask & ((uint32_t)1 << 0)) {
869+
buffer_append_float32_auto(send_buffer, rpy[0], &ind);
870+
}
871+
if (mask & ((uint32_t)1 << 1)) {
872+
buffer_append_float32_auto(send_buffer, rpy[1], &ind);
873+
}
874+
if (mask & ((uint32_t)1 << 2)) {
875+
buffer_append_float32_auto(send_buffer, rpy[2], &ind);
876+
}
877+
878+
if (mask & ((uint32_t)1 << 3)) {
879+
buffer_append_float32_auto(send_buffer, acc[0], &ind);
880+
}
881+
if (mask & ((uint32_t)1 << 4)) {
882+
buffer_append_float32_auto(send_buffer, acc[1], &ind);
883+
}
884+
if (mask & ((uint32_t)1 << 5)) {
885+
buffer_append_float32_auto(send_buffer, acc[2], &ind);
886+
}
887+
888+
if (mask & ((uint32_t)1 << 6)) {
889+
buffer_append_float32_auto(send_buffer, gyro[0], &ind);
890+
}
891+
if (mask & ((uint32_t)1 << 7)) {
892+
buffer_append_float32_auto(send_buffer, gyro[1], &ind);
893+
}
894+
if (mask & ((uint32_t)1 << 8)) {
895+
buffer_append_float32_auto(send_buffer, gyro[2], &ind);
896+
}
897+
898+
if (mask & ((uint32_t)1 << 9)) {
899+
buffer_append_float32_auto(send_buffer, mag[0], &ind);
900+
}
901+
if (mask & ((uint32_t)1 << 10)) {
902+
buffer_append_float32_auto(send_buffer, mag[1], &ind);
903+
}
904+
if (mask & ((uint32_t)1 << 11)) {
905+
buffer_append_float32_auto(send_buffer, mag[2], &ind);
906+
}
907+
908+
if (mask & ((uint32_t)1 << 12)) {
909+
buffer_append_float32_auto(send_buffer, q[0], &ind);
910+
}
911+
if (mask & ((uint32_t)1 << 13)) {
912+
buffer_append_float32_auto(send_buffer, q[1], &ind);
913+
}
914+
if (mask & ((uint32_t)1 << 14)) {
915+
buffer_append_float32_auto(send_buffer, q[2], &ind);
916+
}
917+
if (mask & ((uint32_t)1 << 15)) {
918+
buffer_append_float32_auto(send_buffer, q[3], &ind);
919+
}
920+
921+
reply_func(send_buffer, ind);
922+
} break;
923+
841924
// Blocking commands. Only one of them runs at any given time, in their
842925
// own thread. If other blocking commands come before the previous one has
843926
// finished, they are discarded.
@@ -1222,7 +1305,9 @@ static THD_FUNCTION(blocking_thread, arg) {
12221305

12231306
case COMM_TERMINAL_CMD:
12241307
data[len] = '\0';
1308+
chMtxLock(&terminal_mutex);
12251309
terminal_process_string((char*)data);
1310+
chMtxUnlock(&terminal_mutex);
12261311
break;
12271312

12281313
case COMM_PING_CAN: {

conf_general.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
// Firmware version
2424
#define FW_VERSION_MAJOR 3
25-
#define FW_VERSION_MINOR 51
25+
#define FW_VERSION_MINOR 52
2626

2727
#include "datatypes.h"
2828

@@ -41,12 +41,6 @@
4141
// Disable hardware limits on configuration parameters
4242
//#define DISABLE_HW_LIMITS
4343

44-
// Benjamins first HW60 PCB with PB5 and PB6 swapped
45-
//#define HW60_VEDDER_FIRST_PCB
46-
47-
// Benjamins first HW75_300 PCB with different LED pins and motor temp error
48-
//#define HW75_300_VEDDER_FIRST_PCB
49-
5044
/*
5145
* Select only one hardware version, if it is not passed
5246
* as an argument.
@@ -70,6 +64,9 @@
7064
//#define HW_SOURCE "hw_410.c" // Also for 4.11 and 4.12
7165
//#define HW_HEADER "hw_410.h" // Also for 4.11 and 4.12
7266

67+
// Benjamins first HW60 PCB with PB5 and PB6 swapped
68+
//#define HW60_VEDDER_FIRST_PCB
69+
7370
#define HW_SOURCE "hw_60.c"
7471
#define HW_HEADER "hw_60.h"
7572

@@ -91,6 +88,12 @@
9188
//#define HW_SOURCE "hw_tp.c"
9289
//#define HW_HEADER "hw_tp.h"
9390

91+
// Benjamins first HW75_300 PCB with different LED pins and motor temp error
92+
//#define HW75_300_VEDDER_FIRST_PCB
93+
94+
// Second revision with separate UART for NRF51
95+
//#define HW75_300_REV_2
96+
9497
//#define HW_SOURCE "hw_75_300.c"
9598
//#define HW_HEADER "hw_75_300.h"
9699

confgenerator.c

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ int32_t confgenerator_serialize_appconf(uint8_t *buffer, const app_configuration
147147
buffer_append_uint16(buffer, conf->send_can_status_rate_hz, &ind);
148148
buffer[ind++] = conf->can_baud_rate;
149149
buffer[ind++] = conf->pairing_done;
150+
buffer[ind++] = conf->permanent_uart_enabled;
150151
buffer[ind++] = conf->uavcan_enable;
151152
buffer[ind++] = (uint8_t)conf->uavcan_esc_index;
152153
buffer[ind++] = conf->app_to_use;
@@ -363,6 +364,7 @@ bool confgenerator_deserialize_appconf(const uint8_t *buffer, app_configuration
363364
conf->send_can_status_rate_hz = buffer_get_uint16(buffer, &ind);
364365
conf->can_baud_rate = buffer[ind++];
365366
conf->pairing_done = buffer[ind++];
367+
conf->permanent_uart_enabled = buffer[ind++];
366368
conf->uavcan_enable = buffer[ind++];
367369
conf->uavcan_esc_index = buffer[ind++];
368370
conf->app_to_use = buffer[ind++];
@@ -563,6 +565,7 @@ void confgenerator_set_defaults_appconf(app_configuration *conf) {
563565
conf->send_can_status_rate_hz = APPCONF_SEND_CAN_STATUS_RATE_HZ;
564566
conf->can_baud_rate = APPCONF_CAN_BAUD_RATE;
565567
conf->pairing_done = APPCONF_PAIRING_DONE;
568+
conf->permanent_uart_enabled = APPCONF_PERMANENT_UART_ENABLED;
566569
conf->uavcan_enable = APPCONF_UAVCAN_ENABLE;
567570
conf->uavcan_esc_index = APPCONF_UAVCAN_ESC_INDEX;
568571
conf->app_to_use = APPCONF_APP_TO_USE;

confgenerator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// Constants
1111
#define MCCONF_SIGNATURE 1753222668
12-
#define APPCONF_SIGNATURE 3794395266
12+
#define APPCONF_SIGNATURE 1146628643
1313

1414
// Functions
1515
int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *conf);

datatypes.h

+18-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ typedef struct {
129129
float comm_time_sum;
130130
float comm_time_sum_min_rpm;
131131
int32_t comms;
132-
uint32_t time_at_comm;
132+
float time_at_comm;
133133
} mc_rpm_dep_struct;
134134

135135
typedef enum {
@@ -482,6 +482,7 @@ typedef struct {
482482
uint32_t send_can_status_rate_hz;
483483
CAN_BAUD can_baud_rate;
484484
bool pairing_done;
485+
bool permanent_uart_enabled;
485486

486487
// UAVCAN
487488
bool uavcan_enable;
@@ -571,7 +572,9 @@ typedef enum {
571572
COMM_ERASE_NEW_APP_ALL_CAN,
572573
COMM_WRITE_NEW_APP_DATA_ALL_CAN,
573574
COMM_PING_CAN,
574-
COMM_APP_DISABLE_OUTPUT
575+
COMM_APP_DISABLE_OUTPUT,
576+
COMM_TERMINAL_CMD_SYNC,
577+
COMM_GET_IMU_DATA
575578
} COMM_PACKET_ID;
576579

577580
// CAN commands
@@ -729,4 +732,17 @@ typedef enum {
729732
NRF_PAIR_FAIL
730733
} NRF_PAIR_RES;
731734

735+
// Orientation data
736+
typedef struct {
737+
float q0;
738+
float q1;
739+
float q2;
740+
float q3;
741+
float integralFBx;
742+
float integralFBy;
743+
float integralFBz;
744+
float accMagP;
745+
int initialUpdateDone;
746+
} ATTITUDE_INFO;
747+
732748
#endif /* DATATYPES_H_ */

0 commit comments

Comments
 (0)